@commercengine/storefront-sdk 0.9.3 → 0.10.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.d.ts +5612 -4629
- package/dist/index.iife.js +63 -107
- package/dist/index.iife.js.map +1 -1
- package/dist/index.js +63 -107
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -395,6 +395,15 @@ var BaseAPIClient = class {
|
|
|
395
395
|
getDefaultHeaders() {
|
|
396
396
|
return this.config.defaultHeaders;
|
|
397
397
|
}
|
|
398
|
+
/**
|
|
399
|
+
* Add middleware to the client
|
|
400
|
+
* This allows SDK extensions to add custom middleware like authentication
|
|
401
|
+
*
|
|
402
|
+
* @param middleware - Middleware to add to the client
|
|
403
|
+
*/
|
|
404
|
+
use(middleware) {
|
|
405
|
+
this.client.use(middleware);
|
|
406
|
+
}
|
|
398
407
|
};
|
|
399
408
|
/**
|
|
400
409
|
* Generic URL utility functions for any SDK
|
|
@@ -436,6 +445,7 @@ function extractUserInfoFromToken(token) {
|
|
|
436
445
|
customerId: payload.customer_id,
|
|
437
446
|
customerGroupId: payload.customer_group_id,
|
|
438
447
|
anonymousId: payload.anonymous_id,
|
|
448
|
+
channel: payload.channel,
|
|
439
449
|
tokenExpiry: /* @__PURE__ */ new Date(payload.exp * 1e3),
|
|
440
450
|
tokenIssuedAt: /* @__PURE__ */ new Date(payload.iat * 1e3)
|
|
441
451
|
};
|
|
@@ -1425,10 +1435,10 @@ var CatalogClient = class extends StorefrontAPIClient {
|
|
|
1425
1435
|
* if (error) {
|
|
1426
1436
|
* console.error("Failed to get cross-sell products:", error.message);
|
|
1427
1437
|
* } else {
|
|
1428
|
-
* console.log("Cross-sell products found:", data.
|
|
1429
|
-
* console.log("Pagination:", data.
|
|
1438
|
+
* console.log("Cross-sell products found:", data.products.length);
|
|
1439
|
+
* console.log("Pagination:", data.pagination);
|
|
1430
1440
|
*
|
|
1431
|
-
* data.
|
|
1441
|
+
* data.products.forEach(product => {
|
|
1432
1442
|
* console.log(`Product: ${product.name} - ${product.price}`);
|
|
1433
1443
|
* });
|
|
1434
1444
|
* }
|
|
@@ -1477,10 +1487,10 @@ var CatalogClient = class extends StorefrontAPIClient {
|
|
|
1477
1487
|
* if (error) {
|
|
1478
1488
|
* console.error("Failed to get up-sell products:", error.message);
|
|
1479
1489
|
* } else {
|
|
1480
|
-
* console.log("Up-sell products found:", data.
|
|
1481
|
-
* console.log("Pagination:", data.
|
|
1490
|
+
* console.log("Up-sell products found:", data.products.length);
|
|
1491
|
+
* console.log("Pagination:", data.pagination);
|
|
1482
1492
|
*
|
|
1483
|
-
* data.
|
|
1493
|
+
* data.products.forEach(product => {
|
|
1484
1494
|
* console.log(`Up-sell: ${product.name} - ${product.price}`);
|
|
1485
1495
|
* });
|
|
1486
1496
|
* }
|
|
@@ -1529,10 +1539,10 @@ var CatalogClient = class extends StorefrontAPIClient {
|
|
|
1529
1539
|
* if (error) {
|
|
1530
1540
|
* console.error("Failed to get similar products:", error.message);
|
|
1531
1541
|
* } else {
|
|
1532
|
-
* console.log("Similar products found:", data.
|
|
1533
|
-
* console.log("Pagination:", data.
|
|
1542
|
+
* console.log("Similar products found:", data.products.length);
|
|
1543
|
+
* console.log("Pagination:", data.pagination);
|
|
1534
1544
|
*
|
|
1535
|
-
* data.
|
|
1545
|
+
* data.products.forEach(product => {
|
|
1536
1546
|
* console.log(`Similar: ${product.name} - ${product.price}`);
|
|
1537
1547
|
* });
|
|
1538
1548
|
* }
|
|
@@ -1604,8 +1614,8 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
1604
1614
|
* console.error("Failed to get cart:", error.message);
|
|
1605
1615
|
* } else {
|
|
1606
1616
|
* const cart = data.cart;
|
|
1607
|
-
* console.log("Cart total:", cart.
|
|
1608
|
-
* console.log("Items count:", cart.
|
|
1617
|
+
* console.log("Cart total:", cart.grand_total);
|
|
1618
|
+
* console.log("Items count:", cart.cart_items.length);
|
|
1609
1619
|
* }
|
|
1610
1620
|
* ```
|
|
1611
1621
|
*/
|
|
@@ -1654,7 +1664,7 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
1654
1664
|
* if (error) {
|
|
1655
1665
|
* console.error("Failed to update cart:", error.message);
|
|
1656
1666
|
* } else {
|
|
1657
|
-
* console.log("Cart updated:", data.cart.
|
|
1667
|
+
* console.log("Cart updated:", data.cart.cart_items.length);
|
|
1658
1668
|
* }
|
|
1659
1669
|
*
|
|
1660
1670
|
* // Remove item from cart (set quantity to 0)
|
|
@@ -1805,7 +1815,7 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
1805
1815
|
* if (error) {
|
|
1806
1816
|
* console.error("Failed to apply coupon:", error.message);
|
|
1807
1817
|
* } else {
|
|
1808
|
-
* console.log("Coupon applied, new total:", data.cart.
|
|
1818
|
+
* console.log("Coupon applied, new total:", data.cart.grand_total);
|
|
1809
1819
|
* console.log("Discount amount:", data.cart.coupon_discount_amount);
|
|
1810
1820
|
* }
|
|
1811
1821
|
* ```
|
|
@@ -1830,7 +1840,7 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
1830
1840
|
* if (error) {
|
|
1831
1841
|
* console.error("Failed to remove coupon:", error.message);
|
|
1832
1842
|
* } else {
|
|
1833
|
-
* console.log("Coupon removed, new total:", data.cart.
|
|
1843
|
+
* console.log("Coupon removed, new total:", data.cart.grand_total);
|
|
1834
1844
|
* }
|
|
1835
1845
|
* ```
|
|
1836
1846
|
*/
|
|
@@ -1850,14 +1860,14 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
1850
1860
|
* ```typescript
|
|
1851
1861
|
* const { data, error } = await sdk.cart.redeemLoyaltyPoints(
|
|
1852
1862
|
* { id: "01H9CART12345ABCDE" },
|
|
1853
|
-
* {
|
|
1863
|
+
* { loyalty_point_redeemed: 500 }
|
|
1854
1864
|
* );
|
|
1855
1865
|
*
|
|
1856
1866
|
* if (error) {
|
|
1857
1867
|
* console.error("Failed to redeem loyalty points:", error.message);
|
|
1858
1868
|
* } else {
|
|
1859
|
-
* console.log("Points redeemed, new total:", data.cart.
|
|
1860
|
-
* console.log("Points
|
|
1869
|
+
* console.log("Points redeemed, new total:", data.cart.grand_total);
|
|
1870
|
+
* console.log("Points redeemed:", data.cart.loyalty_points_redeemed);
|
|
1861
1871
|
* }
|
|
1862
1872
|
* ```
|
|
1863
1873
|
*/
|
|
@@ -1881,7 +1891,7 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
1881
1891
|
* if (error) {
|
|
1882
1892
|
* console.error("Failed to remove loyalty points:", error.message);
|
|
1883
1893
|
* } else {
|
|
1884
|
-
* console.log("Loyalty points removed, new total:", data.cart.
|
|
1894
|
+
* console.log("Loyalty points removed, new total:", data.cart.grand_total);
|
|
1885
1895
|
* }
|
|
1886
1896
|
* ```
|
|
1887
1897
|
*/
|
|
@@ -1931,14 +1941,14 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
1931
1941
|
* ```typescript
|
|
1932
1942
|
* const { data, error } = await sdk.cart.redeemCreditBalance(
|
|
1933
1943
|
* { id: "01H9CART12345ABCDE" },
|
|
1934
|
-
* {
|
|
1944
|
+
* { credit_balance_used: 250.00 }
|
|
1935
1945
|
* );
|
|
1936
1946
|
*
|
|
1937
1947
|
* if (error) {
|
|
1938
1948
|
* console.error("Failed to redeem credit balance:", error.message);
|
|
1939
1949
|
* } else {
|
|
1940
|
-
* console.log("Credit applied, new total:", data.cart.
|
|
1941
|
-
* console.log("Credit
|
|
1950
|
+
* console.log("Credit applied, new total:", data.cart.grand_total);
|
|
1951
|
+
* console.log("Credit used:", data.cart.credit_balance_used);
|
|
1942
1952
|
* }
|
|
1943
1953
|
* ```
|
|
1944
1954
|
*/
|
|
@@ -1962,7 +1972,7 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
1962
1972
|
* if (error) {
|
|
1963
1973
|
* console.error("Failed to remove credit balance:", error.message);
|
|
1964
1974
|
* } else {
|
|
1965
|
-
* console.log("Credit balance removed, new total:", data.cart.
|
|
1975
|
+
* console.log("Credit balance removed, new total:", data.cart.grand_total);
|
|
1966
1976
|
* }
|
|
1967
1977
|
* ```
|
|
1968
1978
|
*/
|
|
@@ -1973,60 +1983,6 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
1973
1983
|
}));
|
|
1974
1984
|
}
|
|
1975
1985
|
/**
|
|
1976
|
-
* Redeem gift card
|
|
1977
|
-
*
|
|
1978
|
-
* @param cartId - The ID of the cart
|
|
1979
|
-
* @param body - The body of the request
|
|
1980
|
-
* @returns Promise with updated cart
|
|
1981
|
-
* @example
|
|
1982
|
-
* ```typescript
|
|
1983
|
-
* const { data, error } = await sdk.cart.redeemGiftCard(
|
|
1984
|
-
* { id: "01H9CART12345ABCDE" },
|
|
1985
|
-
* {
|
|
1986
|
-
* gift_card_code: "GIFT2024-ABCD-1234",
|
|
1987
|
-
* amount: 100.00
|
|
1988
|
-
* }
|
|
1989
|
-
* );
|
|
1990
|
-
*
|
|
1991
|
-
* if (error) {
|
|
1992
|
-
* console.error("Failed to redeem gift card:", error.message);
|
|
1993
|
-
* } else {
|
|
1994
|
-
* console.log("Gift card applied, new total:", data.cart.total_amount);
|
|
1995
|
-
* console.log("Gift card discount:", data.cart.gift_card_discount_amount);
|
|
1996
|
-
* }
|
|
1997
|
-
* ```
|
|
1998
|
-
*/
|
|
1999
|
-
async redeemGiftCard(cartId, body) {
|
|
2000
|
-
return this.executeRequest(() => this.client.POST("/carts/{id}/gift-card", {
|
|
2001
|
-
params: { path: cartId },
|
|
2002
|
-
body
|
|
2003
|
-
}));
|
|
2004
|
-
}
|
|
2005
|
-
/**
|
|
2006
|
-
* Remove gift card
|
|
2007
|
-
*
|
|
2008
|
-
* @param cartId - The ID of the cart
|
|
2009
|
-
* @returns Promise with updated cart
|
|
2010
|
-
* @example
|
|
2011
|
-
* ```typescript
|
|
2012
|
-
* const { data, error } = await sdk.cart.removeGiftCard({
|
|
2013
|
-
* id: "01H9CART12345ABCDE"
|
|
2014
|
-
* });
|
|
2015
|
-
*
|
|
2016
|
-
* if (error) {
|
|
2017
|
-
* console.error("Failed to remove gift card:", error.message);
|
|
2018
|
-
* } else {
|
|
2019
|
-
* console.log("Gift card removed, new total:", data.cart.total_amount);
|
|
2020
|
-
* }
|
|
2021
|
-
* ```
|
|
2022
|
-
*/
|
|
2023
|
-
async removeGiftCard(cartId) {
|
|
2024
|
-
return this.executeRequest(() => this.client.DELETE("/carts/{id}/gift-card", {
|
|
2025
|
-
params: { path: cartId },
|
|
2026
|
-
body: void 0
|
|
2027
|
-
}));
|
|
2028
|
-
}
|
|
2029
|
-
/**
|
|
2030
1986
|
* Get wishlist items
|
|
2031
1987
|
*
|
|
2032
1988
|
* @param userId - The ID of the user
|
|
@@ -2909,9 +2865,9 @@ var OrderClient = class extends StorefrontAPIClient {
|
|
|
2909
2865
|
* if (error) {
|
|
2910
2866
|
* console.error("Failed to get order details:", error.message);
|
|
2911
2867
|
* } else {
|
|
2912
|
-
* console.log("Order details:", data.
|
|
2913
|
-
* console.log("Order status:", data.
|
|
2914
|
-
* console.log("Total amount:", data.
|
|
2868
|
+
* console.log("Order details:", data.order);
|
|
2869
|
+
* console.log("Order status:", data.order.status);
|
|
2870
|
+
* console.log("Total amount:", data.order.grand_total);
|
|
2915
2871
|
* }
|
|
2916
2872
|
* ```
|
|
2917
2873
|
*/
|
|
@@ -2952,9 +2908,9 @@ var OrderClient = class extends StorefrontAPIClient {
|
|
|
2952
2908
|
* if (error) {
|
|
2953
2909
|
* console.error("Failed to create order:", error.message);
|
|
2954
2910
|
* } else {
|
|
2955
|
-
* console.log("Order created:", data.
|
|
2956
|
-
* console.log("Payment required:", data.
|
|
2957
|
-
* console.log("Payment info:", data.
|
|
2911
|
+
* console.log("Order created:", data.order.id);
|
|
2912
|
+
* console.log("Payment required:", data.payment_required);
|
|
2913
|
+
* console.log("Payment info:", data.payment_info);
|
|
2958
2914
|
* }
|
|
2959
2915
|
* ```
|
|
2960
2916
|
*/
|
|
@@ -2985,10 +2941,10 @@ var OrderClient = class extends StorefrontAPIClient {
|
|
|
2985
2941
|
* if (error) {
|
|
2986
2942
|
* console.error("Failed to list orders:", error.message);
|
|
2987
2943
|
* } else {
|
|
2988
|
-
* console.log("Orders found:", data.
|
|
2989
|
-
* console.log("Pagination:", data.
|
|
2944
|
+
* console.log("Orders found:", data.orders?.length || 0);
|
|
2945
|
+
* console.log("Pagination:", data.pagination);
|
|
2990
2946
|
*
|
|
2991
|
-
* data.
|
|
2947
|
+
* data.orders?.forEach(order => {
|
|
2992
2948
|
* console.log(`Order ${order.order_number}: ${order.status}`);
|
|
2993
2949
|
* });
|
|
2994
2950
|
* }
|
|
@@ -3009,10 +2965,10 @@ var OrderClient = class extends StorefrontAPIClient {
|
|
|
3009
2965
|
* if (error) {
|
|
3010
2966
|
* console.error("Failed to get payment status:", error.message);
|
|
3011
2967
|
* } else {
|
|
3012
|
-
* console.log("Payment status:", data.
|
|
3013
|
-
* console.log("Amount paid:", data.
|
|
3014
|
-
* console.log("Amount unpaid:", data.
|
|
3015
|
-
* console.log("Retry available:", data.
|
|
2968
|
+
* console.log("Payment status:", data.status);
|
|
2969
|
+
* console.log("Amount paid:", data.amount_paid);
|
|
2970
|
+
* console.log("Amount unpaid:", data.amount_unpaid);
|
|
2971
|
+
* console.log("Retry available:", data.is_retry_available);
|
|
3016
2972
|
* }
|
|
3017
2973
|
* ```
|
|
3018
2974
|
*/
|
|
@@ -3033,9 +2989,9 @@ var OrderClient = class extends StorefrontAPIClient {
|
|
|
3033
2989
|
* if (error) {
|
|
3034
2990
|
* console.error("Failed to get order shipments:", error.message);
|
|
3035
2991
|
* } else {
|
|
3036
|
-
* console.log("Shipments found:", data.
|
|
2992
|
+
* console.log("Shipments found:", data.shipments?.length || 0);
|
|
3037
2993
|
*
|
|
3038
|
-
* data.
|
|
2994
|
+
* data.shipments?.forEach(shipment => {
|
|
3039
2995
|
* console.log(`Shipment ${shipment.id}: ${shipment.status}`);
|
|
3040
2996
|
* console.log("Tracking number:", shipment.tracking_number);
|
|
3041
2997
|
* console.log("Carrier:", shipment.carrier);
|
|
@@ -3060,9 +3016,9 @@ var OrderClient = class extends StorefrontAPIClient {
|
|
|
3060
3016
|
* if (error) {
|
|
3061
3017
|
* console.error("Failed to get order payments:", error.message);
|
|
3062
3018
|
* } else {
|
|
3063
|
-
* console.log("Payments found:", data.
|
|
3019
|
+
* console.log("Payments found:", data.payments?.length || 0);
|
|
3064
3020
|
*
|
|
3065
|
-
* data.
|
|
3021
|
+
* data.payments?.forEach(payment => {
|
|
3066
3022
|
* console.log(`Payment ${payment.id}: ${payment.status}`);
|
|
3067
3023
|
* console.log("Amount:", payment.amount);
|
|
3068
3024
|
* console.log("Gateway:", payment.payment_gateway);
|
|
@@ -3088,13 +3044,13 @@ var OrderClient = class extends StorefrontAPIClient {
|
|
|
3088
3044
|
* if (error) {
|
|
3089
3045
|
* console.error("Failed to get order refunds:", error.message);
|
|
3090
3046
|
* } else {
|
|
3091
|
-
* console.log("Refunds found:", data.
|
|
3047
|
+
* console.log("Refunds found:", data.refunds?.length || 0);
|
|
3092
3048
|
*
|
|
3093
|
-
* data.
|
|
3049
|
+
* data.refunds?.forEach(refund => {
|
|
3094
3050
|
* console.log(`Refund ${refund.id}: ${refund.status}`);
|
|
3095
|
-
* console.log("Amount:", refund.
|
|
3096
|
-
* console.log("Reason:", refund.
|
|
3097
|
-
* console.log("Processed at:", refund.
|
|
3051
|
+
* console.log("Amount:", refund.refund_amount);
|
|
3052
|
+
* console.log("Reason:", refund.refund_remarks);
|
|
3053
|
+
* console.log("Processed at:", refund.refund_date);
|
|
3098
3054
|
* });
|
|
3099
3055
|
* }
|
|
3100
3056
|
* ```
|
|
@@ -3123,8 +3079,8 @@ var OrderClient = class extends StorefrontAPIClient {
|
|
|
3123
3079
|
* console.error("Failed to cancel order:", error.message);
|
|
3124
3080
|
* } else {
|
|
3125
3081
|
* console.log("Order cancelled successfully");
|
|
3126
|
-
* console.log("Updated order status:", data.
|
|
3127
|
-
* console.log("Cancellation reason:", data.
|
|
3082
|
+
* console.log("Updated order status:", data.order?.status);
|
|
3083
|
+
* console.log("Cancellation reason:", data.order?.cancellation_reason);
|
|
3128
3084
|
* }
|
|
3129
3085
|
* ```
|
|
3130
3086
|
*/
|
|
@@ -3172,8 +3128,8 @@ var OrderClient = class extends StorefrontAPIClient {
|
|
|
3172
3128
|
* console.error("Failed to retry payment:", error.message);
|
|
3173
3129
|
* } else {
|
|
3174
3130
|
* console.log("Payment retry initiated");
|
|
3175
|
-
* console.log("Payment info:", data.
|
|
3176
|
-
* console.log("Transaction ID:", data.
|
|
3131
|
+
* console.log("Payment info:", data.payment_info);
|
|
3132
|
+
* console.log("Transaction ID:", data.payment_info.transaction_id);
|
|
3177
3133
|
* }
|
|
3178
3134
|
* ```
|
|
3179
3135
|
*/
|
|
@@ -3206,10 +3162,10 @@ var ShippingClient = class extends StorefrontAPIClient {
|
|
|
3206
3162
|
* if (error) {
|
|
3207
3163
|
* console.error("Failed to get shipping methods:", error.message);
|
|
3208
3164
|
* } else {
|
|
3209
|
-
* console.log("Is serviceable:", data.
|
|
3210
|
-
* console.log("Available shipping methods:", data.
|
|
3165
|
+
* console.log("Is serviceable:", data.is_serviceable);
|
|
3166
|
+
* console.log("Available shipping methods:", data.shipping_methods?.length || 0);
|
|
3211
3167
|
*
|
|
3212
|
-
* data.
|
|
3168
|
+
* data.shipping_methods?.forEach(method => {
|
|
3213
3169
|
* console.log(`Method: ${method.name} (${method.shipping_type})`);
|
|
3214
3170
|
* console.log(`Shipping cost: ${method.shipping_amount}`);
|
|
3215
3171
|
* console.log(`Estimated delivery: ${method.estimated_delivery_days} days`);
|
|
@@ -3239,9 +3195,9 @@ var ShippingClient = class extends StorefrontAPIClient {
|
|
|
3239
3195
|
* if (error) {
|
|
3240
3196
|
* console.error("Failed to check pincode serviceability:", error.message);
|
|
3241
3197
|
* } else {
|
|
3242
|
-
* console.log("Pincode serviceable:", data.
|
|
3198
|
+
* console.log("Pincode serviceable:", data.is_serviceable);
|
|
3243
3199
|
*
|
|
3244
|
-
* if (data.
|
|
3200
|
+
* if (data.is_serviceable) {
|
|
3245
3201
|
* console.log("Delivery is available to this pincode");
|
|
3246
3202
|
* } else {
|
|
3247
3203
|
* console.log("Delivery is not available to this pincode");
|