@commercengine/storefront-sdk 0.1.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 +111 -0
- package/dist/index.d.ts +80 -0
- package/dist/index.js +75 -0
- package/dist/lib/auth.d.ts +261 -0
- package/dist/lib/auth.js +679 -0
- package/dist/lib/cart.d.ts +114 -0
- package/dist/lib/cart.js +209 -0
- package/dist/lib/catalog.d.ts +130 -0
- package/dist/lib/catalog.js +176 -0
- package/dist/lib/client.d.ts +146 -0
- package/dist/lib/client.js +239 -0
- package/dist/types/storefront.d.ts +7588 -0
- package/package.json +44 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { StorefrontAPIClient } from "./client";
|
|
2
|
+
import type { components } from "../types/storefront";
|
|
3
|
+
/**
|
|
4
|
+
* Client for interacting with cart endpoints
|
|
5
|
+
*/
|
|
6
|
+
export declare class CartClient extends StorefrontAPIClient {
|
|
7
|
+
/**
|
|
8
|
+
* Create a new cart
|
|
9
|
+
*
|
|
10
|
+
* @param payload - Object containing the items to add to the cart
|
|
11
|
+
* @returns Promise with the created cart
|
|
12
|
+
*/
|
|
13
|
+
createCart(payload: {
|
|
14
|
+
items: components["schemas"]["UpdateCartItem"][];
|
|
15
|
+
}): Promise<{
|
|
16
|
+
cart: components["schemas"]["Cart"];
|
|
17
|
+
}>;
|
|
18
|
+
/**
|
|
19
|
+
* Get cart details by ID
|
|
20
|
+
*
|
|
21
|
+
* @param cartId - The ID of the cart
|
|
22
|
+
* @returns Promise with cart details
|
|
23
|
+
*/
|
|
24
|
+
getCart(cartId: string): Promise<{
|
|
25
|
+
cart: components["schemas"]["Cart"];
|
|
26
|
+
}>;
|
|
27
|
+
/**
|
|
28
|
+
* Delete a cart by ID
|
|
29
|
+
*
|
|
30
|
+
* @param cartId - The ID of the cart
|
|
31
|
+
* @returns Promise that resolves when the cart is deleted
|
|
32
|
+
*/
|
|
33
|
+
deleteCart(cartId: string): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Get cart details by user ID
|
|
36
|
+
*
|
|
37
|
+
* @param userId - The ID of the user
|
|
38
|
+
* @returns Promise with cart details
|
|
39
|
+
*/
|
|
40
|
+
getUserCart(userId: string): Promise<{
|
|
41
|
+
cart: components["schemas"]["Cart"];
|
|
42
|
+
}>;
|
|
43
|
+
/**
|
|
44
|
+
* Delete a cart by user ID
|
|
45
|
+
*
|
|
46
|
+
* @param userId - The ID of the user
|
|
47
|
+
* @returns Promise that resolves when the cart is deleted
|
|
48
|
+
*/
|
|
49
|
+
deleteUserCart(userId: string): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Update cart items (add, update quantity, remove)
|
|
52
|
+
*
|
|
53
|
+
* @param cartId - The ID of the cart
|
|
54
|
+
* @param item - The item data
|
|
55
|
+
* @returns Promise with updated cart
|
|
56
|
+
*/
|
|
57
|
+
updateCartItem(cartId: string, item: components["schemas"]["UpdateCartItem"]): Promise<{
|
|
58
|
+
cart: components["schemas"]["Cart"];
|
|
59
|
+
}>;
|
|
60
|
+
/**
|
|
61
|
+
* Update cart addresses
|
|
62
|
+
*
|
|
63
|
+
* @param cartId - The ID of the cart
|
|
64
|
+
* @param addressData - The address data
|
|
65
|
+
* @returns Promise with updated cart
|
|
66
|
+
*/
|
|
67
|
+
updateCartAddress(cartId: string, addressData: {
|
|
68
|
+
billing_address_id: string;
|
|
69
|
+
shipping_address_id: string;
|
|
70
|
+
} | {
|
|
71
|
+
billing_address: components["schemas"]["CustomerAddress"];
|
|
72
|
+
shipping_address: components["schemas"]["CustomerAddress"];
|
|
73
|
+
}): Promise<{
|
|
74
|
+
cart: components["schemas"]["Cart"];
|
|
75
|
+
}>;
|
|
76
|
+
/**
|
|
77
|
+
* Apply a coupon to the cart
|
|
78
|
+
*
|
|
79
|
+
* @param cartId - The ID of the cart
|
|
80
|
+
* @param couponCode - The coupon code
|
|
81
|
+
* @returns Promise with updated cart
|
|
82
|
+
*/
|
|
83
|
+
applyCoupon(cartId: string, couponCode: string): Promise<{
|
|
84
|
+
cart: components["schemas"]["Cart"];
|
|
85
|
+
}>;
|
|
86
|
+
/**
|
|
87
|
+
* Remove a coupon from the cart
|
|
88
|
+
*
|
|
89
|
+
* @param cartId - The ID of the cart
|
|
90
|
+
* @returns Promise with updated cart
|
|
91
|
+
*/
|
|
92
|
+
removeCoupon(cartId: string): Promise<{
|
|
93
|
+
cart: components["schemas"]["Cart"];
|
|
94
|
+
}>;
|
|
95
|
+
/**
|
|
96
|
+
* Redeem loyalty points
|
|
97
|
+
*
|
|
98
|
+
* @param cartId - The ID of the cart
|
|
99
|
+
* @param points - The number of points to redeem
|
|
100
|
+
* @returns Promise with updated cart
|
|
101
|
+
*/
|
|
102
|
+
redeemLoyaltyPoints(cartId: string, points: number): Promise<{
|
|
103
|
+
cart: components["schemas"]["Cart"];
|
|
104
|
+
}>;
|
|
105
|
+
/**
|
|
106
|
+
* Remove loyalty points
|
|
107
|
+
*
|
|
108
|
+
* @param cartId - The ID of the cart
|
|
109
|
+
* @returns Promise with updated cart
|
|
110
|
+
*/
|
|
111
|
+
removeLoyaltyPoints(cartId: string): Promise<{
|
|
112
|
+
cart: components["schemas"]["Cart"];
|
|
113
|
+
}>;
|
|
114
|
+
}
|
package/dist/lib/cart.js
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CartClient = void 0;
|
|
4
|
+
const client_1 = require("./client");
|
|
5
|
+
/**
|
|
6
|
+
* Client for interacting with cart endpoints
|
|
7
|
+
*/
|
|
8
|
+
class CartClient extends client_1.StorefrontAPIClient {
|
|
9
|
+
/**
|
|
10
|
+
* Create a new cart
|
|
11
|
+
*
|
|
12
|
+
* @param payload - Object containing the items to add to the cart
|
|
13
|
+
* @returns Promise with the created cart
|
|
14
|
+
*/
|
|
15
|
+
async createCart(payload) {
|
|
16
|
+
return this.executeRequest(async () => {
|
|
17
|
+
const { data, error } = await this.client.POST("/carts", {
|
|
18
|
+
body: payload,
|
|
19
|
+
});
|
|
20
|
+
if (error) {
|
|
21
|
+
this.handleError(error);
|
|
22
|
+
}
|
|
23
|
+
return data?.content;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Get cart details by ID
|
|
28
|
+
*
|
|
29
|
+
* @param cartId - The ID of the cart
|
|
30
|
+
* @returns Promise with cart details
|
|
31
|
+
*/
|
|
32
|
+
async getCart(cartId) {
|
|
33
|
+
return this.executeRequest(async () => {
|
|
34
|
+
const { data, error } = await this.client.GET("/carts/{id}", {
|
|
35
|
+
params: {
|
|
36
|
+
path: { id: cartId },
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
if (error) {
|
|
40
|
+
this.handleError(error);
|
|
41
|
+
}
|
|
42
|
+
return data?.content;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Delete a cart by ID
|
|
47
|
+
*
|
|
48
|
+
* @param cartId - The ID of the cart
|
|
49
|
+
* @returns Promise that resolves when the cart is deleted
|
|
50
|
+
*/
|
|
51
|
+
async deleteCart(cartId) {
|
|
52
|
+
const { error } = await this.client.DELETE("/carts/{id}", {
|
|
53
|
+
params: {
|
|
54
|
+
path: { id: cartId },
|
|
55
|
+
},
|
|
56
|
+
body: undefined,
|
|
57
|
+
});
|
|
58
|
+
if (error) {
|
|
59
|
+
this.handleError(error);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Get cart details by user ID
|
|
64
|
+
*
|
|
65
|
+
* @param userId - The ID of the user
|
|
66
|
+
* @returns Promise with cart details
|
|
67
|
+
*/
|
|
68
|
+
async getUserCart(userId) {
|
|
69
|
+
const { data, error } = await this.client.GET("/carts/users/{user_id}", {
|
|
70
|
+
params: {
|
|
71
|
+
path: { user_id: userId },
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
if (error) {
|
|
75
|
+
this.handleError(error);
|
|
76
|
+
}
|
|
77
|
+
return data?.content;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Delete a cart by user ID
|
|
81
|
+
*
|
|
82
|
+
* @param userId - The ID of the user
|
|
83
|
+
* @returns Promise that resolves when the cart is deleted
|
|
84
|
+
*/
|
|
85
|
+
async deleteUserCart(userId) {
|
|
86
|
+
const { error } = await this.client.DELETE("/carts/users/{user_id}", {
|
|
87
|
+
params: {
|
|
88
|
+
path: { user_id: userId },
|
|
89
|
+
},
|
|
90
|
+
body: undefined,
|
|
91
|
+
});
|
|
92
|
+
if (error) {
|
|
93
|
+
this.handleError(error);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Update cart items (add, update quantity, remove)
|
|
98
|
+
*
|
|
99
|
+
* @param cartId - The ID of the cart
|
|
100
|
+
* @param item - The item data
|
|
101
|
+
* @returns Promise with updated cart
|
|
102
|
+
*/
|
|
103
|
+
async updateCartItem(cartId, item) {
|
|
104
|
+
const { data, error } = await this.client.POST("/carts/{id}/items", {
|
|
105
|
+
params: {
|
|
106
|
+
path: { id: cartId },
|
|
107
|
+
},
|
|
108
|
+
body: item,
|
|
109
|
+
});
|
|
110
|
+
if (error) {
|
|
111
|
+
this.handleError(error);
|
|
112
|
+
}
|
|
113
|
+
return data?.content;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Update cart addresses
|
|
117
|
+
*
|
|
118
|
+
* @param cartId - The ID of the cart
|
|
119
|
+
* @param addressData - The address data
|
|
120
|
+
* @returns Promise with updated cart
|
|
121
|
+
*/
|
|
122
|
+
async updateCartAddress(cartId, addressData) {
|
|
123
|
+
const { data, error } = await this.client.POST("/carts/{id}/address", {
|
|
124
|
+
params: {
|
|
125
|
+
path: { id: cartId },
|
|
126
|
+
},
|
|
127
|
+
body: addressData,
|
|
128
|
+
});
|
|
129
|
+
if (error) {
|
|
130
|
+
this.handleError(error);
|
|
131
|
+
}
|
|
132
|
+
return data?.content;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Apply a coupon to the cart
|
|
136
|
+
*
|
|
137
|
+
* @param cartId - The ID of the cart
|
|
138
|
+
* @param couponCode - The coupon code
|
|
139
|
+
* @returns Promise with updated cart
|
|
140
|
+
*/
|
|
141
|
+
async applyCoupon(cartId, couponCode) {
|
|
142
|
+
const { data, error } = await this.client.POST("/carts/{id}/coupon", {
|
|
143
|
+
params: {
|
|
144
|
+
path: { id: cartId },
|
|
145
|
+
},
|
|
146
|
+
body: { coupon_code: couponCode },
|
|
147
|
+
});
|
|
148
|
+
if (error) {
|
|
149
|
+
this.handleError(error);
|
|
150
|
+
}
|
|
151
|
+
return data?.content;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Remove a coupon from the cart
|
|
155
|
+
*
|
|
156
|
+
* @param cartId - The ID of the cart
|
|
157
|
+
* @returns Promise with updated cart
|
|
158
|
+
*/
|
|
159
|
+
async removeCoupon(cartId) {
|
|
160
|
+
const { data, error } = await this.client.DELETE("/carts/{id}/coupon", {
|
|
161
|
+
params: {
|
|
162
|
+
path: { id: cartId },
|
|
163
|
+
},
|
|
164
|
+
body: undefined,
|
|
165
|
+
});
|
|
166
|
+
if (error) {
|
|
167
|
+
this.handleError(error);
|
|
168
|
+
}
|
|
169
|
+
return data?.content;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Redeem loyalty points
|
|
173
|
+
*
|
|
174
|
+
* @param cartId - The ID of the cart
|
|
175
|
+
* @param points - The number of points to redeem
|
|
176
|
+
* @returns Promise with updated cart
|
|
177
|
+
*/
|
|
178
|
+
async redeemLoyaltyPoints(cartId, points) {
|
|
179
|
+
const { data, error } = await this.client.POST("/carts/{id}/loyalty-points", {
|
|
180
|
+
params: {
|
|
181
|
+
path: { id: cartId },
|
|
182
|
+
},
|
|
183
|
+
body: { loyalty_point_redeemed: points },
|
|
184
|
+
});
|
|
185
|
+
if (error) {
|
|
186
|
+
this.handleError(error);
|
|
187
|
+
}
|
|
188
|
+
return data?.content;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Remove loyalty points
|
|
192
|
+
*
|
|
193
|
+
* @param cartId - The ID of the cart
|
|
194
|
+
* @returns Promise with updated cart
|
|
195
|
+
*/
|
|
196
|
+
async removeLoyaltyPoints(cartId) {
|
|
197
|
+
const { data, error } = await this.client.DELETE("/carts/{id}/loyalty-points", {
|
|
198
|
+
params: {
|
|
199
|
+
path: { id: cartId },
|
|
200
|
+
},
|
|
201
|
+
body: undefined,
|
|
202
|
+
});
|
|
203
|
+
if (error) {
|
|
204
|
+
this.handleError(error);
|
|
205
|
+
}
|
|
206
|
+
return data?.content;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
exports.CartClient = CartClient;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { StorefrontAPIClient } from "./client";
|
|
2
|
+
import type { components } from "../types/storefront";
|
|
3
|
+
/**
|
|
4
|
+
* Client for interacting with catalog endpoints
|
|
5
|
+
*/
|
|
6
|
+
export declare class CatalogClient extends StorefrontAPIClient {
|
|
7
|
+
/**
|
|
8
|
+
* List all products
|
|
9
|
+
*
|
|
10
|
+
* @param options - Optional query parameters
|
|
11
|
+
* @returns Promise with products and pagination info
|
|
12
|
+
*/
|
|
13
|
+
listProducts(options?: {
|
|
14
|
+
page?: number;
|
|
15
|
+
limit?: number;
|
|
16
|
+
sort_by?: string;
|
|
17
|
+
category_id?: string[];
|
|
18
|
+
customer_group_id?: string;
|
|
19
|
+
}): Promise<{
|
|
20
|
+
products: components["schemas"]["Product"][];
|
|
21
|
+
pagination: components["schemas"]["Pagination"];
|
|
22
|
+
}>;
|
|
23
|
+
/**
|
|
24
|
+
* Get details for a specific product
|
|
25
|
+
*
|
|
26
|
+
* @param productId - The ID of the product
|
|
27
|
+
* @param options - Optional query parameters
|
|
28
|
+
* @returns Promise with product details
|
|
29
|
+
*/
|
|
30
|
+
getProductDetail(productId: string, options?: {
|
|
31
|
+
customer_group_id?: string;
|
|
32
|
+
}): Promise<{
|
|
33
|
+
product: components["schemas"]["ProductDetail"];
|
|
34
|
+
}>;
|
|
35
|
+
/**
|
|
36
|
+
* List variants for a specific product
|
|
37
|
+
*
|
|
38
|
+
* @param productId - The ID of the product
|
|
39
|
+
* @param options - Optional query parameters
|
|
40
|
+
* @returns Promise with variants
|
|
41
|
+
*/
|
|
42
|
+
listProductVariants(productId: string, options?: {
|
|
43
|
+
customer_group_id?: string;
|
|
44
|
+
}): Promise<{
|
|
45
|
+
variants: components["schemas"]["Variant"][];
|
|
46
|
+
}>;
|
|
47
|
+
/**
|
|
48
|
+
* Get details for a specific variant
|
|
49
|
+
*
|
|
50
|
+
* @param productId - The ID of the product
|
|
51
|
+
* @param variantId - The ID of the variant
|
|
52
|
+
* @param options - Optional query parameters
|
|
53
|
+
* @returns Promise with variant details
|
|
54
|
+
*/
|
|
55
|
+
getVariantDetail(productId: string, variantId: string, options?: {
|
|
56
|
+
customer_group_id?: string;
|
|
57
|
+
}): Promise<{
|
|
58
|
+
variant: components["schemas"]["VariantDetail"];
|
|
59
|
+
}>;
|
|
60
|
+
/**
|
|
61
|
+
* List all categories
|
|
62
|
+
*
|
|
63
|
+
* @param options - Optional query parameters
|
|
64
|
+
* @returns Promise with categories and pagination info
|
|
65
|
+
*/
|
|
66
|
+
listCategories(options?: {
|
|
67
|
+
parent_category_id?: string;
|
|
68
|
+
nested_level?: number;
|
|
69
|
+
search?: string;
|
|
70
|
+
sort_by?: string;
|
|
71
|
+
}): Promise<{
|
|
72
|
+
categories: components["schemas"]["ProductCategory"][];
|
|
73
|
+
pagination: components["schemas"]["Pagination"];
|
|
74
|
+
}>;
|
|
75
|
+
/**
|
|
76
|
+
* List reviews for a specific product
|
|
77
|
+
*
|
|
78
|
+
* @param productId - The ID of the product
|
|
79
|
+
* @param options - Optional query parameters
|
|
80
|
+
* @returns Promise with reviews and pagination info
|
|
81
|
+
*/
|
|
82
|
+
listProductReviews(productId: string, options?: {
|
|
83
|
+
page?: number;
|
|
84
|
+
limit?: number;
|
|
85
|
+
sort_by?: string;
|
|
86
|
+
search?: string;
|
|
87
|
+
review_tag?: string;
|
|
88
|
+
}): Promise<{
|
|
89
|
+
reviews: components["schemas"]["ProductReview"][];
|
|
90
|
+
review_tags?: string[] | null;
|
|
91
|
+
pagination?: components["schemas"]["Pagination"];
|
|
92
|
+
}>;
|
|
93
|
+
/**
|
|
94
|
+
* Create a review for a specific product
|
|
95
|
+
*
|
|
96
|
+
* @param productId - The ID of the product
|
|
97
|
+
* @param reviewData - The review data
|
|
98
|
+
* @returns Promise that resolves when the review is created
|
|
99
|
+
*/
|
|
100
|
+
createProductReview(productId: string, reviewData: components["schemas"]["CreateReview"]): Promise<void>;
|
|
101
|
+
/**
|
|
102
|
+
* Search for products
|
|
103
|
+
*
|
|
104
|
+
* @param searchData - The search parameters
|
|
105
|
+
* @returns Promise with search results
|
|
106
|
+
*/
|
|
107
|
+
searchProducts(searchData: components["schemas"]["SearchProduct"]): Promise<{
|
|
108
|
+
skus: components["schemas"]["SKU"][];
|
|
109
|
+
facet_distribution: {
|
|
110
|
+
[key: string]: {
|
|
111
|
+
[key: string]: number;
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
facet_stats: {
|
|
115
|
+
[key: string]: {
|
|
116
|
+
min: number;
|
|
117
|
+
max: number;
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
pagination: components["schemas"]["Pagination"];
|
|
121
|
+
}>;
|
|
122
|
+
/**
|
|
123
|
+
* Get product details by ID (alternative implementation)
|
|
124
|
+
* @param productId - The product ID to retrieve
|
|
125
|
+
* @returns Promise with the product details
|
|
126
|
+
*/
|
|
127
|
+
getProduct(productId: string): Promise<{
|
|
128
|
+
product: components["schemas"]["ProductDetail"];
|
|
129
|
+
}>;
|
|
130
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CatalogClient = void 0;
|
|
4
|
+
const client_1 = require("./client");
|
|
5
|
+
/**
|
|
6
|
+
* Client for interacting with catalog endpoints
|
|
7
|
+
*/
|
|
8
|
+
class CatalogClient extends client_1.StorefrontAPIClient {
|
|
9
|
+
/**
|
|
10
|
+
* List all products
|
|
11
|
+
*
|
|
12
|
+
* @param options - Optional query parameters
|
|
13
|
+
* @returns Promise with products and pagination info
|
|
14
|
+
*/
|
|
15
|
+
async listProducts(options) {
|
|
16
|
+
return this.executeRequest(async () => {
|
|
17
|
+
const { data, error } = await this.client.GET("/catalog/products", {
|
|
18
|
+
params: { query: options },
|
|
19
|
+
});
|
|
20
|
+
if (error) {
|
|
21
|
+
this.handleError(error);
|
|
22
|
+
}
|
|
23
|
+
return data?.content;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Get details for a specific product
|
|
28
|
+
*
|
|
29
|
+
* @param productId - The ID of the product
|
|
30
|
+
* @param options - Optional query parameters
|
|
31
|
+
* @returns Promise with product details
|
|
32
|
+
*/
|
|
33
|
+
async getProductDetail(productId, options) {
|
|
34
|
+
const { data, error } = await this.client.GET("/catalog/products/{product_id}", {
|
|
35
|
+
params: {
|
|
36
|
+
path: { product_id: productId },
|
|
37
|
+
query: options,
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
if (error) {
|
|
41
|
+
this.handleError(error);
|
|
42
|
+
}
|
|
43
|
+
return data?.content;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* List variants for a specific product
|
|
47
|
+
*
|
|
48
|
+
* @param productId - The ID of the product
|
|
49
|
+
* @param options - Optional query parameters
|
|
50
|
+
* @returns Promise with variants
|
|
51
|
+
*/
|
|
52
|
+
async listProductVariants(productId, options) {
|
|
53
|
+
const { data, error } = await this.client.GET("/catalog/products/{product_id}/variants", {
|
|
54
|
+
params: {
|
|
55
|
+
path: { product_id: productId },
|
|
56
|
+
query: options,
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
if (error) {
|
|
60
|
+
this.handleError(error);
|
|
61
|
+
}
|
|
62
|
+
return data?.content;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Get details for a specific variant
|
|
66
|
+
*
|
|
67
|
+
* @param productId - The ID of the product
|
|
68
|
+
* @param variantId - The ID of the variant
|
|
69
|
+
* @param options - Optional query parameters
|
|
70
|
+
* @returns Promise with variant details
|
|
71
|
+
*/
|
|
72
|
+
async getVariantDetail(productId, variantId, options) {
|
|
73
|
+
const { data, error } = await this.client.GET("/catalog/products/{product_id}/variants/{variant_id}", {
|
|
74
|
+
params: {
|
|
75
|
+
path: {
|
|
76
|
+
product_id: productId,
|
|
77
|
+
variant_id: variantId,
|
|
78
|
+
},
|
|
79
|
+
query: options,
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
if (error) {
|
|
83
|
+
this.handleError(error);
|
|
84
|
+
}
|
|
85
|
+
return data?.content;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* List all categories
|
|
89
|
+
*
|
|
90
|
+
* @param options - Optional query parameters
|
|
91
|
+
* @returns Promise with categories and pagination info
|
|
92
|
+
*/
|
|
93
|
+
async listCategories(options) {
|
|
94
|
+
const { data, error } = await this.client.GET("/catalog/categories", {
|
|
95
|
+
params: { query: options },
|
|
96
|
+
});
|
|
97
|
+
if (error) {
|
|
98
|
+
this.handleError(error);
|
|
99
|
+
}
|
|
100
|
+
return data?.content;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* List reviews for a specific product
|
|
104
|
+
*
|
|
105
|
+
* @param productId - The ID of the product
|
|
106
|
+
* @param options - Optional query parameters
|
|
107
|
+
* @returns Promise with reviews and pagination info
|
|
108
|
+
*/
|
|
109
|
+
async listProductReviews(productId, options) {
|
|
110
|
+
const { data, error } = await this.client.GET("/catalog/products/{product_id}/reviews", {
|
|
111
|
+
params: {
|
|
112
|
+
path: { product_id: productId },
|
|
113
|
+
query: options,
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
if (error) {
|
|
117
|
+
this.handleError(error);
|
|
118
|
+
}
|
|
119
|
+
return data?.content;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Create a review for a specific product
|
|
123
|
+
*
|
|
124
|
+
* @param productId - The ID of the product
|
|
125
|
+
* @param reviewData - The review data
|
|
126
|
+
* @returns Promise that resolves when the review is created
|
|
127
|
+
*/
|
|
128
|
+
async createProductReview(productId, reviewData) {
|
|
129
|
+
// Note: In a real implementation, you would need to handle multipart/form-data
|
|
130
|
+
// This would require FormData and may need additional handling
|
|
131
|
+
const { error } = await this.client.POST("/catalog/products/{product_id}/reviews", {
|
|
132
|
+
params: {
|
|
133
|
+
path: { product_id: productId },
|
|
134
|
+
},
|
|
135
|
+
body: reviewData,
|
|
136
|
+
// This is simplified as we're not properly handling multipart/form-data
|
|
137
|
+
});
|
|
138
|
+
if (error) {
|
|
139
|
+
this.handleError(error);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Search for products
|
|
144
|
+
*
|
|
145
|
+
* @param searchData - The search parameters
|
|
146
|
+
* @returns Promise with search results
|
|
147
|
+
*/
|
|
148
|
+
async searchProducts(searchData) {
|
|
149
|
+
const { data, error } = await this.client.POST("/catalog/products/search", {
|
|
150
|
+
body: searchData,
|
|
151
|
+
});
|
|
152
|
+
if (error) {
|
|
153
|
+
this.handleError(error);
|
|
154
|
+
}
|
|
155
|
+
return data?.content;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Get product details by ID (alternative implementation)
|
|
159
|
+
* @param productId - The product ID to retrieve
|
|
160
|
+
* @returns Promise with the product details
|
|
161
|
+
*/
|
|
162
|
+
async getProduct(productId) {
|
|
163
|
+
return this.executeRequest(async () => {
|
|
164
|
+
const { data, error } = await this.client.GET("/catalog/products/{product_id}", {
|
|
165
|
+
params: {
|
|
166
|
+
path: { product_id: productId },
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
if (error) {
|
|
170
|
+
this.handleError(error);
|
|
171
|
+
}
|
|
172
|
+
return data?.content;
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
exports.CatalogClient = CatalogClient;
|