@commercengine/storefront-sdk 0.7.0 → 0.8.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/index.cjs +1888 -88
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2662 -653
- package/dist/index.d.ts +2662 -653
- package/dist/index.iife.js +1888 -88
- package/dist/index.iife.js.map +1 -1
- package/dist/index.js +1888 -88
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -212,6 +212,21 @@ var CookieTokenStorage = class {
|
|
|
212
212
|
function createAuthMiddleware(config) {
|
|
213
213
|
let isRefreshing = false;
|
|
214
214
|
let refreshPromise = null;
|
|
215
|
+
let hasAssessedTokens = false;
|
|
216
|
+
const assessTokenStateOnce = async () => {
|
|
217
|
+
if (hasAssessedTokens) return;
|
|
218
|
+
hasAssessedTokens = true;
|
|
219
|
+
try {
|
|
220
|
+
const accessToken = await config.tokenStorage.getAccessToken();
|
|
221
|
+
const refreshToken = await config.tokenStorage.getRefreshToken();
|
|
222
|
+
if (!accessToken && refreshToken) {
|
|
223
|
+
await config.tokenStorage.clearTokens();
|
|
224
|
+
console.info("Cleaned up orphaned refresh token");
|
|
225
|
+
}
|
|
226
|
+
} catch (error) {
|
|
227
|
+
console.warn("Token state assessment failed:", error);
|
|
228
|
+
}
|
|
229
|
+
};
|
|
215
230
|
const refreshTokens = async () => {
|
|
216
231
|
if (isRefreshing && refreshPromise) {
|
|
217
232
|
return refreshPromise;
|
|
@@ -288,17 +303,55 @@ function createAuthMiddleware(config) {
|
|
|
288
303
|
return {
|
|
289
304
|
async onRequest({ request }) {
|
|
290
305
|
const pathname = getPathnameFromUrl(request.url);
|
|
306
|
+
await assessTokenStateOnce();
|
|
291
307
|
if (isAnonymousAuthEndpoint(pathname)) {
|
|
292
308
|
if (config.apiKey) {
|
|
293
309
|
request.headers.set("X-Api-Key", config.apiKey);
|
|
294
310
|
}
|
|
295
311
|
const existingToken = await config.tokenStorage.getAccessToken();
|
|
312
|
+
if (existingToken && !isTokenExpired(existingToken) && isUserLoggedIn(existingToken)) {
|
|
313
|
+
return new Response(
|
|
314
|
+
JSON.stringify({
|
|
315
|
+
message: "Cannot create anonymous session while authenticated",
|
|
316
|
+
success: false,
|
|
317
|
+
code: "USER_ALREADY_AUTHENTICATED"
|
|
318
|
+
}),
|
|
319
|
+
{
|
|
320
|
+
status: 400,
|
|
321
|
+
headers: { "Content-Type": "application/json" }
|
|
322
|
+
}
|
|
323
|
+
);
|
|
324
|
+
}
|
|
296
325
|
if (existingToken) {
|
|
297
326
|
request.headers.set("Authorization", `Bearer ${existingToken}`);
|
|
298
327
|
}
|
|
299
328
|
return request;
|
|
300
329
|
}
|
|
301
330
|
let accessToken = await config.tokenStorage.getAccessToken();
|
|
331
|
+
if (!accessToken) {
|
|
332
|
+
try {
|
|
333
|
+
const response = await fetch(`${config.baseUrl}/auth/anonymous`, {
|
|
334
|
+
method: "POST",
|
|
335
|
+
headers: {
|
|
336
|
+
"Content-Type": "application/json",
|
|
337
|
+
...config.apiKey && { "X-Api-Key": config.apiKey }
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
if (response.ok) {
|
|
341
|
+
const data = await response.json();
|
|
342
|
+
const tokens = data.content;
|
|
343
|
+
if (tokens?.access_token && tokens?.refresh_token) {
|
|
344
|
+
await config.tokenStorage.setAccessToken(tokens.access_token);
|
|
345
|
+
await config.tokenStorage.setRefreshToken(tokens.refresh_token);
|
|
346
|
+
accessToken = tokens.access_token;
|
|
347
|
+
config.onTokensUpdated?.(tokens.access_token, tokens.refresh_token);
|
|
348
|
+
console.info("Automatically created anonymous session for first API request");
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
} catch (error) {
|
|
352
|
+
console.warn("Failed to automatically create anonymous tokens:", error);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
302
355
|
if (accessToken && isTokenExpired(accessToken)) {
|
|
303
356
|
try {
|
|
304
357
|
await refreshTokens();
|
|
@@ -859,6 +912,50 @@ var CatalogClient = class extends StorefrontAPIClient {
|
|
|
859
912
|
* @param options - Optional query parameters
|
|
860
913
|
* @param headers - Optional header parameters (customer_group_id, etc.)
|
|
861
914
|
* @returns Promise with products and pagination info
|
|
915
|
+
*
|
|
916
|
+
* @example
|
|
917
|
+
* ```typescript
|
|
918
|
+
* // Basic product listing
|
|
919
|
+
* const { data, error } = await sdk.catalog.listProducts();
|
|
920
|
+
*
|
|
921
|
+
* if (error) {
|
|
922
|
+
* console.error("Failed to list products:", error);
|
|
923
|
+
* return;
|
|
924
|
+
* }
|
|
925
|
+
*
|
|
926
|
+
* console.log("Products found:", data.products?.length || 0);
|
|
927
|
+
* console.log("Pagination:", data.pagination);
|
|
928
|
+
*
|
|
929
|
+
* // With filtering and pagination
|
|
930
|
+
* const { data: filteredData, error: filteredError } = await sdk.catalog.listProducts({
|
|
931
|
+
* page: 1,
|
|
932
|
+
* limit: 20,
|
|
933
|
+
* sort_by: JSON.stringify({ "created_at": "desc" }),
|
|
934
|
+
* category_slug: ["electronics", "smartphones"]
|
|
935
|
+
* });
|
|
936
|
+
*
|
|
937
|
+
* // Override customer group ID for this specific request
|
|
938
|
+
* const { data: overrideData, error: overrideError } = await sdk.catalog.listProducts(
|
|
939
|
+
* {
|
|
940
|
+
* page: 1,
|
|
941
|
+
* limit: 20,
|
|
942
|
+
* sort_by: JSON.stringify({ "created_at": "desc" }),
|
|
943
|
+
* category_slug: ["electronics", "smartphones"]
|
|
944
|
+
* },
|
|
945
|
+
* {
|
|
946
|
+
* "x-customer-group-id": "01H9XYZ12345USERID" // Override default SDK config
|
|
947
|
+
* }
|
|
948
|
+
* );
|
|
949
|
+
*
|
|
950
|
+
* if (filteredError) {
|
|
951
|
+
* console.error("Failed to get filtered products:", filteredError);
|
|
952
|
+
* return;
|
|
953
|
+
* }
|
|
954
|
+
*
|
|
955
|
+
* filteredData.products?.forEach(product => {
|
|
956
|
+
* console.log(`Product: ${product.name} - ${product.price}`);
|
|
957
|
+
* });
|
|
958
|
+
* ```
|
|
862
959
|
*/
|
|
863
960
|
async listProducts(options, headers) {
|
|
864
961
|
const mergedHeaders = this.mergeHeaders(headers);
|
|
@@ -877,6 +974,46 @@ var CatalogClient = class extends StorefrontAPIClient {
|
|
|
877
974
|
* @param options - Optional query parameters
|
|
878
975
|
* @param headers - Optional header parameters (customer_group_id, etc.)
|
|
879
976
|
* @returns Promise with skus and pagination info
|
|
977
|
+
*
|
|
978
|
+
* @example
|
|
979
|
+
* ```typescript
|
|
980
|
+
* // Basic SKU listing
|
|
981
|
+
* const { data, error } = await sdk.catalog.listSkus();
|
|
982
|
+
*
|
|
983
|
+
* if (error) {
|
|
984
|
+
* console.error("Failed to list SKUs:", error);
|
|
985
|
+
* return;
|
|
986
|
+
* }
|
|
987
|
+
*
|
|
988
|
+
* console.log("SKUs found:", data.skus?.length || 0);
|
|
989
|
+
* console.log("Pagination:", data.pagination);
|
|
990
|
+
*
|
|
991
|
+
* // With pagination
|
|
992
|
+
* const { data: skuData, error: skuError } = await sdk.catalog.listSkus({
|
|
993
|
+
* page: 1,
|
|
994
|
+
* limit: 50
|
|
995
|
+
* });
|
|
996
|
+
*
|
|
997
|
+
* // Override customer group ID for this specific request
|
|
998
|
+
* const { data: overrideData, error: overrideError } = await sdk.catalog.listSkus(
|
|
999
|
+
* {
|
|
1000
|
+
* page: 1,
|
|
1001
|
+
* limit: 50
|
|
1002
|
+
* },
|
|
1003
|
+
* {
|
|
1004
|
+
* "x-customer-group-id": "01H9XYZ12345USERID" // Override default SDK config
|
|
1005
|
+
* }
|
|
1006
|
+
* );
|
|
1007
|
+
*
|
|
1008
|
+
* if (skuError) {
|
|
1009
|
+
* console.error("Failed to get SKUs:", skuError);
|
|
1010
|
+
* return;
|
|
1011
|
+
* }
|
|
1012
|
+
*
|
|
1013
|
+
* skuData.skus?.forEach(sku => {
|
|
1014
|
+
* console.log(`SKU: ${sku.sku} - Price: ${sku.price}`);
|
|
1015
|
+
* });
|
|
1016
|
+
* ```
|
|
880
1017
|
*/
|
|
881
1018
|
async listSkus(options, headers) {
|
|
882
1019
|
const mergedHeaders = this.mergeHeaders(headers);
|
|
@@ -895,6 +1032,43 @@ var CatalogClient = class extends StorefrontAPIClient {
|
|
|
895
1032
|
* @param pathParams - The path parameters (product ID or slug)
|
|
896
1033
|
* @param headers - Optional header parameters (customer_group_id, etc.)
|
|
897
1034
|
* @returns Promise with product details
|
|
1035
|
+
*
|
|
1036
|
+
* @example
|
|
1037
|
+
* ```typescript
|
|
1038
|
+
* // Get product by ID
|
|
1039
|
+
* const { data, error } = await sdk.catalog.getProductDetail(
|
|
1040
|
+
* { product_id_or_slug: "prod_123" }
|
|
1041
|
+
* );
|
|
1042
|
+
*
|
|
1043
|
+
* if (error) {
|
|
1044
|
+
* console.error("Failed to get product details:", error);
|
|
1045
|
+
* return;
|
|
1046
|
+
* }
|
|
1047
|
+
*
|
|
1048
|
+
* console.log("Product:", data.product.name);
|
|
1049
|
+
* console.log("Price:", data.product.price);
|
|
1050
|
+
* console.log("Description:", data.product.description);
|
|
1051
|
+
*
|
|
1052
|
+
* // Get product by slug
|
|
1053
|
+
* const { data: slugData, error: slugError } = await sdk.catalog.getProductDetail({
|
|
1054
|
+
* product_id_or_slug: "detox-candy"
|
|
1055
|
+
* });
|
|
1056
|
+
*
|
|
1057
|
+
* // Override customer group ID for this specific request
|
|
1058
|
+
* const { data: overrideData, error: overrideError } = await sdk.catalog.getProductDetail(
|
|
1059
|
+
* { product_id_or_slug: "detox-candy" },
|
|
1060
|
+
* {
|
|
1061
|
+
* "x-customer-group-id": "premium_customers" // Override default SDK config
|
|
1062
|
+
* }
|
|
1063
|
+
* );
|
|
1064
|
+
*
|
|
1065
|
+
* if (slugError) {
|
|
1066
|
+
* console.error("Failed to get product by slug:", slugError);
|
|
1067
|
+
* return;
|
|
1068
|
+
* }
|
|
1069
|
+
*
|
|
1070
|
+
* console.log("Product with custom pricing:", slugData.product.price);
|
|
1071
|
+
* ```
|
|
898
1072
|
*/
|
|
899
1073
|
async getProductDetail(pathParams, headers) {
|
|
900
1074
|
const mergedHeaders = this.mergeHeaders(headers);
|
|
@@ -908,11 +1082,37 @@ var CatalogClient = class extends StorefrontAPIClient {
|
|
|
908
1082
|
);
|
|
909
1083
|
}
|
|
910
1084
|
/**
|
|
911
|
-
* List variants for a specific product
|
|
1085
|
+
* List all variants for a specific product
|
|
912
1086
|
*
|
|
913
1087
|
* @param pathParams - The path parameters (product ID)
|
|
914
1088
|
* @param headers - Optional header parameters (customer_group_id, etc.)
|
|
915
|
-
* @returns Promise with variants
|
|
1089
|
+
* @returns Promise with product variants and pagination info
|
|
1090
|
+
*
|
|
1091
|
+
* @example
|
|
1092
|
+
* ```typescript
|
|
1093
|
+
* const { data, error } = await sdk.catalog.listProductVariants(
|
|
1094
|
+
* { product_id: "prod_123" }
|
|
1095
|
+
* );
|
|
1096
|
+
*
|
|
1097
|
+
* if (error) {
|
|
1098
|
+
* console.error("Failed to list product variants:", error);
|
|
1099
|
+
* return;
|
|
1100
|
+
* }
|
|
1101
|
+
*
|
|
1102
|
+
* console.log("Variants found:", data.variants?.length || 0);
|
|
1103
|
+
*
|
|
1104
|
+
* data.variants?.forEach(variant => {
|
|
1105
|
+
* console.log(`Variant: ${variant.name} - SKU: ${variant.sku} - Price: ${variant.price}`);
|
|
1106
|
+
* });
|
|
1107
|
+
*
|
|
1108
|
+
* // Override customer group ID for this specific request
|
|
1109
|
+
* const { data: overrideData, error: overrideError } = await sdk.catalog.listProductVariants(
|
|
1110
|
+
* { product_id: "prod_123" },
|
|
1111
|
+
* {
|
|
1112
|
+
* "x-customer-group-id": "wholesale_customers" // Override default SDK config
|
|
1113
|
+
* }
|
|
1114
|
+
* );
|
|
1115
|
+
* ```
|
|
916
1116
|
*/
|
|
917
1117
|
async listProductVariants(pathParams, headers) {
|
|
918
1118
|
const mergedHeaders = this.mergeHeaders(headers);
|
|
@@ -926,11 +1126,31 @@ var CatalogClient = class extends StorefrontAPIClient {
|
|
|
926
1126
|
);
|
|
927
1127
|
}
|
|
928
1128
|
/**
|
|
929
|
-
* Get details for a specific variant
|
|
1129
|
+
* Get details for a specific product variant
|
|
930
1130
|
*
|
|
931
1131
|
* @param pathParams - The path parameters (product ID and variant ID)
|
|
932
1132
|
* @param headers - Optional header parameters (customer_group_id, etc.)
|
|
933
1133
|
* @returns Promise with variant details
|
|
1134
|
+
*
|
|
1135
|
+
* @example
|
|
1136
|
+
* ```typescript
|
|
1137
|
+
* const { data, error } = await sdk.catalog.getVariantDetail(
|
|
1138
|
+
* {
|
|
1139
|
+
* product_id: "prod_123",
|
|
1140
|
+
* variant_id: "var_456"
|
|
1141
|
+
* }
|
|
1142
|
+
* );
|
|
1143
|
+
*
|
|
1144
|
+
* if (error) {
|
|
1145
|
+
* console.error("Failed to get variant details:", error);
|
|
1146
|
+
* return;
|
|
1147
|
+
* }
|
|
1148
|
+
*
|
|
1149
|
+
* console.log("Variant:", data.variant.name);
|
|
1150
|
+
* console.log("SKU:", data.variant.sku);
|
|
1151
|
+
* console.log("Price:", data.variant.price);
|
|
1152
|
+
* console.log("Stock:", data.variant.stock);
|
|
1153
|
+
* ```
|
|
934
1154
|
*/
|
|
935
1155
|
async getVariantDetail(pathParams, headers) {
|
|
936
1156
|
const mergedHeaders = this.mergeHeaders(headers);
|
|
@@ -944,24 +1164,77 @@ var CatalogClient = class extends StorefrontAPIClient {
|
|
|
944
1164
|
);
|
|
945
1165
|
}
|
|
946
1166
|
/**
|
|
947
|
-
* List all categories
|
|
1167
|
+
* List all product categories
|
|
948
1168
|
*
|
|
949
1169
|
* @param options - Optional query parameters
|
|
950
1170
|
* @returns Promise with categories and pagination info
|
|
1171
|
+
*
|
|
1172
|
+
* @example
|
|
1173
|
+
* ```typescript
|
|
1174
|
+
* // Basic category listing
|
|
1175
|
+
* const { data, error } = await sdk.catalog.listCategories();
|
|
1176
|
+
*
|
|
1177
|
+
* if (error) {
|
|
1178
|
+
* console.error("Failed to list categories:", error);
|
|
1179
|
+
* return;
|
|
1180
|
+
* }
|
|
1181
|
+
*
|
|
1182
|
+
* console.log("Categories found:", data.categories?.length || 0);
|
|
1183
|
+
*
|
|
1184
|
+
* data.categories?.forEach(category => {
|
|
1185
|
+
* console.log(`Category: ${category.name} - ${category.description}`);
|
|
1186
|
+
* });
|
|
1187
|
+
*
|
|
1188
|
+
* // With pagination
|
|
1189
|
+
* const { data: catData, error: catError } = await sdk.catalog.listCategories({
|
|
1190
|
+
* page: 1,
|
|
1191
|
+
* limit: 10
|
|
1192
|
+
* });
|
|
1193
|
+
* ```
|
|
951
1194
|
*/
|
|
952
1195
|
async listCategories(options) {
|
|
953
1196
|
return this.executeRequest(
|
|
954
1197
|
() => this.client.GET("/catalog/categories", {
|
|
955
|
-
params: {
|
|
1198
|
+
params: {
|
|
1199
|
+
query: options
|
|
1200
|
+
}
|
|
956
1201
|
})
|
|
957
1202
|
);
|
|
958
1203
|
}
|
|
959
1204
|
/**
|
|
960
|
-
* List reviews for a specific product
|
|
1205
|
+
* List all reviews for a specific product
|
|
961
1206
|
*
|
|
962
1207
|
* @param pathParams - The path parameters (product ID)
|
|
963
1208
|
* @param queryParams - Optional query parameters
|
|
964
|
-
* @returns Promise with reviews and pagination info
|
|
1209
|
+
* @returns Promise with product reviews and pagination info
|
|
1210
|
+
*
|
|
1211
|
+
* @example
|
|
1212
|
+
* ```typescript
|
|
1213
|
+
* const { data, error } = await sdk.catalog.listProductReviews(
|
|
1214
|
+
* { product_id: "prod_123" }
|
|
1215
|
+
* );
|
|
1216
|
+
*
|
|
1217
|
+
* if (error) {
|
|
1218
|
+
* console.error("Failed to list product reviews:", error);
|
|
1219
|
+
* return;
|
|
1220
|
+
* }
|
|
1221
|
+
*
|
|
1222
|
+
* console.log("Reviews found:", data.reviews?.length || 0);
|
|
1223
|
+
*
|
|
1224
|
+
* data.reviews?.forEach(review => {
|
|
1225
|
+
* console.log(`Review by ${review.customer_name}: ${review.rating}/5`);
|
|
1226
|
+
* console.log("Comment:", review.comment);
|
|
1227
|
+
* });
|
|
1228
|
+
*
|
|
1229
|
+
* // With pagination
|
|
1230
|
+
* const { data: reviewData, error: reviewError } = await sdk.catalog.listProductReviews(
|
|
1231
|
+
* { product_id: "prod_123" },
|
|
1232
|
+
* {
|
|
1233
|
+
* page: 1,
|
|
1234
|
+
* limit: 5
|
|
1235
|
+
* }
|
|
1236
|
+
* );
|
|
1237
|
+
* ```
|
|
965
1238
|
*/
|
|
966
1239
|
async listProductReviews(pathParams, queryParams) {
|
|
967
1240
|
return this.executeRequest(
|
|
@@ -974,11 +1247,33 @@ var CatalogClient = class extends StorefrontAPIClient {
|
|
|
974
1247
|
);
|
|
975
1248
|
}
|
|
976
1249
|
/**
|
|
977
|
-
* Create a review
|
|
1250
|
+
* Create a product review
|
|
978
1251
|
*
|
|
979
1252
|
* @param pathParams - The path parameters (product ID)
|
|
980
|
-
* @param formData - The review data
|
|
981
|
-
* @returns Promise
|
|
1253
|
+
* @param formData - The review data including rating, comment, and optional images
|
|
1254
|
+
* @returns Promise with review creation response
|
|
1255
|
+
*
|
|
1256
|
+
* @example
|
|
1257
|
+
* ```typescript
|
|
1258
|
+
* const { data, error } = await sdk.catalog.createProductReview(
|
|
1259
|
+
* { product_id: "prod_123" },
|
|
1260
|
+
* {
|
|
1261
|
+
* rating: 5,
|
|
1262
|
+
* comment: "Excellent product! Highly recommended.",
|
|
1263
|
+
* images: [
|
|
1264
|
+
* new File(["image data"], "review1.jpg", { type: "image/jpeg" }),
|
|
1265
|
+
* new File(["image data"], "review2.jpg", { type: "image/jpeg" })
|
|
1266
|
+
* ]
|
|
1267
|
+
* }
|
|
1268
|
+
* );
|
|
1269
|
+
*
|
|
1270
|
+
* if (error) {
|
|
1271
|
+
* console.error("Failed to create review:", error);
|
|
1272
|
+
* return;
|
|
1273
|
+
* }
|
|
1274
|
+
*
|
|
1275
|
+
* console.log("Review created successfully:", data.message);
|
|
1276
|
+
* ```
|
|
982
1277
|
*/
|
|
983
1278
|
async createProductReview(pathParams, formData) {
|
|
984
1279
|
return this.executeRequest(
|
|
@@ -1006,24 +1301,103 @@ var CatalogClient = class extends StorefrontAPIClient {
|
|
|
1006
1301
|
/**
|
|
1007
1302
|
* Search for products
|
|
1008
1303
|
*
|
|
1009
|
-
* @param searchData - The search
|
|
1010
|
-
* @
|
|
1304
|
+
* @param searchData - The search query and filters
|
|
1305
|
+
* @param headers - Optional header parameters (customer_group_id, etc.)
|
|
1306
|
+
* @returns Promise with search results including products, facets, and pagination
|
|
1307
|
+
*
|
|
1308
|
+
* @example
|
|
1309
|
+
* ```typescript
|
|
1310
|
+
* const { data, error } = await sdk.catalog.searchProducts({
|
|
1311
|
+
* query: "smartphone",
|
|
1312
|
+
* filters: {
|
|
1313
|
+
* category: ["electronics", "mobile"],
|
|
1314
|
+
* price_range: { min: 100, max: 1000 },
|
|
1315
|
+
* brand: ["Apple", "Samsung"] // facet names depend on product configuration
|
|
1316
|
+
* },
|
|
1317
|
+
* page: 1,
|
|
1318
|
+
* limit: 20
|
|
1319
|
+
* });
|
|
1320
|
+
*
|
|
1321
|
+
* if (error) {
|
|
1322
|
+
* console.error("Failed to search products:", error);
|
|
1323
|
+
* return;
|
|
1324
|
+
* }
|
|
1325
|
+
*
|
|
1326
|
+
* console.log("Search results:", data.skus?.length || 0, "products found");
|
|
1327
|
+
* console.log("Facet distribution:", data.facet_distribution);
|
|
1328
|
+
* console.log("Price range:", data.facet_stats.price_range);
|
|
1329
|
+
*
|
|
1330
|
+
* data.skus?.forEach(sku => {
|
|
1331
|
+
* console.log(`Found: ${sku.name} - ${sku.price}`);
|
|
1332
|
+
* });
|
|
1333
|
+
*
|
|
1334
|
+
* // Override customer group ID for this specific request
|
|
1335
|
+
* const { data: overrideData, error: overrideError } = await sdk.catalog.searchProducts(
|
|
1336
|
+
* {
|
|
1337
|
+
* query: "laptop",
|
|
1338
|
+
* filters: { category: ["computers"] }
|
|
1339
|
+
* },
|
|
1340
|
+
* {
|
|
1341
|
+
* "x-customer-group-id": "01H9XYZ12345USERID" // Override default SDK config
|
|
1342
|
+
* }
|
|
1343
|
+
* );
|
|
1344
|
+
* ```
|
|
1011
1345
|
*/
|
|
1012
1346
|
async searchProducts(searchData, headers) {
|
|
1013
1347
|
const mergedHeaders = this.mergeHeaders(headers);
|
|
1014
1348
|
return this.executeRequest(
|
|
1015
1349
|
() => this.client.POST("/catalog/products/search", {
|
|
1016
|
-
|
|
1017
|
-
|
|
1350
|
+
params: {
|
|
1351
|
+
header: mergedHeaders
|
|
1352
|
+
},
|
|
1353
|
+
body: searchData
|
|
1018
1354
|
})
|
|
1019
1355
|
);
|
|
1020
1356
|
}
|
|
1021
1357
|
/**
|
|
1022
1358
|
* List cross-sell products
|
|
1023
1359
|
*
|
|
1024
|
-
* @param options - Optional query parameters
|
|
1360
|
+
* @param options - Optional query parameters for filtering and pagination
|
|
1025
1361
|
* @param headers - Optional header parameters (customer_group_id, etc.)
|
|
1026
1362
|
* @returns Promise with cross-sell products
|
|
1363
|
+
* @example
|
|
1364
|
+
* ```typescript
|
|
1365
|
+
* // Basic usage - get cross-sell products for cart items
|
|
1366
|
+
* const { data, error } = await sdk.catalog.listCrossSellProducts({
|
|
1367
|
+
* product_id: ["prod_01H9XYZ12345ABCDE", "prod_01H9ABC67890FGHIJ"]
|
|
1368
|
+
* });
|
|
1369
|
+
*
|
|
1370
|
+
* // Advanced usage with pagination and custom sorting
|
|
1371
|
+
* const { data, error } = await sdk.catalog.listCrossSellProducts({
|
|
1372
|
+
* product_id: ["prod_01H9XYZ12345ABCDE"],
|
|
1373
|
+
* page: 1,
|
|
1374
|
+
* limit: 10,
|
|
1375
|
+
* sort_by: '{"price":"asc"}'
|
|
1376
|
+
* });
|
|
1377
|
+
*
|
|
1378
|
+
* // Override customer group ID for this specific request
|
|
1379
|
+
* const { data, error } = await sdk.catalog.listCrossSellProducts(
|
|
1380
|
+
* {
|
|
1381
|
+
* product_id: ["prod_01H9XYZ12345ABCDE"],
|
|
1382
|
+
* page: 1,
|
|
1383
|
+
* limit: 10
|
|
1384
|
+
* },
|
|
1385
|
+
* {
|
|
1386
|
+
* "x-customer-group-id": "01H9XYZ12345USERID" // Override default SDK config
|
|
1387
|
+
* }
|
|
1388
|
+
* );
|
|
1389
|
+
*
|
|
1390
|
+
* if (error) {
|
|
1391
|
+
* console.error("Failed to get cross-sell products:", error.message);
|
|
1392
|
+
* } else {
|
|
1393
|
+
* console.log("Cross-sell products found:", data.content.products.length);
|
|
1394
|
+
* console.log("Pagination:", data.content.pagination);
|
|
1395
|
+
*
|
|
1396
|
+
* data.content.products.forEach(product => {
|
|
1397
|
+
* console.log(`Product: ${product.name} - ${product.price}`);
|
|
1398
|
+
* });
|
|
1399
|
+
* }
|
|
1400
|
+
* ```
|
|
1027
1401
|
*/
|
|
1028
1402
|
async listCrossSellProducts(options, headers) {
|
|
1029
1403
|
const mergedHeaders = this.mergeHeaders(headers);
|
|
@@ -1039,9 +1413,47 @@ var CatalogClient = class extends StorefrontAPIClient {
|
|
|
1039
1413
|
/**
|
|
1040
1414
|
* List up-sell products
|
|
1041
1415
|
*
|
|
1042
|
-
* @param options - Optional query parameters
|
|
1416
|
+
* @param options - Optional query parameters for filtering and pagination
|
|
1043
1417
|
* @param headers - Optional header parameters (customer_group_id, etc.)
|
|
1044
1418
|
* @returns Promise with up-sell products
|
|
1419
|
+
* @example
|
|
1420
|
+
* ```typescript
|
|
1421
|
+
* // Basic usage - get up-sell products for cart items
|
|
1422
|
+
* const { data, error } = await sdk.catalog.listUpSellProducts({
|
|
1423
|
+
* product_id: ["prod_01H9XYZ12345ABCDE"]
|
|
1424
|
+
* });
|
|
1425
|
+
*
|
|
1426
|
+
* // Advanced usage with pagination and custom sorting
|
|
1427
|
+
* const { data, error } = await sdk.catalog.listUpSellProducts({
|
|
1428
|
+
* product_id: ["prod_01H9XYZ12345ABCDE"],
|
|
1429
|
+
* page: 1,
|
|
1430
|
+
* limit: 15,
|
|
1431
|
+
* sort_by: '{"relevance":"desc"}'
|
|
1432
|
+
* });
|
|
1433
|
+
*
|
|
1434
|
+
* // Override customer group ID for this specific request
|
|
1435
|
+
* const { data, error } = await sdk.catalog.listUpSellProducts(
|
|
1436
|
+
* {
|
|
1437
|
+
* product_id: ["prod_01H9XYZ12345ABCDE"],
|
|
1438
|
+
* page: 1,
|
|
1439
|
+
* limit: 15
|
|
1440
|
+
* },
|
|
1441
|
+
* {
|
|
1442
|
+
* "x-customer-group-id": "01H9XYZ12345USERID" // Override default SDK config
|
|
1443
|
+
* }
|
|
1444
|
+
* );
|
|
1445
|
+
*
|
|
1446
|
+
* if (error) {
|
|
1447
|
+
* console.error("Failed to get up-sell products:", error.message);
|
|
1448
|
+
* } else {
|
|
1449
|
+
* console.log("Up-sell products found:", data.content.products.length);
|
|
1450
|
+
* console.log("Pagination:", data.content.pagination);
|
|
1451
|
+
*
|
|
1452
|
+
* data.content.products.forEach(product => {
|
|
1453
|
+
* console.log(`Up-sell: ${product.name} - ${product.price}`);
|
|
1454
|
+
* });
|
|
1455
|
+
* }
|
|
1456
|
+
* ```
|
|
1045
1457
|
*/
|
|
1046
1458
|
async listUpSellProducts(options, headers) {
|
|
1047
1459
|
const mergedHeaders = this.mergeHeaders(headers);
|
|
@@ -1057,9 +1469,47 @@ var CatalogClient = class extends StorefrontAPIClient {
|
|
|
1057
1469
|
/**
|
|
1058
1470
|
* List similar products
|
|
1059
1471
|
*
|
|
1060
|
-
* @param options - Optional query parameters
|
|
1472
|
+
* @param options - Optional query parameters for filtering and pagination
|
|
1061
1473
|
* @param headers - Optional header parameters (customer_group_id, etc.)
|
|
1062
1474
|
* @returns Promise with similar products
|
|
1475
|
+
* @example
|
|
1476
|
+
* ```typescript
|
|
1477
|
+
* // Basic usage - get similar products for a specific product
|
|
1478
|
+
* const { data, error } = await sdk.catalog.listSimilarProducts({
|
|
1479
|
+
* product_id: ["prod_01H9XYZ12345ABCDE"]
|
|
1480
|
+
* });
|
|
1481
|
+
*
|
|
1482
|
+
* // Advanced usage with pagination and custom sorting
|
|
1483
|
+
* const { data, error } = await sdk.catalog.listSimilarProducts({
|
|
1484
|
+
* product_id: ["prod_01H9XYZ12345ABCDE"],
|
|
1485
|
+
* page: 1,
|
|
1486
|
+
* limit: 20,
|
|
1487
|
+
* sort_by: '{"relevance":"desc"}'
|
|
1488
|
+
* });
|
|
1489
|
+
*
|
|
1490
|
+
* // Override customer group ID for this specific request
|
|
1491
|
+
* const { data, error } = await sdk.catalog.listSimilarProducts(
|
|
1492
|
+
* {
|
|
1493
|
+
* product_id: ["prod_01H9XYZ12345ABCDE"],
|
|
1494
|
+
* page: 1,
|
|
1495
|
+
* limit: 20
|
|
1496
|
+
* },
|
|
1497
|
+
* {
|
|
1498
|
+
* "x-customer-group-id": "01H9XYZ12345USERID" // Override default SDK config
|
|
1499
|
+
* }
|
|
1500
|
+
* );
|
|
1501
|
+
*
|
|
1502
|
+
* if (error) {
|
|
1503
|
+
* console.error("Failed to get similar products:", error.message);
|
|
1504
|
+
* } else {
|
|
1505
|
+
* console.log("Similar products found:", data.content.products.length);
|
|
1506
|
+
* console.log("Pagination:", data.content.pagination);
|
|
1507
|
+
*
|
|
1508
|
+
* data.content.products.forEach(product => {
|
|
1509
|
+
* console.log(`Similar: ${product.name} - ${product.price}`);
|
|
1510
|
+
* });
|
|
1511
|
+
* }
|
|
1512
|
+
* ```
|
|
1063
1513
|
*/
|
|
1064
1514
|
async listSimilarProducts(options, headers) {
|
|
1065
1515
|
const mergedHeaders = this.mergeHeaders(headers);
|
|
@@ -1081,6 +1531,33 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
1081
1531
|
*
|
|
1082
1532
|
* @param payload - Object containing the items to add to the cart
|
|
1083
1533
|
* @returns Promise with the created cart
|
|
1534
|
+
* @example
|
|
1535
|
+
* ```typescript
|
|
1536
|
+
* const { data, error } = await sdk.cart.createCart({
|
|
1537
|
+
* items: [
|
|
1538
|
+
* {
|
|
1539
|
+
* product_id: "01H9XYZ12345ABCDE",
|
|
1540
|
+
* variant_id: null,
|
|
1541
|
+
* quantity: 2
|
|
1542
|
+
* },
|
|
1543
|
+
* {
|
|
1544
|
+
* product_id: "01H9ABC67890FGHIJ",
|
|
1545
|
+
* variant_id: "01H9XYZ67890KLMNO",
|
|
1546
|
+
* quantity: 1
|
|
1547
|
+
* }
|
|
1548
|
+
* ],
|
|
1549
|
+
* metadata: {
|
|
1550
|
+
* "source": "web",
|
|
1551
|
+
* "campaign": "summer_sale"
|
|
1552
|
+
* }
|
|
1553
|
+
* });
|
|
1554
|
+
*
|
|
1555
|
+
* if (error) {
|
|
1556
|
+
* console.error("Failed to create cart:", error.message);
|
|
1557
|
+
* } else {
|
|
1558
|
+
* console.log("Cart created:", data.cart.id);
|
|
1559
|
+
* }
|
|
1560
|
+
* ```
|
|
1084
1561
|
*/
|
|
1085
1562
|
async createCart(payload) {
|
|
1086
1563
|
return this.executeRequest(
|
|
@@ -1094,6 +1571,20 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
1094
1571
|
*
|
|
1095
1572
|
* @param cartId - The ID of the cart
|
|
1096
1573
|
* @returns Promise with cart details
|
|
1574
|
+
* @example
|
|
1575
|
+
* ```typescript
|
|
1576
|
+
* const { data, error } = await sdk.cart.getCart({
|
|
1577
|
+
* id: "01H9CART12345ABCDE"
|
|
1578
|
+
* });
|
|
1579
|
+
*
|
|
1580
|
+
* if (error) {
|
|
1581
|
+
* console.error("Failed to get cart:", error.message);
|
|
1582
|
+
* } else {
|
|
1583
|
+
* const cart = data.cart;
|
|
1584
|
+
* console.log("Cart total:", cart.total_amount);
|
|
1585
|
+
* console.log("Items count:", cart.items.length);
|
|
1586
|
+
* }
|
|
1587
|
+
* ```
|
|
1097
1588
|
*/
|
|
1098
1589
|
async getCart(cartId) {
|
|
1099
1590
|
return this.executeRequest(
|
|
@@ -1109,6 +1600,18 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
1109
1600
|
*
|
|
1110
1601
|
* @param cartId - The ID of the cart
|
|
1111
1602
|
* @returns Promise that resolves when the cart is deleted
|
|
1603
|
+
* @example
|
|
1604
|
+
* ```typescript
|
|
1605
|
+
* const { data, error } = await sdk.cart.deleteCart({
|
|
1606
|
+
* id: "01H9CART12345ABCDE"
|
|
1607
|
+
* });
|
|
1608
|
+
*
|
|
1609
|
+
* if (error) {
|
|
1610
|
+
* console.error("Failed to delete cart:", error.message);
|
|
1611
|
+
* } else {
|
|
1612
|
+
* console.log("Cart deleted:", data.message);
|
|
1613
|
+
* }
|
|
1614
|
+
* ```
|
|
1112
1615
|
*/
|
|
1113
1616
|
async deleteCart(cartId) {
|
|
1114
1617
|
return this.executeRequest(
|
|
@@ -1125,6 +1628,34 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
1125
1628
|
* @param cartId - The cart id
|
|
1126
1629
|
* @param body - The body of the request
|
|
1127
1630
|
* @returns Promise with updated cart
|
|
1631
|
+
* @example
|
|
1632
|
+
* ```typescript
|
|
1633
|
+
* // Add item to cart
|
|
1634
|
+
* const { data, error } = await sdk.cart.addDeleteCartItem(
|
|
1635
|
+
* { id: "01H9CART12345ABCDE" },
|
|
1636
|
+
* {
|
|
1637
|
+
* product_id: "01H9XYZ12345ABCDE",
|
|
1638
|
+
* variant_id: null,
|
|
1639
|
+
* quantity: 3
|
|
1640
|
+
* }
|
|
1641
|
+
* );
|
|
1642
|
+
*
|
|
1643
|
+
* if (error) {
|
|
1644
|
+
* console.error("Failed to update cart:", error.message);
|
|
1645
|
+
* } else {
|
|
1646
|
+
* console.log("Cart updated:", data.cart.items.length);
|
|
1647
|
+
* }
|
|
1648
|
+
*
|
|
1649
|
+
* // Remove item from cart (set quantity to 0)
|
|
1650
|
+
* const { data: removeData, error: removeError } = await sdk.cart.addDeleteCartItem(
|
|
1651
|
+
* { id: "01H9CART12345ABCDE" },
|
|
1652
|
+
* {
|
|
1653
|
+
* product_id: "01H9XYZ12345ABCDE",
|
|
1654
|
+
* variant_id: null,
|
|
1655
|
+
* quantity: 0
|
|
1656
|
+
* }
|
|
1657
|
+
* );
|
|
1658
|
+
* ```
|
|
1128
1659
|
*/
|
|
1129
1660
|
async addDeleteCartItem(cartId, body) {
|
|
1130
1661
|
return this.executeRequest(
|
|
@@ -1141,6 +1672,19 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
1141
1672
|
*
|
|
1142
1673
|
* @param userId - The ID of the user
|
|
1143
1674
|
* @returns Promise with cart details
|
|
1675
|
+
* @example
|
|
1676
|
+
* ```typescript
|
|
1677
|
+
* const { data, error } = await sdk.cart.getUserCart({
|
|
1678
|
+
* user_id: "01H9USER12345ABCDE"
|
|
1679
|
+
* });
|
|
1680
|
+
*
|
|
1681
|
+
* if (error) {
|
|
1682
|
+
* console.error("Failed to get user cart:", error.message);
|
|
1683
|
+
* } else {
|
|
1684
|
+
* console.log("User cart ID:", data.cart.id);
|
|
1685
|
+
* console.log("Cart value:", data.cart.subtotal_amount);
|
|
1686
|
+
* }
|
|
1687
|
+
* ```
|
|
1144
1688
|
*/
|
|
1145
1689
|
async getUserCart(userId) {
|
|
1146
1690
|
return this.executeRequest(
|
|
@@ -1156,6 +1700,18 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
1156
1700
|
*
|
|
1157
1701
|
* @param userId - The ID of the user
|
|
1158
1702
|
* @returns Promise that resolves when the cart is deleted
|
|
1703
|
+
* @example
|
|
1704
|
+
* ```typescript
|
|
1705
|
+
* const { data, error } = await sdk.cart.deleteUserCart({
|
|
1706
|
+
* user_id: "01H9USER12345ABCDE"
|
|
1707
|
+
* });
|
|
1708
|
+
*
|
|
1709
|
+
* if (error) {
|
|
1710
|
+
* console.error("Failed to delete user cart:", error.message);
|
|
1711
|
+
* } else {
|
|
1712
|
+
* console.log("User cart cleared:", data.message);
|
|
1713
|
+
* }
|
|
1714
|
+
* ```
|
|
1159
1715
|
*/
|
|
1160
1716
|
async deleteUserCart(userId) {
|
|
1161
1717
|
return this.executeRequest(
|
|
@@ -1173,6 +1729,62 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
1173
1729
|
* @param cartId - The ID of the cart
|
|
1174
1730
|
* @param addressData - The address data
|
|
1175
1731
|
* @returns Promise with updated cart
|
|
1732
|
+
* @example
|
|
1733
|
+
* ```typescript
|
|
1734
|
+
* // For registered users with saved addresses
|
|
1735
|
+
* const { data, error } = await sdk.cart.updateCartAddress(
|
|
1736
|
+
* { id: "01H9CART12345ABCDE" },
|
|
1737
|
+
* {
|
|
1738
|
+
* billing_address_id: "01H9ADDR12345BILL",
|
|
1739
|
+
* shipping_address_id: "01H9ADDR12345SHIP"
|
|
1740
|
+
* }
|
|
1741
|
+
* );
|
|
1742
|
+
*
|
|
1743
|
+
* if (error) {
|
|
1744
|
+
* console.error("Failed to update cart address:", error.message);
|
|
1745
|
+
* } else {
|
|
1746
|
+
* console.log("Addresses updated:", data.message);
|
|
1747
|
+
* }
|
|
1748
|
+
*
|
|
1749
|
+
* // For guest checkout with new addresses
|
|
1750
|
+
* const { data: guestData, error: guestError } = await sdk.cart.updateCartAddress(
|
|
1751
|
+
* { id: "01H9CART12345ABCDE" },
|
|
1752
|
+
* {
|
|
1753
|
+
* billing_address: {
|
|
1754
|
+
* first_name: "John",
|
|
1755
|
+
* last_name: "Doe",
|
|
1756
|
+
* email: "john@example.com",
|
|
1757
|
+
* phone: "9876543210",
|
|
1758
|
+
* country_code: "+91",
|
|
1759
|
+
* address_line1: "123 Main Street",
|
|
1760
|
+
* address_line2: "Apt 4B",
|
|
1761
|
+
* city: "Mumbai",
|
|
1762
|
+
* state: "Maharashtra",
|
|
1763
|
+
* pincode: "400001",
|
|
1764
|
+
* country: "India",
|
|
1765
|
+
* landmark: "Near Station",
|
|
1766
|
+
* tax_identification_number: null,
|
|
1767
|
+
* business_name: null
|
|
1768
|
+
* },
|
|
1769
|
+
* shipping_address: {
|
|
1770
|
+
* first_name: "John",
|
|
1771
|
+
* last_name: "Doe",
|
|
1772
|
+
* email: "john@example.com",
|
|
1773
|
+
* phone: "9876543210",
|
|
1774
|
+
* country_code: "+91",
|
|
1775
|
+
* address_line1: "456 Oak Avenue",
|
|
1776
|
+
* address_line2: null,
|
|
1777
|
+
* city: "Pune",
|
|
1778
|
+
* state: "Maharashtra",
|
|
1779
|
+
* pincode: "411001",
|
|
1780
|
+
* country: "India",
|
|
1781
|
+
* landmark: "Near Mall",
|
|
1782
|
+
* tax_identification_number: null,
|
|
1783
|
+
* business_name: null
|
|
1784
|
+
* }
|
|
1785
|
+
* }
|
|
1786
|
+
* );
|
|
1787
|
+
* ```
|
|
1176
1788
|
*/
|
|
1177
1789
|
async updateCartAddress(cartId, addressData) {
|
|
1178
1790
|
return this.executeRequest(
|
|
@@ -1190,6 +1802,20 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
1190
1802
|
* @param cartId - The ID of the cart
|
|
1191
1803
|
* @param couponCode - The coupon code
|
|
1192
1804
|
* @returns Promise with updated cart
|
|
1805
|
+
* @example
|
|
1806
|
+
* ```typescript
|
|
1807
|
+
* const { data, error } = await sdk.cart.applyCoupon(
|
|
1808
|
+
* { id: "01H9CART12345ABCDE" },
|
|
1809
|
+
* { coupon_code: "FLAT100OFF" }
|
|
1810
|
+
* );
|
|
1811
|
+
*
|
|
1812
|
+
* if (error) {
|
|
1813
|
+
* console.error("Failed to apply coupon:", error.message);
|
|
1814
|
+
* } else {
|
|
1815
|
+
* console.log("Coupon applied, new total:", data.cart.total_amount);
|
|
1816
|
+
* console.log("Discount amount:", data.cart.coupon_discount_amount);
|
|
1817
|
+
* }
|
|
1818
|
+
* ```
|
|
1193
1819
|
*/
|
|
1194
1820
|
async applyCoupon(cartId, couponCode) {
|
|
1195
1821
|
return this.executeRequest(
|
|
@@ -1206,6 +1832,18 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
1206
1832
|
*
|
|
1207
1833
|
* @param cartId - The ID of the cart
|
|
1208
1834
|
* @returns Promise with updated cart
|
|
1835
|
+
* @example
|
|
1836
|
+
* ```typescript
|
|
1837
|
+
* const { data, error } = await sdk.cart.removeCoupon({
|
|
1838
|
+
* id: "01H9CART12345ABCDE"
|
|
1839
|
+
* });
|
|
1840
|
+
*
|
|
1841
|
+
* if (error) {
|
|
1842
|
+
* console.error("Failed to remove coupon:", error.message);
|
|
1843
|
+
* } else {
|
|
1844
|
+
* console.log("Coupon removed, new total:", data.cart.total_amount);
|
|
1845
|
+
* }
|
|
1846
|
+
* ```
|
|
1209
1847
|
*/
|
|
1210
1848
|
async removeCoupon(cartId) {
|
|
1211
1849
|
return this.executeRequest(
|
|
@@ -1223,6 +1861,20 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
1223
1861
|
* @param cartId - The ID of the cart
|
|
1224
1862
|
* @param points - The number of points to redeem
|
|
1225
1863
|
* @returns Promise with updated cart
|
|
1864
|
+
* @example
|
|
1865
|
+
* ```typescript
|
|
1866
|
+
* const { data, error } = await sdk.cart.redeemLoyaltyPoints(
|
|
1867
|
+
* { id: "01H9CART12345ABCDE" },
|
|
1868
|
+
* { points: 500 }
|
|
1869
|
+
* );
|
|
1870
|
+
*
|
|
1871
|
+
* if (error) {
|
|
1872
|
+
* console.error("Failed to redeem loyalty points:", error.message);
|
|
1873
|
+
* } else {
|
|
1874
|
+
* console.log("Points redeemed, new total:", data.cart.total_amount);
|
|
1875
|
+
* console.log("Points discount:", data.cart.loyalty_points_discount_amount);
|
|
1876
|
+
* }
|
|
1877
|
+
* ```
|
|
1226
1878
|
*/
|
|
1227
1879
|
async redeemLoyaltyPoints(cartId, points) {
|
|
1228
1880
|
return this.executeRequest(
|
|
@@ -1239,6 +1891,18 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
1239
1891
|
*
|
|
1240
1892
|
* @param cartId - The ID of the cart
|
|
1241
1893
|
* @returns Promise with updated cart
|
|
1894
|
+
* @example
|
|
1895
|
+
* ```typescript
|
|
1896
|
+
* const { data, error } = await sdk.cart.removeLoyaltyPoints({
|
|
1897
|
+
* id: "01H9CART12345ABCDE"
|
|
1898
|
+
* });
|
|
1899
|
+
*
|
|
1900
|
+
* if (error) {
|
|
1901
|
+
* console.error("Failed to remove loyalty points:", error.message);
|
|
1902
|
+
* } else {
|
|
1903
|
+
* console.log("Loyalty points removed, new total:", data.cart.total_amount);
|
|
1904
|
+
* }
|
|
1905
|
+
* ```
|
|
1242
1906
|
*/
|
|
1243
1907
|
async removeLoyaltyPoints(cartId) {
|
|
1244
1908
|
return this.executeRequest(
|
|
@@ -1256,6 +1920,23 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
1256
1920
|
* @param cartId - The ID of the cart
|
|
1257
1921
|
* @param body - The body of the request
|
|
1258
1922
|
* @returns Promise with updated cart
|
|
1923
|
+
* @example
|
|
1924
|
+
* ```typescript
|
|
1925
|
+
* const { data, error } = await sdk.cart.updateShippingMethod(
|
|
1926
|
+
* { id: "01H9CART12345ABCDE" },
|
|
1927
|
+
* {
|
|
1928
|
+
* shipping_method_id: "01H9SHIP12345FAST",
|
|
1929
|
+
* estimated_delivery_date: "2024-01-15"
|
|
1930
|
+
* }
|
|
1931
|
+
* );
|
|
1932
|
+
*
|
|
1933
|
+
* if (error) {
|
|
1934
|
+
* console.error("Failed to update shipping method:", error.message);
|
|
1935
|
+
* } else {
|
|
1936
|
+
* console.log("Shipping method updated:", data.cart.shipping_method?.name);
|
|
1937
|
+
* console.log("Shipping cost:", data.cart.shipping_cost);
|
|
1938
|
+
* }
|
|
1939
|
+
* ```
|
|
1259
1940
|
*/
|
|
1260
1941
|
async updateShippingMethod(cartId, body) {
|
|
1261
1942
|
return this.executeRequest(
|
|
@@ -1273,6 +1954,20 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
1273
1954
|
* @param cartId - The ID of the cart
|
|
1274
1955
|
* @param body - The body of the request
|
|
1275
1956
|
* @returns Promise with updated cart
|
|
1957
|
+
* @example
|
|
1958
|
+
* ```typescript
|
|
1959
|
+
* const { data, error } = await sdk.cart.redeemCreditBalance(
|
|
1960
|
+
* { id: "01H9CART12345ABCDE" },
|
|
1961
|
+
* { amount: 250.00 }
|
|
1962
|
+
* );
|
|
1963
|
+
*
|
|
1964
|
+
* if (error) {
|
|
1965
|
+
* console.error("Failed to redeem credit balance:", error.message);
|
|
1966
|
+
* } else {
|
|
1967
|
+
* console.log("Credit applied, new total:", data.cart.total_amount);
|
|
1968
|
+
* console.log("Credit discount:", data.cart.credit_balance_discount_amount);
|
|
1969
|
+
* }
|
|
1970
|
+
* ```
|
|
1276
1971
|
*/
|
|
1277
1972
|
async redeemCreditBalance(cartId, body) {
|
|
1278
1973
|
return this.executeRequest(
|
|
@@ -1289,6 +1984,18 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
1289
1984
|
*
|
|
1290
1985
|
* @param cartId - The ID of the cart
|
|
1291
1986
|
* @returns Promise with updated cart
|
|
1987
|
+
* @example
|
|
1988
|
+
* ```typescript
|
|
1989
|
+
* const { data, error } = await sdk.cart.removeCreditBalance({
|
|
1990
|
+
* id: "01H9CART12345ABCDE"
|
|
1991
|
+
* });
|
|
1992
|
+
*
|
|
1993
|
+
* if (error) {
|
|
1994
|
+
* console.error("Failed to remove credit balance:", error.message);
|
|
1995
|
+
* } else {
|
|
1996
|
+
* console.log("Credit balance removed, new total:", data.cart.total_amount);
|
|
1997
|
+
* }
|
|
1998
|
+
* ```
|
|
1292
1999
|
*/
|
|
1293
2000
|
async removeCreditBalance(cartId) {
|
|
1294
2001
|
return this.executeRequest(
|
|
@@ -1306,6 +2013,23 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
1306
2013
|
* @param cartId - The ID of the cart
|
|
1307
2014
|
* @param body - The body of the request
|
|
1308
2015
|
* @returns Promise with updated cart
|
|
2016
|
+
* @example
|
|
2017
|
+
* ```typescript
|
|
2018
|
+
* const { data, error } = await sdk.cart.redeemGiftCard(
|
|
2019
|
+
* { id: "01H9CART12345ABCDE" },
|
|
2020
|
+
* {
|
|
2021
|
+
* gift_card_code: "GIFT2024-ABCD-1234",
|
|
2022
|
+
* amount: 100.00
|
|
2023
|
+
* }
|
|
2024
|
+
* );
|
|
2025
|
+
*
|
|
2026
|
+
* if (error) {
|
|
2027
|
+
* console.error("Failed to redeem gift card:", error.message);
|
|
2028
|
+
* } else {
|
|
2029
|
+
* console.log("Gift card applied, new total:", data.cart.total_amount);
|
|
2030
|
+
* console.log("Gift card discount:", data.cart.gift_card_discount_amount);
|
|
2031
|
+
* }
|
|
2032
|
+
* ```
|
|
1309
2033
|
*/
|
|
1310
2034
|
async redeemGiftCard(cartId, body) {
|
|
1311
2035
|
return this.executeRequest(
|
|
@@ -1322,6 +2046,18 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
1322
2046
|
*
|
|
1323
2047
|
* @param cartId - The ID of the cart
|
|
1324
2048
|
* @returns Promise with updated cart
|
|
2049
|
+
* @example
|
|
2050
|
+
* ```typescript
|
|
2051
|
+
* const { data, error } = await sdk.cart.removeGiftCard({
|
|
2052
|
+
* id: "01H9CART12345ABCDE"
|
|
2053
|
+
* });
|
|
2054
|
+
*
|
|
2055
|
+
* if (error) {
|
|
2056
|
+
* console.error("Failed to remove gift card:", error.message);
|
|
2057
|
+
* } else {
|
|
2058
|
+
* console.log("Gift card removed, new total:", data.cart.total_amount);
|
|
2059
|
+
* }
|
|
2060
|
+
* ```
|
|
1325
2061
|
*/
|
|
1326
2062
|
async removeGiftCard(cartId) {
|
|
1327
2063
|
return this.executeRequest(
|
|
@@ -1338,6 +2074,22 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
1338
2074
|
*
|
|
1339
2075
|
* @param userId - The ID of the user
|
|
1340
2076
|
* @returns Promise with wishlist items
|
|
2077
|
+
* @example
|
|
2078
|
+
* ```typescript
|
|
2079
|
+
* const { data, error } = await sdk.cart.getWishlist({
|
|
2080
|
+
* user_id: "01H9USER12345ABCDE"
|
|
2081
|
+
* });
|
|
2082
|
+
*
|
|
2083
|
+
* if (error) {
|
|
2084
|
+
* console.error("Failed to get wishlist:", error.message);
|
|
2085
|
+
* } else {
|
|
2086
|
+
* const products = data.products;
|
|
2087
|
+
* console.log("Wishlist items:", products.length);
|
|
2088
|
+
* products.forEach(product => {
|
|
2089
|
+
* console.log("Product:", product.name, "Price:", product.price);
|
|
2090
|
+
* });
|
|
2091
|
+
* }
|
|
2092
|
+
* ```
|
|
1341
2093
|
*/
|
|
1342
2094
|
async getWishlist(userId) {
|
|
1343
2095
|
return this.executeRequest(
|
|
@@ -1354,6 +2106,23 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
1354
2106
|
* @param userId - The ID of the user
|
|
1355
2107
|
* @param itemId - The ID of the item
|
|
1356
2108
|
* @returns Promise with updated wishlist
|
|
2109
|
+
* @example
|
|
2110
|
+
* ```typescript
|
|
2111
|
+
* const { data, error } = await sdk.cart.addToWishlist(
|
|
2112
|
+
* { user_id: "01H9USER12345ABCDE" },
|
|
2113
|
+
* {
|
|
2114
|
+
* product_id: "01F3Z7KG06J4ACWH1C4926KJEC",
|
|
2115
|
+
* variant_id: null
|
|
2116
|
+
* }
|
|
2117
|
+
* );
|
|
2118
|
+
*
|
|
2119
|
+
* if (error) {
|
|
2120
|
+
* console.error("Failed to add to wishlist:", error.message);
|
|
2121
|
+
* } else {
|
|
2122
|
+
* const products = data.products;
|
|
2123
|
+
* console.log("Item added to wishlist, total items:", products.length);
|
|
2124
|
+
* }
|
|
2125
|
+
* ```
|
|
1357
2126
|
*/
|
|
1358
2127
|
async addToWishlist(userId, itemId) {
|
|
1359
2128
|
return this.executeRequest(
|
|
@@ -1369,8 +2138,25 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
1369
2138
|
* Remove item from wishlist
|
|
1370
2139
|
*
|
|
1371
2140
|
* @param userId - The ID of the user
|
|
1372
|
-
* @param
|
|
2141
|
+
* @param body - The body containing product details to remove
|
|
1373
2142
|
* @returns Promise with updated wishlist
|
|
2143
|
+
* @example
|
|
2144
|
+
* ```typescript
|
|
2145
|
+
* const { data, error } = await sdk.cart.removeFromWishlist(
|
|
2146
|
+
* { user_id: "01H9USER12345ABCDE" },
|
|
2147
|
+
* {
|
|
2148
|
+
* product_id: "01F3Z7KG06J4ACWH1C4926KJEC",
|
|
2149
|
+
* variant_id: null
|
|
2150
|
+
* }
|
|
2151
|
+
* );
|
|
2152
|
+
*
|
|
2153
|
+
* if (error) {
|
|
2154
|
+
* console.error("Failed to remove from wishlist:", error.message);
|
|
2155
|
+
* } else {
|
|
2156
|
+
* const products = data.products;
|
|
2157
|
+
* console.log("Item removed from wishlist, remaining items:", products.length);
|
|
2158
|
+
* }
|
|
2159
|
+
* ```
|
|
1374
2160
|
*/
|
|
1375
2161
|
async removeFromWishlist(userId, body) {
|
|
1376
2162
|
return this.executeRequest(
|
|
@@ -1387,6 +2173,26 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
1387
2173
|
*
|
|
1388
2174
|
* @param headers - Optional header parameters (customer_group_id, etc.)
|
|
1389
2175
|
* @returns Promise with all available coupons
|
|
2176
|
+
* @example
|
|
2177
|
+
* ```typescript
|
|
2178
|
+
* // Get all available coupons
|
|
2179
|
+
* const { data, error } = await sdk.cart.getAvailableCoupons();
|
|
2180
|
+
*
|
|
2181
|
+
* if (error) {
|
|
2182
|
+
* console.error("Failed to get available coupons:", error.message);
|
|
2183
|
+
* } else {
|
|
2184
|
+
* const coupons = data.coupons || [];
|
|
2185
|
+
* console.log("Available coupons:", coupons.length);
|
|
2186
|
+
* coupons.forEach(coupon => {
|
|
2187
|
+
* console.log("Coupon:", coupon.code, "Discount:", coupon.discount_amount);
|
|
2188
|
+
* });
|
|
2189
|
+
* }
|
|
2190
|
+
*
|
|
2191
|
+
* // Override customer group ID for this specific request
|
|
2192
|
+
* const { data: overrideData, error: overrideError } = await sdk.cart.getAvailableCoupons({
|
|
2193
|
+
* "x-customer-group-id": "01H9GROUP12345ABC" // Override default SDK config
|
|
2194
|
+
* });
|
|
2195
|
+
* ```
|
|
1390
2196
|
*/
|
|
1391
2197
|
async getAvailableCoupons(headers) {
|
|
1392
2198
|
const mergedHeaders = this.mergeHeaders(headers);
|
|
@@ -1403,6 +2209,26 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
1403
2209
|
*
|
|
1404
2210
|
* @param headers - Optional header parameters (customer_group_id, etc.)
|
|
1405
2211
|
* @returns Promise with all available promotions
|
|
2212
|
+
* @example
|
|
2213
|
+
* ```typescript
|
|
2214
|
+
* // Get all available promotions
|
|
2215
|
+
* const { data, error } = await sdk.cart.getAvailablePromotions();
|
|
2216
|
+
*
|
|
2217
|
+
* if (error) {
|
|
2218
|
+
* console.error("Failed to get available promotions:", error.message);
|
|
2219
|
+
* } else {
|
|
2220
|
+
* const promotions = data.promotions || [];
|
|
2221
|
+
* console.log("Available promotions:", promotions.length);
|
|
2222
|
+
* promotions.forEach(promotion => {
|
|
2223
|
+
* console.log("Promotion:", promotion.name, "Type:", promotion.promotion_type);
|
|
2224
|
+
* });
|
|
2225
|
+
* }
|
|
2226
|
+
*
|
|
2227
|
+
* // Override customer group ID for this specific request
|
|
2228
|
+
* const { data: overrideData, error: overrideError } = await sdk.cart.getAvailablePromotions({
|
|
2229
|
+
* "x-customer-group-id": "01H9GROUP12345ABC" // Override default SDK config
|
|
2230
|
+
* });
|
|
2231
|
+
* ```
|
|
1406
2232
|
*/
|
|
1407
2233
|
async getAvailablePromotions(headers) {
|
|
1408
2234
|
const mergedHeaders = this.mergeHeaders(headers);
|
|
@@ -1419,6 +2245,29 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
1419
2245
|
*
|
|
1420
2246
|
* @param cartId - The ID of the cart
|
|
1421
2247
|
* @returns Promise with evaluated promotions
|
|
2248
|
+
* @example
|
|
2249
|
+
* ```typescript
|
|
2250
|
+
* const { data, error } = await sdk.cart.evaluatePromotions({
|
|
2251
|
+
* id: "01H9CART12345ABCDE"
|
|
2252
|
+
* });
|
|
2253
|
+
*
|
|
2254
|
+
* if (error) {
|
|
2255
|
+
* console.error("Failed to evaluate promotions:", error.message);
|
|
2256
|
+
* } else {
|
|
2257
|
+
* const applicable = data.applicable_promotions || [];
|
|
2258
|
+
* const inapplicable = data.inapplicable_promotions || [];
|
|
2259
|
+
*
|
|
2260
|
+
* console.log("Applicable promotions:", applicable.length);
|
|
2261
|
+
* applicable.forEach(promo => {
|
|
2262
|
+
* console.log(`- ${promo.name}: ${promo.savings_message}`);
|
|
2263
|
+
* });
|
|
2264
|
+
*
|
|
2265
|
+
* console.log("Inapplicable promotions:", inapplicable.length);
|
|
2266
|
+
* inapplicable.forEach(promo => {
|
|
2267
|
+
* console.log(`- ${promo.name}: ${promo.reason}`);
|
|
2268
|
+
* });
|
|
2269
|
+
* }
|
|
2270
|
+
* ```
|
|
1422
2271
|
*/
|
|
1423
2272
|
async evaluatePromotions(cartId) {
|
|
1424
2273
|
return this.executeRequest(
|
|
@@ -1434,6 +2283,29 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
1434
2283
|
*
|
|
1435
2284
|
* @param cartId - The ID of the cart
|
|
1436
2285
|
* @returns Promise with evaluated coupons
|
|
2286
|
+
* @example
|
|
2287
|
+
* ```typescript
|
|
2288
|
+
* const { data, error } = await sdk.cart.evaluateCoupons({
|
|
2289
|
+
* id: "01H9CART12345ABCDE"
|
|
2290
|
+
* });
|
|
2291
|
+
*
|
|
2292
|
+
* if (error) {
|
|
2293
|
+
* console.error("Failed to evaluate coupons:", error.message);
|
|
2294
|
+
* } else {
|
|
2295
|
+
* const applicable = data.applicable_coupons || [];
|
|
2296
|
+
* const inapplicable = data.inapplicable_coupons || [];
|
|
2297
|
+
*
|
|
2298
|
+
* console.log("Applicable coupons:", applicable.length);
|
|
2299
|
+
* applicable.forEach(coupon => {
|
|
2300
|
+
* console.log(`- ${coupon.code}: Save $${coupon.estimated_discount}`);
|
|
2301
|
+
* });
|
|
2302
|
+
*
|
|
2303
|
+
* console.log("Inapplicable coupons:", inapplicable.length);
|
|
2304
|
+
* inapplicable.forEach(coupon => {
|
|
2305
|
+
* console.log(`- ${coupon.code}: ${coupon.reason}`);
|
|
2306
|
+
* });
|
|
2307
|
+
* }
|
|
2308
|
+
* ```
|
|
1437
2309
|
*/
|
|
1438
2310
|
async evaluateCoupons(cartId) {
|
|
1439
2311
|
return this.executeRequest(
|
|
@@ -1450,19 +2322,45 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
1450
2322
|
var AuthClient = class extends StorefrontAPIClient {
|
|
1451
2323
|
/**
|
|
1452
2324
|
* Get anonymous token for guest users
|
|
2325
|
+
*
|
|
2326
|
+
* @example
|
|
2327
|
+
* ```typescript
|
|
2328
|
+
* // Get token for guest browsing
|
|
2329
|
+
* const { data, error } = await sdk.auth.getAnonymousToken();
|
|
2330
|
+
*
|
|
2331
|
+
* if (error) {
|
|
2332
|
+
* console.error("Failed to get anonymous token:", error.message);
|
|
2333
|
+
* } else {
|
|
2334
|
+
* console.log("Anonymous token:", data.access_token);
|
|
2335
|
+
* // Store token or proceed with guest operations
|
|
2336
|
+
* }
|
|
2337
|
+
* ```
|
|
1453
2338
|
*/
|
|
1454
2339
|
async getAnonymousToken() {
|
|
1455
|
-
return this.executeRequest(
|
|
1456
|
-
() => this.client.POST("/auth/anonymous")
|
|
1457
|
-
);
|
|
2340
|
+
return this.executeRequest(() => this.client.POST("/auth/anonymous"));
|
|
1458
2341
|
}
|
|
1459
2342
|
/**
|
|
1460
2343
|
* Login with phone number
|
|
1461
2344
|
*
|
|
1462
|
-
* @param
|
|
1463
|
-
* @
|
|
1464
|
-
* @
|
|
1465
|
-
*
|
|
2345
|
+
* @param body - Login request body containing phone number and options
|
|
2346
|
+
* @returns Promise with OTP token and action
|
|
2347
|
+
* @example
|
|
2348
|
+
* ```typescript
|
|
2349
|
+
* // Login with phone number
|
|
2350
|
+
* const { data, error } = await sdk.auth.loginWithPhone({
|
|
2351
|
+
* phoneNumber: "9876543210",
|
|
2352
|
+
* countryCode: "+91",
|
|
2353
|
+
* registerIfNotExists: true
|
|
2354
|
+
* });
|
|
2355
|
+
*
|
|
2356
|
+
* if (error) {
|
|
2357
|
+
* console.error("Login failed:", error.message);
|
|
2358
|
+
* } else {
|
|
2359
|
+
* console.log("OTP sent. Token:", data.otpToken);
|
|
2360
|
+
* console.log("Action:", data.action); // "login" or "register"
|
|
2361
|
+
* // Redirect user to OTP verification screen
|
|
2362
|
+
* }
|
|
2363
|
+
* ```
|
|
1466
2364
|
*/
|
|
1467
2365
|
async loginWithPhone(body) {
|
|
1468
2366
|
return this.executeRequest(
|
|
@@ -1474,10 +2372,24 @@ var AuthClient = class extends StorefrontAPIClient {
|
|
|
1474
2372
|
/**
|
|
1475
2373
|
* Login with WhatsApp
|
|
1476
2374
|
*
|
|
1477
|
-
* @param
|
|
1478
|
-
* @param countryCode - Country code (defaults to +91)
|
|
1479
|
-
* @param registerIfNotExists - Whether to register if user doesn't exist
|
|
2375
|
+
* @param body - Login request body containing phone number and options
|
|
1480
2376
|
* @returns Promise with OTP token and action
|
|
2377
|
+
* @example
|
|
2378
|
+
* ```typescript
|
|
2379
|
+
* // Login with WhatsApp number
|
|
2380
|
+
* const { data, error } = await sdk.auth.loginWithWhatsApp({
|
|
2381
|
+
* phone: "9876543210",
|
|
2382
|
+
* country_code: "+91",
|
|
2383
|
+
* register_if_not_exists: true
|
|
2384
|
+
* });
|
|
2385
|
+
*
|
|
2386
|
+
* if (error) {
|
|
2387
|
+
* console.error("WhatsApp login failed:", error.message);
|
|
2388
|
+
* } else {
|
|
2389
|
+
* console.log("OTP sent to WhatsApp. Token:", data.otp_token);
|
|
2390
|
+
* console.log("Action:", data.otp_action); // "login" or "register"
|
|
2391
|
+
* }
|
|
2392
|
+
* ```
|
|
1481
2393
|
*/
|
|
1482
2394
|
async loginWithWhatsApp(body) {
|
|
1483
2395
|
return this.executeRequest(
|
|
@@ -1489,9 +2401,24 @@ var AuthClient = class extends StorefrontAPIClient {
|
|
|
1489
2401
|
/**
|
|
1490
2402
|
* Login with email
|
|
1491
2403
|
*
|
|
1492
|
-
* @param
|
|
1493
|
-
* @param registerIfNotExists - Whether to register if user doesn't exist
|
|
2404
|
+
* @param body - Login request body containing email and options
|
|
1494
2405
|
* @returns Promise with OTP token and action
|
|
2406
|
+
* @example
|
|
2407
|
+
* ```typescript
|
|
2408
|
+
* // Login with email address
|
|
2409
|
+
* const { data, error } = await sdk.auth.loginWithEmail({
|
|
2410
|
+
* email: "customer@example.com",
|
|
2411
|
+
* registerIfNotExists: true
|
|
2412
|
+
* });
|
|
2413
|
+
*
|
|
2414
|
+
* if (error) {
|
|
2415
|
+
* console.error("Email login failed:", error.message);
|
|
2416
|
+
* } else {
|
|
2417
|
+
* console.log("OTP sent to email. Token:", data.otpToken);
|
|
2418
|
+
* console.log("Action:", data.action); // "login" or "register"
|
|
2419
|
+
* // Show OTP input form
|
|
2420
|
+
* }
|
|
2421
|
+
* ```
|
|
1495
2422
|
*/
|
|
1496
2423
|
async loginWithEmail(body) {
|
|
1497
2424
|
return this.executeRequest(
|
|
@@ -1503,8 +2430,23 @@ var AuthClient = class extends StorefrontAPIClient {
|
|
|
1503
2430
|
/**
|
|
1504
2431
|
* Login with password
|
|
1505
2432
|
*
|
|
1506
|
-
* @param
|
|
2433
|
+
* @param body - Login credentials containing email/phone and password
|
|
1507
2434
|
* @returns Promise with user info and tokens
|
|
2435
|
+
* @example
|
|
2436
|
+
* ```typescript
|
|
2437
|
+
* // Login with email and password
|
|
2438
|
+
* const { data, error } = await sdk.auth.loginWithPassword({
|
|
2439
|
+
* email: "customer@example.com",
|
|
2440
|
+
* password: "securePassword123"
|
|
2441
|
+
* });
|
|
2442
|
+
*
|
|
2443
|
+
* if (error) {
|
|
2444
|
+
* console.error("Password login failed:", error.message);
|
|
2445
|
+
* } else {
|
|
2446
|
+
* console.log("Login successful:", data.user.email);
|
|
2447
|
+
* console.log("Access token:", data.access_token);
|
|
2448
|
+
* }
|
|
2449
|
+
* ```
|
|
1508
2450
|
*/
|
|
1509
2451
|
async loginWithPassword(body) {
|
|
1510
2452
|
return this.executeRequest(
|
|
@@ -1516,8 +2458,22 @@ var AuthClient = class extends StorefrontAPIClient {
|
|
|
1516
2458
|
/**
|
|
1517
2459
|
* Forgot password
|
|
1518
2460
|
*
|
|
1519
|
-
* @param
|
|
1520
|
-
* @returns Promise with
|
|
2461
|
+
* @param body - Request body containing email address
|
|
2462
|
+
* @returns Promise with password reset information
|
|
2463
|
+
* @example
|
|
2464
|
+
* ```typescript
|
|
2465
|
+
* // Send password reset email
|
|
2466
|
+
* const { data, error } = await sdk.auth.forgotPassword({
|
|
2467
|
+
* email: "customer@example.com"
|
|
2468
|
+
* });
|
|
2469
|
+
*
|
|
2470
|
+
* if (error) {
|
|
2471
|
+
* console.error("Password reset failed:", error.message);
|
|
2472
|
+
* } else {
|
|
2473
|
+
* console.log("Reset email sent successfully");
|
|
2474
|
+
* // Show confirmation message to user
|
|
2475
|
+
* }
|
|
2476
|
+
* ```
|
|
1521
2477
|
*/
|
|
1522
2478
|
async forgotPassword(body) {
|
|
1523
2479
|
return this.executeRequest(
|
|
@@ -1529,8 +2485,24 @@ var AuthClient = class extends StorefrontAPIClient {
|
|
|
1529
2485
|
/**
|
|
1530
2486
|
* Reset password
|
|
1531
2487
|
*
|
|
1532
|
-
* @param
|
|
1533
|
-
* @returns Promise with
|
|
2488
|
+
* @param body - Reset password request body containing new password and OTP token
|
|
2489
|
+
* @returns Promise with new access and refresh tokens
|
|
2490
|
+
* @example
|
|
2491
|
+
* ```typescript
|
|
2492
|
+
* // Reset password with OTP token from forgot password flow
|
|
2493
|
+
* const { data, error } = await sdk.auth.resetPassword({
|
|
2494
|
+
* new_password: "newSecurePassword123",
|
|
2495
|
+
* confirm_password: "newSecurePassword123",
|
|
2496
|
+
* otp_token: "abc123otptoken"
|
|
2497
|
+
* });
|
|
2498
|
+
*
|
|
2499
|
+
* if (error) {
|
|
2500
|
+
* console.error("Password reset failed:", error.message);
|
|
2501
|
+
* } else {
|
|
2502
|
+
* console.log("Password reset successful");
|
|
2503
|
+
* console.log("New access token:", data.access_token);
|
|
2504
|
+
* }
|
|
2505
|
+
* ```
|
|
1534
2506
|
*/
|
|
1535
2507
|
async resetPassword(body) {
|
|
1536
2508
|
return this.executeRequest(
|
|
@@ -1542,10 +2514,24 @@ var AuthClient = class extends StorefrontAPIClient {
|
|
|
1542
2514
|
/**
|
|
1543
2515
|
* Change password
|
|
1544
2516
|
*
|
|
1545
|
-
* @param
|
|
1546
|
-
* @
|
|
1547
|
-
* @
|
|
1548
|
-
*
|
|
2517
|
+
* @param body - Change password request body containing old and new passwords
|
|
2518
|
+
* @returns Promise with new access and refresh tokens
|
|
2519
|
+
* @example
|
|
2520
|
+
* ```typescript
|
|
2521
|
+
* // Change user's password
|
|
2522
|
+
* const { data, error } = await sdk.auth.changePassword({
|
|
2523
|
+
* old_password: "currentPassword123",
|
|
2524
|
+
* new_password: "newSecurePassword456",
|
|
2525
|
+
* confirm_password: "newSecurePassword456"
|
|
2526
|
+
* });
|
|
2527
|
+
*
|
|
2528
|
+
* if (error) {
|
|
2529
|
+
* console.error("Password change failed:", error.message);
|
|
2530
|
+
* } else {
|
|
2531
|
+
* console.log("Password changed successfully");
|
|
2532
|
+
* console.log("New access token:", data.access_token);
|
|
2533
|
+
* }
|
|
2534
|
+
* ```
|
|
1549
2535
|
*/
|
|
1550
2536
|
async changePassword(body) {
|
|
1551
2537
|
return this.executeRequest(
|
|
@@ -1557,10 +2543,25 @@ var AuthClient = class extends StorefrontAPIClient {
|
|
|
1557
2543
|
/**
|
|
1558
2544
|
* Verify OTP
|
|
1559
2545
|
*
|
|
1560
|
-
* @param
|
|
1561
|
-
* @param otpToken - OTP token from login request
|
|
1562
|
-
* @param otpAction - OTP action from login request
|
|
2546
|
+
* @param body - OTP verification data including code and tokens
|
|
1563
2547
|
* @returns Promise with user info and tokens
|
|
2548
|
+
* @example
|
|
2549
|
+
* ```typescript
|
|
2550
|
+
* // Verify OTP after login attempt
|
|
2551
|
+
* const { data, error } = await sdk.auth.verifyOtp({
|
|
2552
|
+
* otp: "1234",
|
|
2553
|
+
* otpToken: "56895455",
|
|
2554
|
+
* otpAction: "login" // or "register"
|
|
2555
|
+
* });
|
|
2556
|
+
*
|
|
2557
|
+
* if (error) {
|
|
2558
|
+
* console.error("OTP verification failed:", error.message);
|
|
2559
|
+
* // Show error message, allow retry
|
|
2560
|
+
* } else {
|
|
2561
|
+
* console.log("Login successful:", data.user.email);
|
|
2562
|
+
* console.log("User ID:", data.user.id);
|
|
2563
|
+
* }
|
|
2564
|
+
* ```
|
|
1564
2565
|
*/
|
|
1565
2566
|
async verifyOtp(body) {
|
|
1566
2567
|
return this.executeRequest(
|
|
@@ -1572,8 +2573,27 @@ var AuthClient = class extends StorefrontAPIClient {
|
|
|
1572
2573
|
/**
|
|
1573
2574
|
* Register with phone
|
|
1574
2575
|
*
|
|
1575
|
-
* @param
|
|
2576
|
+
* @param body - Registration details including phone number and user information
|
|
1576
2577
|
* @returns Promise with user info and tokens
|
|
2578
|
+
* @example
|
|
2579
|
+
* ```typescript
|
|
2580
|
+
* // Register a new user with phone number
|
|
2581
|
+
* const { data, error } = await sdk.auth.registerWithPhone({
|
|
2582
|
+
* phone: "9876543210",
|
|
2583
|
+
* country_code: "+91",
|
|
2584
|
+
* first_name: "John",
|
|
2585
|
+
* last_name: "Doe",
|
|
2586
|
+
* email: "john.doe@example.com"
|
|
2587
|
+
* });
|
|
2588
|
+
*
|
|
2589
|
+
* if (error) {
|
|
2590
|
+
* console.error("Phone registration failed:", error.message);
|
|
2591
|
+
* } else {
|
|
2592
|
+
* console.log("Registration successful:", data.user.first_name);
|
|
2593
|
+
* console.log("User ID:", data.user.id);
|
|
2594
|
+
* console.log("Access token:", data.access_token);
|
|
2595
|
+
* }
|
|
2596
|
+
* ```
|
|
1577
2597
|
*/
|
|
1578
2598
|
async registerWithPhone(body) {
|
|
1579
2599
|
return this.executeRequest(
|
|
@@ -1585,8 +2605,26 @@ var AuthClient = class extends StorefrontAPIClient {
|
|
|
1585
2605
|
/**
|
|
1586
2606
|
* Register with email
|
|
1587
2607
|
*
|
|
1588
|
-
* @param
|
|
2608
|
+
* @param body - Registration details including email and user information
|
|
1589
2609
|
* @returns Promise with user info and tokens
|
|
2610
|
+
* @example
|
|
2611
|
+
* ```typescript
|
|
2612
|
+
* // Register a new user with email address
|
|
2613
|
+
* const { data, error } = await sdk.auth.registerWithEmail({
|
|
2614
|
+
* email: "jane.smith@example.com",
|
|
2615
|
+
* first_name: "Jane",
|
|
2616
|
+
* last_name: "Smith",
|
|
2617
|
+
* phone: "9876543210"
|
|
2618
|
+
* });
|
|
2619
|
+
*
|
|
2620
|
+
* if (error) {
|
|
2621
|
+
* console.error("Email registration failed:", error.message);
|
|
2622
|
+
* } else {
|
|
2623
|
+
* console.log("Registration successful:", data.user.email);
|
|
2624
|
+
* console.log("User ID:", data.user.id);
|
|
2625
|
+
* console.log("Access token:", data.access_token);
|
|
2626
|
+
* }
|
|
2627
|
+
* ```
|
|
1590
2628
|
*/
|
|
1591
2629
|
async registerWithEmail(body) {
|
|
1592
2630
|
return this.executeRequest(
|
|
@@ -1597,8 +2635,24 @@ var AuthClient = class extends StorefrontAPIClient {
|
|
|
1597
2635
|
}
|
|
1598
2636
|
/**
|
|
1599
2637
|
* Refresh the access token using a refresh token
|
|
1600
|
-
* @param
|
|
2638
|
+
* @param body - Request body containing the refresh token
|
|
1601
2639
|
* @returns Promise with the new access token and refresh token
|
|
2640
|
+
* @example
|
|
2641
|
+
* ```typescript
|
|
2642
|
+
* // Refresh access token when it expires
|
|
2643
|
+
* const { data, error } = await sdk.auth.refreshToken({
|
|
2644
|
+
* refresh_token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
|
|
2645
|
+
* });
|
|
2646
|
+
*
|
|
2647
|
+
* if (error) {
|
|
2648
|
+
* console.error("Token refresh failed:", error.message);
|
|
2649
|
+
* // Redirect to login
|
|
2650
|
+
* } else {
|
|
2651
|
+
* console.log("Token refreshed successfully");
|
|
2652
|
+
* console.log("New access token:", data.access_token);
|
|
2653
|
+
* console.log("New refresh token:", data.refresh_token);
|
|
2654
|
+
* }
|
|
2655
|
+
* ```
|
|
1602
2656
|
*/
|
|
1603
2657
|
async refreshToken(body) {
|
|
1604
2658
|
return this.executeRequest(
|
|
@@ -1611,17 +2665,43 @@ var AuthClient = class extends StorefrontAPIClient {
|
|
|
1611
2665
|
* Logout
|
|
1612
2666
|
*
|
|
1613
2667
|
* @returns Promise that resolves when logout is complete
|
|
2668
|
+
* @example
|
|
2669
|
+
* ```typescript
|
|
2670
|
+
* // Logout current user
|
|
2671
|
+
* const { data, error } = await sdk.auth.logout();
|
|
2672
|
+
*
|
|
2673
|
+
* if (error) {
|
|
2674
|
+
* console.error("Logout failed:", error.message);
|
|
2675
|
+
* } else {
|
|
2676
|
+
* console.log("Logout successful");
|
|
2677
|
+
* console.log("Session ended for user:", data.user.email);
|
|
2678
|
+
* }
|
|
2679
|
+
* ```
|
|
1614
2680
|
*/
|
|
1615
2681
|
async logout() {
|
|
1616
|
-
return this.executeRequest(
|
|
1617
|
-
() => this.client.POST("/auth/logout")
|
|
1618
|
-
);
|
|
2682
|
+
return this.executeRequest(() => this.client.POST("/auth/logout"));
|
|
1619
2683
|
}
|
|
1620
2684
|
/**
|
|
1621
2685
|
* Get user details
|
|
1622
2686
|
*
|
|
1623
|
-
* @param
|
|
2687
|
+
* @param pathParams - Path parameters containing user ID
|
|
1624
2688
|
* @returns Promise with user details
|
|
2689
|
+
* @example
|
|
2690
|
+
* ```typescript
|
|
2691
|
+
* // Get details for a specific user
|
|
2692
|
+
* const { data, error } = await sdk.auth.getUserDetails({
|
|
2693
|
+
* id: "01H9XYZ12345USERID"
|
|
2694
|
+
* });
|
|
2695
|
+
*
|
|
2696
|
+
* if (error) {
|
|
2697
|
+
* console.error("Failed to get user details:", error.message);
|
|
2698
|
+
* } else {
|
|
2699
|
+
* console.log("User details:", data.user);
|
|
2700
|
+
* console.log("Email:", data.user.email);
|
|
2701
|
+
* console.log("Phone:", data.user.phoneNumber);
|
|
2702
|
+
* console.log("Created:", data.user.createdAt);
|
|
2703
|
+
* }
|
|
2704
|
+
* ```
|
|
1625
2705
|
*/
|
|
1626
2706
|
async getUserDetails(pathParams) {
|
|
1627
2707
|
return this.executeRequest(
|
|
@@ -1635,8 +2715,29 @@ var AuthClient = class extends StorefrontAPIClient {
|
|
|
1635
2715
|
/**
|
|
1636
2716
|
* Update user details
|
|
1637
2717
|
*
|
|
1638
|
-
* @param
|
|
1639
|
-
* @
|
|
2718
|
+
* @param pathParams - Path parameters containing user ID
|
|
2719
|
+
* @param body - Updated user information
|
|
2720
|
+
* @returns Promise with updated user details
|
|
2721
|
+
* @example
|
|
2722
|
+
* ```typescript
|
|
2723
|
+
* // Update user profile information
|
|
2724
|
+
* const { data, error } = await sdk.auth.updateUserDetails(
|
|
2725
|
+
* { id: "01H9XYZ12345USERID" },
|
|
2726
|
+
* {
|
|
2727
|
+
* first_name: "John",
|
|
2728
|
+
* last_name: "Doe",
|
|
2729
|
+
* email: "john.doe@example.com",
|
|
2730
|
+
* phone: "9876543210",
|
|
2731
|
+
* country_code: "+91"
|
|
2732
|
+
* }
|
|
2733
|
+
* );
|
|
2734
|
+
*
|
|
2735
|
+
* if (error) {
|
|
2736
|
+
* console.error("Failed to update user:", error.message);
|
|
2737
|
+
* } else {
|
|
2738
|
+
* console.log("User updated successfully:", data.user.first_name);
|
|
2739
|
+
* }
|
|
2740
|
+
* ```
|
|
1640
2741
|
*/
|
|
1641
2742
|
async updateUserDetails(pathParams, body) {
|
|
1642
2743
|
return this.executeRequest(
|
|
@@ -1651,8 +2752,25 @@ var AuthClient = class extends StorefrontAPIClient {
|
|
|
1651
2752
|
/**
|
|
1652
2753
|
* Add profile image
|
|
1653
2754
|
*
|
|
1654
|
-
* @param
|
|
1655
|
-
* @
|
|
2755
|
+
* @param pathParams - Path parameters containing user ID
|
|
2756
|
+
* @param formData - Form data containing the image file
|
|
2757
|
+
* @returns Promise with profile image URL
|
|
2758
|
+
* @example
|
|
2759
|
+
* ```typescript
|
|
2760
|
+
* // Add profile image for a user
|
|
2761
|
+
* const imageFile = document.getElementById('file-input').files[0];
|
|
2762
|
+
* const { data, error } = await sdk.auth.addProfileImage(
|
|
2763
|
+
* { id: "01H9XYZ12345USERID" },
|
|
2764
|
+
* { image: imageFile }
|
|
2765
|
+
* );
|
|
2766
|
+
*
|
|
2767
|
+
* if (error) {
|
|
2768
|
+
* console.error("Failed to add profile image:", error.message);
|
|
2769
|
+
* } else {
|
|
2770
|
+
* console.log("Profile image added successfully");
|
|
2771
|
+
* console.log("Image URL:", data.profile_image_url);
|
|
2772
|
+
* }
|
|
2773
|
+
* ```
|
|
1656
2774
|
*/
|
|
1657
2775
|
async addProfileImage(pathParams, formData) {
|
|
1658
2776
|
return this.executeRequest(
|
|
@@ -1676,8 +2794,25 @@ var AuthClient = class extends StorefrontAPIClient {
|
|
|
1676
2794
|
/**
|
|
1677
2795
|
* Update profile image
|
|
1678
2796
|
*
|
|
1679
|
-
* @param
|
|
1680
|
-
* @
|
|
2797
|
+
* @param pathParams - Path parameters containing user ID
|
|
2798
|
+
* @param formData - Form data containing the new image file
|
|
2799
|
+
* @returns Promise with updated profile image URL
|
|
2800
|
+
* @example
|
|
2801
|
+
* ```typescript
|
|
2802
|
+
* // Update existing profile image
|
|
2803
|
+
* const newImageFile = document.getElementById('file-input').files[0];
|
|
2804
|
+
* const { data, error } = await sdk.auth.updateProfileImage(
|
|
2805
|
+
* { id: "01H9XYZ12345USERID" },
|
|
2806
|
+
* { image: newImageFile }
|
|
2807
|
+
* );
|
|
2808
|
+
*
|
|
2809
|
+
* if (error) {
|
|
2810
|
+
* console.error("Failed to update profile image:", error.message);
|
|
2811
|
+
* } else {
|
|
2812
|
+
* console.log("Profile image updated successfully");
|
|
2813
|
+
* console.log("New image URL:", data.profile_image_url);
|
|
2814
|
+
* }
|
|
2815
|
+
* ```
|
|
1681
2816
|
*/
|
|
1682
2817
|
async updateProfileImage(pathParams, formData) {
|
|
1683
2818
|
return this.executeRequest(
|
|
@@ -1701,8 +2836,22 @@ var AuthClient = class extends StorefrontAPIClient {
|
|
|
1701
2836
|
/**
|
|
1702
2837
|
* Delete profile image
|
|
1703
2838
|
*
|
|
1704
|
-
* @param
|
|
1705
|
-
* @returns Promise with
|
|
2839
|
+
* @param pathParams - Path parameters containing user ID
|
|
2840
|
+
* @returns Promise with deletion confirmation
|
|
2841
|
+
* @example
|
|
2842
|
+
* ```typescript
|
|
2843
|
+
* // Delete user's profile image
|
|
2844
|
+
* const { data, error } = await sdk.auth.deleteProfileImage({
|
|
2845
|
+
* id: "01H9XYZ12345USERID"
|
|
2846
|
+
* });
|
|
2847
|
+
*
|
|
2848
|
+
* if (error) {
|
|
2849
|
+
* console.error("Failed to delete profile image:", error.message);
|
|
2850
|
+
* } else {
|
|
2851
|
+
* console.log("Profile image deleted successfully");
|
|
2852
|
+
* console.log("Success:", data.success);
|
|
2853
|
+
* }
|
|
2854
|
+
* ```
|
|
1706
2855
|
*/
|
|
1707
2856
|
async deleteProfileImage(pathParams) {
|
|
1708
2857
|
return this.executeRequest(
|
|
@@ -1716,8 +2865,21 @@ var AuthClient = class extends StorefrontAPIClient {
|
|
|
1716
2865
|
/**
|
|
1717
2866
|
* Get profile image
|
|
1718
2867
|
*
|
|
1719
|
-
* @param
|
|
1720
|
-
* @returns Promise with
|
|
2868
|
+
* @param pathParams - Path parameters containing user ID
|
|
2869
|
+
* @returns Promise with profile image URL
|
|
2870
|
+
* @example
|
|
2871
|
+
* ```typescript
|
|
2872
|
+
* // Get user's profile image URL
|
|
2873
|
+
* const { data, error } = await sdk.auth.getProfileImage({
|
|
2874
|
+
* id: "01H9XYZ12345USERID"
|
|
2875
|
+
* });
|
|
2876
|
+
*
|
|
2877
|
+
* if (error) {
|
|
2878
|
+
* console.error("Failed to get profile image:", error.message);
|
|
2879
|
+
* } else {
|
|
2880
|
+
* console.log("Profile image URL:", data.profile_image_url);
|
|
2881
|
+
* }
|
|
2882
|
+
* ```
|
|
1721
2883
|
*/
|
|
1722
2884
|
async getProfileImage(pathParams) {
|
|
1723
2885
|
return this.executeRequest(
|
|
@@ -1731,8 +2893,22 @@ var AuthClient = class extends StorefrontAPIClient {
|
|
|
1731
2893
|
/**
|
|
1732
2894
|
* Deactivate user account
|
|
1733
2895
|
*
|
|
1734
|
-
* @param
|
|
1735
|
-
* @returns Promise with
|
|
2896
|
+
* @param pathParams - Path parameters containing user ID
|
|
2897
|
+
* @returns Promise with deactivation confirmation
|
|
2898
|
+
* @example
|
|
2899
|
+
* ```typescript
|
|
2900
|
+
* // Deactivate a user account
|
|
2901
|
+
* const { data, error } = await sdk.auth.deactivateUserAccount({
|
|
2902
|
+
* id: "01H9XYZ12345USERID"
|
|
2903
|
+
* });
|
|
2904
|
+
*
|
|
2905
|
+
* if (error) {
|
|
2906
|
+
* console.error("Failed to deactivate account:", error.message);
|
|
2907
|
+
* } else {
|
|
2908
|
+
* console.log("Account deactivated successfully");
|
|
2909
|
+
* console.log("Success:", data.success);
|
|
2910
|
+
* }
|
|
2911
|
+
* ```
|
|
1736
2912
|
*/
|
|
1737
2913
|
async deactivateUserAccount(pathParams) {
|
|
1738
2914
|
return this.executeRequest(
|
|
@@ -1746,8 +2922,21 @@ var AuthClient = class extends StorefrontAPIClient {
|
|
|
1746
2922
|
/**
|
|
1747
2923
|
* Get user notification preferences
|
|
1748
2924
|
*
|
|
1749
|
-
* @param
|
|
1750
|
-
* @returns Promise with user
|
|
2925
|
+
* @param pathParams - Path parameters containing user ID
|
|
2926
|
+
* @returns Promise with user's notification preferences
|
|
2927
|
+
* @example
|
|
2928
|
+
* ```typescript
|
|
2929
|
+
* // Get user's notification preferences
|
|
2930
|
+
* const { data, error } = await sdk.auth.getUserNotificationPreferences({
|
|
2931
|
+
* id: "01H9XYZ12345USERID"
|
|
2932
|
+
* });
|
|
2933
|
+
*
|
|
2934
|
+
* if (error) {
|
|
2935
|
+
* console.error("Failed to get preferences:", error.message);
|
|
2936
|
+
* } else {
|
|
2937
|
+
* console.log("Notification preferences:", data.notification_preferences);
|
|
2938
|
+
* }
|
|
2939
|
+
* ```
|
|
1751
2940
|
*/
|
|
1752
2941
|
async getUserNotificationPreferences(pathParams) {
|
|
1753
2942
|
return this.executeRequest(
|
|
@@ -1761,8 +2950,27 @@ var AuthClient = class extends StorefrontAPIClient {
|
|
|
1761
2950
|
/**
|
|
1762
2951
|
* Update user notification preferences
|
|
1763
2952
|
*
|
|
1764
|
-
* @param
|
|
1765
|
-
* @
|
|
2953
|
+
* @param pathParams - Path parameters containing user ID
|
|
2954
|
+
* @param body - Updated notification preferences
|
|
2955
|
+
* @returns Promise with updated notification preferences
|
|
2956
|
+
* @example
|
|
2957
|
+
* ```typescript
|
|
2958
|
+
* // Update user's notification preferences
|
|
2959
|
+
* const { data, error } = await sdk.auth.updateUserNotificationPreferences(
|
|
2960
|
+
* { id: "01H9XYZ12345USERID" },
|
|
2961
|
+
* {
|
|
2962
|
+
* email_notifications: true,
|
|
2963
|
+
* sms_notifications: false,
|
|
2964
|
+
* push_notifications: true
|
|
2965
|
+
* }
|
|
2966
|
+
* );
|
|
2967
|
+
*
|
|
2968
|
+
* if (error) {
|
|
2969
|
+
* console.error("Failed to update preferences:", error.message);
|
|
2970
|
+
* } else {
|
|
2971
|
+
* console.log("Preferences updated successfully");
|
|
2972
|
+
* }
|
|
2973
|
+
* ```
|
|
1766
2974
|
*/
|
|
1767
2975
|
async updateUserNotificationPreferences(pathParams, body) {
|
|
1768
2976
|
return this.executeRequest(
|
|
@@ -1777,8 +2985,27 @@ var AuthClient = class extends StorefrontAPIClient {
|
|
|
1777
2985
|
/**
|
|
1778
2986
|
* Create user notification preference
|
|
1779
2987
|
*
|
|
1780
|
-
* @param
|
|
1781
|
-
* @
|
|
2988
|
+
* @param pathParams - Path parameters containing user ID
|
|
2989
|
+
* @param body - Notification preferences to create
|
|
2990
|
+
* @returns Promise with created notification preferences
|
|
2991
|
+
* @example
|
|
2992
|
+
* ```typescript
|
|
2993
|
+
* // Create notification preferences for a user
|
|
2994
|
+
* const { data, error } = await sdk.auth.createUserNotificationPreference(
|
|
2995
|
+
* { id: "01H9XYZ12345USERID" },
|
|
2996
|
+
* {
|
|
2997
|
+
* email_notifications: true,
|
|
2998
|
+
* sms_notifications: true,
|
|
2999
|
+
* push_notifications: false
|
|
3000
|
+
* }
|
|
3001
|
+
* );
|
|
3002
|
+
*
|
|
3003
|
+
* if (error) {
|
|
3004
|
+
* console.error("Failed to create preferences:", error.message);
|
|
3005
|
+
* } else {
|
|
3006
|
+
* console.log("Preferences created successfully");
|
|
3007
|
+
* }
|
|
3008
|
+
* ```
|
|
1782
3009
|
*/
|
|
1783
3010
|
async createUserNotificationPreference(pathParams, body) {
|
|
1784
3011
|
return this.executeRequest(
|
|
@@ -1792,9 +3019,25 @@ var AuthClient = class extends StorefrontAPIClient {
|
|
|
1792
3019
|
}
|
|
1793
3020
|
/**
|
|
1794
3021
|
* Generate OTP
|
|
1795
|
-
*
|
|
1796
|
-
* @param body - OTP generation body
|
|
1797
|
-
* @returns Promise with OTP
|
|
3022
|
+
*
|
|
3023
|
+
* @param body - OTP generation body (phone or email)
|
|
3024
|
+
* @returns Promise with OTP token and action
|
|
3025
|
+
* @example
|
|
3026
|
+
* ```typescript
|
|
3027
|
+
* // Generate OTP for phone number
|
|
3028
|
+
* const { data, error } = await sdk.auth.generateOtp({
|
|
3029
|
+
* phone: "9876543210",
|
|
3030
|
+
* country_code: "+91"
|
|
3031
|
+
* });
|
|
3032
|
+
*
|
|
3033
|
+
* if (error) {
|
|
3034
|
+
* console.error("OTP generation failed:", error.message);
|
|
3035
|
+
* } else {
|
|
3036
|
+
* console.log("OTP sent successfully");
|
|
3037
|
+
* console.log("OTP token:", data.otp_token);
|
|
3038
|
+
* console.log("Action:", data.otp_action);
|
|
3039
|
+
* }
|
|
3040
|
+
* ```
|
|
1798
3041
|
*/
|
|
1799
3042
|
async generateOtp(body) {
|
|
1800
3043
|
return this.executeRequest(
|
|
@@ -1806,8 +3049,23 @@ var AuthClient = class extends StorefrontAPIClient {
|
|
|
1806
3049
|
/**
|
|
1807
3050
|
* Check whether email or phone is already verified
|
|
1808
3051
|
*
|
|
1809
|
-
* @param body -
|
|
1810
|
-
* @returns Promise with
|
|
3052
|
+
* @param body - Request body containing phone numbers or email addresses to verify
|
|
3053
|
+
* @returns Promise with verification status for provided contacts
|
|
3054
|
+
* @example
|
|
3055
|
+
* ```typescript
|
|
3056
|
+
* // Check verification status for multiple contacts
|
|
3057
|
+
* const { data, error } = await sdk.auth.checkEmailOrPhoneIsVerified({
|
|
3058
|
+
* phone: ["9876543210", "9123456789"],
|
|
3059
|
+
* email: ["user1@example.com", "user2@example.com"]
|
|
3060
|
+
* });
|
|
3061
|
+
*
|
|
3062
|
+
* if (error) {
|
|
3063
|
+
* console.error("Verification check failed:", error.message);
|
|
3064
|
+
* } else {
|
|
3065
|
+
* console.log("Verified phones:", data.verified_phone);
|
|
3066
|
+
* console.log("Verified emails:", data.verified_email);
|
|
3067
|
+
* }
|
|
3068
|
+
* ```
|
|
1811
3069
|
*/
|
|
1812
3070
|
async checkEmailOrPhoneIsVerified(body) {
|
|
1813
3071
|
return this.executeRequest(
|
|
@@ -1825,6 +3083,20 @@ var OrderClient = class extends StorefrontAPIClient {
|
|
|
1825
3083
|
*
|
|
1826
3084
|
* @param orderNumber - Order number
|
|
1827
3085
|
* @returns Promise with order details
|
|
3086
|
+
* @example
|
|
3087
|
+
* ```typescript
|
|
3088
|
+
* const { data, error } = await sdk.order.getOrderDetails({
|
|
3089
|
+
* order_number: "ORD-2024-001"
|
|
3090
|
+
* });
|
|
3091
|
+
*
|
|
3092
|
+
* if (error) {
|
|
3093
|
+
* console.error("Failed to get order details:", error.message);
|
|
3094
|
+
* } else {
|
|
3095
|
+
* console.log("Order details:", data.content.order);
|
|
3096
|
+
* console.log("Order status:", data.content.order.status);
|
|
3097
|
+
* console.log("Total amount:", data.content.order.total_amount);
|
|
3098
|
+
* }
|
|
3099
|
+
* ```
|
|
1828
3100
|
*/
|
|
1829
3101
|
async getOrderDetails(pathParams) {
|
|
1830
3102
|
return this.executeRequest(
|
|
@@ -1838,10 +3110,42 @@ var OrderClient = class extends StorefrontAPIClient {
|
|
|
1838
3110
|
/**
|
|
1839
3111
|
* Create order
|
|
1840
3112
|
*
|
|
1841
|
-
* @param
|
|
1842
|
-
* @param paymentGateway - Payment gateway
|
|
1843
|
-
* @param paymentGatewayParams - Params for the selected payment gateway
|
|
3113
|
+
* @param body - Order creation request body
|
|
1844
3114
|
* @returns Promise with order details
|
|
3115
|
+
* @example
|
|
3116
|
+
* ```typescript
|
|
3117
|
+
* // Example with PayU payment gateway
|
|
3118
|
+
* const { data, error } = await sdk.order.createOrder({
|
|
3119
|
+
* cart_id: "cart_01H9XYZ12345ABCDE",
|
|
3120
|
+
* payment_gateway: "PAYU",
|
|
3121
|
+
* payment_gateway_params: {
|
|
3122
|
+
* payment_gateway: "PAYU",
|
|
3123
|
+
* furl: "https://yourapp.com/payment/failure",
|
|
3124
|
+
* surl: "https://yourapp.com/payment/success"
|
|
3125
|
+
* }
|
|
3126
|
+
* });
|
|
3127
|
+
*
|
|
3128
|
+
* // Example with Juspay payment gateway
|
|
3129
|
+
* const { data, error } = await sdk.order.createOrder({
|
|
3130
|
+
* cart_id: "cart_01H9XYZ12345ABCDE",
|
|
3131
|
+
* payment_gateway: "JUSPAY",
|
|
3132
|
+
* payment_gateway_params: {
|
|
3133
|
+
* payment_gateway: "JUSPAY",
|
|
3134
|
+
* action: "paymentPage",
|
|
3135
|
+
* integration_type: "hyper-checkout",
|
|
3136
|
+
* return_url: "https://yourapp.com/payment/return",
|
|
3137
|
+
* gateway_reference_id: "juspay_gateway_ref_123"
|
|
3138
|
+
* }
|
|
3139
|
+
* });
|
|
3140
|
+
*
|
|
3141
|
+
* if (error) {
|
|
3142
|
+
* console.error("Failed to create order:", error.message);
|
|
3143
|
+
* } else {
|
|
3144
|
+
* console.log("Order created:", data.content.order.id);
|
|
3145
|
+
* console.log("Payment required:", data.content.payment_required);
|
|
3146
|
+
* console.log("Payment info:", data.content.payment_info);
|
|
3147
|
+
* }
|
|
3148
|
+
* ```
|
|
1845
3149
|
*/
|
|
1846
3150
|
async createOrder(body) {
|
|
1847
3151
|
return this.executeRequest(
|
|
@@ -1853,8 +3157,35 @@ var OrderClient = class extends StorefrontAPIClient {
|
|
|
1853
3157
|
/**
|
|
1854
3158
|
* List all orders
|
|
1855
3159
|
*
|
|
1856
|
-
* @param queryParams - Query parameters
|
|
1857
|
-
* @returns Promise with order
|
|
3160
|
+
* @param queryParams - Query parameters for filtering and pagination
|
|
3161
|
+
* @returns Promise with order list
|
|
3162
|
+
* @example
|
|
3163
|
+
* ```typescript
|
|
3164
|
+
* // Basic usage - only required parameter
|
|
3165
|
+
* const { data, error } = await sdk.order.listOrders({
|
|
3166
|
+
* user_id: "user_01H9XYZ12345ABCDE"
|
|
3167
|
+
* });
|
|
3168
|
+
*
|
|
3169
|
+
* // Advanced usage with optional parameters
|
|
3170
|
+
* const { data, error } = await sdk.order.listOrders({
|
|
3171
|
+
* user_id: "user_01H9XYZ12345ABCDE",
|
|
3172
|
+
* page: 1,
|
|
3173
|
+
* limit: 20,
|
|
3174
|
+
* sort_by: '{"created_at":"desc"}',
|
|
3175
|
+
* status: ["confirmed", "shipped", "delivered"]
|
|
3176
|
+
* });
|
|
3177
|
+
*
|
|
3178
|
+
* if (error) {
|
|
3179
|
+
* console.error("Failed to list orders:", error.message);
|
|
3180
|
+
* } else {
|
|
3181
|
+
* console.log("Orders found:", data.content.orders?.length || 0);
|
|
3182
|
+
* console.log("Pagination:", data.content.pagination);
|
|
3183
|
+
*
|
|
3184
|
+
* data.content.orders?.forEach(order => {
|
|
3185
|
+
* console.log(`Order ${order.order_number}: ${order.status}`);
|
|
3186
|
+
* });
|
|
3187
|
+
* }
|
|
3188
|
+
* ```
|
|
1858
3189
|
*/
|
|
1859
3190
|
async listOrders(queryParams) {
|
|
1860
3191
|
return this.executeRequest(
|
|
@@ -1870,6 +3201,19 @@ var OrderClient = class extends StorefrontAPIClient {
|
|
|
1870
3201
|
*
|
|
1871
3202
|
* @param orderNumber - Order number
|
|
1872
3203
|
* @returns Promise with payment status
|
|
3204
|
+
* @example
|
|
3205
|
+
* ```typescript
|
|
3206
|
+
* const { data, error } = await sdk.order.getPaymentStatus("ORD-2024-001");
|
|
3207
|
+
*
|
|
3208
|
+
* if (error) {
|
|
3209
|
+
* console.error("Failed to get payment status:", error.message);
|
|
3210
|
+
* } else {
|
|
3211
|
+
* console.log("Payment status:", data.content.status);
|
|
3212
|
+
* console.log("Amount paid:", data.content.amount_paid);
|
|
3213
|
+
* console.log("Amount unpaid:", data.content.amount_unpaid);
|
|
3214
|
+
* console.log("Retry available:", data.content.is_retry_available);
|
|
3215
|
+
* }
|
|
3216
|
+
* ```
|
|
1873
3217
|
*/
|
|
1874
3218
|
async getPaymentStatus(orderNumber) {
|
|
1875
3219
|
return this.executeRequest(
|
|
@@ -1883,8 +3227,26 @@ var OrderClient = class extends StorefrontAPIClient {
|
|
|
1883
3227
|
/**
|
|
1884
3228
|
* Get all shipments for an order
|
|
1885
3229
|
*
|
|
1886
|
-
* @param
|
|
3230
|
+
* @param pathParams - Order number path parameters
|
|
1887
3231
|
* @returns Promise with shipments
|
|
3232
|
+
* @example
|
|
3233
|
+
* ```typescript
|
|
3234
|
+
* const { data, error } = await sdk.order.listOrderShipments({
|
|
3235
|
+
* order_number: "ORD-2024-001"
|
|
3236
|
+
* });
|
|
3237
|
+
*
|
|
3238
|
+
* if (error) {
|
|
3239
|
+
* console.error("Failed to get order shipments:", error.message);
|
|
3240
|
+
* } else {
|
|
3241
|
+
* console.log("Shipments found:", data.content.shipments?.length || 0);
|
|
3242
|
+
*
|
|
3243
|
+
* data.content.shipments?.forEach(shipment => {
|
|
3244
|
+
* console.log(`Shipment ${shipment.id}: ${shipment.status}`);
|
|
3245
|
+
* console.log("Tracking number:", shipment.tracking_number);
|
|
3246
|
+
* console.log("Carrier:", shipment.carrier);
|
|
3247
|
+
* });
|
|
3248
|
+
* }
|
|
3249
|
+
* ```
|
|
1888
3250
|
*/
|
|
1889
3251
|
async listOrderShipments(pathParams) {
|
|
1890
3252
|
return this.executeRequest(
|
|
@@ -1898,8 +3260,27 @@ var OrderClient = class extends StorefrontAPIClient {
|
|
|
1898
3260
|
/**
|
|
1899
3261
|
* List order payments
|
|
1900
3262
|
*
|
|
1901
|
-
* @param
|
|
3263
|
+
* @param pathParams - Order number path parameters
|
|
1902
3264
|
* @returns Promise with payments
|
|
3265
|
+
* @example
|
|
3266
|
+
* ```typescript
|
|
3267
|
+
* const { data, error } = await sdk.order.listOrderPayments({
|
|
3268
|
+
* order_number: "ORD-2024-001"
|
|
3269
|
+
* });
|
|
3270
|
+
*
|
|
3271
|
+
* if (error) {
|
|
3272
|
+
* console.error("Failed to get order payments:", error.message);
|
|
3273
|
+
* } else {
|
|
3274
|
+
* console.log("Payments found:", data.content.payments?.length || 0);
|
|
3275
|
+
*
|
|
3276
|
+
* data.content.payments?.forEach(payment => {
|
|
3277
|
+
* console.log(`Payment ${payment.id}: ${payment.status}`);
|
|
3278
|
+
* console.log("Amount:", payment.amount);
|
|
3279
|
+
* console.log("Gateway:", payment.payment_gateway);
|
|
3280
|
+
* console.log("Transaction ID:", payment.transaction_id);
|
|
3281
|
+
* });
|
|
3282
|
+
* }
|
|
3283
|
+
* ```
|
|
1903
3284
|
*/
|
|
1904
3285
|
async listOrderPayments(pathParams) {
|
|
1905
3286
|
return this.executeRequest(
|
|
@@ -1913,8 +3294,27 @@ var OrderClient = class extends StorefrontAPIClient {
|
|
|
1913
3294
|
/**
|
|
1914
3295
|
* List order refunds
|
|
1915
3296
|
*
|
|
1916
|
-
* @param
|
|
3297
|
+
* @param pathParams - Order number path parameters
|
|
1917
3298
|
* @returns Promise with refunds
|
|
3299
|
+
* @example
|
|
3300
|
+
* ```typescript
|
|
3301
|
+
* const { data, error } = await sdk.order.listOrderRefunds({
|
|
3302
|
+
* order_number: "ORD-2024-001"
|
|
3303
|
+
* });
|
|
3304
|
+
*
|
|
3305
|
+
* if (error) {
|
|
3306
|
+
* console.error("Failed to get order refunds:", error.message);
|
|
3307
|
+
* } else {
|
|
3308
|
+
* console.log("Refunds found:", data.content.refunds?.length || 0);
|
|
3309
|
+
*
|
|
3310
|
+
* data.content.refunds?.forEach(refund => {
|
|
3311
|
+
* console.log(`Refund ${refund.id}: ${refund.status}`);
|
|
3312
|
+
* console.log("Amount:", refund.amount);
|
|
3313
|
+
* console.log("Reason:", refund.reason);
|
|
3314
|
+
* console.log("Processed at:", refund.processed_at);
|
|
3315
|
+
* });
|
|
3316
|
+
* }
|
|
3317
|
+
* ```
|
|
1918
3318
|
*/
|
|
1919
3319
|
async listOrderRefunds(pathParams) {
|
|
1920
3320
|
return this.executeRequest(
|
|
@@ -1928,8 +3328,28 @@ var OrderClient = class extends StorefrontAPIClient {
|
|
|
1928
3328
|
/**
|
|
1929
3329
|
* Cancel an order
|
|
1930
3330
|
*
|
|
1931
|
-
* @param
|
|
3331
|
+
* @param pathParams - Order number path parameters
|
|
3332
|
+
* @param body - Cancellation request body
|
|
1932
3333
|
* @returns Promise with order details
|
|
3334
|
+
* @example
|
|
3335
|
+
* ```typescript
|
|
3336
|
+
* const { data, error } = await sdk.order.cancelOrder(
|
|
3337
|
+
* { order_number: "ORD-2024-001" },
|
|
3338
|
+
* {
|
|
3339
|
+
* cancellation_reason: "Customer requested cancellation",
|
|
3340
|
+
* refund_mode: "original_payment_mode",
|
|
3341
|
+
* feedback: "Customer changed their mind about the purchase"
|
|
3342
|
+
* }
|
|
3343
|
+
* );
|
|
3344
|
+
*
|
|
3345
|
+
* if (error) {
|
|
3346
|
+
* console.error("Failed to cancel order:", error.message);
|
|
3347
|
+
* } else {
|
|
3348
|
+
* console.log("Order cancelled successfully");
|
|
3349
|
+
* console.log("Updated order status:", data.content.order?.status);
|
|
3350
|
+
* console.log("Cancellation reason:", data.content.order?.cancellation_reason);
|
|
3351
|
+
* }
|
|
3352
|
+
* ```
|
|
1933
3353
|
*/
|
|
1934
3354
|
async cancelOrder(pathParams, body) {
|
|
1935
3355
|
return this.executeRequest(
|
|
@@ -1944,8 +3364,45 @@ var OrderClient = class extends StorefrontAPIClient {
|
|
|
1944
3364
|
/**
|
|
1945
3365
|
* Retry payment for an order
|
|
1946
3366
|
*
|
|
1947
|
-
* @param
|
|
1948
|
-
* @
|
|
3367
|
+
* @param pathParams - Order number path parameters
|
|
3368
|
+
* @param body - Payment retry request body
|
|
3369
|
+
* @returns Promise with payment information
|
|
3370
|
+
* @example
|
|
3371
|
+
* ```typescript
|
|
3372
|
+
* // Example with PayU payment gateway
|
|
3373
|
+
* const { data, error } = await sdk.order.retryOrderPayment(
|
|
3374
|
+
* { order_number: "ORD-2024-001" },
|
|
3375
|
+
* {
|
|
3376
|
+
* payment_gateway_params: {
|
|
3377
|
+
* payment_gateway: "PAYU",
|
|
3378
|
+
* furl: "https://yourapp.com/payment/failure",
|
|
3379
|
+
* surl: "https://yourapp.com/payment/success"
|
|
3380
|
+
* }
|
|
3381
|
+
* }
|
|
3382
|
+
* );
|
|
3383
|
+
*
|
|
3384
|
+
* // Example with Juspay payment gateway
|
|
3385
|
+
* const { data, error } = await sdk.order.retryOrderPayment(
|
|
3386
|
+
* { order_number: "ORD-2024-001" },
|
|
3387
|
+
* {
|
|
3388
|
+
* payment_gateway_params: {
|
|
3389
|
+
* payment_gateway: "JUSPAY",
|
|
3390
|
+
* action: "paymentPage",
|
|
3391
|
+
* integration_type: "hyper-checkout",
|
|
3392
|
+
* return_url: "https://yourapp.com/payment/return",
|
|
3393
|
+
* gateway_reference_id: "juspay_gateway_ref_123"
|
|
3394
|
+
* }
|
|
3395
|
+
* }
|
|
3396
|
+
* );
|
|
3397
|
+
*
|
|
3398
|
+
* if (error) {
|
|
3399
|
+
* console.error("Failed to retry payment:", error.message);
|
|
3400
|
+
* } else {
|
|
3401
|
+
* console.log("Payment retry initiated");
|
|
3402
|
+
* console.log("Payment info:", data.content.payment_info);
|
|
3403
|
+
* console.log("Transaction ID:", data.content.payment_info.transaction_id);
|
|
3404
|
+
* }
|
|
3405
|
+
* ```
|
|
1949
3406
|
*/
|
|
1950
3407
|
async retryOrderPayment(pathParams, body) {
|
|
1951
3408
|
return this.executeRequest(
|
|
@@ -1966,6 +3423,31 @@ var ShippingClient = class extends StorefrontAPIClient {
|
|
|
1966
3423
|
*
|
|
1967
3424
|
* @param body - Shipping methods body
|
|
1968
3425
|
* @returns Promise with shipping options
|
|
3426
|
+
* @example
|
|
3427
|
+
* ```typescript
|
|
3428
|
+
* const { data, error } = await sdk.shipping.getShippingMethods({
|
|
3429
|
+
* delivery_pincode: "400001",
|
|
3430
|
+
* cart_id: "cart_01H9XYZ12345ABCDE"
|
|
3431
|
+
* });
|
|
3432
|
+
*
|
|
3433
|
+
* if (error) {
|
|
3434
|
+
* console.error("Failed to get shipping methods:", error.message);
|
|
3435
|
+
* } else {
|
|
3436
|
+
* console.log("Is serviceable:", data.content.is_serviceable);
|
|
3437
|
+
* console.log("Available shipping methods:", data.content.shipping_methods?.length || 0);
|
|
3438
|
+
*
|
|
3439
|
+
* data.content.shipping_methods?.forEach(method => {
|
|
3440
|
+
* console.log(`Method: ${method.name} (${method.shipping_type})`);
|
|
3441
|
+
* console.log(`Shipping cost: ${method.shipping_amount}`);
|
|
3442
|
+
* console.log(`Estimated delivery: ${method.estimated_delivery_days} days`);
|
|
3443
|
+
*
|
|
3444
|
+
* method.courier_companies?.forEach(courier => {
|
|
3445
|
+
* console.log(` - ${courier.name}: ${courier.shipping_amount} (${courier.mode})`);
|
|
3446
|
+
* console.log(` Rating: ${courier.rating}/5, Recommended: ${courier.is_recommended}`);
|
|
3447
|
+
* });
|
|
3448
|
+
* });
|
|
3449
|
+
* }
|
|
3450
|
+
* ```
|
|
1969
3451
|
*/
|
|
1970
3452
|
async getShippingMethods(body) {
|
|
1971
3453
|
return this.executeRequest(
|
|
@@ -1979,6 +3461,24 @@ var ShippingClient = class extends StorefrontAPIClient {
|
|
|
1979
3461
|
*
|
|
1980
3462
|
* @param pathParams - Path parameters
|
|
1981
3463
|
* @returns Promise with pincode deliverability result
|
|
3464
|
+
* @example
|
|
3465
|
+
* ```typescript
|
|
3466
|
+
* const { data, error } = await sdk.shipping.checkPincodeDeliverability({
|
|
3467
|
+
* pincode: "400001"
|
|
3468
|
+
* });
|
|
3469
|
+
*
|
|
3470
|
+
* if (error) {
|
|
3471
|
+
* console.error("Failed to check pincode serviceability:", error.message);
|
|
3472
|
+
* } else {
|
|
3473
|
+
* console.log("Pincode serviceable:", data.content.is_serviceable);
|
|
3474
|
+
*
|
|
3475
|
+
* if (data.content.is_serviceable) {
|
|
3476
|
+
* console.log("Delivery is available to this pincode");
|
|
3477
|
+
* } else {
|
|
3478
|
+
* console.log("Delivery is not available to this pincode");
|
|
3479
|
+
* }
|
|
3480
|
+
* }
|
|
3481
|
+
* ```
|
|
1982
3482
|
*/
|
|
1983
3483
|
async checkPincodeDeliverability(pathParams) {
|
|
1984
3484
|
return this.executeRequest(
|
|
@@ -1997,17 +3497,64 @@ var HelpersClient = class extends StorefrontAPIClient {
|
|
|
1997
3497
|
* Get a list of countries
|
|
1998
3498
|
*
|
|
1999
3499
|
* @returns Promise with countries
|
|
3500
|
+
*
|
|
3501
|
+
* @example
|
|
3502
|
+
* ```typescript
|
|
3503
|
+
* const { data, error } = await sdk.helpers.listCountries();
|
|
3504
|
+
*
|
|
3505
|
+
* if (error) {
|
|
3506
|
+
* console.error("Failed to get countries:", error);
|
|
3507
|
+
* return;
|
|
3508
|
+
* }
|
|
3509
|
+
*
|
|
3510
|
+
* console.log("Countries found:", data.countries?.length || 0);
|
|
3511
|
+
*
|
|
3512
|
+
* data.countries?.forEach(country => {
|
|
3513
|
+
* console.log(`Country: ${country.name} (${country.iso_code})`);
|
|
3514
|
+
* console.log("Phone code:", country.phone_code);
|
|
3515
|
+
* console.log("Currency:", country.currency?.code);
|
|
3516
|
+
* });
|
|
3517
|
+
* ```
|
|
2000
3518
|
*/
|
|
2001
3519
|
async listCountries() {
|
|
2002
|
-
return this.executeRequest(
|
|
2003
|
-
() => this.client.GET("/common/countries", {})
|
|
2004
|
-
);
|
|
3520
|
+
return this.executeRequest(() => this.client.GET("/common/countries", {}));
|
|
2005
3521
|
}
|
|
2006
3522
|
/**
|
|
2007
|
-
*
|
|
3523
|
+
* Get a list of states for a country
|
|
2008
3524
|
*
|
|
2009
3525
|
* @param pathParams - Path parameters
|
|
2010
3526
|
* @returns Promise with states
|
|
3527
|
+
*
|
|
3528
|
+
* @example
|
|
3529
|
+
* ```typescript
|
|
3530
|
+
* const { data, error } = await sdk.helpers.listCountryStates({
|
|
3531
|
+
* country_iso_code: "IN"
|
|
3532
|
+
* });
|
|
3533
|
+
*
|
|
3534
|
+
* if (error) {
|
|
3535
|
+
* console.error("Failed to get states:", error);
|
|
3536
|
+
* return;
|
|
3537
|
+
* }
|
|
3538
|
+
*
|
|
3539
|
+
* console.log("States found:", data.states?.length || 0);
|
|
3540
|
+
*
|
|
3541
|
+
* data.states?.forEach(state => {
|
|
3542
|
+
* console.log(`State: ${state.name} (${state.iso_code})`);
|
|
3543
|
+
* console.log("Type:", state.type);
|
|
3544
|
+
* });
|
|
3545
|
+
*
|
|
3546
|
+
* // Get states for different country
|
|
3547
|
+
* const { data: usStates, error: usError } = await sdk.helpers.listCountryStates({
|
|
3548
|
+
* country_iso_code: "US"
|
|
3549
|
+
* });
|
|
3550
|
+
*
|
|
3551
|
+
* if (usError) {
|
|
3552
|
+
* console.error("Failed to get US states:", usError);
|
|
3553
|
+
* return;
|
|
3554
|
+
* }
|
|
3555
|
+
*
|
|
3556
|
+
* console.log("US States:", usStates.states?.map(s => s.name).join(", "));
|
|
3557
|
+
* ```
|
|
2011
3558
|
*/
|
|
2012
3559
|
async listCountryStates(pathParams) {
|
|
2013
3560
|
return this.executeRequest(
|
|
@@ -2023,6 +3570,38 @@ var HelpersClient = class extends StorefrontAPIClient {
|
|
|
2023
3570
|
*
|
|
2024
3571
|
* @param pathParams - Path parameters
|
|
2025
3572
|
* @returns Promise with pincodes
|
|
3573
|
+
*
|
|
3574
|
+
* @example
|
|
3575
|
+
* ```typescript
|
|
3576
|
+
* const { data, error } = await sdk.helpers.listCountryPincodes({
|
|
3577
|
+
* country_iso_code: "IN"
|
|
3578
|
+
* });
|
|
3579
|
+
*
|
|
3580
|
+
* if (error) {
|
|
3581
|
+
* console.error("Failed to get pincodes:", error);
|
|
3582
|
+
* return;
|
|
3583
|
+
* }
|
|
3584
|
+
*
|
|
3585
|
+
* console.log("Pincodes found:", data.pincodes?.length || 0);
|
|
3586
|
+
*
|
|
3587
|
+
* data.pincodes?.forEach(pincode => {
|
|
3588
|
+
* console.log(`Pincode: ${pincode.pincode} - ${pincode.city}, ${pincode.state}`);
|
|
3589
|
+
* console.log("District:", pincode.district);
|
|
3590
|
+
* console.log("Area:", pincode.area);
|
|
3591
|
+
* });
|
|
3592
|
+
*
|
|
3593
|
+
* // Get pincodes for different country
|
|
3594
|
+
* const { data: usPincodes, error: usError } = await sdk.helpers.listCountryPincodes({
|
|
3595
|
+
* country_iso_code: "US"
|
|
3596
|
+
* });
|
|
3597
|
+
*
|
|
3598
|
+
* if (usError) {
|
|
3599
|
+
* console.error("Failed to get US pincodes:", usError);
|
|
3600
|
+
* return;
|
|
3601
|
+
* }
|
|
3602
|
+
*
|
|
3603
|
+
* console.log("US Pincodes:", usPincodes.pincodes?.map(p => p.pincode).join(", "));
|
|
3604
|
+
* ```
|
|
2026
3605
|
*/
|
|
2027
3606
|
async listCountryPincodes(pathParams) {
|
|
2028
3607
|
return this.executeRequest(
|
|
@@ -2042,6 +3621,24 @@ var CustomerClient = class extends StorefrontAPIClient {
|
|
|
2042
3621
|
*
|
|
2043
3622
|
* @param body - Customer creation body
|
|
2044
3623
|
* @returns Promise with customer details
|
|
3624
|
+
*
|
|
3625
|
+
* @example
|
|
3626
|
+
* ```typescript
|
|
3627
|
+
* const { data, error } = await sdk.customer.createCustomer({
|
|
3628
|
+
* first_name: "John",
|
|
3629
|
+
* last_name: "Doe",
|
|
3630
|
+
* email: "john.doe@example.com",
|
|
3631
|
+
* phone: "+1234567890",
|
|
3632
|
+
* password: "securePassword123"
|
|
3633
|
+
* });
|
|
3634
|
+
*
|
|
3635
|
+
* if (error) {
|
|
3636
|
+
* console.error("Failed to create customer:", error);
|
|
3637
|
+
* return;
|
|
3638
|
+
* }
|
|
3639
|
+
*
|
|
3640
|
+
* console.log("Customer created:", data.customer_detail);
|
|
3641
|
+
* ```
|
|
2045
3642
|
*/
|
|
2046
3643
|
async createCustomer(body) {
|
|
2047
3644
|
return this.executeRequest(
|
|
@@ -2055,6 +3652,20 @@ var CustomerClient = class extends StorefrontAPIClient {
|
|
|
2055
3652
|
*
|
|
2056
3653
|
* @param pathParams - Path parameters
|
|
2057
3654
|
* @returns Promise with customer details
|
|
3655
|
+
*
|
|
3656
|
+
* @example
|
|
3657
|
+
* ```typescript
|
|
3658
|
+
* const { data, error } = await sdk.customer.getCustomer({
|
|
3659
|
+
* id: "customer_123"
|
|
3660
|
+
* });
|
|
3661
|
+
*
|
|
3662
|
+
* if (error) {
|
|
3663
|
+
* console.error("Failed to get customer:", error);
|
|
3664
|
+
* return;
|
|
3665
|
+
* }
|
|
3666
|
+
*
|
|
3667
|
+
* console.log("Customer details:", data.customer_detail);
|
|
3668
|
+
* ```
|
|
2058
3669
|
*/
|
|
2059
3670
|
async getCustomer(pathParams) {
|
|
2060
3671
|
return this.executeRequest(
|
|
@@ -2071,6 +3682,25 @@ var CustomerClient = class extends StorefrontAPIClient {
|
|
|
2071
3682
|
* @param pathParams - Path parameters
|
|
2072
3683
|
* @param body - Customer update body
|
|
2073
3684
|
* @returns Promise with customer details
|
|
3685
|
+
*
|
|
3686
|
+
* @example
|
|
3687
|
+
* ```typescript
|
|
3688
|
+
* const { data, error } = await sdk.customer.updateCustomer(
|
|
3689
|
+
* { id: "customer_123" },
|
|
3690
|
+
* {
|
|
3691
|
+
* first_name: "John",
|
|
3692
|
+
* last_name: "Smith",
|
|
3693
|
+
* email: "john.smith@example.com"
|
|
3694
|
+
* }
|
|
3695
|
+
* );
|
|
3696
|
+
*
|
|
3697
|
+
* if (error) {
|
|
3698
|
+
* console.error("Failed to update customer:", error);
|
|
3699
|
+
* return;
|
|
3700
|
+
* }
|
|
3701
|
+
*
|
|
3702
|
+
* console.log("Customer updated:", data.customer_detail);
|
|
3703
|
+
* ```
|
|
2074
3704
|
*/
|
|
2075
3705
|
async updateCustomer(pathParams, body) {
|
|
2076
3706
|
return this.executeRequest(
|
|
@@ -2087,6 +3717,28 @@ var CustomerClient = class extends StorefrontAPIClient {
|
|
|
2087
3717
|
*
|
|
2088
3718
|
* @param pathParams - Path parameters
|
|
2089
3719
|
* @returns Promise with addresses
|
|
3720
|
+
*
|
|
3721
|
+
* @example
|
|
3722
|
+
* ```typescript
|
|
3723
|
+
* const { data, error } = await sdk.customer.listAddresses({
|
|
3724
|
+
* user_id: "user_456"
|
|
3725
|
+
* });
|
|
3726
|
+
*
|
|
3727
|
+
* if (error) {
|
|
3728
|
+
* console.error("Failed to list addresses:", error);
|
|
3729
|
+
* return;
|
|
3730
|
+
* }
|
|
3731
|
+
*
|
|
3732
|
+
* console.log("Addresses:", data.addresses);
|
|
3733
|
+
* console.log("Pagination:", data.pagination);
|
|
3734
|
+
*
|
|
3735
|
+
* // With pagination
|
|
3736
|
+
* const { data: page2, error: page2Error } = await sdk.customer.listAddresses({
|
|
3737
|
+
* user_id: "user_456",
|
|
3738
|
+
* page: 2,
|
|
3739
|
+
* limit: 10
|
|
3740
|
+
* });
|
|
3741
|
+
* ```
|
|
2090
3742
|
*/
|
|
2091
3743
|
async listAddresses(pathParams) {
|
|
2092
3744
|
return this.executeRequest(
|
|
@@ -2103,6 +3755,30 @@ var CustomerClient = class extends StorefrontAPIClient {
|
|
|
2103
3755
|
* @param pathParams - Path parameters
|
|
2104
3756
|
* @param body - Address creation body
|
|
2105
3757
|
* @returns Promise with address details
|
|
3758
|
+
*
|
|
3759
|
+
* @example
|
|
3760
|
+
* ```typescript
|
|
3761
|
+
* const { data, error } = await sdk.customer.createAddress(
|
|
3762
|
+
* { user_id: "user_456" },
|
|
3763
|
+
* {
|
|
3764
|
+
* address_line1: "123 Main Street",
|
|
3765
|
+
* address_line2: "Apt 4B",
|
|
3766
|
+
* city: "New York",
|
|
3767
|
+
* state: "NY",
|
|
3768
|
+
* country: "US",
|
|
3769
|
+
* pincode: "10001",
|
|
3770
|
+
* is_default_billing: true,
|
|
3771
|
+
* is_default_shipping: false
|
|
3772
|
+
* }
|
|
3773
|
+
* );
|
|
3774
|
+
*
|
|
3775
|
+
* if (error) {
|
|
3776
|
+
* console.error("Failed to create address:", error);
|
|
3777
|
+
* return;
|
|
3778
|
+
* }
|
|
3779
|
+
*
|
|
3780
|
+
* console.log("Address created:", data.address);
|
|
3781
|
+
* ```
|
|
2106
3782
|
*/
|
|
2107
3783
|
async createAddress(pathParams, body) {
|
|
2108
3784
|
return this.executeRequest(
|
|
@@ -2119,6 +3795,21 @@ var CustomerClient = class extends StorefrontAPIClient {
|
|
|
2119
3795
|
*
|
|
2120
3796
|
* @param pathParams - Path parameters
|
|
2121
3797
|
* @returns Promise with address details
|
|
3798
|
+
*
|
|
3799
|
+
* @example
|
|
3800
|
+
* ```typescript
|
|
3801
|
+
* const { data, error } = await sdk.customer.getAddress({
|
|
3802
|
+
* user_id: "user_456",
|
|
3803
|
+
* address_id: "addr_789"
|
|
3804
|
+
* });
|
|
3805
|
+
*
|
|
3806
|
+
* if (error) {
|
|
3807
|
+
* console.error("Failed to get address:", error);
|
|
3808
|
+
* return;
|
|
3809
|
+
* }
|
|
3810
|
+
*
|
|
3811
|
+
* console.log("Address details:", data.address);
|
|
3812
|
+
* ```
|
|
2122
3813
|
*/
|
|
2123
3814
|
async getAddress(pathParams) {
|
|
2124
3815
|
return this.executeRequest(
|
|
@@ -2135,6 +3826,29 @@ var CustomerClient = class extends StorefrontAPIClient {
|
|
|
2135
3826
|
* @param pathParams - Path parameters
|
|
2136
3827
|
* @param body - Address update body
|
|
2137
3828
|
* @returns Promise with address details
|
|
3829
|
+
*
|
|
3830
|
+
* @example
|
|
3831
|
+
* ```typescript
|
|
3832
|
+
* const { data, error } = await sdk.customer.updateAddress(
|
|
3833
|
+
* {
|
|
3834
|
+
* user_id: "user_456",
|
|
3835
|
+
* address_id: "addr_789"
|
|
3836
|
+
* },
|
|
3837
|
+
* {
|
|
3838
|
+
* address_line1: "456 Oak Avenue",
|
|
3839
|
+
* city: "Los Angeles",
|
|
3840
|
+
* state: "CA",
|
|
3841
|
+
* pincode: "90210"
|
|
3842
|
+
* }
|
|
3843
|
+
* );
|
|
3844
|
+
*
|
|
3845
|
+
* if (error) {
|
|
3846
|
+
* console.error("Failed to update address:", error);
|
|
3847
|
+
* return;
|
|
3848
|
+
* }
|
|
3849
|
+
*
|
|
3850
|
+
* console.log("Address updated:", data.address);
|
|
3851
|
+
* ```
|
|
2138
3852
|
*/
|
|
2139
3853
|
async updateAddress(pathParams, body) {
|
|
2140
3854
|
return this.executeRequest(
|
|
@@ -2150,7 +3864,22 @@ var CustomerClient = class extends StorefrontAPIClient {
|
|
|
2150
3864
|
* Delete an address for a customer
|
|
2151
3865
|
*
|
|
2152
3866
|
* @param pathParams - Path parameters
|
|
2153
|
-
* @returns Promise with
|
|
3867
|
+
* @returns Promise with deletion response
|
|
3868
|
+
*
|
|
3869
|
+
* @example
|
|
3870
|
+
* ```typescript
|
|
3871
|
+
* const { data, error } = await sdk.customer.deleteAddress({
|
|
3872
|
+
* user_id: "user_456",
|
|
3873
|
+
* address_id: "addr_789"
|
|
3874
|
+
* });
|
|
3875
|
+
*
|
|
3876
|
+
* if (error) {
|
|
3877
|
+
* console.error("Failed to delete address:", error);
|
|
3878
|
+
* return;
|
|
3879
|
+
* }
|
|
3880
|
+
*
|
|
3881
|
+
* console.log("Address deleted:", data.message);
|
|
3882
|
+
* ```
|
|
2154
3883
|
*/
|
|
2155
3884
|
async deleteAddress(pathParams) {
|
|
2156
3885
|
return this.executeRequest(
|
|
@@ -2166,6 +3895,21 @@ var CustomerClient = class extends StorefrontAPIClient {
|
|
|
2166
3895
|
*
|
|
2167
3896
|
* @param pathParams - Path parameters
|
|
2168
3897
|
* @returns Promise with loyalty details
|
|
3898
|
+
*
|
|
3899
|
+
* @example
|
|
3900
|
+
* ```typescript
|
|
3901
|
+
* const { data, error } = await sdk.customer.getLoyaltyDetails({
|
|
3902
|
+
* user_id: "user_456"
|
|
3903
|
+
* });
|
|
3904
|
+
*
|
|
3905
|
+
* if (error) {
|
|
3906
|
+
* console.error("Failed to get loyalty details:", error);
|
|
3907
|
+
* return;
|
|
3908
|
+
* }
|
|
3909
|
+
*
|
|
3910
|
+
* console.log("Loyalty info:", data.loyalty);
|
|
3911
|
+
* console.log("Points balance:", data.loyalty_point_balance);
|
|
3912
|
+
* ```
|
|
2169
3913
|
*/
|
|
2170
3914
|
async getLoyaltyDetails(pathParams) {
|
|
2171
3915
|
return this.executeRequest(
|
|
@@ -2181,6 +3925,28 @@ var CustomerClient = class extends StorefrontAPIClient {
|
|
|
2181
3925
|
*
|
|
2182
3926
|
* @param pathParams - Path parameters
|
|
2183
3927
|
* @returns Promise with loyalty points activity
|
|
3928
|
+
*
|
|
3929
|
+
* @example
|
|
3930
|
+
* ```typescript
|
|
3931
|
+
* const { data, error } = await sdk.customer.listLoyaltyPointsActivity({
|
|
3932
|
+
* user_id: "user_456"
|
|
3933
|
+
* });
|
|
3934
|
+
*
|
|
3935
|
+
* if (error) {
|
|
3936
|
+
* console.error("Failed to get loyalty activity:", error);
|
|
3937
|
+
* return;
|
|
3938
|
+
* }
|
|
3939
|
+
*
|
|
3940
|
+
* console.log("Loyalty activity:", data.loyalty_points_activity);
|
|
3941
|
+
*
|
|
3942
|
+
* // With pagination and sorting
|
|
3943
|
+
* const { data: sortedData, error: sortedError } = await sdk.customer.listLoyaltyPointsActivity({
|
|
3944
|
+
* user_id: "user_456",
|
|
3945
|
+
* page: 1,
|
|
3946
|
+
* limit: 20,
|
|
3947
|
+
* sort_by: JSON.stringify({ "created_at": "desc" })
|
|
3948
|
+
* });
|
|
3949
|
+
* ```
|
|
2184
3950
|
*/
|
|
2185
3951
|
async listLoyaltyPointsActivity(pathParams) {
|
|
2186
3952
|
return this.executeRequest(
|
|
@@ -2196,6 +3962,21 @@ var CustomerClient = class extends StorefrontAPIClient {
|
|
|
2196
3962
|
*
|
|
2197
3963
|
* @param pathParams - Path parameters
|
|
2198
3964
|
* @returns Promise with reviews
|
|
3965
|
+
*
|
|
3966
|
+
* @example
|
|
3967
|
+
* ```typescript
|
|
3968
|
+
* const { data, error } = await sdk.customer.listCustomerReviews({
|
|
3969
|
+
* user_id: "user_456"
|
|
3970
|
+
* });
|
|
3971
|
+
*
|
|
3972
|
+
* if (error) {
|
|
3973
|
+
* console.error("Failed to get customer reviews:", error);
|
|
3974
|
+
* return;
|
|
3975
|
+
* }
|
|
3976
|
+
*
|
|
3977
|
+
* console.log("Customer reviews:", data.reviews);
|
|
3978
|
+
* console.log("Ready for review:", data.ready_for_review);
|
|
3979
|
+
* ```
|
|
2199
3980
|
*/
|
|
2200
3981
|
async listCustomerReviews(pathParams) {
|
|
2201
3982
|
return this.executeRequest(
|
|
@@ -2212,6 +3993,25 @@ var CustomerClient = class extends StorefrontAPIClient {
|
|
|
2212
3993
|
var StoreConfigClient = class extends StorefrontAPIClient {
|
|
2213
3994
|
/**
|
|
2214
3995
|
* Get store config
|
|
3996
|
+
*
|
|
3997
|
+
* @returns Promise with store configuration data
|
|
3998
|
+
*
|
|
3999
|
+
* @example
|
|
4000
|
+
* ```typescript
|
|
4001
|
+
* const { data, error } = await sdk.storeConfig.getStoreConfig();
|
|
4002
|
+
*
|
|
4003
|
+
* if (error) {
|
|
4004
|
+
* console.error('Failed to get store config:', error.message);
|
|
4005
|
+
* return;
|
|
4006
|
+
* }
|
|
4007
|
+
*
|
|
4008
|
+
* // Access store configuration data
|
|
4009
|
+
* const storeConfig = data.store_config;
|
|
4010
|
+
* console.log('Store brand:', storeConfig.brand.name);
|
|
4011
|
+
* console.log('Currency:', storeConfig.currency.code);
|
|
4012
|
+
* console.log('KYC enabled:', storeConfig.is_kyc_enabled);
|
|
4013
|
+
* console.log('Customer groups enabled:', storeConfig.is_customer_group_enabled);
|
|
4014
|
+
* ```
|
|
2215
4015
|
*/
|
|
2216
4016
|
async getStoreConfig() {
|
|
2217
4017
|
return this.executeRequest(() => this.client.GET("/store/config"));
|