@shopkit/data-layer 1.0.0 → 1.2.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/README.md +67 -7
- package/dist/adapters/index.d.mts +2 -1
- package/dist/adapters/index.d.ts +2 -1
- package/dist/adapters/index.js +221 -64
- package/dist/adapters/index.js.map +1 -1
- package/dist/adapters/index.mjs +221 -64
- package/dist/adapters/index.mjs.map +1 -1
- package/dist/index.d.mts +65 -11
- package/dist/index.d.ts +65 -11
- package/dist/index.js +357 -65
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +354 -66
- package/dist/index.mjs.map +1 -1
- package/dist/interface-NJcjuqaL.d.mts +236 -0
- package/dist/interface-dqoKc63z.d.ts +236 -0
- package/dist/models/index.d.mts +45 -62
- package/dist/models/index.d.ts +45 -62
- package/dist/{service-NPmqCNGb.d.mts → service-BHCLUEim.d.ts} +38 -279
- package/dist/{service-Q7zlmyFk.d.ts → service-DBKEK2oS.d.mts} +38 -279
- package/dist/static-params/index.d.mts +65 -0
- package/dist/static-params/index.d.ts +65 -0
- package/dist/static-params/index.js +275 -0
- package/dist/static-params/index.js.map +1 -0
- package/dist/static-params/index.mjs +270 -0
- package/dist/static-params/index.mjs.map +1 -0
- package/package.json +6 -1
package/dist/index.mjs
CHANGED
|
@@ -782,7 +782,7 @@ function createLogger(config = {}) {
|
|
|
782
782
|
}
|
|
783
783
|
return new UniversalLogger(fullConfig);
|
|
784
784
|
}
|
|
785
|
-
createLogger({
|
|
785
|
+
var logger = createLogger({
|
|
786
786
|
enabled: false,
|
|
787
787
|
level: "info",
|
|
788
788
|
prettyPrint: false
|
|
@@ -848,14 +848,25 @@ var BaseCommerceClient = class {
|
|
|
848
848
|
}
|
|
849
849
|
/**
|
|
850
850
|
* Retrieve multiple products by their handles
|
|
851
|
-
* @param
|
|
851
|
+
* @param params - Object containing array of product handles
|
|
852
852
|
* @param options - Request options (headers, timeout, etc.)
|
|
853
853
|
* @returns Promise resolving to array of products
|
|
854
854
|
* @throws NotImplementedError if not implemented in adapter
|
|
855
855
|
*/
|
|
856
|
-
getProductsByHandles(
|
|
856
|
+
getProductsByHandles(params, options) {
|
|
857
857
|
this.throwNotImplemented("getProductsByHandles");
|
|
858
858
|
}
|
|
859
|
+
/**
|
|
860
|
+
* Retrieve product recommendations for a given product
|
|
861
|
+
* Uses platform-specific recommendation algorithms (e.g., Shopify's productRecommendations)
|
|
862
|
+
* @param productId - Product ID or handle to get recommendations for
|
|
863
|
+
* @param options - Request options (headers, timeout, etc.)
|
|
864
|
+
* @returns Promise resolving to array of recommended products
|
|
865
|
+
* @throws NotImplementedError if not implemented in adapter
|
|
866
|
+
*/
|
|
867
|
+
getProductRecommendations(params, options) {
|
|
868
|
+
this.throwNotImplemented("getProductRecommendations");
|
|
869
|
+
}
|
|
859
870
|
// ========================================
|
|
860
871
|
// COLLECTION OPERATIONS
|
|
861
872
|
// ========================================
|
|
@@ -897,8 +908,8 @@ var BaseCommerceClient = class {
|
|
|
897
908
|
* @returns Promise resolving to collections data with individual query results
|
|
898
909
|
* @throws NotImplementedError if not implemented in adapter
|
|
899
910
|
*/
|
|
900
|
-
|
|
901
|
-
this.throwNotImplemented("
|
|
911
|
+
getCollectionsByHandles(params, options) {
|
|
912
|
+
this.throwNotImplemented("getCollectionsByHandles");
|
|
902
913
|
}
|
|
903
914
|
/**
|
|
904
915
|
* Retrieve available filters for collections
|
|
@@ -935,12 +946,12 @@ var BaseCommerceClient = class {
|
|
|
935
946
|
}
|
|
936
947
|
/**
|
|
937
948
|
* Create a new order
|
|
938
|
-
* @param
|
|
949
|
+
* @param params - Order data to create
|
|
939
950
|
* @param options - Request options (headers, timeout, etc.)
|
|
940
951
|
* @returns Promise resolving to created order
|
|
941
952
|
* @throws NotImplementedError if not implemented in adapter
|
|
942
953
|
*/
|
|
943
|
-
createOrder(
|
|
954
|
+
createOrder(params, options) {
|
|
944
955
|
this.throwNotImplemented("createOrder");
|
|
945
956
|
}
|
|
946
957
|
/**
|
|
@@ -998,12 +1009,12 @@ var BaseCommerceClient = class {
|
|
|
998
1009
|
}
|
|
999
1010
|
/**
|
|
1000
1011
|
* Create a new customer account
|
|
1001
|
-
* @param
|
|
1012
|
+
* @param params - Customer data to create
|
|
1002
1013
|
* @param options - Request options (headers, timeout, etc.)
|
|
1003
1014
|
* @returns Promise resolving to created customer
|
|
1004
1015
|
* @throws NotImplementedError if not implemented in adapter
|
|
1005
1016
|
*/
|
|
1006
|
-
createCustomer(
|
|
1017
|
+
createCustomer(params, options) {
|
|
1007
1018
|
this.throwNotImplemented("createCustomer");
|
|
1008
1019
|
}
|
|
1009
1020
|
/**
|
|
@@ -1081,28 +1092,6 @@ var BaseCommerceClient = class {
|
|
|
1081
1092
|
createCheckout(params, options) {
|
|
1082
1093
|
this.throwNotImplemented("createCheckout");
|
|
1083
1094
|
}
|
|
1084
|
-
/**
|
|
1085
|
-
* Update an existing checkout session
|
|
1086
|
-
* @param id - Checkout identifier
|
|
1087
|
-
* @param data - Checkout update data
|
|
1088
|
-
* @param options - Request options (headers, timeout, etc.)
|
|
1089
|
-
* @returns Promise resolving to updated checkout
|
|
1090
|
-
* @throws NotImplementedError if not implemented in adapter
|
|
1091
|
-
*/
|
|
1092
|
-
updateCheckout(id, data, options) {
|
|
1093
|
-
this.throwNotImplemented("updateCheckout");
|
|
1094
|
-
}
|
|
1095
|
-
/**
|
|
1096
|
-
* Complete a checkout and create an order
|
|
1097
|
-
* @param id - Checkout identifier
|
|
1098
|
-
* @param paymentData - Payment information
|
|
1099
|
-
* @param options - Request options (headers, timeout, etc.)
|
|
1100
|
-
* @returns Promise resolving to created order
|
|
1101
|
-
* @throws NotImplementedError if not implemented in adapter
|
|
1102
|
-
*/
|
|
1103
|
-
completeCheckout(id, paymentData, options) {
|
|
1104
|
-
this.throwNotImplemented("completeCheckout");
|
|
1105
|
-
}
|
|
1106
1095
|
// ========================================
|
|
1107
1096
|
// ARTICLE/BLOG OPERATIONS
|
|
1108
1097
|
// ========================================
|
|
@@ -1151,22 +1140,21 @@ var BaseCommerceClient = class {
|
|
|
1151
1140
|
// ========================================
|
|
1152
1141
|
/**
|
|
1153
1142
|
* Utility method to make GraphQL requests
|
|
1154
|
-
* @param
|
|
1155
|
-
* @param variables - GraphQL variables
|
|
1143
|
+
* @param params - Object containing query string and optional variables
|
|
1156
1144
|
* @returns Promise resolving to standardized response
|
|
1157
1145
|
* @throws NotImplementedError if not implemented in adapter
|
|
1158
1146
|
*/
|
|
1159
|
-
graphqlRequest(
|
|
1147
|
+
graphqlRequest(params) {
|
|
1160
1148
|
this.throwNotImplemented("graphqlRequest");
|
|
1161
1149
|
}
|
|
1162
1150
|
/**
|
|
1163
1151
|
* Utility method to make custom fetch requests to any endpoint
|
|
1164
|
-
* @param
|
|
1165
|
-
* @param options - Request options
|
|
1152
|
+
* @param params - Object containing url and optional fetch options
|
|
1166
1153
|
* @returns Promise resolving to standardized response
|
|
1167
1154
|
*/
|
|
1168
|
-
async fetchRequest(
|
|
1155
|
+
async fetchRequest(params) {
|
|
1169
1156
|
try {
|
|
1157
|
+
const { url, ...fetchOptions } = params;
|
|
1170
1158
|
const response = await fetch(url, fetchOptions);
|
|
1171
1159
|
const data = await response.json();
|
|
1172
1160
|
if (response.ok) {
|
|
@@ -1624,6 +1612,92 @@ var GET_COLLECTION = `
|
|
|
1624
1612
|
}
|
|
1625
1613
|
}
|
|
1626
1614
|
`;
|
|
1615
|
+
var GET_PRODUCT_RECOMMENDATIONS = `
|
|
1616
|
+
query GetProductRecommendations($productId: ID!) {
|
|
1617
|
+
productRecommendations(productId: $productId) {
|
|
1618
|
+
id
|
|
1619
|
+
title
|
|
1620
|
+
description
|
|
1621
|
+
handle
|
|
1622
|
+
productType
|
|
1623
|
+
vendor
|
|
1624
|
+
tags
|
|
1625
|
+
availableForSale
|
|
1626
|
+
options {
|
|
1627
|
+
id
|
|
1628
|
+
name
|
|
1629
|
+
values
|
|
1630
|
+
}
|
|
1631
|
+
variants(first: 10) {
|
|
1632
|
+
nodes {
|
|
1633
|
+
id
|
|
1634
|
+
title
|
|
1635
|
+
sku
|
|
1636
|
+
availableForSale
|
|
1637
|
+
selectedOptions {
|
|
1638
|
+
name
|
|
1639
|
+
value
|
|
1640
|
+
}
|
|
1641
|
+
price {
|
|
1642
|
+
amount
|
|
1643
|
+
currencyCode
|
|
1644
|
+
}
|
|
1645
|
+
compareAtPrice {
|
|
1646
|
+
amount
|
|
1647
|
+
currencyCode
|
|
1648
|
+
}
|
|
1649
|
+
image {
|
|
1650
|
+
id
|
|
1651
|
+
url
|
|
1652
|
+
altText
|
|
1653
|
+
width
|
|
1654
|
+
height
|
|
1655
|
+
}
|
|
1656
|
+
}
|
|
1657
|
+
}
|
|
1658
|
+
images(first: 10) {
|
|
1659
|
+
nodes {
|
|
1660
|
+
id
|
|
1661
|
+
url
|
|
1662
|
+
altText
|
|
1663
|
+
width
|
|
1664
|
+
height
|
|
1665
|
+
}
|
|
1666
|
+
}
|
|
1667
|
+
priceRange {
|
|
1668
|
+
minVariantPrice {
|
|
1669
|
+
amount
|
|
1670
|
+
currencyCode
|
|
1671
|
+
}
|
|
1672
|
+
maxVariantPrice {
|
|
1673
|
+
amount
|
|
1674
|
+
currencyCode
|
|
1675
|
+
}
|
|
1676
|
+
}
|
|
1677
|
+
compareAtPriceRange {
|
|
1678
|
+
minVariantPrice {
|
|
1679
|
+
amount
|
|
1680
|
+
currencyCode
|
|
1681
|
+
}
|
|
1682
|
+
maxVariantPrice {
|
|
1683
|
+
amount
|
|
1684
|
+
currencyCode
|
|
1685
|
+
}
|
|
1686
|
+
}
|
|
1687
|
+
metafields(
|
|
1688
|
+
identifiers: [
|
|
1689
|
+
{ namespace: "reviews", key: "rating" },
|
|
1690
|
+
{ namespace: "reviews", key: "rating_count" }
|
|
1691
|
+
]
|
|
1692
|
+
) {
|
|
1693
|
+
key
|
|
1694
|
+
namespace
|
|
1695
|
+
value
|
|
1696
|
+
type
|
|
1697
|
+
}
|
|
1698
|
+
}
|
|
1699
|
+
}
|
|
1700
|
+
`;
|
|
1627
1701
|
var GET_COLLECTIONS = `
|
|
1628
1702
|
query GetCollections(
|
|
1629
1703
|
$first: Int,
|
|
@@ -1850,11 +1924,78 @@ var ProductService = class extends BaseShopifyService {
|
|
|
1850
1924
|
});
|
|
1851
1925
|
}
|
|
1852
1926
|
}
|
|
1927
|
+
/**
|
|
1928
|
+
* Get product recommendations for a given product
|
|
1929
|
+
* Uses Shopify's productRecommendations API
|
|
1930
|
+
*/
|
|
1931
|
+
async getProductRecommendations(params, options) {
|
|
1932
|
+
try {
|
|
1933
|
+
const { productId } = params;
|
|
1934
|
+
if (!productId) {
|
|
1935
|
+
return formatResponse({
|
|
1936
|
+
success: false,
|
|
1937
|
+
message: "No product ID provided."
|
|
1938
|
+
});
|
|
1939
|
+
}
|
|
1940
|
+
const formattedId = productId.includes("gid://") ? productId : `gid://shopify/Product/${productId}`;
|
|
1941
|
+
const query = options?.query || GET_PRODUCT_RECOMMENDATIONS;
|
|
1942
|
+
const variables = options?.variables || { productId: formattedId };
|
|
1943
|
+
const { result, errors } = await this.query(query, variables, options);
|
|
1944
|
+
if (errors && errors.length > 0) {
|
|
1945
|
+
this.logger.error(
|
|
1946
|
+
"GraphQL errors in GET_PRODUCT_RECOMMENDATIONS",
|
|
1947
|
+
void 0,
|
|
1948
|
+
{ errors }
|
|
1949
|
+
);
|
|
1950
|
+
return formatResponse({
|
|
1951
|
+
success: false,
|
|
1952
|
+
message: "Failed to fetch product recommendations due to upstream errors.",
|
|
1953
|
+
error: {
|
|
1954
|
+
message: "GraphQL errors received.",
|
|
1955
|
+
details: errors
|
|
1956
|
+
}
|
|
1957
|
+
});
|
|
1958
|
+
}
|
|
1959
|
+
if (!result.data || !result.data.productRecommendations) {
|
|
1960
|
+
return formatResponse({
|
|
1961
|
+
success: true,
|
|
1962
|
+
message: "No product recommendations found.",
|
|
1963
|
+
data: [],
|
|
1964
|
+
meta: void 0
|
|
1965
|
+
});
|
|
1966
|
+
}
|
|
1967
|
+
return formatResponse({
|
|
1968
|
+
success: true,
|
|
1969
|
+
message: "Product recommendations retrieved successfully.",
|
|
1970
|
+
data: mapGetProductsToResponse({
|
|
1971
|
+
nodes: result.data.productRecommendations
|
|
1972
|
+
}),
|
|
1973
|
+
meta: {
|
|
1974
|
+
sourceProductId: productId,
|
|
1975
|
+
recommendationCount: result.data.productRecommendations.length
|
|
1976
|
+
}
|
|
1977
|
+
});
|
|
1978
|
+
} catch (error) {
|
|
1979
|
+
this.logger.error("Error in getProductRecommendations", void 0, {
|
|
1980
|
+
error
|
|
1981
|
+
});
|
|
1982
|
+
const safeMessage = error instanceof Error ? error.message : "An unexpected error occurred while processing the request.";
|
|
1983
|
+
return formatResponse({
|
|
1984
|
+
success: false,
|
|
1985
|
+
message: "An error occurred while processing the request.",
|
|
1986
|
+
error: {
|
|
1987
|
+
message: safeMessage,
|
|
1988
|
+
details: error
|
|
1989
|
+
}
|
|
1990
|
+
});
|
|
1991
|
+
}
|
|
1992
|
+
}
|
|
1853
1993
|
/**
|
|
1854
1994
|
* Get multiple products by their handles using batch query
|
|
1855
1995
|
*/
|
|
1856
|
-
async getProductsByHandles(
|
|
1996
|
+
async getProductsByHandles(params, options) {
|
|
1857
1997
|
try {
|
|
1998
|
+
const { handles } = params;
|
|
1858
1999
|
if (!handles || handles.length === 0) {
|
|
1859
2000
|
return formatResponse({
|
|
1860
2001
|
success: true,
|
|
@@ -3935,8 +4076,15 @@ var ShopifyCommerceClient = class extends BaseCommerceClient {
|
|
|
3935
4076
|
/**
|
|
3936
4077
|
* Get multiple products by their handles using batch query
|
|
3937
4078
|
*/
|
|
3938
|
-
async getProductsByHandles(
|
|
3939
|
-
return this.productService.getProductsByHandles(
|
|
4079
|
+
async getProductsByHandles(params, options) {
|
|
4080
|
+
return this.productService.getProductsByHandles(params, options);
|
|
4081
|
+
}
|
|
4082
|
+
/**
|
|
4083
|
+
* Get product recommendations for a given product
|
|
4084
|
+
* Uses Shopify's productRecommendations API
|
|
4085
|
+
*/
|
|
4086
|
+
async getProductRecommendations(params, options) {
|
|
4087
|
+
return this.productService.getProductRecommendations(params, options);
|
|
3940
4088
|
}
|
|
3941
4089
|
// ============================================================================
|
|
3942
4090
|
// COLLECTION API METHODS - Now delegated to ProductService
|
|
@@ -3953,19 +4101,30 @@ var ShopifyCommerceClient = class extends BaseCommerceClient {
|
|
|
3953
4101
|
async getCollection(params, options) {
|
|
3954
4102
|
return this.productService.getCollection(params, options);
|
|
3955
4103
|
}
|
|
3956
|
-
/**
|
|
3957
|
-
* Retrieve multiple collections by their handles with individual query parameters
|
|
3958
|
-
* Each collection can have its own specific filtering, pagination, and sorting options
|
|
3959
|
-
* @param params - Array of collection objects with handles and their respective query parameters
|
|
3960
|
-
* @param options - Request options (headers, timeout, etc.)
|
|
3961
|
-
* @returns Promise resolving to collections data with individual query results
|
|
3962
|
-
*/
|
|
3963
4104
|
/**
|
|
3964
4105
|
* Get multiple collections by their handles (preferred method name)
|
|
3965
4106
|
*/
|
|
3966
4107
|
getCollectionsByHandles(params, options) {
|
|
3967
4108
|
return this.productService.getCollectionsByHandles(params, options);
|
|
3968
4109
|
}
|
|
4110
|
+
/**
|
|
4111
|
+
* Get collection filters (available filter options for a collection)
|
|
4112
|
+
*/
|
|
4113
|
+
async getCollectionFilters(params, options) {
|
|
4114
|
+
const result = await this.productService.getCollection(
|
|
4115
|
+
{ handle: params.handle },
|
|
4116
|
+
options
|
|
4117
|
+
);
|
|
4118
|
+
if (!result.success) {
|
|
4119
|
+
return result;
|
|
4120
|
+
}
|
|
4121
|
+
return formatResponse({
|
|
4122
|
+
success: true,
|
|
4123
|
+
message: "Collection filters retrieved successfully",
|
|
4124
|
+
data: result.meta?.filters || [],
|
|
4125
|
+
meta: void 0
|
|
4126
|
+
});
|
|
4127
|
+
}
|
|
3969
4128
|
// ============================================================================
|
|
3970
4129
|
// CART API METHODS - Delegated to CartService
|
|
3971
4130
|
// ============================================================================
|
|
@@ -4067,7 +4226,8 @@ var ShopifyCommerceClient = class extends BaseCommerceClient {
|
|
|
4067
4226
|
/**
|
|
4068
4227
|
* Utility method to make GraphQL requests using Shopify client
|
|
4069
4228
|
*/
|
|
4070
|
-
async graphqlRequest(
|
|
4229
|
+
async graphqlRequest(params) {
|
|
4230
|
+
const { query, variables } = params;
|
|
4071
4231
|
this.logger.info("Making GraphQL request", {
|
|
4072
4232
|
query: query.substring(0, 100) + "..."
|
|
4073
4233
|
});
|
|
@@ -4233,7 +4393,7 @@ var PRODUCT_ENDPOINTS = {
|
|
|
4233
4393
|
getCollections: (v = DEFAULT_VERSION) => `/api/${v}/collections`,
|
|
4234
4394
|
getCollectionByHandle: (v = DEFAULT_VERSION, h) => `/api/${v}/collections/handle/${h}`,
|
|
4235
4395
|
getCollectionById: (v = DEFAULT_VERSION, id) => `/api/${v}/collections/${id}`,
|
|
4236
|
-
|
|
4396
|
+
getCollectionsByHandles: (v = DEFAULT_VERSION) => `/api/${v}/collections/details`,
|
|
4237
4397
|
getCollectionFilters: (v = DEFAULT_VERSION, collectionHandle) => `/api/${v}/storefront/collections/${collectionHandle}/filters`
|
|
4238
4398
|
};
|
|
4239
4399
|
|
|
@@ -4345,8 +4505,9 @@ var ProductService2 = class extends BaseCustomService {
|
|
|
4345
4505
|
/**
|
|
4346
4506
|
* Get multiple products by their handles using batch query
|
|
4347
4507
|
*/
|
|
4348
|
-
async getProductsByHandles(
|
|
4508
|
+
async getProductsByHandles(params, options) {
|
|
4349
4509
|
try {
|
|
4510
|
+
const { handles } = params;
|
|
4350
4511
|
if (!handles || handles.length === 0) {
|
|
4351
4512
|
return formatResponse({
|
|
4352
4513
|
success: true,
|
|
@@ -4512,7 +4673,7 @@ var ProductService2 = class extends BaseCustomService {
|
|
|
4512
4673
|
* Get multiple collections by their handles with individual query parameters
|
|
4513
4674
|
* Each collection can have its own specific filtering, pagination, and sorting options
|
|
4514
4675
|
*/
|
|
4515
|
-
async
|
|
4676
|
+
async getCollectionsByHandles(params, options) {
|
|
4516
4677
|
try {
|
|
4517
4678
|
const { handles } = params;
|
|
4518
4679
|
if (!handles || handles.length === 0) {
|
|
@@ -4547,7 +4708,7 @@ var ProductService2 = class extends BaseCustomService {
|
|
|
4547
4708
|
);
|
|
4548
4709
|
}
|
|
4549
4710
|
const result = await this.request(
|
|
4550
|
-
PRODUCT_ENDPOINTS.
|
|
4711
|
+
PRODUCT_ENDPOINTS.getCollectionsByHandles(options?.version),
|
|
4551
4712
|
"POST",
|
|
4552
4713
|
payload,
|
|
4553
4714
|
options
|
|
@@ -4560,7 +4721,9 @@ var ProductService2 = class extends BaseCustomService {
|
|
|
4560
4721
|
meta: { pagination: void 0 }
|
|
4561
4722
|
});
|
|
4562
4723
|
}
|
|
4563
|
-
const mappedCollections = result.collections.
|
|
4724
|
+
const mappedCollections = result.collections.filter(
|
|
4725
|
+
(collection) => collection !== null && collection !== void 0
|
|
4726
|
+
).map((collection) => ({
|
|
4564
4727
|
handle: collection.handle,
|
|
4565
4728
|
data: mapGetCollectionsByHandelsResponse(collection),
|
|
4566
4729
|
meta: {
|
|
@@ -4576,7 +4739,7 @@ var ProductService2 = class extends BaseCustomService {
|
|
|
4576
4739
|
meta: void 0
|
|
4577
4740
|
});
|
|
4578
4741
|
} catch (error) {
|
|
4579
|
-
this.logger.error("Error in
|
|
4742
|
+
this.logger.error("Error in getCollectionsByHandles", void 0, {
|
|
4580
4743
|
error
|
|
4581
4744
|
});
|
|
4582
4745
|
const safeMessage = error instanceof Error ? error.message : "An unexpected error occurred while processing the request.";
|
|
@@ -5177,9 +5340,9 @@ var CustomBackendClient = class extends BaseCommerceClient {
|
|
|
5177
5340
|
async getProducts(params, options) {
|
|
5178
5341
|
return this.productService.getProducts(params, filterRestOptions(options));
|
|
5179
5342
|
}
|
|
5180
|
-
async getProductsByHandles(
|
|
5343
|
+
async getProductsByHandles(params, options) {
|
|
5181
5344
|
return this.productService.getProductsByHandles(
|
|
5182
|
-
|
|
5345
|
+
params,
|
|
5183
5346
|
filterRestOptions(options)
|
|
5184
5347
|
);
|
|
5185
5348
|
}
|
|
@@ -5198,7 +5361,7 @@ var CustomBackendClient = class extends BaseCommerceClient {
|
|
|
5198
5361
|
/**
|
|
5199
5362
|
* Get a collection by ID
|
|
5200
5363
|
*/
|
|
5201
|
-
getCollection(params, options) {
|
|
5364
|
+
async getCollection(params, options) {
|
|
5202
5365
|
return this.productService.getCollection(
|
|
5203
5366
|
params,
|
|
5204
5367
|
filterRestOptions(options)
|
|
@@ -5211,8 +5374,8 @@ var CustomBackendClient = class extends BaseCommerceClient {
|
|
|
5211
5374
|
* @param options - Request options (headers, timeout, etc.)
|
|
5212
5375
|
* @returns Promise resolving to collections data with individual query results
|
|
5213
5376
|
*/
|
|
5214
|
-
|
|
5215
|
-
return this.productService.
|
|
5377
|
+
async getCollectionsByHandles(params, options) {
|
|
5378
|
+
return this.productService.getCollectionsByHandles(
|
|
5216
5379
|
params,
|
|
5217
5380
|
filterRestOptions(options)
|
|
5218
5381
|
);
|
|
@@ -5249,12 +5412,6 @@ var CustomBackendClient = class extends BaseCommerceClient {
|
|
|
5249
5412
|
async createCheckout(params, options) {
|
|
5250
5413
|
return this.cartService.createCheckout(params, filterRestOptions(options));
|
|
5251
5414
|
}
|
|
5252
|
-
async updateCheckout(id, data, options) {
|
|
5253
|
-
throw new Error("Checkout service not implemented in custom adapter");
|
|
5254
|
-
}
|
|
5255
|
-
async completeCheckout(id, paymentData, options) {
|
|
5256
|
-
throw new Error("Checkout service not implemented in custom adapter");
|
|
5257
|
-
}
|
|
5258
5415
|
// ========================================
|
|
5259
5416
|
// CUSTOMER OPERATIONS
|
|
5260
5417
|
// ========================================
|
|
@@ -5371,6 +5528,137 @@ var EFulfillmentStatus = /* @__PURE__ */ ((EFulfillmentStatus2) => {
|
|
|
5371
5528
|
return EFulfillmentStatus2;
|
|
5372
5529
|
})(EFulfillmentStatus || {});
|
|
5373
5530
|
|
|
5374
|
-
|
|
5531
|
+
// src/static-params/index.ts
|
|
5532
|
+
var log = logger.child({ module: "static-params" });
|
|
5533
|
+
async function withConcurrency(thunks, limit) {
|
|
5534
|
+
const results = new Array(thunks.length);
|
|
5535
|
+
let next = 0;
|
|
5536
|
+
async function worker() {
|
|
5537
|
+
while (next < thunks.length) {
|
|
5538
|
+
const i = next++;
|
|
5539
|
+
results[i] = await thunks[i]().catch(() => []);
|
|
5540
|
+
}
|
|
5541
|
+
}
|
|
5542
|
+
await Promise.all(Array.from({ length: Math.min(limit, thunks.length) }, worker));
|
|
5543
|
+
return results;
|
|
5544
|
+
}
|
|
5545
|
+
async function traverseCollectionProducts(client, collectionsLimit, productsPerCollection, concurrency) {
|
|
5546
|
+
const collectionsResult = await client.getCollections({ first: collectionsLimit });
|
|
5547
|
+
const collections = Array.isArray(collectionsResult?.data) ? collectionsResult.data : [];
|
|
5548
|
+
if (collections.length === 0) return [];
|
|
5549
|
+
if (collections.length >= collectionsLimit) {
|
|
5550
|
+
log.warn(
|
|
5551
|
+
"getCollections hit the collections limit \u2014 some collections may be missing from static build; increase options.collectionsLimit if needed",
|
|
5552
|
+
{ count: collections.length, limit: collectionsLimit }
|
|
5553
|
+
);
|
|
5554
|
+
}
|
|
5555
|
+
const thunks = collections.map((collection) => async () => {
|
|
5556
|
+
const collectionname = collection?.handle;
|
|
5557
|
+
if (!collectionname) return [];
|
|
5558
|
+
try {
|
|
5559
|
+
const result = await client.getCollection({
|
|
5560
|
+
handle: collectionname,
|
|
5561
|
+
productLimit: productsPerCollection
|
|
5562
|
+
});
|
|
5563
|
+
const col = result?.data;
|
|
5564
|
+
const products = Array.isArray(col?.products) ? col.products : [];
|
|
5565
|
+
return products.map((p) => p?.handle).filter((h) => Boolean(h)).map((productHandle) => ({ collectionname, productHandle }));
|
|
5566
|
+
} catch (err) {
|
|
5567
|
+
log.warn(
|
|
5568
|
+
"Skipping collection during static generation \u2014 getCollection failed",
|
|
5569
|
+
{ collection: collectionname, err: err instanceof Error ? err.message : String(err) }
|
|
5570
|
+
);
|
|
5571
|
+
return [];
|
|
5572
|
+
}
|
|
5573
|
+
});
|
|
5574
|
+
const pairsNested = await withConcurrency(thunks, concurrency);
|
|
5575
|
+
return pairsNested.flat();
|
|
5576
|
+
}
|
|
5577
|
+
function createCollectionStaticParams(getClient, options) {
|
|
5578
|
+
return async function generateStaticParams() {
|
|
5579
|
+
const limit = options?.limit ?? 250;
|
|
5580
|
+
try {
|
|
5581
|
+
const result = await getClient().getCollections({ first: limit });
|
|
5582
|
+
const collections = Array.isArray(result?.data) ? result.data : [];
|
|
5583
|
+
if (collections.length >= limit) {
|
|
5584
|
+
log.warn(
|
|
5585
|
+
"getCollections returned max limit \u2014 some collections may be missing from static build; increase options.limit if needed",
|
|
5586
|
+
{ count: collections.length, limit }
|
|
5587
|
+
);
|
|
5588
|
+
}
|
|
5589
|
+
return collections.map((c) => c?.handle).filter((h) => Boolean(h)).map((handle) => ({ collectionname: handle }));
|
|
5590
|
+
} catch (error) {
|
|
5591
|
+
log.error("getCollections failed during static generation", error instanceof Error ? error : new Error(String(error)));
|
|
5592
|
+
return [];
|
|
5593
|
+
}
|
|
5594
|
+
};
|
|
5595
|
+
}
|
|
5596
|
+
function createProductStaticParams(getClient, options) {
|
|
5597
|
+
return async function generateStaticParams() {
|
|
5598
|
+
const limit = options?.limit ?? 250;
|
|
5599
|
+
try {
|
|
5600
|
+
const result = await getClient().getProducts({ first: limit });
|
|
5601
|
+
const products = Array.isArray(result?.data) ? result.data : [];
|
|
5602
|
+
if (products.length >= limit) {
|
|
5603
|
+
log.warn(
|
|
5604
|
+
"getProducts returned max limit \u2014 some products may be missing from static build; increase options.limit if needed",
|
|
5605
|
+
{ count: products.length, limit }
|
|
5606
|
+
);
|
|
5607
|
+
}
|
|
5608
|
+
return products.map((p) => p?.handle).filter((h) => Boolean(h)).map((handle) => ({ handle }));
|
|
5609
|
+
} catch (error) {
|
|
5610
|
+
log.error("getProducts failed during static generation", error instanceof Error ? error : new Error(String(error)));
|
|
5611
|
+
return [];
|
|
5612
|
+
}
|
|
5613
|
+
};
|
|
5614
|
+
}
|
|
5615
|
+
function createProductViaCollectionsStaticParams(getClient, options) {
|
|
5616
|
+
return async function generateStaticParams() {
|
|
5617
|
+
try {
|
|
5618
|
+
const pairs = await traverseCollectionProducts(
|
|
5619
|
+
getClient(),
|
|
5620
|
+
options?.collectionsLimit ?? 250,
|
|
5621
|
+
options?.productsPerCollection ?? 100,
|
|
5622
|
+
options?.concurrency ?? 10
|
|
5623
|
+
);
|
|
5624
|
+
const seen = /* @__PURE__ */ new Set();
|
|
5625
|
+
return pairs.filter(({ productHandle }) => {
|
|
5626
|
+
if (seen.has(productHandle)) return false;
|
|
5627
|
+
seen.add(productHandle);
|
|
5628
|
+
return true;
|
|
5629
|
+
}).map(({ productHandle }) => ({ handle: productHandle }));
|
|
5630
|
+
} catch (error) {
|
|
5631
|
+
log.error("getProductHandlesViaCollections failed during static generation", error instanceof Error ? error : new Error(String(error)));
|
|
5632
|
+
return [];
|
|
5633
|
+
}
|
|
5634
|
+
};
|
|
5635
|
+
}
|
|
5636
|
+
function createCollectionProductStaticParams(getClient, options) {
|
|
5637
|
+
return async function generateStaticParams() {
|
|
5638
|
+
try {
|
|
5639
|
+
const pairs = await traverseCollectionProducts(
|
|
5640
|
+
getClient(),
|
|
5641
|
+
options?.collectionsLimit ?? 50,
|
|
5642
|
+
options?.productsPerCollection ?? 20,
|
|
5643
|
+
options?.concurrency ?? 10
|
|
5644
|
+
);
|
|
5645
|
+
const seen = /* @__PURE__ */ new Set();
|
|
5646
|
+
return pairs.filter(({ collectionname, productHandle }) => {
|
|
5647
|
+
const key = `${collectionname}:${productHandle}`;
|
|
5648
|
+
if (seen.has(key)) return false;
|
|
5649
|
+
seen.add(key);
|
|
5650
|
+
return true;
|
|
5651
|
+
}).map(({ collectionname, productHandle }) => ({
|
|
5652
|
+
collectionname,
|
|
5653
|
+
handle: productHandle
|
|
5654
|
+
}));
|
|
5655
|
+
} catch (error) {
|
|
5656
|
+
log.error("getCollectionProducts failed during static generation", error instanceof Error ? error : new Error(String(error)));
|
|
5657
|
+
return [];
|
|
5658
|
+
}
|
|
5659
|
+
};
|
|
5660
|
+
}
|
|
5661
|
+
|
|
5662
|
+
export { EAvailability, ECollectionSortKey, EFulfillmentStatus, EOrderSortKey, EOrderStatus, EPaymentStatus, EProductSortKey, createCollectionProductStaticParams, createCollectionStaticParams, createCommerceClient, createCustomClient, createProductStaticParams, createProductViaCollectionsStaticParams, createShopifyClient };
|
|
5375
5663
|
//# sourceMappingURL=index.mjs.map
|
|
5376
5664
|
//# sourceMappingURL=index.mjs.map
|