@commercengine/storefront-sdk 0.9.2 → 0.9.4

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.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
@@ -1425,10 +1434,10 @@ var CatalogClient = class extends StorefrontAPIClient {
1425
1434
  * if (error) {
1426
1435
  * console.error("Failed to get cross-sell products:", error.message);
1427
1436
  * } else {
1428
- * console.log("Cross-sell products found:", data.content.products.length);
1429
- * console.log("Pagination:", data.content.pagination);
1437
+ * console.log("Cross-sell products found:", data.products.length);
1438
+ * console.log("Pagination:", data.pagination);
1430
1439
  *
1431
- * data.content.products.forEach(product => {
1440
+ * data.products.forEach(product => {
1432
1441
  * console.log(`Product: ${product.name} - ${product.price}`);
1433
1442
  * });
1434
1443
  * }
@@ -1477,10 +1486,10 @@ var CatalogClient = class extends StorefrontAPIClient {
1477
1486
  * if (error) {
1478
1487
  * console.error("Failed to get up-sell products:", error.message);
1479
1488
  * } else {
1480
- * console.log("Up-sell products found:", data.content.products.length);
1481
- * console.log("Pagination:", data.content.pagination);
1489
+ * console.log("Up-sell products found:", data.products.length);
1490
+ * console.log("Pagination:", data.pagination);
1482
1491
  *
1483
- * data.content.products.forEach(product => {
1492
+ * data.products.forEach(product => {
1484
1493
  * console.log(`Up-sell: ${product.name} - ${product.price}`);
1485
1494
  * });
1486
1495
  * }
@@ -1529,10 +1538,10 @@ var CatalogClient = class extends StorefrontAPIClient {
1529
1538
  * if (error) {
1530
1539
  * console.error("Failed to get similar products:", error.message);
1531
1540
  * } else {
1532
- * console.log("Similar products found:", data.content.products.length);
1533
- * console.log("Pagination:", data.content.pagination);
1541
+ * console.log("Similar products found:", data.products.length);
1542
+ * console.log("Pagination:", data.pagination);
1534
1543
  *
1535
- * data.content.products.forEach(product => {
1544
+ * data.products.forEach(product => {
1536
1545
  * console.log(`Similar: ${product.name} - ${product.price}`);
1537
1546
  * });
1538
1547
  * }
@@ -1604,8 +1613,8 @@ var CartClient = class extends StorefrontAPIClient {
1604
1613
  * console.error("Failed to get cart:", error.message);
1605
1614
  * } else {
1606
1615
  * const cart = data.cart;
1607
- * console.log("Cart total:", cart.total_amount);
1608
- * console.log("Items count:", cart.items.length);
1616
+ * console.log("Cart total:", cart.grand_total);
1617
+ * console.log("Items count:", cart.cart_items.length);
1609
1618
  * }
1610
1619
  * ```
1611
1620
  */
@@ -1654,7 +1663,7 @@ var CartClient = class extends StorefrontAPIClient {
1654
1663
  * if (error) {
1655
1664
  * console.error("Failed to update cart:", error.message);
1656
1665
  * } else {
1657
- * console.log("Cart updated:", data.cart.items.length);
1666
+ * console.log("Cart updated:", data.cart.cart_items.length);
1658
1667
  * }
1659
1668
  *
1660
1669
  * // Remove item from cart (set quantity to 0)
@@ -1805,7 +1814,7 @@ var CartClient = class extends StorefrontAPIClient {
1805
1814
  * if (error) {
1806
1815
  * console.error("Failed to apply coupon:", error.message);
1807
1816
  * } else {
1808
- * console.log("Coupon applied, new total:", data.cart.total_amount);
1817
+ * console.log("Coupon applied, new total:", data.cart.grand_total);
1809
1818
  * console.log("Discount amount:", data.cart.coupon_discount_amount);
1810
1819
  * }
1811
1820
  * ```
@@ -1830,7 +1839,7 @@ var CartClient = class extends StorefrontAPIClient {
1830
1839
  * if (error) {
1831
1840
  * console.error("Failed to remove coupon:", error.message);
1832
1841
  * } else {
1833
- * console.log("Coupon removed, new total:", data.cart.total_amount);
1842
+ * console.log("Coupon removed, new total:", data.cart.grand_total);
1834
1843
  * }
1835
1844
  * ```
1836
1845
  */
@@ -1850,14 +1859,14 @@ var CartClient = class extends StorefrontAPIClient {
1850
1859
  * ```typescript
1851
1860
  * const { data, error } = await sdk.cart.redeemLoyaltyPoints(
1852
1861
  * { id: "01H9CART12345ABCDE" },
1853
- * { points: 500 }
1862
+ * { loyalty_point_redeemed: 500 }
1854
1863
  * );
1855
1864
  *
1856
1865
  * if (error) {
1857
1866
  * console.error("Failed to redeem loyalty points:", error.message);
1858
1867
  * } else {
1859
- * console.log("Points redeemed, new total:", data.cart.total_amount);
1860
- * console.log("Points discount:", data.cart.loyalty_points_discount_amount);
1868
+ * console.log("Points redeemed, new total:", data.cart.grand_total);
1869
+ * console.log("Points redeemed:", data.cart.loyalty_points_redeemed);
1861
1870
  * }
1862
1871
  * ```
1863
1872
  */
@@ -1881,7 +1890,7 @@ var CartClient = class extends StorefrontAPIClient {
1881
1890
  * if (error) {
1882
1891
  * console.error("Failed to remove loyalty points:", error.message);
1883
1892
  * } else {
1884
- * console.log("Loyalty points removed, new total:", data.cart.total_amount);
1893
+ * console.log("Loyalty points removed, new total:", data.cart.grand_total);
1885
1894
  * }
1886
1895
  * ```
1887
1896
  */
@@ -1931,14 +1940,14 @@ var CartClient = class extends StorefrontAPIClient {
1931
1940
  * ```typescript
1932
1941
  * const { data, error } = await sdk.cart.redeemCreditBalance(
1933
1942
  * { id: "01H9CART12345ABCDE" },
1934
- * { amount: 250.00 }
1943
+ * { credit_balance_used: 250.00 }
1935
1944
  * );
1936
1945
  *
1937
1946
  * if (error) {
1938
1947
  * console.error("Failed to redeem credit balance:", error.message);
1939
1948
  * } else {
1940
- * console.log("Credit applied, new total:", data.cart.total_amount);
1941
- * console.log("Credit discount:", data.cart.credit_balance_discount_amount);
1949
+ * console.log("Credit applied, new total:", data.cart.grand_total);
1950
+ * console.log("Credit used:", data.cart.credit_balance_used);
1942
1951
  * }
1943
1952
  * ```
1944
1953
  */
@@ -1962,7 +1971,7 @@ var CartClient = class extends StorefrontAPIClient {
1962
1971
  * if (error) {
1963
1972
  * console.error("Failed to remove credit balance:", error.message);
1964
1973
  * } else {
1965
- * console.log("Credit balance removed, new total:", data.cart.total_amount);
1974
+ * console.log("Credit balance removed, new total:", data.cart.grand_total);
1966
1975
  * }
1967
1976
  * ```
1968
1977
  */
@@ -2909,9 +2918,9 @@ var OrderClient = class extends StorefrontAPIClient {
2909
2918
  * if (error) {
2910
2919
  * console.error("Failed to get order details:", error.message);
2911
2920
  * } else {
2912
- * console.log("Order details:", data.content.order);
2913
- * console.log("Order status:", data.content.order.status);
2914
- * console.log("Total amount:", data.content.order.total_amount);
2921
+ * console.log("Order details:", data.order);
2922
+ * console.log("Order status:", data.order.status);
2923
+ * console.log("Total amount:", data.order.grand_total);
2915
2924
  * }
2916
2925
  * ```
2917
2926
  */
@@ -2952,9 +2961,9 @@ var OrderClient = class extends StorefrontAPIClient {
2952
2961
  * if (error) {
2953
2962
  * console.error("Failed to create order:", error.message);
2954
2963
  * } else {
2955
- * console.log("Order created:", data.content.order.id);
2956
- * console.log("Payment required:", data.content.payment_required);
2957
- * console.log("Payment info:", data.content.payment_info);
2964
+ * console.log("Order created:", data.order.id);
2965
+ * console.log("Payment required:", data.payment_required);
2966
+ * console.log("Payment info:", data.payment_info);
2958
2967
  * }
2959
2968
  * ```
2960
2969
  */
@@ -2985,10 +2994,10 @@ var OrderClient = class extends StorefrontAPIClient {
2985
2994
  * if (error) {
2986
2995
  * console.error("Failed to list orders:", error.message);
2987
2996
  * } else {
2988
- * console.log("Orders found:", data.content.orders?.length || 0);
2989
- * console.log("Pagination:", data.content.pagination);
2997
+ * console.log("Orders found:", data.orders?.length || 0);
2998
+ * console.log("Pagination:", data.pagination);
2990
2999
  *
2991
- * data.content.orders?.forEach(order => {
3000
+ * data.orders?.forEach(order => {
2992
3001
  * console.log(`Order ${order.order_number}: ${order.status}`);
2993
3002
  * });
2994
3003
  * }
@@ -3009,10 +3018,10 @@ var OrderClient = class extends StorefrontAPIClient {
3009
3018
  * if (error) {
3010
3019
  * console.error("Failed to get payment status:", error.message);
3011
3020
  * } else {
3012
- * console.log("Payment status:", data.content.status);
3013
- * console.log("Amount paid:", data.content.amount_paid);
3014
- * console.log("Amount unpaid:", data.content.amount_unpaid);
3015
- * console.log("Retry available:", data.content.is_retry_available);
3021
+ * console.log("Payment status:", data.status);
3022
+ * console.log("Amount paid:", data.amount_paid);
3023
+ * console.log("Amount unpaid:", data.amount_unpaid);
3024
+ * console.log("Retry available:", data.is_retry_available);
3016
3025
  * }
3017
3026
  * ```
3018
3027
  */
@@ -3033,9 +3042,9 @@ var OrderClient = class extends StorefrontAPIClient {
3033
3042
  * if (error) {
3034
3043
  * console.error("Failed to get order shipments:", error.message);
3035
3044
  * } else {
3036
- * console.log("Shipments found:", data.content.shipments?.length || 0);
3045
+ * console.log("Shipments found:", data.shipments?.length || 0);
3037
3046
  *
3038
- * data.content.shipments?.forEach(shipment => {
3047
+ * data.shipments?.forEach(shipment => {
3039
3048
  * console.log(`Shipment ${shipment.id}: ${shipment.status}`);
3040
3049
  * console.log("Tracking number:", shipment.tracking_number);
3041
3050
  * console.log("Carrier:", shipment.carrier);
@@ -3060,9 +3069,9 @@ var OrderClient = class extends StorefrontAPIClient {
3060
3069
  * if (error) {
3061
3070
  * console.error("Failed to get order payments:", error.message);
3062
3071
  * } else {
3063
- * console.log("Payments found:", data.content.payments?.length || 0);
3072
+ * console.log("Payments found:", data.payments?.length || 0);
3064
3073
  *
3065
- * data.content.payments?.forEach(payment => {
3074
+ * data.payments?.forEach(payment => {
3066
3075
  * console.log(`Payment ${payment.id}: ${payment.status}`);
3067
3076
  * console.log("Amount:", payment.amount);
3068
3077
  * console.log("Gateway:", payment.payment_gateway);
@@ -3088,13 +3097,13 @@ var OrderClient = class extends StorefrontAPIClient {
3088
3097
  * if (error) {
3089
3098
  * console.error("Failed to get order refunds:", error.message);
3090
3099
  * } else {
3091
- * console.log("Refunds found:", data.content.refunds?.length || 0);
3100
+ * console.log("Refunds found:", data.refunds?.length || 0);
3092
3101
  *
3093
- * data.content.refunds?.forEach(refund => {
3102
+ * data.refunds?.forEach(refund => {
3094
3103
  * console.log(`Refund ${refund.id}: ${refund.status}`);
3095
- * console.log("Amount:", refund.amount);
3096
- * console.log("Reason:", refund.reason);
3097
- * console.log("Processed at:", refund.processed_at);
3104
+ * console.log("Amount:", refund.refund_amount);
3105
+ * console.log("Reason:", refund.refund_remarks);
3106
+ * console.log("Processed at:", refund.refund_date);
3098
3107
  * });
3099
3108
  * }
3100
3109
  * ```
@@ -3123,8 +3132,8 @@ var OrderClient = class extends StorefrontAPIClient {
3123
3132
  * console.error("Failed to cancel order:", error.message);
3124
3133
  * } else {
3125
3134
  * console.log("Order cancelled successfully");
3126
- * console.log("Updated order status:", data.content.order?.status);
3127
- * console.log("Cancellation reason:", data.content.order?.cancellation_reason);
3135
+ * console.log("Updated order status:", data.order?.status);
3136
+ * console.log("Cancellation reason:", data.order?.cancellation_reason);
3128
3137
  * }
3129
3138
  * ```
3130
3139
  */
@@ -3172,8 +3181,8 @@ var OrderClient = class extends StorefrontAPIClient {
3172
3181
  * console.error("Failed to retry payment:", error.message);
3173
3182
  * } else {
3174
3183
  * console.log("Payment retry initiated");
3175
- * console.log("Payment info:", data.content.payment_info);
3176
- * console.log("Transaction ID:", data.content.payment_info.transaction_id);
3184
+ * console.log("Payment info:", data.payment_info);
3185
+ * console.log("Transaction ID:", data.payment_info.transaction_id);
3177
3186
  * }
3178
3187
  * ```
3179
3188
  */
@@ -3206,10 +3215,10 @@ var ShippingClient = class extends StorefrontAPIClient {
3206
3215
  * if (error) {
3207
3216
  * console.error("Failed to get shipping methods:", error.message);
3208
3217
  * } else {
3209
- * console.log("Is serviceable:", data.content.is_serviceable);
3210
- * console.log("Available shipping methods:", data.content.shipping_methods?.length || 0);
3218
+ * console.log("Is serviceable:", data.is_serviceable);
3219
+ * console.log("Available shipping methods:", data.shipping_methods?.length || 0);
3211
3220
  *
3212
- * data.content.shipping_methods?.forEach(method => {
3221
+ * data.shipping_methods?.forEach(method => {
3213
3222
  * console.log(`Method: ${method.name} (${method.shipping_type})`);
3214
3223
  * console.log(`Shipping cost: ${method.shipping_amount}`);
3215
3224
  * console.log(`Estimated delivery: ${method.estimated_delivery_days} days`);
@@ -3239,9 +3248,9 @@ var ShippingClient = class extends StorefrontAPIClient {
3239
3248
  * if (error) {
3240
3249
  * console.error("Failed to check pincode serviceability:", error.message);
3241
3250
  * } else {
3242
- * console.log("Pincode serviceable:", data.content.is_serviceable);
3251
+ * console.log("Pincode serviceable:", data.is_serviceable);
3243
3252
  *
3244
- * if (data.content.is_serviceable) {
3253
+ * if (data.is_serviceable) {
3245
3254
  * console.log("Delivery is available to this pincode");
3246
3255
  * } else {
3247
3256
  * console.log("Delivery is not available to this pincode");