@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.cjs
CHANGED
|
@@ -263,6 +263,21 @@ var CookieTokenStorage = class {
|
|
|
263
263
|
function createAuthMiddleware(config) {
|
|
264
264
|
let isRefreshing = false;
|
|
265
265
|
let refreshPromise = null;
|
|
266
|
+
let hasAssessedTokens = false;
|
|
267
|
+
const assessTokenStateOnce = async () => {
|
|
268
|
+
if (hasAssessedTokens) return;
|
|
269
|
+
hasAssessedTokens = true;
|
|
270
|
+
try {
|
|
271
|
+
const accessToken = await config.tokenStorage.getAccessToken();
|
|
272
|
+
const refreshToken = await config.tokenStorage.getRefreshToken();
|
|
273
|
+
if (!accessToken && refreshToken) {
|
|
274
|
+
await config.tokenStorage.clearTokens();
|
|
275
|
+
console.info("Cleaned up orphaned refresh token");
|
|
276
|
+
}
|
|
277
|
+
} catch (error) {
|
|
278
|
+
console.warn("Token state assessment failed:", error);
|
|
279
|
+
}
|
|
280
|
+
};
|
|
266
281
|
const refreshTokens = async () => {
|
|
267
282
|
if (isRefreshing && refreshPromise) {
|
|
268
283
|
return refreshPromise;
|
|
@@ -339,17 +354,55 @@ function createAuthMiddleware(config) {
|
|
|
339
354
|
return {
|
|
340
355
|
async onRequest({ request }) {
|
|
341
356
|
const pathname = getPathnameFromUrl(request.url);
|
|
357
|
+
await assessTokenStateOnce();
|
|
342
358
|
if (isAnonymousAuthEndpoint(pathname)) {
|
|
343
359
|
if (config.apiKey) {
|
|
344
360
|
request.headers.set("X-Api-Key", config.apiKey);
|
|
345
361
|
}
|
|
346
362
|
const existingToken = await config.tokenStorage.getAccessToken();
|
|
363
|
+
if (existingToken && !isTokenExpired(existingToken) && isUserLoggedIn(existingToken)) {
|
|
364
|
+
return new Response(
|
|
365
|
+
JSON.stringify({
|
|
366
|
+
message: "Cannot create anonymous session while authenticated",
|
|
367
|
+
success: false,
|
|
368
|
+
code: "USER_ALREADY_AUTHENTICATED"
|
|
369
|
+
}),
|
|
370
|
+
{
|
|
371
|
+
status: 400,
|
|
372
|
+
headers: { "Content-Type": "application/json" }
|
|
373
|
+
}
|
|
374
|
+
);
|
|
375
|
+
}
|
|
347
376
|
if (existingToken) {
|
|
348
377
|
request.headers.set("Authorization", `Bearer ${existingToken}`);
|
|
349
378
|
}
|
|
350
379
|
return request;
|
|
351
380
|
}
|
|
352
381
|
let accessToken = await config.tokenStorage.getAccessToken();
|
|
382
|
+
if (!accessToken) {
|
|
383
|
+
try {
|
|
384
|
+
const response = await fetch(`${config.baseUrl}/auth/anonymous`, {
|
|
385
|
+
method: "POST",
|
|
386
|
+
headers: {
|
|
387
|
+
"Content-Type": "application/json",
|
|
388
|
+
...config.apiKey && { "X-Api-Key": config.apiKey }
|
|
389
|
+
}
|
|
390
|
+
});
|
|
391
|
+
if (response.ok) {
|
|
392
|
+
const data = await response.json();
|
|
393
|
+
const tokens = data.content;
|
|
394
|
+
if (tokens?.access_token && tokens?.refresh_token) {
|
|
395
|
+
await config.tokenStorage.setAccessToken(tokens.access_token);
|
|
396
|
+
await config.tokenStorage.setRefreshToken(tokens.refresh_token);
|
|
397
|
+
accessToken = tokens.access_token;
|
|
398
|
+
config.onTokensUpdated?.(tokens.access_token, tokens.refresh_token);
|
|
399
|
+
console.info("Automatically created anonymous session for first API request");
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
} catch (error) {
|
|
403
|
+
console.warn("Failed to automatically create anonymous tokens:", error);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
353
406
|
if (accessToken && isTokenExpired(accessToken)) {
|
|
354
407
|
try {
|
|
355
408
|
await refreshTokens();
|
|
@@ -910,6 +963,50 @@ var CatalogClient = class extends StorefrontAPIClient {
|
|
|
910
963
|
* @param options - Optional query parameters
|
|
911
964
|
* @param headers - Optional header parameters (customer_group_id, etc.)
|
|
912
965
|
* @returns Promise with products and pagination info
|
|
966
|
+
*
|
|
967
|
+
* @example
|
|
968
|
+
* ```typescript
|
|
969
|
+
* // Basic product listing
|
|
970
|
+
* const { data, error } = await sdk.catalog.listProducts();
|
|
971
|
+
*
|
|
972
|
+
* if (error) {
|
|
973
|
+
* console.error("Failed to list products:", error);
|
|
974
|
+
* return;
|
|
975
|
+
* }
|
|
976
|
+
*
|
|
977
|
+
* console.log("Products found:", data.products?.length || 0);
|
|
978
|
+
* console.log("Pagination:", data.pagination);
|
|
979
|
+
*
|
|
980
|
+
* // With filtering and pagination
|
|
981
|
+
* const { data: filteredData, error: filteredError } = await sdk.catalog.listProducts({
|
|
982
|
+
* page: 1,
|
|
983
|
+
* limit: 20,
|
|
984
|
+
* sort_by: JSON.stringify({ "created_at": "desc" }),
|
|
985
|
+
* category_slug: ["electronics", "smartphones"]
|
|
986
|
+
* });
|
|
987
|
+
*
|
|
988
|
+
* // Override customer group ID for this specific request
|
|
989
|
+
* const { data: overrideData, error: overrideError } = await sdk.catalog.listProducts(
|
|
990
|
+
* {
|
|
991
|
+
* page: 1,
|
|
992
|
+
* limit: 20,
|
|
993
|
+
* sort_by: JSON.stringify({ "created_at": "desc" }),
|
|
994
|
+
* category_slug: ["electronics", "smartphones"]
|
|
995
|
+
* },
|
|
996
|
+
* {
|
|
997
|
+
* "x-customer-group-id": "01H9XYZ12345USERID" // Override default SDK config
|
|
998
|
+
* }
|
|
999
|
+
* );
|
|
1000
|
+
*
|
|
1001
|
+
* if (filteredError) {
|
|
1002
|
+
* console.error("Failed to get filtered products:", filteredError);
|
|
1003
|
+
* return;
|
|
1004
|
+
* }
|
|
1005
|
+
*
|
|
1006
|
+
* filteredData.products?.forEach(product => {
|
|
1007
|
+
* console.log(`Product: ${product.name} - ${product.price}`);
|
|
1008
|
+
* });
|
|
1009
|
+
* ```
|
|
913
1010
|
*/
|
|
914
1011
|
async listProducts(options, headers) {
|
|
915
1012
|
const mergedHeaders = this.mergeHeaders(headers);
|
|
@@ -928,6 +1025,46 @@ var CatalogClient = class extends StorefrontAPIClient {
|
|
|
928
1025
|
* @param options - Optional query parameters
|
|
929
1026
|
* @param headers - Optional header parameters (customer_group_id, etc.)
|
|
930
1027
|
* @returns Promise with skus and pagination info
|
|
1028
|
+
*
|
|
1029
|
+
* @example
|
|
1030
|
+
* ```typescript
|
|
1031
|
+
* // Basic SKU listing
|
|
1032
|
+
* const { data, error } = await sdk.catalog.listSkus();
|
|
1033
|
+
*
|
|
1034
|
+
* if (error) {
|
|
1035
|
+
* console.error("Failed to list SKUs:", error);
|
|
1036
|
+
* return;
|
|
1037
|
+
* }
|
|
1038
|
+
*
|
|
1039
|
+
* console.log("SKUs found:", data.skus?.length || 0);
|
|
1040
|
+
* console.log("Pagination:", data.pagination);
|
|
1041
|
+
*
|
|
1042
|
+
* // With pagination
|
|
1043
|
+
* const { data: skuData, error: skuError } = await sdk.catalog.listSkus({
|
|
1044
|
+
* page: 1,
|
|
1045
|
+
* limit: 50
|
|
1046
|
+
* });
|
|
1047
|
+
*
|
|
1048
|
+
* // Override customer group ID for this specific request
|
|
1049
|
+
* const { data: overrideData, error: overrideError } = await sdk.catalog.listSkus(
|
|
1050
|
+
* {
|
|
1051
|
+
* page: 1,
|
|
1052
|
+
* limit: 50
|
|
1053
|
+
* },
|
|
1054
|
+
* {
|
|
1055
|
+
* "x-customer-group-id": "01H9XYZ12345USERID" // Override default SDK config
|
|
1056
|
+
* }
|
|
1057
|
+
* );
|
|
1058
|
+
*
|
|
1059
|
+
* if (skuError) {
|
|
1060
|
+
* console.error("Failed to get SKUs:", skuError);
|
|
1061
|
+
* return;
|
|
1062
|
+
* }
|
|
1063
|
+
*
|
|
1064
|
+
* skuData.skus?.forEach(sku => {
|
|
1065
|
+
* console.log(`SKU: ${sku.sku} - Price: ${sku.price}`);
|
|
1066
|
+
* });
|
|
1067
|
+
* ```
|
|
931
1068
|
*/
|
|
932
1069
|
async listSkus(options, headers) {
|
|
933
1070
|
const mergedHeaders = this.mergeHeaders(headers);
|
|
@@ -946,6 +1083,43 @@ var CatalogClient = class extends StorefrontAPIClient {
|
|
|
946
1083
|
* @param pathParams - The path parameters (product ID or slug)
|
|
947
1084
|
* @param headers - Optional header parameters (customer_group_id, etc.)
|
|
948
1085
|
* @returns Promise with product details
|
|
1086
|
+
*
|
|
1087
|
+
* @example
|
|
1088
|
+
* ```typescript
|
|
1089
|
+
* // Get product by ID
|
|
1090
|
+
* const { data, error } = await sdk.catalog.getProductDetail(
|
|
1091
|
+
* { product_id_or_slug: "prod_123" }
|
|
1092
|
+
* );
|
|
1093
|
+
*
|
|
1094
|
+
* if (error) {
|
|
1095
|
+
* console.error("Failed to get product details:", error);
|
|
1096
|
+
* return;
|
|
1097
|
+
* }
|
|
1098
|
+
*
|
|
1099
|
+
* console.log("Product:", data.product.name);
|
|
1100
|
+
* console.log("Price:", data.product.price);
|
|
1101
|
+
* console.log("Description:", data.product.description);
|
|
1102
|
+
*
|
|
1103
|
+
* // Get product by slug
|
|
1104
|
+
* const { data: slugData, error: slugError } = await sdk.catalog.getProductDetail({
|
|
1105
|
+
* product_id_or_slug: "detox-candy"
|
|
1106
|
+
* });
|
|
1107
|
+
*
|
|
1108
|
+
* // Override customer group ID for this specific request
|
|
1109
|
+
* const { data: overrideData, error: overrideError } = await sdk.catalog.getProductDetail(
|
|
1110
|
+
* { product_id_or_slug: "detox-candy" },
|
|
1111
|
+
* {
|
|
1112
|
+
* "x-customer-group-id": "premium_customers" // Override default SDK config
|
|
1113
|
+
* }
|
|
1114
|
+
* );
|
|
1115
|
+
*
|
|
1116
|
+
* if (slugError) {
|
|
1117
|
+
* console.error("Failed to get product by slug:", slugError);
|
|
1118
|
+
* return;
|
|
1119
|
+
* }
|
|
1120
|
+
*
|
|
1121
|
+
* console.log("Product with custom pricing:", slugData.product.price);
|
|
1122
|
+
* ```
|
|
949
1123
|
*/
|
|
950
1124
|
async getProductDetail(pathParams, headers) {
|
|
951
1125
|
const mergedHeaders = this.mergeHeaders(headers);
|
|
@@ -959,11 +1133,37 @@ var CatalogClient = class extends StorefrontAPIClient {
|
|
|
959
1133
|
);
|
|
960
1134
|
}
|
|
961
1135
|
/**
|
|
962
|
-
* List variants for a specific product
|
|
1136
|
+
* List all variants for a specific product
|
|
963
1137
|
*
|
|
964
1138
|
* @param pathParams - The path parameters (product ID)
|
|
965
1139
|
* @param headers - Optional header parameters (customer_group_id, etc.)
|
|
966
|
-
* @returns Promise with variants
|
|
1140
|
+
* @returns Promise with product variants and pagination info
|
|
1141
|
+
*
|
|
1142
|
+
* @example
|
|
1143
|
+
* ```typescript
|
|
1144
|
+
* const { data, error } = await sdk.catalog.listProductVariants(
|
|
1145
|
+
* { product_id: "prod_123" }
|
|
1146
|
+
* );
|
|
1147
|
+
*
|
|
1148
|
+
* if (error) {
|
|
1149
|
+
* console.error("Failed to list product variants:", error);
|
|
1150
|
+
* return;
|
|
1151
|
+
* }
|
|
1152
|
+
*
|
|
1153
|
+
* console.log("Variants found:", data.variants?.length || 0);
|
|
1154
|
+
*
|
|
1155
|
+
* data.variants?.forEach(variant => {
|
|
1156
|
+
* console.log(`Variant: ${variant.name} - SKU: ${variant.sku} - Price: ${variant.price}`);
|
|
1157
|
+
* });
|
|
1158
|
+
*
|
|
1159
|
+
* // Override customer group ID for this specific request
|
|
1160
|
+
* const { data: overrideData, error: overrideError } = await sdk.catalog.listProductVariants(
|
|
1161
|
+
* { product_id: "prod_123" },
|
|
1162
|
+
* {
|
|
1163
|
+
* "x-customer-group-id": "wholesale_customers" // Override default SDK config
|
|
1164
|
+
* }
|
|
1165
|
+
* );
|
|
1166
|
+
* ```
|
|
967
1167
|
*/
|
|
968
1168
|
async listProductVariants(pathParams, headers) {
|
|
969
1169
|
const mergedHeaders = this.mergeHeaders(headers);
|
|
@@ -977,11 +1177,31 @@ var CatalogClient = class extends StorefrontAPIClient {
|
|
|
977
1177
|
);
|
|
978
1178
|
}
|
|
979
1179
|
/**
|
|
980
|
-
* Get details for a specific variant
|
|
1180
|
+
* Get details for a specific product variant
|
|
981
1181
|
*
|
|
982
1182
|
* @param pathParams - The path parameters (product ID and variant ID)
|
|
983
1183
|
* @param headers - Optional header parameters (customer_group_id, etc.)
|
|
984
1184
|
* @returns Promise with variant details
|
|
1185
|
+
*
|
|
1186
|
+
* @example
|
|
1187
|
+
* ```typescript
|
|
1188
|
+
* const { data, error } = await sdk.catalog.getVariantDetail(
|
|
1189
|
+
* {
|
|
1190
|
+
* product_id: "prod_123",
|
|
1191
|
+
* variant_id: "var_456"
|
|
1192
|
+
* }
|
|
1193
|
+
* );
|
|
1194
|
+
*
|
|
1195
|
+
* if (error) {
|
|
1196
|
+
* console.error("Failed to get variant details:", error);
|
|
1197
|
+
* return;
|
|
1198
|
+
* }
|
|
1199
|
+
*
|
|
1200
|
+
* console.log("Variant:", data.variant.name);
|
|
1201
|
+
* console.log("SKU:", data.variant.sku);
|
|
1202
|
+
* console.log("Price:", data.variant.price);
|
|
1203
|
+
* console.log("Stock:", data.variant.stock);
|
|
1204
|
+
* ```
|
|
985
1205
|
*/
|
|
986
1206
|
async getVariantDetail(pathParams, headers) {
|
|
987
1207
|
const mergedHeaders = this.mergeHeaders(headers);
|
|
@@ -995,24 +1215,77 @@ var CatalogClient = class extends StorefrontAPIClient {
|
|
|
995
1215
|
);
|
|
996
1216
|
}
|
|
997
1217
|
/**
|
|
998
|
-
* List all categories
|
|
1218
|
+
* List all product categories
|
|
999
1219
|
*
|
|
1000
1220
|
* @param options - Optional query parameters
|
|
1001
1221
|
* @returns Promise with categories and pagination info
|
|
1222
|
+
*
|
|
1223
|
+
* @example
|
|
1224
|
+
* ```typescript
|
|
1225
|
+
* // Basic category listing
|
|
1226
|
+
* const { data, error } = await sdk.catalog.listCategories();
|
|
1227
|
+
*
|
|
1228
|
+
* if (error) {
|
|
1229
|
+
* console.error("Failed to list categories:", error);
|
|
1230
|
+
* return;
|
|
1231
|
+
* }
|
|
1232
|
+
*
|
|
1233
|
+
* console.log("Categories found:", data.categories?.length || 0);
|
|
1234
|
+
*
|
|
1235
|
+
* data.categories?.forEach(category => {
|
|
1236
|
+
* console.log(`Category: ${category.name} - ${category.description}`);
|
|
1237
|
+
* });
|
|
1238
|
+
*
|
|
1239
|
+
* // With pagination
|
|
1240
|
+
* const { data: catData, error: catError } = await sdk.catalog.listCategories({
|
|
1241
|
+
* page: 1,
|
|
1242
|
+
* limit: 10
|
|
1243
|
+
* });
|
|
1244
|
+
* ```
|
|
1002
1245
|
*/
|
|
1003
1246
|
async listCategories(options) {
|
|
1004
1247
|
return this.executeRequest(
|
|
1005
1248
|
() => this.client.GET("/catalog/categories", {
|
|
1006
|
-
params: {
|
|
1249
|
+
params: {
|
|
1250
|
+
query: options
|
|
1251
|
+
}
|
|
1007
1252
|
})
|
|
1008
1253
|
);
|
|
1009
1254
|
}
|
|
1010
1255
|
/**
|
|
1011
|
-
* List reviews for a specific product
|
|
1256
|
+
* List all reviews for a specific product
|
|
1012
1257
|
*
|
|
1013
1258
|
* @param pathParams - The path parameters (product ID)
|
|
1014
1259
|
* @param queryParams - Optional query parameters
|
|
1015
|
-
* @returns Promise with reviews and pagination info
|
|
1260
|
+
* @returns Promise with product reviews and pagination info
|
|
1261
|
+
*
|
|
1262
|
+
* @example
|
|
1263
|
+
* ```typescript
|
|
1264
|
+
* const { data, error } = await sdk.catalog.listProductReviews(
|
|
1265
|
+
* { product_id: "prod_123" }
|
|
1266
|
+
* );
|
|
1267
|
+
*
|
|
1268
|
+
* if (error) {
|
|
1269
|
+
* console.error("Failed to list product reviews:", error);
|
|
1270
|
+
* return;
|
|
1271
|
+
* }
|
|
1272
|
+
*
|
|
1273
|
+
* console.log("Reviews found:", data.reviews?.length || 0);
|
|
1274
|
+
*
|
|
1275
|
+
* data.reviews?.forEach(review => {
|
|
1276
|
+
* console.log(`Review by ${review.customer_name}: ${review.rating}/5`);
|
|
1277
|
+
* console.log("Comment:", review.comment);
|
|
1278
|
+
* });
|
|
1279
|
+
*
|
|
1280
|
+
* // With pagination
|
|
1281
|
+
* const { data: reviewData, error: reviewError } = await sdk.catalog.listProductReviews(
|
|
1282
|
+
* { product_id: "prod_123" },
|
|
1283
|
+
* {
|
|
1284
|
+
* page: 1,
|
|
1285
|
+
* limit: 5
|
|
1286
|
+
* }
|
|
1287
|
+
* );
|
|
1288
|
+
* ```
|
|
1016
1289
|
*/
|
|
1017
1290
|
async listProductReviews(pathParams, queryParams) {
|
|
1018
1291
|
return this.executeRequest(
|
|
@@ -1025,11 +1298,33 @@ var CatalogClient = class extends StorefrontAPIClient {
|
|
|
1025
1298
|
);
|
|
1026
1299
|
}
|
|
1027
1300
|
/**
|
|
1028
|
-
* Create a review
|
|
1301
|
+
* Create a product review
|
|
1029
1302
|
*
|
|
1030
1303
|
* @param pathParams - The path parameters (product ID)
|
|
1031
|
-
* @param formData - The review data
|
|
1032
|
-
* @returns Promise
|
|
1304
|
+
* @param formData - The review data including rating, comment, and optional images
|
|
1305
|
+
* @returns Promise with review creation response
|
|
1306
|
+
*
|
|
1307
|
+
* @example
|
|
1308
|
+
* ```typescript
|
|
1309
|
+
* const { data, error } = await sdk.catalog.createProductReview(
|
|
1310
|
+
* { product_id: "prod_123" },
|
|
1311
|
+
* {
|
|
1312
|
+
* rating: 5,
|
|
1313
|
+
* comment: "Excellent product! Highly recommended.",
|
|
1314
|
+
* images: [
|
|
1315
|
+
* new File(["image data"], "review1.jpg", { type: "image/jpeg" }),
|
|
1316
|
+
* new File(["image data"], "review2.jpg", { type: "image/jpeg" })
|
|
1317
|
+
* ]
|
|
1318
|
+
* }
|
|
1319
|
+
* );
|
|
1320
|
+
*
|
|
1321
|
+
* if (error) {
|
|
1322
|
+
* console.error("Failed to create review:", error);
|
|
1323
|
+
* return;
|
|
1324
|
+
* }
|
|
1325
|
+
*
|
|
1326
|
+
* console.log("Review created successfully:", data.message);
|
|
1327
|
+
* ```
|
|
1033
1328
|
*/
|
|
1034
1329
|
async createProductReview(pathParams, formData) {
|
|
1035
1330
|
return this.executeRequest(
|
|
@@ -1057,24 +1352,103 @@ var CatalogClient = class extends StorefrontAPIClient {
|
|
|
1057
1352
|
/**
|
|
1058
1353
|
* Search for products
|
|
1059
1354
|
*
|
|
1060
|
-
* @param searchData - The search
|
|
1061
|
-
* @
|
|
1355
|
+
* @param searchData - The search query and filters
|
|
1356
|
+
* @param headers - Optional header parameters (customer_group_id, etc.)
|
|
1357
|
+
* @returns Promise with search results including products, facets, and pagination
|
|
1358
|
+
*
|
|
1359
|
+
* @example
|
|
1360
|
+
* ```typescript
|
|
1361
|
+
* const { data, error } = await sdk.catalog.searchProducts({
|
|
1362
|
+
* query: "smartphone",
|
|
1363
|
+
* filters: {
|
|
1364
|
+
* category: ["electronics", "mobile"],
|
|
1365
|
+
* price_range: { min: 100, max: 1000 },
|
|
1366
|
+
* brand: ["Apple", "Samsung"] // facet names depend on product configuration
|
|
1367
|
+
* },
|
|
1368
|
+
* page: 1,
|
|
1369
|
+
* limit: 20
|
|
1370
|
+
* });
|
|
1371
|
+
*
|
|
1372
|
+
* if (error) {
|
|
1373
|
+
* console.error("Failed to search products:", error);
|
|
1374
|
+
* return;
|
|
1375
|
+
* }
|
|
1376
|
+
*
|
|
1377
|
+
* console.log("Search results:", data.skus?.length || 0, "products found");
|
|
1378
|
+
* console.log("Facet distribution:", data.facet_distribution);
|
|
1379
|
+
* console.log("Price range:", data.facet_stats.price_range);
|
|
1380
|
+
*
|
|
1381
|
+
* data.skus?.forEach(sku => {
|
|
1382
|
+
* console.log(`Found: ${sku.name} - ${sku.price}`);
|
|
1383
|
+
* });
|
|
1384
|
+
*
|
|
1385
|
+
* // Override customer group ID for this specific request
|
|
1386
|
+
* const { data: overrideData, error: overrideError } = await sdk.catalog.searchProducts(
|
|
1387
|
+
* {
|
|
1388
|
+
* query: "laptop",
|
|
1389
|
+
* filters: { category: ["computers"] }
|
|
1390
|
+
* },
|
|
1391
|
+
* {
|
|
1392
|
+
* "x-customer-group-id": "01H9XYZ12345USERID" // Override default SDK config
|
|
1393
|
+
* }
|
|
1394
|
+
* );
|
|
1395
|
+
* ```
|
|
1062
1396
|
*/
|
|
1063
1397
|
async searchProducts(searchData, headers) {
|
|
1064
1398
|
const mergedHeaders = this.mergeHeaders(headers);
|
|
1065
1399
|
return this.executeRequest(
|
|
1066
1400
|
() => this.client.POST("/catalog/products/search", {
|
|
1067
|
-
|
|
1068
|
-
|
|
1401
|
+
params: {
|
|
1402
|
+
header: mergedHeaders
|
|
1403
|
+
},
|
|
1404
|
+
body: searchData
|
|
1069
1405
|
})
|
|
1070
1406
|
);
|
|
1071
1407
|
}
|
|
1072
1408
|
/**
|
|
1073
1409
|
* List cross-sell products
|
|
1074
1410
|
*
|
|
1075
|
-
* @param options - Optional query parameters
|
|
1411
|
+
* @param options - Optional query parameters for filtering and pagination
|
|
1076
1412
|
* @param headers - Optional header parameters (customer_group_id, etc.)
|
|
1077
1413
|
* @returns Promise with cross-sell products
|
|
1414
|
+
* @example
|
|
1415
|
+
* ```typescript
|
|
1416
|
+
* // Basic usage - get cross-sell products for cart items
|
|
1417
|
+
* const { data, error } = await sdk.catalog.listCrossSellProducts({
|
|
1418
|
+
* product_id: ["prod_01H9XYZ12345ABCDE", "prod_01H9ABC67890FGHIJ"]
|
|
1419
|
+
* });
|
|
1420
|
+
*
|
|
1421
|
+
* // Advanced usage with pagination and custom sorting
|
|
1422
|
+
* const { data, error } = await sdk.catalog.listCrossSellProducts({
|
|
1423
|
+
* product_id: ["prod_01H9XYZ12345ABCDE"],
|
|
1424
|
+
* page: 1,
|
|
1425
|
+
* limit: 10,
|
|
1426
|
+
* sort_by: '{"price":"asc"}'
|
|
1427
|
+
* });
|
|
1428
|
+
*
|
|
1429
|
+
* // Override customer group ID for this specific request
|
|
1430
|
+
* const { data, error } = await sdk.catalog.listCrossSellProducts(
|
|
1431
|
+
* {
|
|
1432
|
+
* product_id: ["prod_01H9XYZ12345ABCDE"],
|
|
1433
|
+
* page: 1,
|
|
1434
|
+
* limit: 10
|
|
1435
|
+
* },
|
|
1436
|
+
* {
|
|
1437
|
+
* "x-customer-group-id": "01H9XYZ12345USERID" // Override default SDK config
|
|
1438
|
+
* }
|
|
1439
|
+
* );
|
|
1440
|
+
*
|
|
1441
|
+
* if (error) {
|
|
1442
|
+
* console.error("Failed to get cross-sell products:", error.message);
|
|
1443
|
+
* } else {
|
|
1444
|
+
* console.log("Cross-sell products found:", data.content.products.length);
|
|
1445
|
+
* console.log("Pagination:", data.content.pagination);
|
|
1446
|
+
*
|
|
1447
|
+
* data.content.products.forEach(product => {
|
|
1448
|
+
* console.log(`Product: ${product.name} - ${product.price}`);
|
|
1449
|
+
* });
|
|
1450
|
+
* }
|
|
1451
|
+
* ```
|
|
1078
1452
|
*/
|
|
1079
1453
|
async listCrossSellProducts(options, headers) {
|
|
1080
1454
|
const mergedHeaders = this.mergeHeaders(headers);
|
|
@@ -1090,9 +1464,47 @@ var CatalogClient = class extends StorefrontAPIClient {
|
|
|
1090
1464
|
/**
|
|
1091
1465
|
* List up-sell products
|
|
1092
1466
|
*
|
|
1093
|
-
* @param options - Optional query parameters
|
|
1467
|
+
* @param options - Optional query parameters for filtering and pagination
|
|
1094
1468
|
* @param headers - Optional header parameters (customer_group_id, etc.)
|
|
1095
1469
|
* @returns Promise with up-sell products
|
|
1470
|
+
* @example
|
|
1471
|
+
* ```typescript
|
|
1472
|
+
* // Basic usage - get up-sell products for cart items
|
|
1473
|
+
* const { data, error } = await sdk.catalog.listUpSellProducts({
|
|
1474
|
+
* product_id: ["prod_01H9XYZ12345ABCDE"]
|
|
1475
|
+
* });
|
|
1476
|
+
*
|
|
1477
|
+
* // Advanced usage with pagination and custom sorting
|
|
1478
|
+
* const { data, error } = await sdk.catalog.listUpSellProducts({
|
|
1479
|
+
* product_id: ["prod_01H9XYZ12345ABCDE"],
|
|
1480
|
+
* page: 1,
|
|
1481
|
+
* limit: 15,
|
|
1482
|
+
* sort_by: '{"relevance":"desc"}'
|
|
1483
|
+
* });
|
|
1484
|
+
*
|
|
1485
|
+
* // Override customer group ID for this specific request
|
|
1486
|
+
* const { data, error } = await sdk.catalog.listUpSellProducts(
|
|
1487
|
+
* {
|
|
1488
|
+
* product_id: ["prod_01H9XYZ12345ABCDE"],
|
|
1489
|
+
* page: 1,
|
|
1490
|
+
* limit: 15
|
|
1491
|
+
* },
|
|
1492
|
+
* {
|
|
1493
|
+
* "x-customer-group-id": "01H9XYZ12345USERID" // Override default SDK config
|
|
1494
|
+
* }
|
|
1495
|
+
* );
|
|
1496
|
+
*
|
|
1497
|
+
* if (error) {
|
|
1498
|
+
* console.error("Failed to get up-sell products:", error.message);
|
|
1499
|
+
* } else {
|
|
1500
|
+
* console.log("Up-sell products found:", data.content.products.length);
|
|
1501
|
+
* console.log("Pagination:", data.content.pagination);
|
|
1502
|
+
*
|
|
1503
|
+
* data.content.products.forEach(product => {
|
|
1504
|
+
* console.log(`Up-sell: ${product.name} - ${product.price}`);
|
|
1505
|
+
* });
|
|
1506
|
+
* }
|
|
1507
|
+
* ```
|
|
1096
1508
|
*/
|
|
1097
1509
|
async listUpSellProducts(options, headers) {
|
|
1098
1510
|
const mergedHeaders = this.mergeHeaders(headers);
|
|
@@ -1108,9 +1520,47 @@ var CatalogClient = class extends StorefrontAPIClient {
|
|
|
1108
1520
|
/**
|
|
1109
1521
|
* List similar products
|
|
1110
1522
|
*
|
|
1111
|
-
* @param options - Optional query parameters
|
|
1523
|
+
* @param options - Optional query parameters for filtering and pagination
|
|
1112
1524
|
* @param headers - Optional header parameters (customer_group_id, etc.)
|
|
1113
1525
|
* @returns Promise with similar products
|
|
1526
|
+
* @example
|
|
1527
|
+
* ```typescript
|
|
1528
|
+
* // Basic usage - get similar products for a specific product
|
|
1529
|
+
* const { data, error } = await sdk.catalog.listSimilarProducts({
|
|
1530
|
+
* product_id: ["prod_01H9XYZ12345ABCDE"]
|
|
1531
|
+
* });
|
|
1532
|
+
*
|
|
1533
|
+
* // Advanced usage with pagination and custom sorting
|
|
1534
|
+
* const { data, error } = await sdk.catalog.listSimilarProducts({
|
|
1535
|
+
* product_id: ["prod_01H9XYZ12345ABCDE"],
|
|
1536
|
+
* page: 1,
|
|
1537
|
+
* limit: 20,
|
|
1538
|
+
* sort_by: '{"relevance":"desc"}'
|
|
1539
|
+
* });
|
|
1540
|
+
*
|
|
1541
|
+
* // Override customer group ID for this specific request
|
|
1542
|
+
* const { data, error } = await sdk.catalog.listSimilarProducts(
|
|
1543
|
+
* {
|
|
1544
|
+
* product_id: ["prod_01H9XYZ12345ABCDE"],
|
|
1545
|
+
* page: 1,
|
|
1546
|
+
* limit: 20
|
|
1547
|
+
* },
|
|
1548
|
+
* {
|
|
1549
|
+
* "x-customer-group-id": "01H9XYZ12345USERID" // Override default SDK config
|
|
1550
|
+
* }
|
|
1551
|
+
* );
|
|
1552
|
+
*
|
|
1553
|
+
* if (error) {
|
|
1554
|
+
* console.error("Failed to get similar products:", error.message);
|
|
1555
|
+
* } else {
|
|
1556
|
+
* console.log("Similar products found:", data.content.products.length);
|
|
1557
|
+
* console.log("Pagination:", data.content.pagination);
|
|
1558
|
+
*
|
|
1559
|
+
* data.content.products.forEach(product => {
|
|
1560
|
+
* console.log(`Similar: ${product.name} - ${product.price}`);
|
|
1561
|
+
* });
|
|
1562
|
+
* }
|
|
1563
|
+
* ```
|
|
1114
1564
|
*/
|
|
1115
1565
|
async listSimilarProducts(options, headers) {
|
|
1116
1566
|
const mergedHeaders = this.mergeHeaders(headers);
|
|
@@ -1132,6 +1582,33 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
1132
1582
|
*
|
|
1133
1583
|
* @param payload - Object containing the items to add to the cart
|
|
1134
1584
|
* @returns Promise with the created cart
|
|
1585
|
+
* @example
|
|
1586
|
+
* ```typescript
|
|
1587
|
+
* const { data, error } = await sdk.cart.createCart({
|
|
1588
|
+
* items: [
|
|
1589
|
+
* {
|
|
1590
|
+
* product_id: "01H9XYZ12345ABCDE",
|
|
1591
|
+
* variant_id: null,
|
|
1592
|
+
* quantity: 2
|
|
1593
|
+
* },
|
|
1594
|
+
* {
|
|
1595
|
+
* product_id: "01H9ABC67890FGHIJ",
|
|
1596
|
+
* variant_id: "01H9XYZ67890KLMNO",
|
|
1597
|
+
* quantity: 1
|
|
1598
|
+
* }
|
|
1599
|
+
* ],
|
|
1600
|
+
* metadata: {
|
|
1601
|
+
* "source": "web",
|
|
1602
|
+
* "campaign": "summer_sale"
|
|
1603
|
+
* }
|
|
1604
|
+
* });
|
|
1605
|
+
*
|
|
1606
|
+
* if (error) {
|
|
1607
|
+
* console.error("Failed to create cart:", error.message);
|
|
1608
|
+
* } else {
|
|
1609
|
+
* console.log("Cart created:", data.cart.id);
|
|
1610
|
+
* }
|
|
1611
|
+
* ```
|
|
1135
1612
|
*/
|
|
1136
1613
|
async createCart(payload) {
|
|
1137
1614
|
return this.executeRequest(
|
|
@@ -1145,6 +1622,20 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
1145
1622
|
*
|
|
1146
1623
|
* @param cartId - The ID of the cart
|
|
1147
1624
|
* @returns Promise with cart details
|
|
1625
|
+
* @example
|
|
1626
|
+
* ```typescript
|
|
1627
|
+
* const { data, error } = await sdk.cart.getCart({
|
|
1628
|
+
* id: "01H9CART12345ABCDE"
|
|
1629
|
+
* });
|
|
1630
|
+
*
|
|
1631
|
+
* if (error) {
|
|
1632
|
+
* console.error("Failed to get cart:", error.message);
|
|
1633
|
+
* } else {
|
|
1634
|
+
* const cart = data.cart;
|
|
1635
|
+
* console.log("Cart total:", cart.total_amount);
|
|
1636
|
+
* console.log("Items count:", cart.items.length);
|
|
1637
|
+
* }
|
|
1638
|
+
* ```
|
|
1148
1639
|
*/
|
|
1149
1640
|
async getCart(cartId) {
|
|
1150
1641
|
return this.executeRequest(
|
|
@@ -1160,6 +1651,18 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
1160
1651
|
*
|
|
1161
1652
|
* @param cartId - The ID of the cart
|
|
1162
1653
|
* @returns Promise that resolves when the cart is deleted
|
|
1654
|
+
* @example
|
|
1655
|
+
* ```typescript
|
|
1656
|
+
* const { data, error } = await sdk.cart.deleteCart({
|
|
1657
|
+
* id: "01H9CART12345ABCDE"
|
|
1658
|
+
* });
|
|
1659
|
+
*
|
|
1660
|
+
* if (error) {
|
|
1661
|
+
* console.error("Failed to delete cart:", error.message);
|
|
1662
|
+
* } else {
|
|
1663
|
+
* console.log("Cart deleted:", data.message);
|
|
1664
|
+
* }
|
|
1665
|
+
* ```
|
|
1163
1666
|
*/
|
|
1164
1667
|
async deleteCart(cartId) {
|
|
1165
1668
|
return this.executeRequest(
|
|
@@ -1176,6 +1679,34 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
1176
1679
|
* @param cartId - The cart id
|
|
1177
1680
|
* @param body - The body of the request
|
|
1178
1681
|
* @returns Promise with updated cart
|
|
1682
|
+
* @example
|
|
1683
|
+
* ```typescript
|
|
1684
|
+
* // Add item to cart
|
|
1685
|
+
* const { data, error } = await sdk.cart.addDeleteCartItem(
|
|
1686
|
+
* { id: "01H9CART12345ABCDE" },
|
|
1687
|
+
* {
|
|
1688
|
+
* product_id: "01H9XYZ12345ABCDE",
|
|
1689
|
+
* variant_id: null,
|
|
1690
|
+
* quantity: 3
|
|
1691
|
+
* }
|
|
1692
|
+
* );
|
|
1693
|
+
*
|
|
1694
|
+
* if (error) {
|
|
1695
|
+
* console.error("Failed to update cart:", error.message);
|
|
1696
|
+
* } else {
|
|
1697
|
+
* console.log("Cart updated:", data.cart.items.length);
|
|
1698
|
+
* }
|
|
1699
|
+
*
|
|
1700
|
+
* // Remove item from cart (set quantity to 0)
|
|
1701
|
+
* const { data: removeData, error: removeError } = await sdk.cart.addDeleteCartItem(
|
|
1702
|
+
* { id: "01H9CART12345ABCDE" },
|
|
1703
|
+
* {
|
|
1704
|
+
* product_id: "01H9XYZ12345ABCDE",
|
|
1705
|
+
* variant_id: null,
|
|
1706
|
+
* quantity: 0
|
|
1707
|
+
* }
|
|
1708
|
+
* );
|
|
1709
|
+
* ```
|
|
1179
1710
|
*/
|
|
1180
1711
|
async addDeleteCartItem(cartId, body) {
|
|
1181
1712
|
return this.executeRequest(
|
|
@@ -1192,6 +1723,19 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
1192
1723
|
*
|
|
1193
1724
|
* @param userId - The ID of the user
|
|
1194
1725
|
* @returns Promise with cart details
|
|
1726
|
+
* @example
|
|
1727
|
+
* ```typescript
|
|
1728
|
+
* const { data, error } = await sdk.cart.getUserCart({
|
|
1729
|
+
* user_id: "01H9USER12345ABCDE"
|
|
1730
|
+
* });
|
|
1731
|
+
*
|
|
1732
|
+
* if (error) {
|
|
1733
|
+
* console.error("Failed to get user cart:", error.message);
|
|
1734
|
+
* } else {
|
|
1735
|
+
* console.log("User cart ID:", data.cart.id);
|
|
1736
|
+
* console.log("Cart value:", data.cart.subtotal_amount);
|
|
1737
|
+
* }
|
|
1738
|
+
* ```
|
|
1195
1739
|
*/
|
|
1196
1740
|
async getUserCart(userId) {
|
|
1197
1741
|
return this.executeRequest(
|
|
@@ -1207,6 +1751,18 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
1207
1751
|
*
|
|
1208
1752
|
* @param userId - The ID of the user
|
|
1209
1753
|
* @returns Promise that resolves when the cart is deleted
|
|
1754
|
+
* @example
|
|
1755
|
+
* ```typescript
|
|
1756
|
+
* const { data, error } = await sdk.cart.deleteUserCart({
|
|
1757
|
+
* user_id: "01H9USER12345ABCDE"
|
|
1758
|
+
* });
|
|
1759
|
+
*
|
|
1760
|
+
* if (error) {
|
|
1761
|
+
* console.error("Failed to delete user cart:", error.message);
|
|
1762
|
+
* } else {
|
|
1763
|
+
* console.log("User cart cleared:", data.message);
|
|
1764
|
+
* }
|
|
1765
|
+
* ```
|
|
1210
1766
|
*/
|
|
1211
1767
|
async deleteUserCart(userId) {
|
|
1212
1768
|
return this.executeRequest(
|
|
@@ -1224,6 +1780,62 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
1224
1780
|
* @param cartId - The ID of the cart
|
|
1225
1781
|
* @param addressData - The address data
|
|
1226
1782
|
* @returns Promise with updated cart
|
|
1783
|
+
* @example
|
|
1784
|
+
* ```typescript
|
|
1785
|
+
* // For registered users with saved addresses
|
|
1786
|
+
* const { data, error } = await sdk.cart.updateCartAddress(
|
|
1787
|
+
* { id: "01H9CART12345ABCDE" },
|
|
1788
|
+
* {
|
|
1789
|
+
* billing_address_id: "01H9ADDR12345BILL",
|
|
1790
|
+
* shipping_address_id: "01H9ADDR12345SHIP"
|
|
1791
|
+
* }
|
|
1792
|
+
* );
|
|
1793
|
+
*
|
|
1794
|
+
* if (error) {
|
|
1795
|
+
* console.error("Failed to update cart address:", error.message);
|
|
1796
|
+
* } else {
|
|
1797
|
+
* console.log("Addresses updated:", data.message);
|
|
1798
|
+
* }
|
|
1799
|
+
*
|
|
1800
|
+
* // For guest checkout with new addresses
|
|
1801
|
+
* const { data: guestData, error: guestError } = await sdk.cart.updateCartAddress(
|
|
1802
|
+
* { id: "01H9CART12345ABCDE" },
|
|
1803
|
+
* {
|
|
1804
|
+
* billing_address: {
|
|
1805
|
+
* first_name: "John",
|
|
1806
|
+
* last_name: "Doe",
|
|
1807
|
+
* email: "john@example.com",
|
|
1808
|
+
* phone: "9876543210",
|
|
1809
|
+
* country_code: "+91",
|
|
1810
|
+
* address_line1: "123 Main Street",
|
|
1811
|
+
* address_line2: "Apt 4B",
|
|
1812
|
+
* city: "Mumbai",
|
|
1813
|
+
* state: "Maharashtra",
|
|
1814
|
+
* pincode: "400001",
|
|
1815
|
+
* country: "India",
|
|
1816
|
+
* landmark: "Near Station",
|
|
1817
|
+
* tax_identification_number: null,
|
|
1818
|
+
* business_name: null
|
|
1819
|
+
* },
|
|
1820
|
+
* shipping_address: {
|
|
1821
|
+
* first_name: "John",
|
|
1822
|
+
* last_name: "Doe",
|
|
1823
|
+
* email: "john@example.com",
|
|
1824
|
+
* phone: "9876543210",
|
|
1825
|
+
* country_code: "+91",
|
|
1826
|
+
* address_line1: "456 Oak Avenue",
|
|
1827
|
+
* address_line2: null,
|
|
1828
|
+
* city: "Pune",
|
|
1829
|
+
* state: "Maharashtra",
|
|
1830
|
+
* pincode: "411001",
|
|
1831
|
+
* country: "India",
|
|
1832
|
+
* landmark: "Near Mall",
|
|
1833
|
+
* tax_identification_number: null,
|
|
1834
|
+
* business_name: null
|
|
1835
|
+
* }
|
|
1836
|
+
* }
|
|
1837
|
+
* );
|
|
1838
|
+
* ```
|
|
1227
1839
|
*/
|
|
1228
1840
|
async updateCartAddress(cartId, addressData) {
|
|
1229
1841
|
return this.executeRequest(
|
|
@@ -1241,6 +1853,20 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
1241
1853
|
* @param cartId - The ID of the cart
|
|
1242
1854
|
* @param couponCode - The coupon code
|
|
1243
1855
|
* @returns Promise with updated cart
|
|
1856
|
+
* @example
|
|
1857
|
+
* ```typescript
|
|
1858
|
+
* const { data, error } = await sdk.cart.applyCoupon(
|
|
1859
|
+
* { id: "01H9CART12345ABCDE" },
|
|
1860
|
+
* { coupon_code: "FLAT100OFF" }
|
|
1861
|
+
* );
|
|
1862
|
+
*
|
|
1863
|
+
* if (error) {
|
|
1864
|
+
* console.error("Failed to apply coupon:", error.message);
|
|
1865
|
+
* } else {
|
|
1866
|
+
* console.log("Coupon applied, new total:", data.cart.total_amount);
|
|
1867
|
+
* console.log("Discount amount:", data.cart.coupon_discount_amount);
|
|
1868
|
+
* }
|
|
1869
|
+
* ```
|
|
1244
1870
|
*/
|
|
1245
1871
|
async applyCoupon(cartId, couponCode) {
|
|
1246
1872
|
return this.executeRequest(
|
|
@@ -1257,6 +1883,18 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
1257
1883
|
*
|
|
1258
1884
|
* @param cartId - The ID of the cart
|
|
1259
1885
|
* @returns Promise with updated cart
|
|
1886
|
+
* @example
|
|
1887
|
+
* ```typescript
|
|
1888
|
+
* const { data, error } = await sdk.cart.removeCoupon({
|
|
1889
|
+
* id: "01H9CART12345ABCDE"
|
|
1890
|
+
* });
|
|
1891
|
+
*
|
|
1892
|
+
* if (error) {
|
|
1893
|
+
* console.error("Failed to remove coupon:", error.message);
|
|
1894
|
+
* } else {
|
|
1895
|
+
* console.log("Coupon removed, new total:", data.cart.total_amount);
|
|
1896
|
+
* }
|
|
1897
|
+
* ```
|
|
1260
1898
|
*/
|
|
1261
1899
|
async removeCoupon(cartId) {
|
|
1262
1900
|
return this.executeRequest(
|
|
@@ -1274,6 +1912,20 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
1274
1912
|
* @param cartId - The ID of the cart
|
|
1275
1913
|
* @param points - The number of points to redeem
|
|
1276
1914
|
* @returns Promise with updated cart
|
|
1915
|
+
* @example
|
|
1916
|
+
* ```typescript
|
|
1917
|
+
* const { data, error } = await sdk.cart.redeemLoyaltyPoints(
|
|
1918
|
+
* { id: "01H9CART12345ABCDE" },
|
|
1919
|
+
* { points: 500 }
|
|
1920
|
+
* );
|
|
1921
|
+
*
|
|
1922
|
+
* if (error) {
|
|
1923
|
+
* console.error("Failed to redeem loyalty points:", error.message);
|
|
1924
|
+
* } else {
|
|
1925
|
+
* console.log("Points redeemed, new total:", data.cart.total_amount);
|
|
1926
|
+
* console.log("Points discount:", data.cart.loyalty_points_discount_amount);
|
|
1927
|
+
* }
|
|
1928
|
+
* ```
|
|
1277
1929
|
*/
|
|
1278
1930
|
async redeemLoyaltyPoints(cartId, points) {
|
|
1279
1931
|
return this.executeRequest(
|
|
@@ -1290,6 +1942,18 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
1290
1942
|
*
|
|
1291
1943
|
* @param cartId - The ID of the cart
|
|
1292
1944
|
* @returns Promise with updated cart
|
|
1945
|
+
* @example
|
|
1946
|
+
* ```typescript
|
|
1947
|
+
* const { data, error } = await sdk.cart.removeLoyaltyPoints({
|
|
1948
|
+
* id: "01H9CART12345ABCDE"
|
|
1949
|
+
* });
|
|
1950
|
+
*
|
|
1951
|
+
* if (error) {
|
|
1952
|
+
* console.error("Failed to remove loyalty points:", error.message);
|
|
1953
|
+
* } else {
|
|
1954
|
+
* console.log("Loyalty points removed, new total:", data.cart.total_amount);
|
|
1955
|
+
* }
|
|
1956
|
+
* ```
|
|
1293
1957
|
*/
|
|
1294
1958
|
async removeLoyaltyPoints(cartId) {
|
|
1295
1959
|
return this.executeRequest(
|
|
@@ -1307,6 +1971,23 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
1307
1971
|
* @param cartId - The ID of the cart
|
|
1308
1972
|
* @param body - The body of the request
|
|
1309
1973
|
* @returns Promise with updated cart
|
|
1974
|
+
* @example
|
|
1975
|
+
* ```typescript
|
|
1976
|
+
* const { data, error } = await sdk.cart.updateShippingMethod(
|
|
1977
|
+
* { id: "01H9CART12345ABCDE" },
|
|
1978
|
+
* {
|
|
1979
|
+
* shipping_method_id: "01H9SHIP12345FAST",
|
|
1980
|
+
* estimated_delivery_date: "2024-01-15"
|
|
1981
|
+
* }
|
|
1982
|
+
* );
|
|
1983
|
+
*
|
|
1984
|
+
* if (error) {
|
|
1985
|
+
* console.error("Failed to update shipping method:", error.message);
|
|
1986
|
+
* } else {
|
|
1987
|
+
* console.log("Shipping method updated:", data.cart.shipping_method?.name);
|
|
1988
|
+
* console.log("Shipping cost:", data.cart.shipping_cost);
|
|
1989
|
+
* }
|
|
1990
|
+
* ```
|
|
1310
1991
|
*/
|
|
1311
1992
|
async updateShippingMethod(cartId, body) {
|
|
1312
1993
|
return this.executeRequest(
|
|
@@ -1324,6 +2005,20 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
1324
2005
|
* @param cartId - The ID of the cart
|
|
1325
2006
|
* @param body - The body of the request
|
|
1326
2007
|
* @returns Promise with updated cart
|
|
2008
|
+
* @example
|
|
2009
|
+
* ```typescript
|
|
2010
|
+
* const { data, error } = await sdk.cart.redeemCreditBalance(
|
|
2011
|
+
* { id: "01H9CART12345ABCDE" },
|
|
2012
|
+
* { amount: 250.00 }
|
|
2013
|
+
* );
|
|
2014
|
+
*
|
|
2015
|
+
* if (error) {
|
|
2016
|
+
* console.error("Failed to redeem credit balance:", error.message);
|
|
2017
|
+
* } else {
|
|
2018
|
+
* console.log("Credit applied, new total:", data.cart.total_amount);
|
|
2019
|
+
* console.log("Credit discount:", data.cart.credit_balance_discount_amount);
|
|
2020
|
+
* }
|
|
2021
|
+
* ```
|
|
1327
2022
|
*/
|
|
1328
2023
|
async redeemCreditBalance(cartId, body) {
|
|
1329
2024
|
return this.executeRequest(
|
|
@@ -1340,6 +2035,18 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
1340
2035
|
*
|
|
1341
2036
|
* @param cartId - The ID of the cart
|
|
1342
2037
|
* @returns Promise with updated cart
|
|
2038
|
+
* @example
|
|
2039
|
+
* ```typescript
|
|
2040
|
+
* const { data, error } = await sdk.cart.removeCreditBalance({
|
|
2041
|
+
* id: "01H9CART12345ABCDE"
|
|
2042
|
+
* });
|
|
2043
|
+
*
|
|
2044
|
+
* if (error) {
|
|
2045
|
+
* console.error("Failed to remove credit balance:", error.message);
|
|
2046
|
+
* } else {
|
|
2047
|
+
* console.log("Credit balance removed, new total:", data.cart.total_amount);
|
|
2048
|
+
* }
|
|
2049
|
+
* ```
|
|
1343
2050
|
*/
|
|
1344
2051
|
async removeCreditBalance(cartId) {
|
|
1345
2052
|
return this.executeRequest(
|
|
@@ -1357,6 +2064,23 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
1357
2064
|
* @param cartId - The ID of the cart
|
|
1358
2065
|
* @param body - The body of the request
|
|
1359
2066
|
* @returns Promise with updated cart
|
|
2067
|
+
* @example
|
|
2068
|
+
* ```typescript
|
|
2069
|
+
* const { data, error } = await sdk.cart.redeemGiftCard(
|
|
2070
|
+
* { id: "01H9CART12345ABCDE" },
|
|
2071
|
+
* {
|
|
2072
|
+
* gift_card_code: "GIFT2024-ABCD-1234",
|
|
2073
|
+
* amount: 100.00
|
|
2074
|
+
* }
|
|
2075
|
+
* );
|
|
2076
|
+
*
|
|
2077
|
+
* if (error) {
|
|
2078
|
+
* console.error("Failed to redeem gift card:", error.message);
|
|
2079
|
+
* } else {
|
|
2080
|
+
* console.log("Gift card applied, new total:", data.cart.total_amount);
|
|
2081
|
+
* console.log("Gift card discount:", data.cart.gift_card_discount_amount);
|
|
2082
|
+
* }
|
|
2083
|
+
* ```
|
|
1360
2084
|
*/
|
|
1361
2085
|
async redeemGiftCard(cartId, body) {
|
|
1362
2086
|
return this.executeRequest(
|
|
@@ -1373,6 +2097,18 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
1373
2097
|
*
|
|
1374
2098
|
* @param cartId - The ID of the cart
|
|
1375
2099
|
* @returns Promise with updated cart
|
|
2100
|
+
* @example
|
|
2101
|
+
* ```typescript
|
|
2102
|
+
* const { data, error } = await sdk.cart.removeGiftCard({
|
|
2103
|
+
* id: "01H9CART12345ABCDE"
|
|
2104
|
+
* });
|
|
2105
|
+
*
|
|
2106
|
+
* if (error) {
|
|
2107
|
+
* console.error("Failed to remove gift card:", error.message);
|
|
2108
|
+
* } else {
|
|
2109
|
+
* console.log("Gift card removed, new total:", data.cart.total_amount);
|
|
2110
|
+
* }
|
|
2111
|
+
* ```
|
|
1376
2112
|
*/
|
|
1377
2113
|
async removeGiftCard(cartId) {
|
|
1378
2114
|
return this.executeRequest(
|
|
@@ -1389,6 +2125,22 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
1389
2125
|
*
|
|
1390
2126
|
* @param userId - The ID of the user
|
|
1391
2127
|
* @returns Promise with wishlist items
|
|
2128
|
+
* @example
|
|
2129
|
+
* ```typescript
|
|
2130
|
+
* const { data, error } = await sdk.cart.getWishlist({
|
|
2131
|
+
* user_id: "01H9USER12345ABCDE"
|
|
2132
|
+
* });
|
|
2133
|
+
*
|
|
2134
|
+
* if (error) {
|
|
2135
|
+
* console.error("Failed to get wishlist:", error.message);
|
|
2136
|
+
* } else {
|
|
2137
|
+
* const products = data.products;
|
|
2138
|
+
* console.log("Wishlist items:", products.length);
|
|
2139
|
+
* products.forEach(product => {
|
|
2140
|
+
* console.log("Product:", product.name, "Price:", product.price);
|
|
2141
|
+
* });
|
|
2142
|
+
* }
|
|
2143
|
+
* ```
|
|
1392
2144
|
*/
|
|
1393
2145
|
async getWishlist(userId) {
|
|
1394
2146
|
return this.executeRequest(
|
|
@@ -1405,6 +2157,23 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
1405
2157
|
* @param userId - The ID of the user
|
|
1406
2158
|
* @param itemId - The ID of the item
|
|
1407
2159
|
* @returns Promise with updated wishlist
|
|
2160
|
+
* @example
|
|
2161
|
+
* ```typescript
|
|
2162
|
+
* const { data, error } = await sdk.cart.addToWishlist(
|
|
2163
|
+
* { user_id: "01H9USER12345ABCDE" },
|
|
2164
|
+
* {
|
|
2165
|
+
* product_id: "01F3Z7KG06J4ACWH1C4926KJEC",
|
|
2166
|
+
* variant_id: null
|
|
2167
|
+
* }
|
|
2168
|
+
* );
|
|
2169
|
+
*
|
|
2170
|
+
* if (error) {
|
|
2171
|
+
* console.error("Failed to add to wishlist:", error.message);
|
|
2172
|
+
* } else {
|
|
2173
|
+
* const products = data.products;
|
|
2174
|
+
* console.log("Item added to wishlist, total items:", products.length);
|
|
2175
|
+
* }
|
|
2176
|
+
* ```
|
|
1408
2177
|
*/
|
|
1409
2178
|
async addToWishlist(userId, itemId) {
|
|
1410
2179
|
return this.executeRequest(
|
|
@@ -1420,8 +2189,25 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
1420
2189
|
* Remove item from wishlist
|
|
1421
2190
|
*
|
|
1422
2191
|
* @param userId - The ID of the user
|
|
1423
|
-
* @param
|
|
2192
|
+
* @param body - The body containing product details to remove
|
|
1424
2193
|
* @returns Promise with updated wishlist
|
|
2194
|
+
* @example
|
|
2195
|
+
* ```typescript
|
|
2196
|
+
* const { data, error } = await sdk.cart.removeFromWishlist(
|
|
2197
|
+
* { user_id: "01H9USER12345ABCDE" },
|
|
2198
|
+
* {
|
|
2199
|
+
* product_id: "01F3Z7KG06J4ACWH1C4926KJEC",
|
|
2200
|
+
* variant_id: null
|
|
2201
|
+
* }
|
|
2202
|
+
* );
|
|
2203
|
+
*
|
|
2204
|
+
* if (error) {
|
|
2205
|
+
* console.error("Failed to remove from wishlist:", error.message);
|
|
2206
|
+
* } else {
|
|
2207
|
+
* const products = data.products;
|
|
2208
|
+
* console.log("Item removed from wishlist, remaining items:", products.length);
|
|
2209
|
+
* }
|
|
2210
|
+
* ```
|
|
1425
2211
|
*/
|
|
1426
2212
|
async removeFromWishlist(userId, body) {
|
|
1427
2213
|
return this.executeRequest(
|
|
@@ -1438,6 +2224,26 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
1438
2224
|
*
|
|
1439
2225
|
* @param headers - Optional header parameters (customer_group_id, etc.)
|
|
1440
2226
|
* @returns Promise with all available coupons
|
|
2227
|
+
* @example
|
|
2228
|
+
* ```typescript
|
|
2229
|
+
* // Get all available coupons
|
|
2230
|
+
* const { data, error } = await sdk.cart.getAvailableCoupons();
|
|
2231
|
+
*
|
|
2232
|
+
* if (error) {
|
|
2233
|
+
* console.error("Failed to get available coupons:", error.message);
|
|
2234
|
+
* } else {
|
|
2235
|
+
* const coupons = data.coupons || [];
|
|
2236
|
+
* console.log("Available coupons:", coupons.length);
|
|
2237
|
+
* coupons.forEach(coupon => {
|
|
2238
|
+
* console.log("Coupon:", coupon.code, "Discount:", coupon.discount_amount);
|
|
2239
|
+
* });
|
|
2240
|
+
* }
|
|
2241
|
+
*
|
|
2242
|
+
* // Override customer group ID for this specific request
|
|
2243
|
+
* const { data: overrideData, error: overrideError } = await sdk.cart.getAvailableCoupons({
|
|
2244
|
+
* "x-customer-group-id": "01H9GROUP12345ABC" // Override default SDK config
|
|
2245
|
+
* });
|
|
2246
|
+
* ```
|
|
1441
2247
|
*/
|
|
1442
2248
|
async getAvailableCoupons(headers) {
|
|
1443
2249
|
const mergedHeaders = this.mergeHeaders(headers);
|
|
@@ -1454,6 +2260,26 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
1454
2260
|
*
|
|
1455
2261
|
* @param headers - Optional header parameters (customer_group_id, etc.)
|
|
1456
2262
|
* @returns Promise with all available promotions
|
|
2263
|
+
* @example
|
|
2264
|
+
* ```typescript
|
|
2265
|
+
* // Get all available promotions
|
|
2266
|
+
* const { data, error } = await sdk.cart.getAvailablePromotions();
|
|
2267
|
+
*
|
|
2268
|
+
* if (error) {
|
|
2269
|
+
* console.error("Failed to get available promotions:", error.message);
|
|
2270
|
+
* } else {
|
|
2271
|
+
* const promotions = data.promotions || [];
|
|
2272
|
+
* console.log("Available promotions:", promotions.length);
|
|
2273
|
+
* promotions.forEach(promotion => {
|
|
2274
|
+
* console.log("Promotion:", promotion.name, "Type:", promotion.promotion_type);
|
|
2275
|
+
* });
|
|
2276
|
+
* }
|
|
2277
|
+
*
|
|
2278
|
+
* // Override customer group ID for this specific request
|
|
2279
|
+
* const { data: overrideData, error: overrideError } = await sdk.cart.getAvailablePromotions({
|
|
2280
|
+
* "x-customer-group-id": "01H9GROUP12345ABC" // Override default SDK config
|
|
2281
|
+
* });
|
|
2282
|
+
* ```
|
|
1457
2283
|
*/
|
|
1458
2284
|
async getAvailablePromotions(headers) {
|
|
1459
2285
|
const mergedHeaders = this.mergeHeaders(headers);
|
|
@@ -1470,6 +2296,29 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
1470
2296
|
*
|
|
1471
2297
|
* @param cartId - The ID of the cart
|
|
1472
2298
|
* @returns Promise with evaluated promotions
|
|
2299
|
+
* @example
|
|
2300
|
+
* ```typescript
|
|
2301
|
+
* const { data, error } = await sdk.cart.evaluatePromotions({
|
|
2302
|
+
* id: "01H9CART12345ABCDE"
|
|
2303
|
+
* });
|
|
2304
|
+
*
|
|
2305
|
+
* if (error) {
|
|
2306
|
+
* console.error("Failed to evaluate promotions:", error.message);
|
|
2307
|
+
* } else {
|
|
2308
|
+
* const applicable = data.applicable_promotions || [];
|
|
2309
|
+
* const inapplicable = data.inapplicable_promotions || [];
|
|
2310
|
+
*
|
|
2311
|
+
* console.log("Applicable promotions:", applicable.length);
|
|
2312
|
+
* applicable.forEach(promo => {
|
|
2313
|
+
* console.log(`- ${promo.name}: ${promo.savings_message}`);
|
|
2314
|
+
* });
|
|
2315
|
+
*
|
|
2316
|
+
* console.log("Inapplicable promotions:", inapplicable.length);
|
|
2317
|
+
* inapplicable.forEach(promo => {
|
|
2318
|
+
* console.log(`- ${promo.name}: ${promo.reason}`);
|
|
2319
|
+
* });
|
|
2320
|
+
* }
|
|
2321
|
+
* ```
|
|
1473
2322
|
*/
|
|
1474
2323
|
async evaluatePromotions(cartId) {
|
|
1475
2324
|
return this.executeRequest(
|
|
@@ -1485,6 +2334,29 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
1485
2334
|
*
|
|
1486
2335
|
* @param cartId - The ID of the cart
|
|
1487
2336
|
* @returns Promise with evaluated coupons
|
|
2337
|
+
* @example
|
|
2338
|
+
* ```typescript
|
|
2339
|
+
* const { data, error } = await sdk.cart.evaluateCoupons({
|
|
2340
|
+
* id: "01H9CART12345ABCDE"
|
|
2341
|
+
* });
|
|
2342
|
+
*
|
|
2343
|
+
* if (error) {
|
|
2344
|
+
* console.error("Failed to evaluate coupons:", error.message);
|
|
2345
|
+
* } else {
|
|
2346
|
+
* const applicable = data.applicable_coupons || [];
|
|
2347
|
+
* const inapplicable = data.inapplicable_coupons || [];
|
|
2348
|
+
*
|
|
2349
|
+
* console.log("Applicable coupons:", applicable.length);
|
|
2350
|
+
* applicable.forEach(coupon => {
|
|
2351
|
+
* console.log(`- ${coupon.code}: Save $${coupon.estimated_discount}`);
|
|
2352
|
+
* });
|
|
2353
|
+
*
|
|
2354
|
+
* console.log("Inapplicable coupons:", inapplicable.length);
|
|
2355
|
+
* inapplicable.forEach(coupon => {
|
|
2356
|
+
* console.log(`- ${coupon.code}: ${coupon.reason}`);
|
|
2357
|
+
* });
|
|
2358
|
+
* }
|
|
2359
|
+
* ```
|
|
1488
2360
|
*/
|
|
1489
2361
|
async evaluateCoupons(cartId) {
|
|
1490
2362
|
return this.executeRequest(
|
|
@@ -1501,19 +2373,45 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
1501
2373
|
var AuthClient = class extends StorefrontAPIClient {
|
|
1502
2374
|
/**
|
|
1503
2375
|
* Get anonymous token for guest users
|
|
2376
|
+
*
|
|
2377
|
+
* @example
|
|
2378
|
+
* ```typescript
|
|
2379
|
+
* // Get token for guest browsing
|
|
2380
|
+
* const { data, error } = await sdk.auth.getAnonymousToken();
|
|
2381
|
+
*
|
|
2382
|
+
* if (error) {
|
|
2383
|
+
* console.error("Failed to get anonymous token:", error.message);
|
|
2384
|
+
* } else {
|
|
2385
|
+
* console.log("Anonymous token:", data.access_token);
|
|
2386
|
+
* // Store token or proceed with guest operations
|
|
2387
|
+
* }
|
|
2388
|
+
* ```
|
|
1504
2389
|
*/
|
|
1505
2390
|
async getAnonymousToken() {
|
|
1506
|
-
return this.executeRequest(
|
|
1507
|
-
() => this.client.POST("/auth/anonymous")
|
|
1508
|
-
);
|
|
2391
|
+
return this.executeRequest(() => this.client.POST("/auth/anonymous"));
|
|
1509
2392
|
}
|
|
1510
2393
|
/**
|
|
1511
2394
|
* Login with phone number
|
|
1512
2395
|
*
|
|
1513
|
-
* @param
|
|
1514
|
-
* @
|
|
1515
|
-
* @
|
|
1516
|
-
*
|
|
2396
|
+
* @param body - Login request body containing phone number and options
|
|
2397
|
+
* @returns Promise with OTP token and action
|
|
2398
|
+
* @example
|
|
2399
|
+
* ```typescript
|
|
2400
|
+
* // Login with phone number
|
|
2401
|
+
* const { data, error } = await sdk.auth.loginWithPhone({
|
|
2402
|
+
* phoneNumber: "9876543210",
|
|
2403
|
+
* countryCode: "+91",
|
|
2404
|
+
* registerIfNotExists: true
|
|
2405
|
+
* });
|
|
2406
|
+
*
|
|
2407
|
+
* if (error) {
|
|
2408
|
+
* console.error("Login failed:", error.message);
|
|
2409
|
+
* } else {
|
|
2410
|
+
* console.log("OTP sent. Token:", data.otpToken);
|
|
2411
|
+
* console.log("Action:", data.action); // "login" or "register"
|
|
2412
|
+
* // Redirect user to OTP verification screen
|
|
2413
|
+
* }
|
|
2414
|
+
* ```
|
|
1517
2415
|
*/
|
|
1518
2416
|
async loginWithPhone(body) {
|
|
1519
2417
|
return this.executeRequest(
|
|
@@ -1525,10 +2423,24 @@ var AuthClient = class extends StorefrontAPIClient {
|
|
|
1525
2423
|
/**
|
|
1526
2424
|
* Login with WhatsApp
|
|
1527
2425
|
*
|
|
1528
|
-
* @param
|
|
1529
|
-
* @param countryCode - Country code (defaults to +91)
|
|
1530
|
-
* @param registerIfNotExists - Whether to register if user doesn't exist
|
|
2426
|
+
* @param body - Login request body containing phone number and options
|
|
1531
2427
|
* @returns Promise with OTP token and action
|
|
2428
|
+
* @example
|
|
2429
|
+
* ```typescript
|
|
2430
|
+
* // Login with WhatsApp number
|
|
2431
|
+
* const { data, error } = await sdk.auth.loginWithWhatsApp({
|
|
2432
|
+
* phone: "9876543210",
|
|
2433
|
+
* country_code: "+91",
|
|
2434
|
+
* register_if_not_exists: true
|
|
2435
|
+
* });
|
|
2436
|
+
*
|
|
2437
|
+
* if (error) {
|
|
2438
|
+
* console.error("WhatsApp login failed:", error.message);
|
|
2439
|
+
* } else {
|
|
2440
|
+
* console.log("OTP sent to WhatsApp. Token:", data.otp_token);
|
|
2441
|
+
* console.log("Action:", data.otp_action); // "login" or "register"
|
|
2442
|
+
* }
|
|
2443
|
+
* ```
|
|
1532
2444
|
*/
|
|
1533
2445
|
async loginWithWhatsApp(body) {
|
|
1534
2446
|
return this.executeRequest(
|
|
@@ -1540,9 +2452,24 @@ var AuthClient = class extends StorefrontAPIClient {
|
|
|
1540
2452
|
/**
|
|
1541
2453
|
* Login with email
|
|
1542
2454
|
*
|
|
1543
|
-
* @param
|
|
1544
|
-
* @param registerIfNotExists - Whether to register if user doesn't exist
|
|
2455
|
+
* @param body - Login request body containing email and options
|
|
1545
2456
|
* @returns Promise with OTP token and action
|
|
2457
|
+
* @example
|
|
2458
|
+
* ```typescript
|
|
2459
|
+
* // Login with email address
|
|
2460
|
+
* const { data, error } = await sdk.auth.loginWithEmail({
|
|
2461
|
+
* email: "customer@example.com",
|
|
2462
|
+
* registerIfNotExists: true
|
|
2463
|
+
* });
|
|
2464
|
+
*
|
|
2465
|
+
* if (error) {
|
|
2466
|
+
* console.error("Email login failed:", error.message);
|
|
2467
|
+
* } else {
|
|
2468
|
+
* console.log("OTP sent to email. Token:", data.otpToken);
|
|
2469
|
+
* console.log("Action:", data.action); // "login" or "register"
|
|
2470
|
+
* // Show OTP input form
|
|
2471
|
+
* }
|
|
2472
|
+
* ```
|
|
1546
2473
|
*/
|
|
1547
2474
|
async loginWithEmail(body) {
|
|
1548
2475
|
return this.executeRequest(
|
|
@@ -1554,8 +2481,23 @@ var AuthClient = class extends StorefrontAPIClient {
|
|
|
1554
2481
|
/**
|
|
1555
2482
|
* Login with password
|
|
1556
2483
|
*
|
|
1557
|
-
* @param
|
|
2484
|
+
* @param body - Login credentials containing email/phone and password
|
|
1558
2485
|
* @returns Promise with user info and tokens
|
|
2486
|
+
* @example
|
|
2487
|
+
* ```typescript
|
|
2488
|
+
* // Login with email and password
|
|
2489
|
+
* const { data, error } = await sdk.auth.loginWithPassword({
|
|
2490
|
+
* email: "customer@example.com",
|
|
2491
|
+
* password: "securePassword123"
|
|
2492
|
+
* });
|
|
2493
|
+
*
|
|
2494
|
+
* if (error) {
|
|
2495
|
+
* console.error("Password login failed:", error.message);
|
|
2496
|
+
* } else {
|
|
2497
|
+
* console.log("Login successful:", data.user.email);
|
|
2498
|
+
* console.log("Access token:", data.access_token);
|
|
2499
|
+
* }
|
|
2500
|
+
* ```
|
|
1559
2501
|
*/
|
|
1560
2502
|
async loginWithPassword(body) {
|
|
1561
2503
|
return this.executeRequest(
|
|
@@ -1567,8 +2509,22 @@ var AuthClient = class extends StorefrontAPIClient {
|
|
|
1567
2509
|
/**
|
|
1568
2510
|
* Forgot password
|
|
1569
2511
|
*
|
|
1570
|
-
* @param
|
|
1571
|
-
* @returns Promise with
|
|
2512
|
+
* @param body - Request body containing email address
|
|
2513
|
+
* @returns Promise with password reset information
|
|
2514
|
+
* @example
|
|
2515
|
+
* ```typescript
|
|
2516
|
+
* // Send password reset email
|
|
2517
|
+
* const { data, error } = await sdk.auth.forgotPassword({
|
|
2518
|
+
* email: "customer@example.com"
|
|
2519
|
+
* });
|
|
2520
|
+
*
|
|
2521
|
+
* if (error) {
|
|
2522
|
+
* console.error("Password reset failed:", error.message);
|
|
2523
|
+
* } else {
|
|
2524
|
+
* console.log("Reset email sent successfully");
|
|
2525
|
+
* // Show confirmation message to user
|
|
2526
|
+
* }
|
|
2527
|
+
* ```
|
|
1572
2528
|
*/
|
|
1573
2529
|
async forgotPassword(body) {
|
|
1574
2530
|
return this.executeRequest(
|
|
@@ -1580,8 +2536,24 @@ var AuthClient = class extends StorefrontAPIClient {
|
|
|
1580
2536
|
/**
|
|
1581
2537
|
* Reset password
|
|
1582
2538
|
*
|
|
1583
|
-
* @param
|
|
1584
|
-
* @returns Promise with
|
|
2539
|
+
* @param body - Reset password request body containing new password and OTP token
|
|
2540
|
+
* @returns Promise with new access and refresh tokens
|
|
2541
|
+
* @example
|
|
2542
|
+
* ```typescript
|
|
2543
|
+
* // Reset password with OTP token from forgot password flow
|
|
2544
|
+
* const { data, error } = await sdk.auth.resetPassword({
|
|
2545
|
+
* new_password: "newSecurePassword123",
|
|
2546
|
+
* confirm_password: "newSecurePassword123",
|
|
2547
|
+
* otp_token: "abc123otptoken"
|
|
2548
|
+
* });
|
|
2549
|
+
*
|
|
2550
|
+
* if (error) {
|
|
2551
|
+
* console.error("Password reset failed:", error.message);
|
|
2552
|
+
* } else {
|
|
2553
|
+
* console.log("Password reset successful");
|
|
2554
|
+
* console.log("New access token:", data.access_token);
|
|
2555
|
+
* }
|
|
2556
|
+
* ```
|
|
1585
2557
|
*/
|
|
1586
2558
|
async resetPassword(body) {
|
|
1587
2559
|
return this.executeRequest(
|
|
@@ -1593,10 +2565,24 @@ var AuthClient = class extends StorefrontAPIClient {
|
|
|
1593
2565
|
/**
|
|
1594
2566
|
* Change password
|
|
1595
2567
|
*
|
|
1596
|
-
* @param
|
|
1597
|
-
* @
|
|
1598
|
-
* @
|
|
1599
|
-
*
|
|
2568
|
+
* @param body - Change password request body containing old and new passwords
|
|
2569
|
+
* @returns Promise with new access and refresh tokens
|
|
2570
|
+
* @example
|
|
2571
|
+
* ```typescript
|
|
2572
|
+
* // Change user's password
|
|
2573
|
+
* const { data, error } = await sdk.auth.changePassword({
|
|
2574
|
+
* old_password: "currentPassword123",
|
|
2575
|
+
* new_password: "newSecurePassword456",
|
|
2576
|
+
* confirm_password: "newSecurePassword456"
|
|
2577
|
+
* });
|
|
2578
|
+
*
|
|
2579
|
+
* if (error) {
|
|
2580
|
+
* console.error("Password change failed:", error.message);
|
|
2581
|
+
* } else {
|
|
2582
|
+
* console.log("Password changed successfully");
|
|
2583
|
+
* console.log("New access token:", data.access_token);
|
|
2584
|
+
* }
|
|
2585
|
+
* ```
|
|
1600
2586
|
*/
|
|
1601
2587
|
async changePassword(body) {
|
|
1602
2588
|
return this.executeRequest(
|
|
@@ -1608,10 +2594,25 @@ var AuthClient = class extends StorefrontAPIClient {
|
|
|
1608
2594
|
/**
|
|
1609
2595
|
* Verify OTP
|
|
1610
2596
|
*
|
|
1611
|
-
* @param
|
|
1612
|
-
* @param otpToken - OTP token from login request
|
|
1613
|
-
* @param otpAction - OTP action from login request
|
|
2597
|
+
* @param body - OTP verification data including code and tokens
|
|
1614
2598
|
* @returns Promise with user info and tokens
|
|
2599
|
+
* @example
|
|
2600
|
+
* ```typescript
|
|
2601
|
+
* // Verify OTP after login attempt
|
|
2602
|
+
* const { data, error } = await sdk.auth.verifyOtp({
|
|
2603
|
+
* otp: "1234",
|
|
2604
|
+
* otpToken: "56895455",
|
|
2605
|
+
* otpAction: "login" // or "register"
|
|
2606
|
+
* });
|
|
2607
|
+
*
|
|
2608
|
+
* if (error) {
|
|
2609
|
+
* console.error("OTP verification failed:", error.message);
|
|
2610
|
+
* // Show error message, allow retry
|
|
2611
|
+
* } else {
|
|
2612
|
+
* console.log("Login successful:", data.user.email);
|
|
2613
|
+
* console.log("User ID:", data.user.id);
|
|
2614
|
+
* }
|
|
2615
|
+
* ```
|
|
1615
2616
|
*/
|
|
1616
2617
|
async verifyOtp(body) {
|
|
1617
2618
|
return this.executeRequest(
|
|
@@ -1623,8 +2624,27 @@ var AuthClient = class extends StorefrontAPIClient {
|
|
|
1623
2624
|
/**
|
|
1624
2625
|
* Register with phone
|
|
1625
2626
|
*
|
|
1626
|
-
* @param
|
|
2627
|
+
* @param body - Registration details including phone number and user information
|
|
1627
2628
|
* @returns Promise with user info and tokens
|
|
2629
|
+
* @example
|
|
2630
|
+
* ```typescript
|
|
2631
|
+
* // Register a new user with phone number
|
|
2632
|
+
* const { data, error } = await sdk.auth.registerWithPhone({
|
|
2633
|
+
* phone: "9876543210",
|
|
2634
|
+
* country_code: "+91",
|
|
2635
|
+
* first_name: "John",
|
|
2636
|
+
* last_name: "Doe",
|
|
2637
|
+
* email: "john.doe@example.com"
|
|
2638
|
+
* });
|
|
2639
|
+
*
|
|
2640
|
+
* if (error) {
|
|
2641
|
+
* console.error("Phone registration failed:", error.message);
|
|
2642
|
+
* } else {
|
|
2643
|
+
* console.log("Registration successful:", data.user.first_name);
|
|
2644
|
+
* console.log("User ID:", data.user.id);
|
|
2645
|
+
* console.log("Access token:", data.access_token);
|
|
2646
|
+
* }
|
|
2647
|
+
* ```
|
|
1628
2648
|
*/
|
|
1629
2649
|
async registerWithPhone(body) {
|
|
1630
2650
|
return this.executeRequest(
|
|
@@ -1636,8 +2656,26 @@ var AuthClient = class extends StorefrontAPIClient {
|
|
|
1636
2656
|
/**
|
|
1637
2657
|
* Register with email
|
|
1638
2658
|
*
|
|
1639
|
-
* @param
|
|
2659
|
+
* @param body - Registration details including email and user information
|
|
1640
2660
|
* @returns Promise with user info and tokens
|
|
2661
|
+
* @example
|
|
2662
|
+
* ```typescript
|
|
2663
|
+
* // Register a new user with email address
|
|
2664
|
+
* const { data, error } = await sdk.auth.registerWithEmail({
|
|
2665
|
+
* email: "jane.smith@example.com",
|
|
2666
|
+
* first_name: "Jane",
|
|
2667
|
+
* last_name: "Smith",
|
|
2668
|
+
* phone: "9876543210"
|
|
2669
|
+
* });
|
|
2670
|
+
*
|
|
2671
|
+
* if (error) {
|
|
2672
|
+
* console.error("Email registration failed:", error.message);
|
|
2673
|
+
* } else {
|
|
2674
|
+
* console.log("Registration successful:", data.user.email);
|
|
2675
|
+
* console.log("User ID:", data.user.id);
|
|
2676
|
+
* console.log("Access token:", data.access_token);
|
|
2677
|
+
* }
|
|
2678
|
+
* ```
|
|
1641
2679
|
*/
|
|
1642
2680
|
async registerWithEmail(body) {
|
|
1643
2681
|
return this.executeRequest(
|
|
@@ -1648,8 +2686,24 @@ var AuthClient = class extends StorefrontAPIClient {
|
|
|
1648
2686
|
}
|
|
1649
2687
|
/**
|
|
1650
2688
|
* Refresh the access token using a refresh token
|
|
1651
|
-
* @param
|
|
2689
|
+
* @param body - Request body containing the refresh token
|
|
1652
2690
|
* @returns Promise with the new access token and refresh token
|
|
2691
|
+
* @example
|
|
2692
|
+
* ```typescript
|
|
2693
|
+
* // Refresh access token when it expires
|
|
2694
|
+
* const { data, error } = await sdk.auth.refreshToken({
|
|
2695
|
+
* refresh_token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
|
|
2696
|
+
* });
|
|
2697
|
+
*
|
|
2698
|
+
* if (error) {
|
|
2699
|
+
* console.error("Token refresh failed:", error.message);
|
|
2700
|
+
* // Redirect to login
|
|
2701
|
+
* } else {
|
|
2702
|
+
* console.log("Token refreshed successfully");
|
|
2703
|
+
* console.log("New access token:", data.access_token);
|
|
2704
|
+
* console.log("New refresh token:", data.refresh_token);
|
|
2705
|
+
* }
|
|
2706
|
+
* ```
|
|
1653
2707
|
*/
|
|
1654
2708
|
async refreshToken(body) {
|
|
1655
2709
|
return this.executeRequest(
|
|
@@ -1662,17 +2716,43 @@ var AuthClient = class extends StorefrontAPIClient {
|
|
|
1662
2716
|
* Logout
|
|
1663
2717
|
*
|
|
1664
2718
|
* @returns Promise that resolves when logout is complete
|
|
2719
|
+
* @example
|
|
2720
|
+
* ```typescript
|
|
2721
|
+
* // Logout current user
|
|
2722
|
+
* const { data, error } = await sdk.auth.logout();
|
|
2723
|
+
*
|
|
2724
|
+
* if (error) {
|
|
2725
|
+
* console.error("Logout failed:", error.message);
|
|
2726
|
+
* } else {
|
|
2727
|
+
* console.log("Logout successful");
|
|
2728
|
+
* console.log("Session ended for user:", data.user.email);
|
|
2729
|
+
* }
|
|
2730
|
+
* ```
|
|
1665
2731
|
*/
|
|
1666
2732
|
async logout() {
|
|
1667
|
-
return this.executeRequest(
|
|
1668
|
-
() => this.client.POST("/auth/logout")
|
|
1669
|
-
);
|
|
2733
|
+
return this.executeRequest(() => this.client.POST("/auth/logout"));
|
|
1670
2734
|
}
|
|
1671
2735
|
/**
|
|
1672
2736
|
* Get user details
|
|
1673
2737
|
*
|
|
1674
|
-
* @param
|
|
2738
|
+
* @param pathParams - Path parameters containing user ID
|
|
1675
2739
|
* @returns Promise with user details
|
|
2740
|
+
* @example
|
|
2741
|
+
* ```typescript
|
|
2742
|
+
* // Get details for a specific user
|
|
2743
|
+
* const { data, error } = await sdk.auth.getUserDetails({
|
|
2744
|
+
* id: "01H9XYZ12345USERID"
|
|
2745
|
+
* });
|
|
2746
|
+
*
|
|
2747
|
+
* if (error) {
|
|
2748
|
+
* console.error("Failed to get user details:", error.message);
|
|
2749
|
+
* } else {
|
|
2750
|
+
* console.log("User details:", data.user);
|
|
2751
|
+
* console.log("Email:", data.user.email);
|
|
2752
|
+
* console.log("Phone:", data.user.phoneNumber);
|
|
2753
|
+
* console.log("Created:", data.user.createdAt);
|
|
2754
|
+
* }
|
|
2755
|
+
* ```
|
|
1676
2756
|
*/
|
|
1677
2757
|
async getUserDetails(pathParams) {
|
|
1678
2758
|
return this.executeRequest(
|
|
@@ -1686,8 +2766,29 @@ var AuthClient = class extends StorefrontAPIClient {
|
|
|
1686
2766
|
/**
|
|
1687
2767
|
* Update user details
|
|
1688
2768
|
*
|
|
1689
|
-
* @param
|
|
1690
|
-
* @
|
|
2769
|
+
* @param pathParams - Path parameters containing user ID
|
|
2770
|
+
* @param body - Updated user information
|
|
2771
|
+
* @returns Promise with updated user details
|
|
2772
|
+
* @example
|
|
2773
|
+
* ```typescript
|
|
2774
|
+
* // Update user profile information
|
|
2775
|
+
* const { data, error } = await sdk.auth.updateUserDetails(
|
|
2776
|
+
* { id: "01H9XYZ12345USERID" },
|
|
2777
|
+
* {
|
|
2778
|
+
* first_name: "John",
|
|
2779
|
+
* last_name: "Doe",
|
|
2780
|
+
* email: "john.doe@example.com",
|
|
2781
|
+
* phone: "9876543210",
|
|
2782
|
+
* country_code: "+91"
|
|
2783
|
+
* }
|
|
2784
|
+
* );
|
|
2785
|
+
*
|
|
2786
|
+
* if (error) {
|
|
2787
|
+
* console.error("Failed to update user:", error.message);
|
|
2788
|
+
* } else {
|
|
2789
|
+
* console.log("User updated successfully:", data.user.first_name);
|
|
2790
|
+
* }
|
|
2791
|
+
* ```
|
|
1691
2792
|
*/
|
|
1692
2793
|
async updateUserDetails(pathParams, body) {
|
|
1693
2794
|
return this.executeRequest(
|
|
@@ -1702,8 +2803,25 @@ var AuthClient = class extends StorefrontAPIClient {
|
|
|
1702
2803
|
/**
|
|
1703
2804
|
* Add profile image
|
|
1704
2805
|
*
|
|
1705
|
-
* @param
|
|
1706
|
-
* @
|
|
2806
|
+
* @param pathParams - Path parameters containing user ID
|
|
2807
|
+
* @param formData - Form data containing the image file
|
|
2808
|
+
* @returns Promise with profile image URL
|
|
2809
|
+
* @example
|
|
2810
|
+
* ```typescript
|
|
2811
|
+
* // Add profile image for a user
|
|
2812
|
+
* const imageFile = document.getElementById('file-input').files[0];
|
|
2813
|
+
* const { data, error } = await sdk.auth.addProfileImage(
|
|
2814
|
+
* { id: "01H9XYZ12345USERID" },
|
|
2815
|
+
* { image: imageFile }
|
|
2816
|
+
* );
|
|
2817
|
+
*
|
|
2818
|
+
* if (error) {
|
|
2819
|
+
* console.error("Failed to add profile image:", error.message);
|
|
2820
|
+
* } else {
|
|
2821
|
+
* console.log("Profile image added successfully");
|
|
2822
|
+
* console.log("Image URL:", data.profile_image_url);
|
|
2823
|
+
* }
|
|
2824
|
+
* ```
|
|
1707
2825
|
*/
|
|
1708
2826
|
async addProfileImage(pathParams, formData) {
|
|
1709
2827
|
return this.executeRequest(
|
|
@@ -1727,8 +2845,25 @@ var AuthClient = class extends StorefrontAPIClient {
|
|
|
1727
2845
|
/**
|
|
1728
2846
|
* Update profile image
|
|
1729
2847
|
*
|
|
1730
|
-
* @param
|
|
1731
|
-
* @
|
|
2848
|
+
* @param pathParams - Path parameters containing user ID
|
|
2849
|
+
* @param formData - Form data containing the new image file
|
|
2850
|
+
* @returns Promise with updated profile image URL
|
|
2851
|
+
* @example
|
|
2852
|
+
* ```typescript
|
|
2853
|
+
* // Update existing profile image
|
|
2854
|
+
* const newImageFile = document.getElementById('file-input').files[0];
|
|
2855
|
+
* const { data, error } = await sdk.auth.updateProfileImage(
|
|
2856
|
+
* { id: "01H9XYZ12345USERID" },
|
|
2857
|
+
* { image: newImageFile }
|
|
2858
|
+
* );
|
|
2859
|
+
*
|
|
2860
|
+
* if (error) {
|
|
2861
|
+
* console.error("Failed to update profile image:", error.message);
|
|
2862
|
+
* } else {
|
|
2863
|
+
* console.log("Profile image updated successfully");
|
|
2864
|
+
* console.log("New image URL:", data.profile_image_url);
|
|
2865
|
+
* }
|
|
2866
|
+
* ```
|
|
1732
2867
|
*/
|
|
1733
2868
|
async updateProfileImage(pathParams, formData) {
|
|
1734
2869
|
return this.executeRequest(
|
|
@@ -1752,8 +2887,22 @@ var AuthClient = class extends StorefrontAPIClient {
|
|
|
1752
2887
|
/**
|
|
1753
2888
|
* Delete profile image
|
|
1754
2889
|
*
|
|
1755
|
-
* @param
|
|
1756
|
-
* @returns Promise with
|
|
2890
|
+
* @param pathParams - Path parameters containing user ID
|
|
2891
|
+
* @returns Promise with deletion confirmation
|
|
2892
|
+
* @example
|
|
2893
|
+
* ```typescript
|
|
2894
|
+
* // Delete user's profile image
|
|
2895
|
+
* const { data, error } = await sdk.auth.deleteProfileImage({
|
|
2896
|
+
* id: "01H9XYZ12345USERID"
|
|
2897
|
+
* });
|
|
2898
|
+
*
|
|
2899
|
+
* if (error) {
|
|
2900
|
+
* console.error("Failed to delete profile image:", error.message);
|
|
2901
|
+
* } else {
|
|
2902
|
+
* console.log("Profile image deleted successfully");
|
|
2903
|
+
* console.log("Success:", data.success);
|
|
2904
|
+
* }
|
|
2905
|
+
* ```
|
|
1757
2906
|
*/
|
|
1758
2907
|
async deleteProfileImage(pathParams) {
|
|
1759
2908
|
return this.executeRequest(
|
|
@@ -1767,8 +2916,21 @@ var AuthClient = class extends StorefrontAPIClient {
|
|
|
1767
2916
|
/**
|
|
1768
2917
|
* Get profile image
|
|
1769
2918
|
*
|
|
1770
|
-
* @param
|
|
1771
|
-
* @returns Promise with
|
|
2919
|
+
* @param pathParams - Path parameters containing user ID
|
|
2920
|
+
* @returns Promise with profile image URL
|
|
2921
|
+
* @example
|
|
2922
|
+
* ```typescript
|
|
2923
|
+
* // Get user's profile image URL
|
|
2924
|
+
* const { data, error } = await sdk.auth.getProfileImage({
|
|
2925
|
+
* id: "01H9XYZ12345USERID"
|
|
2926
|
+
* });
|
|
2927
|
+
*
|
|
2928
|
+
* if (error) {
|
|
2929
|
+
* console.error("Failed to get profile image:", error.message);
|
|
2930
|
+
* } else {
|
|
2931
|
+
* console.log("Profile image URL:", data.profile_image_url);
|
|
2932
|
+
* }
|
|
2933
|
+
* ```
|
|
1772
2934
|
*/
|
|
1773
2935
|
async getProfileImage(pathParams) {
|
|
1774
2936
|
return this.executeRequest(
|
|
@@ -1782,8 +2944,22 @@ var AuthClient = class extends StorefrontAPIClient {
|
|
|
1782
2944
|
/**
|
|
1783
2945
|
* Deactivate user account
|
|
1784
2946
|
*
|
|
1785
|
-
* @param
|
|
1786
|
-
* @returns Promise with
|
|
2947
|
+
* @param pathParams - Path parameters containing user ID
|
|
2948
|
+
* @returns Promise with deactivation confirmation
|
|
2949
|
+
* @example
|
|
2950
|
+
* ```typescript
|
|
2951
|
+
* // Deactivate a user account
|
|
2952
|
+
* const { data, error } = await sdk.auth.deactivateUserAccount({
|
|
2953
|
+
* id: "01H9XYZ12345USERID"
|
|
2954
|
+
* });
|
|
2955
|
+
*
|
|
2956
|
+
* if (error) {
|
|
2957
|
+
* console.error("Failed to deactivate account:", error.message);
|
|
2958
|
+
* } else {
|
|
2959
|
+
* console.log("Account deactivated successfully");
|
|
2960
|
+
* console.log("Success:", data.success);
|
|
2961
|
+
* }
|
|
2962
|
+
* ```
|
|
1787
2963
|
*/
|
|
1788
2964
|
async deactivateUserAccount(pathParams) {
|
|
1789
2965
|
return this.executeRequest(
|
|
@@ -1797,8 +2973,21 @@ var AuthClient = class extends StorefrontAPIClient {
|
|
|
1797
2973
|
/**
|
|
1798
2974
|
* Get user notification preferences
|
|
1799
2975
|
*
|
|
1800
|
-
* @param
|
|
1801
|
-
* @returns Promise with user
|
|
2976
|
+
* @param pathParams - Path parameters containing user ID
|
|
2977
|
+
* @returns Promise with user's notification preferences
|
|
2978
|
+
* @example
|
|
2979
|
+
* ```typescript
|
|
2980
|
+
* // Get user's notification preferences
|
|
2981
|
+
* const { data, error } = await sdk.auth.getUserNotificationPreferences({
|
|
2982
|
+
* id: "01H9XYZ12345USERID"
|
|
2983
|
+
* });
|
|
2984
|
+
*
|
|
2985
|
+
* if (error) {
|
|
2986
|
+
* console.error("Failed to get preferences:", error.message);
|
|
2987
|
+
* } else {
|
|
2988
|
+
* console.log("Notification preferences:", data.notification_preferences);
|
|
2989
|
+
* }
|
|
2990
|
+
* ```
|
|
1802
2991
|
*/
|
|
1803
2992
|
async getUserNotificationPreferences(pathParams) {
|
|
1804
2993
|
return this.executeRequest(
|
|
@@ -1812,8 +3001,27 @@ var AuthClient = class extends StorefrontAPIClient {
|
|
|
1812
3001
|
/**
|
|
1813
3002
|
* Update user notification preferences
|
|
1814
3003
|
*
|
|
1815
|
-
* @param
|
|
1816
|
-
* @
|
|
3004
|
+
* @param pathParams - Path parameters containing user ID
|
|
3005
|
+
* @param body - Updated notification preferences
|
|
3006
|
+
* @returns Promise with updated notification preferences
|
|
3007
|
+
* @example
|
|
3008
|
+
* ```typescript
|
|
3009
|
+
* // Update user's notification preferences
|
|
3010
|
+
* const { data, error } = await sdk.auth.updateUserNotificationPreferences(
|
|
3011
|
+
* { id: "01H9XYZ12345USERID" },
|
|
3012
|
+
* {
|
|
3013
|
+
* email_notifications: true,
|
|
3014
|
+
* sms_notifications: false,
|
|
3015
|
+
* push_notifications: true
|
|
3016
|
+
* }
|
|
3017
|
+
* );
|
|
3018
|
+
*
|
|
3019
|
+
* if (error) {
|
|
3020
|
+
* console.error("Failed to update preferences:", error.message);
|
|
3021
|
+
* } else {
|
|
3022
|
+
* console.log("Preferences updated successfully");
|
|
3023
|
+
* }
|
|
3024
|
+
* ```
|
|
1817
3025
|
*/
|
|
1818
3026
|
async updateUserNotificationPreferences(pathParams, body) {
|
|
1819
3027
|
return this.executeRequest(
|
|
@@ -1828,8 +3036,27 @@ var AuthClient = class extends StorefrontAPIClient {
|
|
|
1828
3036
|
/**
|
|
1829
3037
|
* Create user notification preference
|
|
1830
3038
|
*
|
|
1831
|
-
* @param
|
|
1832
|
-
* @
|
|
3039
|
+
* @param pathParams - Path parameters containing user ID
|
|
3040
|
+
* @param body - Notification preferences to create
|
|
3041
|
+
* @returns Promise with created notification preferences
|
|
3042
|
+
* @example
|
|
3043
|
+
* ```typescript
|
|
3044
|
+
* // Create notification preferences for a user
|
|
3045
|
+
* const { data, error } = await sdk.auth.createUserNotificationPreference(
|
|
3046
|
+
* { id: "01H9XYZ12345USERID" },
|
|
3047
|
+
* {
|
|
3048
|
+
* email_notifications: true,
|
|
3049
|
+
* sms_notifications: true,
|
|
3050
|
+
* push_notifications: false
|
|
3051
|
+
* }
|
|
3052
|
+
* );
|
|
3053
|
+
*
|
|
3054
|
+
* if (error) {
|
|
3055
|
+
* console.error("Failed to create preferences:", error.message);
|
|
3056
|
+
* } else {
|
|
3057
|
+
* console.log("Preferences created successfully");
|
|
3058
|
+
* }
|
|
3059
|
+
* ```
|
|
1833
3060
|
*/
|
|
1834
3061
|
async createUserNotificationPreference(pathParams, body) {
|
|
1835
3062
|
return this.executeRequest(
|
|
@@ -1843,9 +3070,25 @@ var AuthClient = class extends StorefrontAPIClient {
|
|
|
1843
3070
|
}
|
|
1844
3071
|
/**
|
|
1845
3072
|
* Generate OTP
|
|
1846
|
-
*
|
|
1847
|
-
* @param body - OTP generation body
|
|
1848
|
-
* @returns Promise with OTP
|
|
3073
|
+
*
|
|
3074
|
+
* @param body - OTP generation body (phone or email)
|
|
3075
|
+
* @returns Promise with OTP token and action
|
|
3076
|
+
* @example
|
|
3077
|
+
* ```typescript
|
|
3078
|
+
* // Generate OTP for phone number
|
|
3079
|
+
* const { data, error } = await sdk.auth.generateOtp({
|
|
3080
|
+
* phone: "9876543210",
|
|
3081
|
+
* country_code: "+91"
|
|
3082
|
+
* });
|
|
3083
|
+
*
|
|
3084
|
+
* if (error) {
|
|
3085
|
+
* console.error("OTP generation failed:", error.message);
|
|
3086
|
+
* } else {
|
|
3087
|
+
* console.log("OTP sent successfully");
|
|
3088
|
+
* console.log("OTP token:", data.otp_token);
|
|
3089
|
+
* console.log("Action:", data.otp_action);
|
|
3090
|
+
* }
|
|
3091
|
+
* ```
|
|
1849
3092
|
*/
|
|
1850
3093
|
async generateOtp(body) {
|
|
1851
3094
|
return this.executeRequest(
|
|
@@ -1857,8 +3100,23 @@ var AuthClient = class extends StorefrontAPIClient {
|
|
|
1857
3100
|
/**
|
|
1858
3101
|
* Check whether email or phone is already verified
|
|
1859
3102
|
*
|
|
1860
|
-
* @param body -
|
|
1861
|
-
* @returns Promise with
|
|
3103
|
+
* @param body - Request body containing phone numbers or email addresses to verify
|
|
3104
|
+
* @returns Promise with verification status for provided contacts
|
|
3105
|
+
* @example
|
|
3106
|
+
* ```typescript
|
|
3107
|
+
* // Check verification status for multiple contacts
|
|
3108
|
+
* const { data, error } = await sdk.auth.checkEmailOrPhoneIsVerified({
|
|
3109
|
+
* phone: ["9876543210", "9123456789"],
|
|
3110
|
+
* email: ["user1@example.com", "user2@example.com"]
|
|
3111
|
+
* });
|
|
3112
|
+
*
|
|
3113
|
+
* if (error) {
|
|
3114
|
+
* console.error("Verification check failed:", error.message);
|
|
3115
|
+
* } else {
|
|
3116
|
+
* console.log("Verified phones:", data.verified_phone);
|
|
3117
|
+
* console.log("Verified emails:", data.verified_email);
|
|
3118
|
+
* }
|
|
3119
|
+
* ```
|
|
1862
3120
|
*/
|
|
1863
3121
|
async checkEmailOrPhoneIsVerified(body) {
|
|
1864
3122
|
return this.executeRequest(
|
|
@@ -1876,6 +3134,20 @@ var OrderClient = class extends StorefrontAPIClient {
|
|
|
1876
3134
|
*
|
|
1877
3135
|
* @param orderNumber - Order number
|
|
1878
3136
|
* @returns Promise with order details
|
|
3137
|
+
* @example
|
|
3138
|
+
* ```typescript
|
|
3139
|
+
* const { data, error } = await sdk.order.getOrderDetails({
|
|
3140
|
+
* order_number: "ORD-2024-001"
|
|
3141
|
+
* });
|
|
3142
|
+
*
|
|
3143
|
+
* if (error) {
|
|
3144
|
+
* console.error("Failed to get order details:", error.message);
|
|
3145
|
+
* } else {
|
|
3146
|
+
* console.log("Order details:", data.content.order);
|
|
3147
|
+
* console.log("Order status:", data.content.order.status);
|
|
3148
|
+
* console.log("Total amount:", data.content.order.total_amount);
|
|
3149
|
+
* }
|
|
3150
|
+
* ```
|
|
1879
3151
|
*/
|
|
1880
3152
|
async getOrderDetails(pathParams) {
|
|
1881
3153
|
return this.executeRequest(
|
|
@@ -1889,10 +3161,42 @@ var OrderClient = class extends StorefrontAPIClient {
|
|
|
1889
3161
|
/**
|
|
1890
3162
|
* Create order
|
|
1891
3163
|
*
|
|
1892
|
-
* @param
|
|
1893
|
-
* @param paymentGateway - Payment gateway
|
|
1894
|
-
* @param paymentGatewayParams - Params for the selected payment gateway
|
|
3164
|
+
* @param body - Order creation request body
|
|
1895
3165
|
* @returns Promise with order details
|
|
3166
|
+
* @example
|
|
3167
|
+
* ```typescript
|
|
3168
|
+
* // Example with PayU payment gateway
|
|
3169
|
+
* const { data, error } = await sdk.order.createOrder({
|
|
3170
|
+
* cart_id: "cart_01H9XYZ12345ABCDE",
|
|
3171
|
+
* payment_gateway: "PAYU",
|
|
3172
|
+
* payment_gateway_params: {
|
|
3173
|
+
* payment_gateway: "PAYU",
|
|
3174
|
+
* furl: "https://yourapp.com/payment/failure",
|
|
3175
|
+
* surl: "https://yourapp.com/payment/success"
|
|
3176
|
+
* }
|
|
3177
|
+
* });
|
|
3178
|
+
*
|
|
3179
|
+
* // Example with Juspay payment gateway
|
|
3180
|
+
* const { data, error } = await sdk.order.createOrder({
|
|
3181
|
+
* cart_id: "cart_01H9XYZ12345ABCDE",
|
|
3182
|
+
* payment_gateway: "JUSPAY",
|
|
3183
|
+
* payment_gateway_params: {
|
|
3184
|
+
* payment_gateway: "JUSPAY",
|
|
3185
|
+
* action: "paymentPage",
|
|
3186
|
+
* integration_type: "hyper-checkout",
|
|
3187
|
+
* return_url: "https://yourapp.com/payment/return",
|
|
3188
|
+
* gateway_reference_id: "juspay_gateway_ref_123"
|
|
3189
|
+
* }
|
|
3190
|
+
* });
|
|
3191
|
+
*
|
|
3192
|
+
* if (error) {
|
|
3193
|
+
* console.error("Failed to create order:", error.message);
|
|
3194
|
+
* } else {
|
|
3195
|
+
* console.log("Order created:", data.content.order.id);
|
|
3196
|
+
* console.log("Payment required:", data.content.payment_required);
|
|
3197
|
+
* console.log("Payment info:", data.content.payment_info);
|
|
3198
|
+
* }
|
|
3199
|
+
* ```
|
|
1896
3200
|
*/
|
|
1897
3201
|
async createOrder(body) {
|
|
1898
3202
|
return this.executeRequest(
|
|
@@ -1904,8 +3208,35 @@ var OrderClient = class extends StorefrontAPIClient {
|
|
|
1904
3208
|
/**
|
|
1905
3209
|
* List all orders
|
|
1906
3210
|
*
|
|
1907
|
-
* @param queryParams - Query parameters
|
|
1908
|
-
* @returns Promise with order
|
|
3211
|
+
* @param queryParams - Query parameters for filtering and pagination
|
|
3212
|
+
* @returns Promise with order list
|
|
3213
|
+
* @example
|
|
3214
|
+
* ```typescript
|
|
3215
|
+
* // Basic usage - only required parameter
|
|
3216
|
+
* const { data, error } = await sdk.order.listOrders({
|
|
3217
|
+
* user_id: "user_01H9XYZ12345ABCDE"
|
|
3218
|
+
* });
|
|
3219
|
+
*
|
|
3220
|
+
* // Advanced usage with optional parameters
|
|
3221
|
+
* const { data, error } = await sdk.order.listOrders({
|
|
3222
|
+
* user_id: "user_01H9XYZ12345ABCDE",
|
|
3223
|
+
* page: 1,
|
|
3224
|
+
* limit: 20,
|
|
3225
|
+
* sort_by: '{"created_at":"desc"}',
|
|
3226
|
+
* status: ["confirmed", "shipped", "delivered"]
|
|
3227
|
+
* });
|
|
3228
|
+
*
|
|
3229
|
+
* if (error) {
|
|
3230
|
+
* console.error("Failed to list orders:", error.message);
|
|
3231
|
+
* } else {
|
|
3232
|
+
* console.log("Orders found:", data.content.orders?.length || 0);
|
|
3233
|
+
* console.log("Pagination:", data.content.pagination);
|
|
3234
|
+
*
|
|
3235
|
+
* data.content.orders?.forEach(order => {
|
|
3236
|
+
* console.log(`Order ${order.order_number}: ${order.status}`);
|
|
3237
|
+
* });
|
|
3238
|
+
* }
|
|
3239
|
+
* ```
|
|
1909
3240
|
*/
|
|
1910
3241
|
async listOrders(queryParams) {
|
|
1911
3242
|
return this.executeRequest(
|
|
@@ -1921,6 +3252,19 @@ var OrderClient = class extends StorefrontAPIClient {
|
|
|
1921
3252
|
*
|
|
1922
3253
|
* @param orderNumber - Order number
|
|
1923
3254
|
* @returns Promise with payment status
|
|
3255
|
+
* @example
|
|
3256
|
+
* ```typescript
|
|
3257
|
+
* const { data, error } = await sdk.order.getPaymentStatus("ORD-2024-001");
|
|
3258
|
+
*
|
|
3259
|
+
* if (error) {
|
|
3260
|
+
* console.error("Failed to get payment status:", error.message);
|
|
3261
|
+
* } else {
|
|
3262
|
+
* console.log("Payment status:", data.content.status);
|
|
3263
|
+
* console.log("Amount paid:", data.content.amount_paid);
|
|
3264
|
+
* console.log("Amount unpaid:", data.content.amount_unpaid);
|
|
3265
|
+
* console.log("Retry available:", data.content.is_retry_available);
|
|
3266
|
+
* }
|
|
3267
|
+
* ```
|
|
1924
3268
|
*/
|
|
1925
3269
|
async getPaymentStatus(orderNumber) {
|
|
1926
3270
|
return this.executeRequest(
|
|
@@ -1934,8 +3278,26 @@ var OrderClient = class extends StorefrontAPIClient {
|
|
|
1934
3278
|
/**
|
|
1935
3279
|
* Get all shipments for an order
|
|
1936
3280
|
*
|
|
1937
|
-
* @param
|
|
3281
|
+
* @param pathParams - Order number path parameters
|
|
1938
3282
|
* @returns Promise with shipments
|
|
3283
|
+
* @example
|
|
3284
|
+
* ```typescript
|
|
3285
|
+
* const { data, error } = await sdk.order.listOrderShipments({
|
|
3286
|
+
* order_number: "ORD-2024-001"
|
|
3287
|
+
* });
|
|
3288
|
+
*
|
|
3289
|
+
* if (error) {
|
|
3290
|
+
* console.error("Failed to get order shipments:", error.message);
|
|
3291
|
+
* } else {
|
|
3292
|
+
* console.log("Shipments found:", data.content.shipments?.length || 0);
|
|
3293
|
+
*
|
|
3294
|
+
* data.content.shipments?.forEach(shipment => {
|
|
3295
|
+
* console.log(`Shipment ${shipment.id}: ${shipment.status}`);
|
|
3296
|
+
* console.log("Tracking number:", shipment.tracking_number);
|
|
3297
|
+
* console.log("Carrier:", shipment.carrier);
|
|
3298
|
+
* });
|
|
3299
|
+
* }
|
|
3300
|
+
* ```
|
|
1939
3301
|
*/
|
|
1940
3302
|
async listOrderShipments(pathParams) {
|
|
1941
3303
|
return this.executeRequest(
|
|
@@ -1949,8 +3311,27 @@ var OrderClient = class extends StorefrontAPIClient {
|
|
|
1949
3311
|
/**
|
|
1950
3312
|
* List order payments
|
|
1951
3313
|
*
|
|
1952
|
-
* @param
|
|
3314
|
+
* @param pathParams - Order number path parameters
|
|
1953
3315
|
* @returns Promise with payments
|
|
3316
|
+
* @example
|
|
3317
|
+
* ```typescript
|
|
3318
|
+
* const { data, error } = await sdk.order.listOrderPayments({
|
|
3319
|
+
* order_number: "ORD-2024-001"
|
|
3320
|
+
* });
|
|
3321
|
+
*
|
|
3322
|
+
* if (error) {
|
|
3323
|
+
* console.error("Failed to get order payments:", error.message);
|
|
3324
|
+
* } else {
|
|
3325
|
+
* console.log("Payments found:", data.content.payments?.length || 0);
|
|
3326
|
+
*
|
|
3327
|
+
* data.content.payments?.forEach(payment => {
|
|
3328
|
+
* console.log(`Payment ${payment.id}: ${payment.status}`);
|
|
3329
|
+
* console.log("Amount:", payment.amount);
|
|
3330
|
+
* console.log("Gateway:", payment.payment_gateway);
|
|
3331
|
+
* console.log("Transaction ID:", payment.transaction_id);
|
|
3332
|
+
* });
|
|
3333
|
+
* }
|
|
3334
|
+
* ```
|
|
1954
3335
|
*/
|
|
1955
3336
|
async listOrderPayments(pathParams) {
|
|
1956
3337
|
return this.executeRequest(
|
|
@@ -1964,8 +3345,27 @@ var OrderClient = class extends StorefrontAPIClient {
|
|
|
1964
3345
|
/**
|
|
1965
3346
|
* List order refunds
|
|
1966
3347
|
*
|
|
1967
|
-
* @param
|
|
3348
|
+
* @param pathParams - Order number path parameters
|
|
1968
3349
|
* @returns Promise with refunds
|
|
3350
|
+
* @example
|
|
3351
|
+
* ```typescript
|
|
3352
|
+
* const { data, error } = await sdk.order.listOrderRefunds({
|
|
3353
|
+
* order_number: "ORD-2024-001"
|
|
3354
|
+
* });
|
|
3355
|
+
*
|
|
3356
|
+
* if (error) {
|
|
3357
|
+
* console.error("Failed to get order refunds:", error.message);
|
|
3358
|
+
* } else {
|
|
3359
|
+
* console.log("Refunds found:", data.content.refunds?.length || 0);
|
|
3360
|
+
*
|
|
3361
|
+
* data.content.refunds?.forEach(refund => {
|
|
3362
|
+
* console.log(`Refund ${refund.id}: ${refund.status}`);
|
|
3363
|
+
* console.log("Amount:", refund.amount);
|
|
3364
|
+
* console.log("Reason:", refund.reason);
|
|
3365
|
+
* console.log("Processed at:", refund.processed_at);
|
|
3366
|
+
* });
|
|
3367
|
+
* }
|
|
3368
|
+
* ```
|
|
1969
3369
|
*/
|
|
1970
3370
|
async listOrderRefunds(pathParams) {
|
|
1971
3371
|
return this.executeRequest(
|
|
@@ -1979,8 +3379,28 @@ var OrderClient = class extends StorefrontAPIClient {
|
|
|
1979
3379
|
/**
|
|
1980
3380
|
* Cancel an order
|
|
1981
3381
|
*
|
|
1982
|
-
* @param
|
|
3382
|
+
* @param pathParams - Order number path parameters
|
|
3383
|
+
* @param body - Cancellation request body
|
|
1983
3384
|
* @returns Promise with order details
|
|
3385
|
+
* @example
|
|
3386
|
+
* ```typescript
|
|
3387
|
+
* const { data, error } = await sdk.order.cancelOrder(
|
|
3388
|
+
* { order_number: "ORD-2024-001" },
|
|
3389
|
+
* {
|
|
3390
|
+
* cancellation_reason: "Customer requested cancellation",
|
|
3391
|
+
* refund_mode: "original_payment_mode",
|
|
3392
|
+
* feedback: "Customer changed their mind about the purchase"
|
|
3393
|
+
* }
|
|
3394
|
+
* );
|
|
3395
|
+
*
|
|
3396
|
+
* if (error) {
|
|
3397
|
+
* console.error("Failed to cancel order:", error.message);
|
|
3398
|
+
* } else {
|
|
3399
|
+
* console.log("Order cancelled successfully");
|
|
3400
|
+
* console.log("Updated order status:", data.content.order?.status);
|
|
3401
|
+
* console.log("Cancellation reason:", data.content.order?.cancellation_reason);
|
|
3402
|
+
* }
|
|
3403
|
+
* ```
|
|
1984
3404
|
*/
|
|
1985
3405
|
async cancelOrder(pathParams, body) {
|
|
1986
3406
|
return this.executeRequest(
|
|
@@ -1995,8 +3415,45 @@ var OrderClient = class extends StorefrontAPIClient {
|
|
|
1995
3415
|
/**
|
|
1996
3416
|
* Retry payment for an order
|
|
1997
3417
|
*
|
|
1998
|
-
* @param
|
|
1999
|
-
* @
|
|
3418
|
+
* @param pathParams - Order number path parameters
|
|
3419
|
+
* @param body - Payment retry request body
|
|
3420
|
+
* @returns Promise with payment information
|
|
3421
|
+
* @example
|
|
3422
|
+
* ```typescript
|
|
3423
|
+
* // Example with PayU payment gateway
|
|
3424
|
+
* const { data, error } = await sdk.order.retryOrderPayment(
|
|
3425
|
+
* { order_number: "ORD-2024-001" },
|
|
3426
|
+
* {
|
|
3427
|
+
* payment_gateway_params: {
|
|
3428
|
+
* payment_gateway: "PAYU",
|
|
3429
|
+
* furl: "https://yourapp.com/payment/failure",
|
|
3430
|
+
* surl: "https://yourapp.com/payment/success"
|
|
3431
|
+
* }
|
|
3432
|
+
* }
|
|
3433
|
+
* );
|
|
3434
|
+
*
|
|
3435
|
+
* // Example with Juspay payment gateway
|
|
3436
|
+
* const { data, error } = await sdk.order.retryOrderPayment(
|
|
3437
|
+
* { order_number: "ORD-2024-001" },
|
|
3438
|
+
* {
|
|
3439
|
+
* payment_gateway_params: {
|
|
3440
|
+
* payment_gateway: "JUSPAY",
|
|
3441
|
+
* action: "paymentPage",
|
|
3442
|
+
* integration_type: "hyper-checkout",
|
|
3443
|
+
* return_url: "https://yourapp.com/payment/return",
|
|
3444
|
+
* gateway_reference_id: "juspay_gateway_ref_123"
|
|
3445
|
+
* }
|
|
3446
|
+
* }
|
|
3447
|
+
* );
|
|
3448
|
+
*
|
|
3449
|
+
* if (error) {
|
|
3450
|
+
* console.error("Failed to retry payment:", error.message);
|
|
3451
|
+
* } else {
|
|
3452
|
+
* console.log("Payment retry initiated");
|
|
3453
|
+
* console.log("Payment info:", data.content.payment_info);
|
|
3454
|
+
* console.log("Transaction ID:", data.content.payment_info.transaction_id);
|
|
3455
|
+
* }
|
|
3456
|
+
* ```
|
|
2000
3457
|
*/
|
|
2001
3458
|
async retryOrderPayment(pathParams, body) {
|
|
2002
3459
|
return this.executeRequest(
|
|
@@ -2017,6 +3474,31 @@ var ShippingClient = class extends StorefrontAPIClient {
|
|
|
2017
3474
|
*
|
|
2018
3475
|
* @param body - Shipping methods body
|
|
2019
3476
|
* @returns Promise with shipping options
|
|
3477
|
+
* @example
|
|
3478
|
+
* ```typescript
|
|
3479
|
+
* const { data, error } = await sdk.shipping.getShippingMethods({
|
|
3480
|
+
* delivery_pincode: "400001",
|
|
3481
|
+
* cart_id: "cart_01H9XYZ12345ABCDE"
|
|
3482
|
+
* });
|
|
3483
|
+
*
|
|
3484
|
+
* if (error) {
|
|
3485
|
+
* console.error("Failed to get shipping methods:", error.message);
|
|
3486
|
+
* } else {
|
|
3487
|
+
* console.log("Is serviceable:", data.content.is_serviceable);
|
|
3488
|
+
* console.log("Available shipping methods:", data.content.shipping_methods?.length || 0);
|
|
3489
|
+
*
|
|
3490
|
+
* data.content.shipping_methods?.forEach(method => {
|
|
3491
|
+
* console.log(`Method: ${method.name} (${method.shipping_type})`);
|
|
3492
|
+
* console.log(`Shipping cost: ${method.shipping_amount}`);
|
|
3493
|
+
* console.log(`Estimated delivery: ${method.estimated_delivery_days} days`);
|
|
3494
|
+
*
|
|
3495
|
+
* method.courier_companies?.forEach(courier => {
|
|
3496
|
+
* console.log(` - ${courier.name}: ${courier.shipping_amount} (${courier.mode})`);
|
|
3497
|
+
* console.log(` Rating: ${courier.rating}/5, Recommended: ${courier.is_recommended}`);
|
|
3498
|
+
* });
|
|
3499
|
+
* });
|
|
3500
|
+
* }
|
|
3501
|
+
* ```
|
|
2020
3502
|
*/
|
|
2021
3503
|
async getShippingMethods(body) {
|
|
2022
3504
|
return this.executeRequest(
|
|
@@ -2030,6 +3512,24 @@ var ShippingClient = class extends StorefrontAPIClient {
|
|
|
2030
3512
|
*
|
|
2031
3513
|
* @param pathParams - Path parameters
|
|
2032
3514
|
* @returns Promise with pincode deliverability result
|
|
3515
|
+
* @example
|
|
3516
|
+
* ```typescript
|
|
3517
|
+
* const { data, error } = await sdk.shipping.checkPincodeDeliverability({
|
|
3518
|
+
* pincode: "400001"
|
|
3519
|
+
* });
|
|
3520
|
+
*
|
|
3521
|
+
* if (error) {
|
|
3522
|
+
* console.error("Failed to check pincode serviceability:", error.message);
|
|
3523
|
+
* } else {
|
|
3524
|
+
* console.log("Pincode serviceable:", data.content.is_serviceable);
|
|
3525
|
+
*
|
|
3526
|
+
* if (data.content.is_serviceable) {
|
|
3527
|
+
* console.log("Delivery is available to this pincode");
|
|
3528
|
+
* } else {
|
|
3529
|
+
* console.log("Delivery is not available to this pincode");
|
|
3530
|
+
* }
|
|
3531
|
+
* }
|
|
3532
|
+
* ```
|
|
2033
3533
|
*/
|
|
2034
3534
|
async checkPincodeDeliverability(pathParams) {
|
|
2035
3535
|
return this.executeRequest(
|
|
@@ -2048,17 +3548,64 @@ var HelpersClient = class extends StorefrontAPIClient {
|
|
|
2048
3548
|
* Get a list of countries
|
|
2049
3549
|
*
|
|
2050
3550
|
* @returns Promise with countries
|
|
3551
|
+
*
|
|
3552
|
+
* @example
|
|
3553
|
+
* ```typescript
|
|
3554
|
+
* const { data, error } = await sdk.helpers.listCountries();
|
|
3555
|
+
*
|
|
3556
|
+
* if (error) {
|
|
3557
|
+
* console.error("Failed to get countries:", error);
|
|
3558
|
+
* return;
|
|
3559
|
+
* }
|
|
3560
|
+
*
|
|
3561
|
+
* console.log("Countries found:", data.countries?.length || 0);
|
|
3562
|
+
*
|
|
3563
|
+
* data.countries?.forEach(country => {
|
|
3564
|
+
* console.log(`Country: ${country.name} (${country.iso_code})`);
|
|
3565
|
+
* console.log("Phone code:", country.phone_code);
|
|
3566
|
+
* console.log("Currency:", country.currency?.code);
|
|
3567
|
+
* });
|
|
3568
|
+
* ```
|
|
2051
3569
|
*/
|
|
2052
3570
|
async listCountries() {
|
|
2053
|
-
return this.executeRequest(
|
|
2054
|
-
() => this.client.GET("/common/countries", {})
|
|
2055
|
-
);
|
|
3571
|
+
return this.executeRequest(() => this.client.GET("/common/countries", {}));
|
|
2056
3572
|
}
|
|
2057
3573
|
/**
|
|
2058
|
-
*
|
|
3574
|
+
* Get a list of states for a country
|
|
2059
3575
|
*
|
|
2060
3576
|
* @param pathParams - Path parameters
|
|
2061
3577
|
* @returns Promise with states
|
|
3578
|
+
*
|
|
3579
|
+
* @example
|
|
3580
|
+
* ```typescript
|
|
3581
|
+
* const { data, error } = await sdk.helpers.listCountryStates({
|
|
3582
|
+
* country_iso_code: "IN"
|
|
3583
|
+
* });
|
|
3584
|
+
*
|
|
3585
|
+
* if (error) {
|
|
3586
|
+
* console.error("Failed to get states:", error);
|
|
3587
|
+
* return;
|
|
3588
|
+
* }
|
|
3589
|
+
*
|
|
3590
|
+
* console.log("States found:", data.states?.length || 0);
|
|
3591
|
+
*
|
|
3592
|
+
* data.states?.forEach(state => {
|
|
3593
|
+
* console.log(`State: ${state.name} (${state.iso_code})`);
|
|
3594
|
+
* console.log("Type:", state.type);
|
|
3595
|
+
* });
|
|
3596
|
+
*
|
|
3597
|
+
* // Get states for different country
|
|
3598
|
+
* const { data: usStates, error: usError } = await sdk.helpers.listCountryStates({
|
|
3599
|
+
* country_iso_code: "US"
|
|
3600
|
+
* });
|
|
3601
|
+
*
|
|
3602
|
+
* if (usError) {
|
|
3603
|
+
* console.error("Failed to get US states:", usError);
|
|
3604
|
+
* return;
|
|
3605
|
+
* }
|
|
3606
|
+
*
|
|
3607
|
+
* console.log("US States:", usStates.states?.map(s => s.name).join(", "));
|
|
3608
|
+
* ```
|
|
2062
3609
|
*/
|
|
2063
3610
|
async listCountryStates(pathParams) {
|
|
2064
3611
|
return this.executeRequest(
|
|
@@ -2074,6 +3621,38 @@ var HelpersClient = class extends StorefrontAPIClient {
|
|
|
2074
3621
|
*
|
|
2075
3622
|
* @param pathParams - Path parameters
|
|
2076
3623
|
* @returns Promise with pincodes
|
|
3624
|
+
*
|
|
3625
|
+
* @example
|
|
3626
|
+
* ```typescript
|
|
3627
|
+
* const { data, error } = await sdk.helpers.listCountryPincodes({
|
|
3628
|
+
* country_iso_code: "IN"
|
|
3629
|
+
* });
|
|
3630
|
+
*
|
|
3631
|
+
* if (error) {
|
|
3632
|
+
* console.error("Failed to get pincodes:", error);
|
|
3633
|
+
* return;
|
|
3634
|
+
* }
|
|
3635
|
+
*
|
|
3636
|
+
* console.log("Pincodes found:", data.pincodes?.length || 0);
|
|
3637
|
+
*
|
|
3638
|
+
* data.pincodes?.forEach(pincode => {
|
|
3639
|
+
* console.log(`Pincode: ${pincode.pincode} - ${pincode.city}, ${pincode.state}`);
|
|
3640
|
+
* console.log("District:", pincode.district);
|
|
3641
|
+
* console.log("Area:", pincode.area);
|
|
3642
|
+
* });
|
|
3643
|
+
*
|
|
3644
|
+
* // Get pincodes for different country
|
|
3645
|
+
* const { data: usPincodes, error: usError } = await sdk.helpers.listCountryPincodes({
|
|
3646
|
+
* country_iso_code: "US"
|
|
3647
|
+
* });
|
|
3648
|
+
*
|
|
3649
|
+
* if (usError) {
|
|
3650
|
+
* console.error("Failed to get US pincodes:", usError);
|
|
3651
|
+
* return;
|
|
3652
|
+
* }
|
|
3653
|
+
*
|
|
3654
|
+
* console.log("US Pincodes:", usPincodes.pincodes?.map(p => p.pincode).join(", "));
|
|
3655
|
+
* ```
|
|
2077
3656
|
*/
|
|
2078
3657
|
async listCountryPincodes(pathParams) {
|
|
2079
3658
|
return this.executeRequest(
|
|
@@ -2093,6 +3672,24 @@ var CustomerClient = class extends StorefrontAPIClient {
|
|
|
2093
3672
|
*
|
|
2094
3673
|
* @param body - Customer creation body
|
|
2095
3674
|
* @returns Promise with customer details
|
|
3675
|
+
*
|
|
3676
|
+
* @example
|
|
3677
|
+
* ```typescript
|
|
3678
|
+
* const { data, error } = await sdk.customer.createCustomer({
|
|
3679
|
+
* first_name: "John",
|
|
3680
|
+
* last_name: "Doe",
|
|
3681
|
+
* email: "john.doe@example.com",
|
|
3682
|
+
* phone: "+1234567890",
|
|
3683
|
+
* password: "securePassword123"
|
|
3684
|
+
* });
|
|
3685
|
+
*
|
|
3686
|
+
* if (error) {
|
|
3687
|
+
* console.error("Failed to create customer:", error);
|
|
3688
|
+
* return;
|
|
3689
|
+
* }
|
|
3690
|
+
*
|
|
3691
|
+
* console.log("Customer created:", data.customer_detail);
|
|
3692
|
+
* ```
|
|
2096
3693
|
*/
|
|
2097
3694
|
async createCustomer(body) {
|
|
2098
3695
|
return this.executeRequest(
|
|
@@ -2106,6 +3703,20 @@ var CustomerClient = class extends StorefrontAPIClient {
|
|
|
2106
3703
|
*
|
|
2107
3704
|
* @param pathParams - Path parameters
|
|
2108
3705
|
* @returns Promise with customer details
|
|
3706
|
+
*
|
|
3707
|
+
* @example
|
|
3708
|
+
* ```typescript
|
|
3709
|
+
* const { data, error } = await sdk.customer.getCustomer({
|
|
3710
|
+
* id: "customer_123"
|
|
3711
|
+
* });
|
|
3712
|
+
*
|
|
3713
|
+
* if (error) {
|
|
3714
|
+
* console.error("Failed to get customer:", error);
|
|
3715
|
+
* return;
|
|
3716
|
+
* }
|
|
3717
|
+
*
|
|
3718
|
+
* console.log("Customer details:", data.customer_detail);
|
|
3719
|
+
* ```
|
|
2109
3720
|
*/
|
|
2110
3721
|
async getCustomer(pathParams) {
|
|
2111
3722
|
return this.executeRequest(
|
|
@@ -2122,6 +3733,25 @@ var CustomerClient = class extends StorefrontAPIClient {
|
|
|
2122
3733
|
* @param pathParams - Path parameters
|
|
2123
3734
|
* @param body - Customer update body
|
|
2124
3735
|
* @returns Promise with customer details
|
|
3736
|
+
*
|
|
3737
|
+
* @example
|
|
3738
|
+
* ```typescript
|
|
3739
|
+
* const { data, error } = await sdk.customer.updateCustomer(
|
|
3740
|
+
* { id: "customer_123" },
|
|
3741
|
+
* {
|
|
3742
|
+
* first_name: "John",
|
|
3743
|
+
* last_name: "Smith",
|
|
3744
|
+
* email: "john.smith@example.com"
|
|
3745
|
+
* }
|
|
3746
|
+
* );
|
|
3747
|
+
*
|
|
3748
|
+
* if (error) {
|
|
3749
|
+
* console.error("Failed to update customer:", error);
|
|
3750
|
+
* return;
|
|
3751
|
+
* }
|
|
3752
|
+
*
|
|
3753
|
+
* console.log("Customer updated:", data.customer_detail);
|
|
3754
|
+
* ```
|
|
2125
3755
|
*/
|
|
2126
3756
|
async updateCustomer(pathParams, body) {
|
|
2127
3757
|
return this.executeRequest(
|
|
@@ -2138,6 +3768,28 @@ var CustomerClient = class extends StorefrontAPIClient {
|
|
|
2138
3768
|
*
|
|
2139
3769
|
* @param pathParams - Path parameters
|
|
2140
3770
|
* @returns Promise with addresses
|
|
3771
|
+
*
|
|
3772
|
+
* @example
|
|
3773
|
+
* ```typescript
|
|
3774
|
+
* const { data, error } = await sdk.customer.listAddresses({
|
|
3775
|
+
* user_id: "user_456"
|
|
3776
|
+
* });
|
|
3777
|
+
*
|
|
3778
|
+
* if (error) {
|
|
3779
|
+
* console.error("Failed to list addresses:", error);
|
|
3780
|
+
* return;
|
|
3781
|
+
* }
|
|
3782
|
+
*
|
|
3783
|
+
* console.log("Addresses:", data.addresses);
|
|
3784
|
+
* console.log("Pagination:", data.pagination);
|
|
3785
|
+
*
|
|
3786
|
+
* // With pagination
|
|
3787
|
+
* const { data: page2, error: page2Error } = await sdk.customer.listAddresses({
|
|
3788
|
+
* user_id: "user_456",
|
|
3789
|
+
* page: 2,
|
|
3790
|
+
* limit: 10
|
|
3791
|
+
* });
|
|
3792
|
+
* ```
|
|
2141
3793
|
*/
|
|
2142
3794
|
async listAddresses(pathParams) {
|
|
2143
3795
|
return this.executeRequest(
|
|
@@ -2154,6 +3806,30 @@ var CustomerClient = class extends StorefrontAPIClient {
|
|
|
2154
3806
|
* @param pathParams - Path parameters
|
|
2155
3807
|
* @param body - Address creation body
|
|
2156
3808
|
* @returns Promise with address details
|
|
3809
|
+
*
|
|
3810
|
+
* @example
|
|
3811
|
+
* ```typescript
|
|
3812
|
+
* const { data, error } = await sdk.customer.createAddress(
|
|
3813
|
+
* { user_id: "user_456" },
|
|
3814
|
+
* {
|
|
3815
|
+
* address_line1: "123 Main Street",
|
|
3816
|
+
* address_line2: "Apt 4B",
|
|
3817
|
+
* city: "New York",
|
|
3818
|
+
* state: "NY",
|
|
3819
|
+
* country: "US",
|
|
3820
|
+
* pincode: "10001",
|
|
3821
|
+
* is_default_billing: true,
|
|
3822
|
+
* is_default_shipping: false
|
|
3823
|
+
* }
|
|
3824
|
+
* );
|
|
3825
|
+
*
|
|
3826
|
+
* if (error) {
|
|
3827
|
+
* console.error("Failed to create address:", error);
|
|
3828
|
+
* return;
|
|
3829
|
+
* }
|
|
3830
|
+
*
|
|
3831
|
+
* console.log("Address created:", data.address);
|
|
3832
|
+
* ```
|
|
2157
3833
|
*/
|
|
2158
3834
|
async createAddress(pathParams, body) {
|
|
2159
3835
|
return this.executeRequest(
|
|
@@ -2170,6 +3846,21 @@ var CustomerClient = class extends StorefrontAPIClient {
|
|
|
2170
3846
|
*
|
|
2171
3847
|
* @param pathParams - Path parameters
|
|
2172
3848
|
* @returns Promise with address details
|
|
3849
|
+
*
|
|
3850
|
+
* @example
|
|
3851
|
+
* ```typescript
|
|
3852
|
+
* const { data, error } = await sdk.customer.getAddress({
|
|
3853
|
+
* user_id: "user_456",
|
|
3854
|
+
* address_id: "addr_789"
|
|
3855
|
+
* });
|
|
3856
|
+
*
|
|
3857
|
+
* if (error) {
|
|
3858
|
+
* console.error("Failed to get address:", error);
|
|
3859
|
+
* return;
|
|
3860
|
+
* }
|
|
3861
|
+
*
|
|
3862
|
+
* console.log("Address details:", data.address);
|
|
3863
|
+
* ```
|
|
2173
3864
|
*/
|
|
2174
3865
|
async getAddress(pathParams) {
|
|
2175
3866
|
return this.executeRequest(
|
|
@@ -2186,6 +3877,29 @@ var CustomerClient = class extends StorefrontAPIClient {
|
|
|
2186
3877
|
* @param pathParams - Path parameters
|
|
2187
3878
|
* @param body - Address update body
|
|
2188
3879
|
* @returns Promise with address details
|
|
3880
|
+
*
|
|
3881
|
+
* @example
|
|
3882
|
+
* ```typescript
|
|
3883
|
+
* const { data, error } = await sdk.customer.updateAddress(
|
|
3884
|
+
* {
|
|
3885
|
+
* user_id: "user_456",
|
|
3886
|
+
* address_id: "addr_789"
|
|
3887
|
+
* },
|
|
3888
|
+
* {
|
|
3889
|
+
* address_line1: "456 Oak Avenue",
|
|
3890
|
+
* city: "Los Angeles",
|
|
3891
|
+
* state: "CA",
|
|
3892
|
+
* pincode: "90210"
|
|
3893
|
+
* }
|
|
3894
|
+
* );
|
|
3895
|
+
*
|
|
3896
|
+
* if (error) {
|
|
3897
|
+
* console.error("Failed to update address:", error);
|
|
3898
|
+
* return;
|
|
3899
|
+
* }
|
|
3900
|
+
*
|
|
3901
|
+
* console.log("Address updated:", data.address);
|
|
3902
|
+
* ```
|
|
2189
3903
|
*/
|
|
2190
3904
|
async updateAddress(pathParams, body) {
|
|
2191
3905
|
return this.executeRequest(
|
|
@@ -2201,7 +3915,22 @@ var CustomerClient = class extends StorefrontAPIClient {
|
|
|
2201
3915
|
* Delete an address for a customer
|
|
2202
3916
|
*
|
|
2203
3917
|
* @param pathParams - Path parameters
|
|
2204
|
-
* @returns Promise with
|
|
3918
|
+
* @returns Promise with deletion response
|
|
3919
|
+
*
|
|
3920
|
+
* @example
|
|
3921
|
+
* ```typescript
|
|
3922
|
+
* const { data, error } = await sdk.customer.deleteAddress({
|
|
3923
|
+
* user_id: "user_456",
|
|
3924
|
+
* address_id: "addr_789"
|
|
3925
|
+
* });
|
|
3926
|
+
*
|
|
3927
|
+
* if (error) {
|
|
3928
|
+
* console.error("Failed to delete address:", error);
|
|
3929
|
+
* return;
|
|
3930
|
+
* }
|
|
3931
|
+
*
|
|
3932
|
+
* console.log("Address deleted:", data.message);
|
|
3933
|
+
* ```
|
|
2205
3934
|
*/
|
|
2206
3935
|
async deleteAddress(pathParams) {
|
|
2207
3936
|
return this.executeRequest(
|
|
@@ -2217,6 +3946,21 @@ var CustomerClient = class extends StorefrontAPIClient {
|
|
|
2217
3946
|
*
|
|
2218
3947
|
* @param pathParams - Path parameters
|
|
2219
3948
|
* @returns Promise with loyalty details
|
|
3949
|
+
*
|
|
3950
|
+
* @example
|
|
3951
|
+
* ```typescript
|
|
3952
|
+
* const { data, error } = await sdk.customer.getLoyaltyDetails({
|
|
3953
|
+
* user_id: "user_456"
|
|
3954
|
+
* });
|
|
3955
|
+
*
|
|
3956
|
+
* if (error) {
|
|
3957
|
+
* console.error("Failed to get loyalty details:", error);
|
|
3958
|
+
* return;
|
|
3959
|
+
* }
|
|
3960
|
+
*
|
|
3961
|
+
* console.log("Loyalty info:", data.loyalty);
|
|
3962
|
+
* console.log("Points balance:", data.loyalty_point_balance);
|
|
3963
|
+
* ```
|
|
2220
3964
|
*/
|
|
2221
3965
|
async getLoyaltyDetails(pathParams) {
|
|
2222
3966
|
return this.executeRequest(
|
|
@@ -2232,6 +3976,28 @@ var CustomerClient = class extends StorefrontAPIClient {
|
|
|
2232
3976
|
*
|
|
2233
3977
|
* @param pathParams - Path parameters
|
|
2234
3978
|
* @returns Promise with loyalty points activity
|
|
3979
|
+
*
|
|
3980
|
+
* @example
|
|
3981
|
+
* ```typescript
|
|
3982
|
+
* const { data, error } = await sdk.customer.listLoyaltyPointsActivity({
|
|
3983
|
+
* user_id: "user_456"
|
|
3984
|
+
* });
|
|
3985
|
+
*
|
|
3986
|
+
* if (error) {
|
|
3987
|
+
* console.error("Failed to get loyalty activity:", error);
|
|
3988
|
+
* return;
|
|
3989
|
+
* }
|
|
3990
|
+
*
|
|
3991
|
+
* console.log("Loyalty activity:", data.loyalty_points_activity);
|
|
3992
|
+
*
|
|
3993
|
+
* // With pagination and sorting
|
|
3994
|
+
* const { data: sortedData, error: sortedError } = await sdk.customer.listLoyaltyPointsActivity({
|
|
3995
|
+
* user_id: "user_456",
|
|
3996
|
+
* page: 1,
|
|
3997
|
+
* limit: 20,
|
|
3998
|
+
* sort_by: JSON.stringify({ "created_at": "desc" })
|
|
3999
|
+
* });
|
|
4000
|
+
* ```
|
|
2235
4001
|
*/
|
|
2236
4002
|
async listLoyaltyPointsActivity(pathParams) {
|
|
2237
4003
|
return this.executeRequest(
|
|
@@ -2247,6 +4013,21 @@ var CustomerClient = class extends StorefrontAPIClient {
|
|
|
2247
4013
|
*
|
|
2248
4014
|
* @param pathParams - Path parameters
|
|
2249
4015
|
* @returns Promise with reviews
|
|
4016
|
+
*
|
|
4017
|
+
* @example
|
|
4018
|
+
* ```typescript
|
|
4019
|
+
* const { data, error } = await sdk.customer.listCustomerReviews({
|
|
4020
|
+
* user_id: "user_456"
|
|
4021
|
+
* });
|
|
4022
|
+
*
|
|
4023
|
+
* if (error) {
|
|
4024
|
+
* console.error("Failed to get customer reviews:", error);
|
|
4025
|
+
* return;
|
|
4026
|
+
* }
|
|
4027
|
+
*
|
|
4028
|
+
* console.log("Customer reviews:", data.reviews);
|
|
4029
|
+
* console.log("Ready for review:", data.ready_for_review);
|
|
4030
|
+
* ```
|
|
2250
4031
|
*/
|
|
2251
4032
|
async listCustomerReviews(pathParams) {
|
|
2252
4033
|
return this.executeRequest(
|
|
@@ -2263,6 +4044,25 @@ var CustomerClient = class extends StorefrontAPIClient {
|
|
|
2263
4044
|
var StoreConfigClient = class extends StorefrontAPIClient {
|
|
2264
4045
|
/**
|
|
2265
4046
|
* Get store config
|
|
4047
|
+
*
|
|
4048
|
+
* @returns Promise with store configuration data
|
|
4049
|
+
*
|
|
4050
|
+
* @example
|
|
4051
|
+
* ```typescript
|
|
4052
|
+
* const { data, error } = await sdk.storeConfig.getStoreConfig();
|
|
4053
|
+
*
|
|
4054
|
+
* if (error) {
|
|
4055
|
+
* console.error('Failed to get store config:', error.message);
|
|
4056
|
+
* return;
|
|
4057
|
+
* }
|
|
4058
|
+
*
|
|
4059
|
+
* // Access store configuration data
|
|
4060
|
+
* const storeConfig = data.store_config;
|
|
4061
|
+
* console.log('Store brand:', storeConfig.brand.name);
|
|
4062
|
+
* console.log('Currency:', storeConfig.currency.code);
|
|
4063
|
+
* console.log('KYC enabled:', storeConfig.is_kyc_enabled);
|
|
4064
|
+
* console.log('Customer groups enabled:', storeConfig.is_customer_group_enabled);
|
|
4065
|
+
* ```
|
|
2266
4066
|
*/
|
|
2267
4067
|
async getStoreConfig() {
|
|
2268
4068
|
return this.executeRequest(() => this.client.GET("/store/config"));
|