@commercengine/storefront-sdk 0.9.3 → 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.
@@ -766,6 +766,15 @@ var BaseAPIClient = class {
766
766
  getDefaultHeaders() {
767
767
  return this.config.defaultHeaders;
768
768
  }
769
+ /**
770
+ * Add middleware to the client
771
+ * This allows SDK extensions to add custom middleware like authentication
772
+ *
773
+ * @param middleware - Middleware to add to the client
774
+ */
775
+ use(middleware) {
776
+ this.client.use(middleware);
777
+ }
769
778
  };
770
779
  /**
771
780
  * Generic URL utility functions for any SDK
@@ -1887,10 +1896,10 @@ var CatalogClient = class extends StorefrontAPIClient {
1887
1896
  * if (error) {
1888
1897
  * console.error("Failed to get cross-sell products:", error.message);
1889
1898
  * } else {
1890
- * console.log("Cross-sell products found:", data.content.products.length);
1891
- * console.log("Pagination:", data.content.pagination);
1899
+ * console.log("Cross-sell products found:", data.products.length);
1900
+ * console.log("Pagination:", data.pagination);
1892
1901
  *
1893
- * data.content.products.forEach(product => {
1902
+ * data.products.forEach(product => {
1894
1903
  * console.log(`Product: ${product.name} - ${product.price}`);
1895
1904
  * });
1896
1905
  * }
@@ -1939,10 +1948,10 @@ var CatalogClient = class extends StorefrontAPIClient {
1939
1948
  * if (error) {
1940
1949
  * console.error("Failed to get up-sell products:", error.message);
1941
1950
  * } else {
1942
- * console.log("Up-sell products found:", data.content.products.length);
1943
- * console.log("Pagination:", data.content.pagination);
1951
+ * console.log("Up-sell products found:", data.products.length);
1952
+ * console.log("Pagination:", data.pagination);
1944
1953
  *
1945
- * data.content.products.forEach(product => {
1954
+ * data.products.forEach(product => {
1946
1955
  * console.log(`Up-sell: ${product.name} - ${product.price}`);
1947
1956
  * });
1948
1957
  * }
@@ -1991,10 +2000,10 @@ var CatalogClient = class extends StorefrontAPIClient {
1991
2000
  * if (error) {
1992
2001
  * console.error("Failed to get similar products:", error.message);
1993
2002
  * } else {
1994
- * console.log("Similar products found:", data.content.products.length);
1995
- * console.log("Pagination:", data.content.pagination);
2003
+ * console.log("Similar products found:", data.products.length);
2004
+ * console.log("Pagination:", data.pagination);
1996
2005
  *
1997
- * data.content.products.forEach(product => {
2006
+ * data.products.forEach(product => {
1998
2007
  * console.log(`Similar: ${product.name} - ${product.price}`);
1999
2008
  * });
2000
2009
  * }
@@ -2066,8 +2075,8 @@ var CartClient = class extends StorefrontAPIClient {
2066
2075
  * console.error("Failed to get cart:", error.message);
2067
2076
  * } else {
2068
2077
  * const cart = data.cart;
2069
- * console.log("Cart total:", cart.total_amount);
2070
- * console.log("Items count:", cart.items.length);
2078
+ * console.log("Cart total:", cart.grand_total);
2079
+ * console.log("Items count:", cart.cart_items.length);
2071
2080
  * }
2072
2081
  * ```
2073
2082
  */
@@ -2116,7 +2125,7 @@ var CartClient = class extends StorefrontAPIClient {
2116
2125
  * if (error) {
2117
2126
  * console.error("Failed to update cart:", error.message);
2118
2127
  * } else {
2119
- * console.log("Cart updated:", data.cart.items.length);
2128
+ * console.log("Cart updated:", data.cart.cart_items.length);
2120
2129
  * }
2121
2130
  *
2122
2131
  * // Remove item from cart (set quantity to 0)
@@ -2267,7 +2276,7 @@ var CartClient = class extends StorefrontAPIClient {
2267
2276
  * if (error) {
2268
2277
  * console.error("Failed to apply coupon:", error.message);
2269
2278
  * } else {
2270
- * console.log("Coupon applied, new total:", data.cart.total_amount);
2279
+ * console.log("Coupon applied, new total:", data.cart.grand_total);
2271
2280
  * console.log("Discount amount:", data.cart.coupon_discount_amount);
2272
2281
  * }
2273
2282
  * ```
@@ -2292,7 +2301,7 @@ var CartClient = class extends StorefrontAPIClient {
2292
2301
  * if (error) {
2293
2302
  * console.error("Failed to remove coupon:", error.message);
2294
2303
  * } else {
2295
- * console.log("Coupon removed, new total:", data.cart.total_amount);
2304
+ * console.log("Coupon removed, new total:", data.cart.grand_total);
2296
2305
  * }
2297
2306
  * ```
2298
2307
  */
@@ -2312,14 +2321,14 @@ var CartClient = class extends StorefrontAPIClient {
2312
2321
  * ```typescript
2313
2322
  * const { data, error } = await sdk.cart.redeemLoyaltyPoints(
2314
2323
  * { id: "01H9CART12345ABCDE" },
2315
- * { points: 500 }
2324
+ * { loyalty_point_redeemed: 500 }
2316
2325
  * );
2317
2326
  *
2318
2327
  * if (error) {
2319
2328
  * console.error("Failed to redeem loyalty points:", error.message);
2320
2329
  * } else {
2321
- * console.log("Points redeemed, new total:", data.cart.total_amount);
2322
- * console.log("Points discount:", data.cart.loyalty_points_discount_amount);
2330
+ * console.log("Points redeemed, new total:", data.cart.grand_total);
2331
+ * console.log("Points redeemed:", data.cart.loyalty_points_redeemed);
2323
2332
  * }
2324
2333
  * ```
2325
2334
  */
@@ -2343,7 +2352,7 @@ var CartClient = class extends StorefrontAPIClient {
2343
2352
  * if (error) {
2344
2353
  * console.error("Failed to remove loyalty points:", error.message);
2345
2354
  * } else {
2346
- * console.log("Loyalty points removed, new total:", data.cart.total_amount);
2355
+ * console.log("Loyalty points removed, new total:", data.cart.grand_total);
2347
2356
  * }
2348
2357
  * ```
2349
2358
  */
@@ -2393,14 +2402,14 @@ var CartClient = class extends StorefrontAPIClient {
2393
2402
  * ```typescript
2394
2403
  * const { data, error } = await sdk.cart.redeemCreditBalance(
2395
2404
  * { id: "01H9CART12345ABCDE" },
2396
- * { amount: 250.00 }
2405
+ * { credit_balance_used: 250.00 }
2397
2406
  * );
2398
2407
  *
2399
2408
  * if (error) {
2400
2409
  * console.error("Failed to redeem credit balance:", error.message);
2401
2410
  * } else {
2402
- * console.log("Credit applied, new total:", data.cart.total_amount);
2403
- * console.log("Credit discount:", data.cart.credit_balance_discount_amount);
2411
+ * console.log("Credit applied, new total:", data.cart.grand_total);
2412
+ * console.log("Credit used:", data.cart.credit_balance_used);
2404
2413
  * }
2405
2414
  * ```
2406
2415
  */
@@ -2424,7 +2433,7 @@ var CartClient = class extends StorefrontAPIClient {
2424
2433
  * if (error) {
2425
2434
  * console.error("Failed to remove credit balance:", error.message);
2426
2435
  * } else {
2427
- * console.log("Credit balance removed, new total:", data.cart.total_amount);
2436
+ * console.log("Credit balance removed, new total:", data.cart.grand_total);
2428
2437
  * }
2429
2438
  * ```
2430
2439
  */
@@ -3371,9 +3380,9 @@ var OrderClient = class extends StorefrontAPIClient {
3371
3380
  * if (error) {
3372
3381
  * console.error("Failed to get order details:", error.message);
3373
3382
  * } else {
3374
- * console.log("Order details:", data.content.order);
3375
- * console.log("Order status:", data.content.order.status);
3376
- * console.log("Total amount:", data.content.order.total_amount);
3383
+ * console.log("Order details:", data.order);
3384
+ * console.log("Order status:", data.order.status);
3385
+ * console.log("Total amount:", data.order.grand_total);
3377
3386
  * }
3378
3387
  * ```
3379
3388
  */
@@ -3414,9 +3423,9 @@ var OrderClient = class extends StorefrontAPIClient {
3414
3423
  * if (error) {
3415
3424
  * console.error("Failed to create order:", error.message);
3416
3425
  * } else {
3417
- * console.log("Order created:", data.content.order.id);
3418
- * console.log("Payment required:", data.content.payment_required);
3419
- * console.log("Payment info:", data.content.payment_info);
3426
+ * console.log("Order created:", data.order.id);
3427
+ * console.log("Payment required:", data.payment_required);
3428
+ * console.log("Payment info:", data.payment_info);
3420
3429
  * }
3421
3430
  * ```
3422
3431
  */
@@ -3447,10 +3456,10 @@ var OrderClient = class extends StorefrontAPIClient {
3447
3456
  * if (error) {
3448
3457
  * console.error("Failed to list orders:", error.message);
3449
3458
  * } else {
3450
- * console.log("Orders found:", data.content.orders?.length || 0);
3451
- * console.log("Pagination:", data.content.pagination);
3459
+ * console.log("Orders found:", data.orders?.length || 0);
3460
+ * console.log("Pagination:", data.pagination);
3452
3461
  *
3453
- * data.content.orders?.forEach(order => {
3462
+ * data.orders?.forEach(order => {
3454
3463
  * console.log(`Order ${order.order_number}: ${order.status}`);
3455
3464
  * });
3456
3465
  * }
@@ -3471,10 +3480,10 @@ var OrderClient = class extends StorefrontAPIClient {
3471
3480
  * if (error) {
3472
3481
  * console.error("Failed to get payment status:", error.message);
3473
3482
  * } else {
3474
- * console.log("Payment status:", data.content.status);
3475
- * console.log("Amount paid:", data.content.amount_paid);
3476
- * console.log("Amount unpaid:", data.content.amount_unpaid);
3477
- * console.log("Retry available:", data.content.is_retry_available);
3483
+ * console.log("Payment status:", data.status);
3484
+ * console.log("Amount paid:", data.amount_paid);
3485
+ * console.log("Amount unpaid:", data.amount_unpaid);
3486
+ * console.log("Retry available:", data.is_retry_available);
3478
3487
  * }
3479
3488
  * ```
3480
3489
  */
@@ -3495,9 +3504,9 @@ var OrderClient = class extends StorefrontAPIClient {
3495
3504
  * if (error) {
3496
3505
  * console.error("Failed to get order shipments:", error.message);
3497
3506
  * } else {
3498
- * console.log("Shipments found:", data.content.shipments?.length || 0);
3507
+ * console.log("Shipments found:", data.shipments?.length || 0);
3499
3508
  *
3500
- * data.content.shipments?.forEach(shipment => {
3509
+ * data.shipments?.forEach(shipment => {
3501
3510
  * console.log(`Shipment ${shipment.id}: ${shipment.status}`);
3502
3511
  * console.log("Tracking number:", shipment.tracking_number);
3503
3512
  * console.log("Carrier:", shipment.carrier);
@@ -3522,9 +3531,9 @@ var OrderClient = class extends StorefrontAPIClient {
3522
3531
  * if (error) {
3523
3532
  * console.error("Failed to get order payments:", error.message);
3524
3533
  * } else {
3525
- * console.log("Payments found:", data.content.payments?.length || 0);
3534
+ * console.log("Payments found:", data.payments?.length || 0);
3526
3535
  *
3527
- * data.content.payments?.forEach(payment => {
3536
+ * data.payments?.forEach(payment => {
3528
3537
  * console.log(`Payment ${payment.id}: ${payment.status}`);
3529
3538
  * console.log("Amount:", payment.amount);
3530
3539
  * console.log("Gateway:", payment.payment_gateway);
@@ -3550,13 +3559,13 @@ var OrderClient = class extends StorefrontAPIClient {
3550
3559
  * if (error) {
3551
3560
  * console.error("Failed to get order refunds:", error.message);
3552
3561
  * } else {
3553
- * console.log("Refunds found:", data.content.refunds?.length || 0);
3562
+ * console.log("Refunds found:", data.refunds?.length || 0);
3554
3563
  *
3555
- * data.content.refunds?.forEach(refund => {
3564
+ * data.refunds?.forEach(refund => {
3556
3565
  * console.log(`Refund ${refund.id}: ${refund.status}`);
3557
- * console.log("Amount:", refund.amount);
3558
- * console.log("Reason:", refund.reason);
3559
- * console.log("Processed at:", refund.processed_at);
3566
+ * console.log("Amount:", refund.refund_amount);
3567
+ * console.log("Reason:", refund.refund_remarks);
3568
+ * console.log("Processed at:", refund.refund_date);
3560
3569
  * });
3561
3570
  * }
3562
3571
  * ```
@@ -3585,8 +3594,8 @@ var OrderClient = class extends StorefrontAPIClient {
3585
3594
  * console.error("Failed to cancel order:", error.message);
3586
3595
  * } else {
3587
3596
  * console.log("Order cancelled successfully");
3588
- * console.log("Updated order status:", data.content.order?.status);
3589
- * console.log("Cancellation reason:", data.content.order?.cancellation_reason);
3597
+ * console.log("Updated order status:", data.order?.status);
3598
+ * console.log("Cancellation reason:", data.order?.cancellation_reason);
3590
3599
  * }
3591
3600
  * ```
3592
3601
  */
@@ -3634,8 +3643,8 @@ var OrderClient = class extends StorefrontAPIClient {
3634
3643
  * console.error("Failed to retry payment:", error.message);
3635
3644
  * } else {
3636
3645
  * console.log("Payment retry initiated");
3637
- * console.log("Payment info:", data.content.payment_info);
3638
- * console.log("Transaction ID:", data.content.payment_info.transaction_id);
3646
+ * console.log("Payment info:", data.payment_info);
3647
+ * console.log("Transaction ID:", data.payment_info.transaction_id);
3639
3648
  * }
3640
3649
  * ```
3641
3650
  */
@@ -3668,10 +3677,10 @@ var ShippingClient = class extends StorefrontAPIClient {
3668
3677
  * if (error) {
3669
3678
  * console.error("Failed to get shipping methods:", error.message);
3670
3679
  * } else {
3671
- * console.log("Is serviceable:", data.content.is_serviceable);
3672
- * console.log("Available shipping methods:", data.content.shipping_methods?.length || 0);
3680
+ * console.log("Is serviceable:", data.is_serviceable);
3681
+ * console.log("Available shipping methods:", data.shipping_methods?.length || 0);
3673
3682
  *
3674
- * data.content.shipping_methods?.forEach(method => {
3683
+ * data.shipping_methods?.forEach(method => {
3675
3684
  * console.log(`Method: ${method.name} (${method.shipping_type})`);
3676
3685
  * console.log(`Shipping cost: ${method.shipping_amount}`);
3677
3686
  * console.log(`Estimated delivery: ${method.estimated_delivery_days} days`);
@@ -3701,9 +3710,9 @@ var ShippingClient = class extends StorefrontAPIClient {
3701
3710
  * if (error) {
3702
3711
  * console.error("Failed to check pincode serviceability:", error.message);
3703
3712
  * } else {
3704
- * console.log("Pincode serviceable:", data.content.is_serviceable);
3713
+ * console.log("Pincode serviceable:", data.is_serviceable);
3705
3714
  *
3706
- * if (data.content.is_serviceable) {
3715
+ * if (data.is_serviceable) {
3707
3716
  * console.log("Delivery is available to this pincode");
3708
3717
  * } else {
3709
3718
  * console.log("Delivery is not available to this pincode");