@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.iife.js
CHANGED
|
@@ -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
|
|
@@ -898,6 +907,7 @@ function extractUserInfoFromToken(token) {
|
|
|
898
907
|
customerId: payload.customer_id,
|
|
899
908
|
customerGroupId: payload.customer_group_id,
|
|
900
909
|
anonymousId: payload.anonymous_id,
|
|
910
|
+
channel: payload.channel,
|
|
901
911
|
tokenExpiry: /* @__PURE__ */ new Date(payload.exp * 1e3),
|
|
902
912
|
tokenIssuedAt: /* @__PURE__ */ new Date(payload.iat * 1e3)
|
|
903
913
|
};
|
|
@@ -1887,10 +1897,10 @@ var CatalogClient = class extends StorefrontAPIClient {
|
|
|
1887
1897
|
* if (error) {
|
|
1888
1898
|
* console.error("Failed to get cross-sell products:", error.message);
|
|
1889
1899
|
* } else {
|
|
1890
|
-
* console.log("Cross-sell products found:", data.
|
|
1891
|
-
* console.log("Pagination:", data.
|
|
1900
|
+
* console.log("Cross-sell products found:", data.products.length);
|
|
1901
|
+
* console.log("Pagination:", data.pagination);
|
|
1892
1902
|
*
|
|
1893
|
-
* data.
|
|
1903
|
+
* data.products.forEach(product => {
|
|
1894
1904
|
* console.log(`Product: ${product.name} - ${product.price}`);
|
|
1895
1905
|
* });
|
|
1896
1906
|
* }
|
|
@@ -1939,10 +1949,10 @@ var CatalogClient = class extends StorefrontAPIClient {
|
|
|
1939
1949
|
* if (error) {
|
|
1940
1950
|
* console.error("Failed to get up-sell products:", error.message);
|
|
1941
1951
|
* } else {
|
|
1942
|
-
* console.log("Up-sell products found:", data.
|
|
1943
|
-
* console.log("Pagination:", data.
|
|
1952
|
+
* console.log("Up-sell products found:", data.products.length);
|
|
1953
|
+
* console.log("Pagination:", data.pagination);
|
|
1944
1954
|
*
|
|
1945
|
-
* data.
|
|
1955
|
+
* data.products.forEach(product => {
|
|
1946
1956
|
* console.log(`Up-sell: ${product.name} - ${product.price}`);
|
|
1947
1957
|
* });
|
|
1948
1958
|
* }
|
|
@@ -1991,10 +2001,10 @@ var CatalogClient = class extends StorefrontAPIClient {
|
|
|
1991
2001
|
* if (error) {
|
|
1992
2002
|
* console.error("Failed to get similar products:", error.message);
|
|
1993
2003
|
* } else {
|
|
1994
|
-
* console.log("Similar products found:", data.
|
|
1995
|
-
* console.log("Pagination:", data.
|
|
2004
|
+
* console.log("Similar products found:", data.products.length);
|
|
2005
|
+
* console.log("Pagination:", data.pagination);
|
|
1996
2006
|
*
|
|
1997
|
-
* data.
|
|
2007
|
+
* data.products.forEach(product => {
|
|
1998
2008
|
* console.log(`Similar: ${product.name} - ${product.price}`);
|
|
1999
2009
|
* });
|
|
2000
2010
|
* }
|
|
@@ -2066,8 +2076,8 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
2066
2076
|
* console.error("Failed to get cart:", error.message);
|
|
2067
2077
|
* } else {
|
|
2068
2078
|
* const cart = data.cart;
|
|
2069
|
-
* console.log("Cart total:", cart.
|
|
2070
|
-
* console.log("Items count:", cart.
|
|
2079
|
+
* console.log("Cart total:", cart.grand_total);
|
|
2080
|
+
* console.log("Items count:", cart.cart_items.length);
|
|
2071
2081
|
* }
|
|
2072
2082
|
* ```
|
|
2073
2083
|
*/
|
|
@@ -2116,7 +2126,7 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
2116
2126
|
* if (error) {
|
|
2117
2127
|
* console.error("Failed to update cart:", error.message);
|
|
2118
2128
|
* } else {
|
|
2119
|
-
* console.log("Cart updated:", data.cart.
|
|
2129
|
+
* console.log("Cart updated:", data.cart.cart_items.length);
|
|
2120
2130
|
* }
|
|
2121
2131
|
*
|
|
2122
2132
|
* // Remove item from cart (set quantity to 0)
|
|
@@ -2267,7 +2277,7 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
2267
2277
|
* if (error) {
|
|
2268
2278
|
* console.error("Failed to apply coupon:", error.message);
|
|
2269
2279
|
* } else {
|
|
2270
|
-
* console.log("Coupon applied, new total:", data.cart.
|
|
2280
|
+
* console.log("Coupon applied, new total:", data.cart.grand_total);
|
|
2271
2281
|
* console.log("Discount amount:", data.cart.coupon_discount_amount);
|
|
2272
2282
|
* }
|
|
2273
2283
|
* ```
|
|
@@ -2292,7 +2302,7 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
2292
2302
|
* if (error) {
|
|
2293
2303
|
* console.error("Failed to remove coupon:", error.message);
|
|
2294
2304
|
* } else {
|
|
2295
|
-
* console.log("Coupon removed, new total:", data.cart.
|
|
2305
|
+
* console.log("Coupon removed, new total:", data.cart.grand_total);
|
|
2296
2306
|
* }
|
|
2297
2307
|
* ```
|
|
2298
2308
|
*/
|
|
@@ -2312,14 +2322,14 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
2312
2322
|
* ```typescript
|
|
2313
2323
|
* const { data, error } = await sdk.cart.redeemLoyaltyPoints(
|
|
2314
2324
|
* { id: "01H9CART12345ABCDE" },
|
|
2315
|
-
* {
|
|
2325
|
+
* { loyalty_point_redeemed: 500 }
|
|
2316
2326
|
* );
|
|
2317
2327
|
*
|
|
2318
2328
|
* if (error) {
|
|
2319
2329
|
* console.error("Failed to redeem loyalty points:", error.message);
|
|
2320
2330
|
* } else {
|
|
2321
|
-
* console.log("Points redeemed, new total:", data.cart.
|
|
2322
|
-
* console.log("Points
|
|
2331
|
+
* console.log("Points redeemed, new total:", data.cart.grand_total);
|
|
2332
|
+
* console.log("Points redeemed:", data.cart.loyalty_points_redeemed);
|
|
2323
2333
|
* }
|
|
2324
2334
|
* ```
|
|
2325
2335
|
*/
|
|
@@ -2343,7 +2353,7 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
2343
2353
|
* if (error) {
|
|
2344
2354
|
* console.error("Failed to remove loyalty points:", error.message);
|
|
2345
2355
|
* } else {
|
|
2346
|
-
* console.log("Loyalty points removed, new total:", data.cart.
|
|
2356
|
+
* console.log("Loyalty points removed, new total:", data.cart.grand_total);
|
|
2347
2357
|
* }
|
|
2348
2358
|
* ```
|
|
2349
2359
|
*/
|
|
@@ -2393,14 +2403,14 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
2393
2403
|
* ```typescript
|
|
2394
2404
|
* const { data, error } = await sdk.cart.redeemCreditBalance(
|
|
2395
2405
|
* { id: "01H9CART12345ABCDE" },
|
|
2396
|
-
* {
|
|
2406
|
+
* { credit_balance_used: 250.00 }
|
|
2397
2407
|
* );
|
|
2398
2408
|
*
|
|
2399
2409
|
* if (error) {
|
|
2400
2410
|
* console.error("Failed to redeem credit balance:", error.message);
|
|
2401
2411
|
* } else {
|
|
2402
|
-
* console.log("Credit applied, new total:", data.cart.
|
|
2403
|
-
* console.log("Credit
|
|
2412
|
+
* console.log("Credit applied, new total:", data.cart.grand_total);
|
|
2413
|
+
* console.log("Credit used:", data.cart.credit_balance_used);
|
|
2404
2414
|
* }
|
|
2405
2415
|
* ```
|
|
2406
2416
|
*/
|
|
@@ -2424,7 +2434,7 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
2424
2434
|
* if (error) {
|
|
2425
2435
|
* console.error("Failed to remove credit balance:", error.message);
|
|
2426
2436
|
* } else {
|
|
2427
|
-
* console.log("Credit balance removed, new total:", data.cart.
|
|
2437
|
+
* console.log("Credit balance removed, new total:", data.cart.grand_total);
|
|
2428
2438
|
* }
|
|
2429
2439
|
* ```
|
|
2430
2440
|
*/
|
|
@@ -2435,60 +2445,6 @@ var CartClient = class extends StorefrontAPIClient {
|
|
|
2435
2445
|
}));
|
|
2436
2446
|
}
|
|
2437
2447
|
/**
|
|
2438
|
-
* Redeem gift card
|
|
2439
|
-
*
|
|
2440
|
-
* @param cartId - The ID of the cart
|
|
2441
|
-
* @param body - The body of the request
|
|
2442
|
-
* @returns Promise with updated cart
|
|
2443
|
-
* @example
|
|
2444
|
-
* ```typescript
|
|
2445
|
-
* const { data, error } = await sdk.cart.redeemGiftCard(
|
|
2446
|
-
* { id: "01H9CART12345ABCDE" },
|
|
2447
|
-
* {
|
|
2448
|
-
* gift_card_code: "GIFT2024-ABCD-1234",
|
|
2449
|
-
* amount: 100.00
|
|
2450
|
-
* }
|
|
2451
|
-
* );
|
|
2452
|
-
*
|
|
2453
|
-
* if (error) {
|
|
2454
|
-
* console.error("Failed to redeem gift card:", error.message);
|
|
2455
|
-
* } else {
|
|
2456
|
-
* console.log("Gift card applied, new total:", data.cart.total_amount);
|
|
2457
|
-
* console.log("Gift card discount:", data.cart.gift_card_discount_amount);
|
|
2458
|
-
* }
|
|
2459
|
-
* ```
|
|
2460
|
-
*/
|
|
2461
|
-
async redeemGiftCard(cartId, body) {
|
|
2462
|
-
return this.executeRequest(() => this.client.POST("/carts/{id}/gift-card", {
|
|
2463
|
-
params: { path: cartId },
|
|
2464
|
-
body
|
|
2465
|
-
}));
|
|
2466
|
-
}
|
|
2467
|
-
/**
|
|
2468
|
-
* Remove gift card
|
|
2469
|
-
*
|
|
2470
|
-
* @param cartId - The ID of the cart
|
|
2471
|
-
* @returns Promise with updated cart
|
|
2472
|
-
* @example
|
|
2473
|
-
* ```typescript
|
|
2474
|
-
* const { data, error } = await sdk.cart.removeGiftCard({
|
|
2475
|
-
* id: "01H9CART12345ABCDE"
|
|
2476
|
-
* });
|
|
2477
|
-
*
|
|
2478
|
-
* if (error) {
|
|
2479
|
-
* console.error("Failed to remove gift card:", error.message);
|
|
2480
|
-
* } else {
|
|
2481
|
-
* console.log("Gift card removed, new total:", data.cart.total_amount);
|
|
2482
|
-
* }
|
|
2483
|
-
* ```
|
|
2484
|
-
*/
|
|
2485
|
-
async removeGiftCard(cartId) {
|
|
2486
|
-
return this.executeRequest(() => this.client.DELETE("/carts/{id}/gift-card", {
|
|
2487
|
-
params: { path: cartId },
|
|
2488
|
-
body: void 0
|
|
2489
|
-
}));
|
|
2490
|
-
}
|
|
2491
|
-
/**
|
|
2492
2448
|
* Get wishlist items
|
|
2493
2449
|
*
|
|
2494
2450
|
* @param userId - The ID of the user
|
|
@@ -3371,9 +3327,9 @@ var OrderClient = class extends StorefrontAPIClient {
|
|
|
3371
3327
|
* if (error) {
|
|
3372
3328
|
* console.error("Failed to get order details:", error.message);
|
|
3373
3329
|
* } else {
|
|
3374
|
-
* console.log("Order details:", data.
|
|
3375
|
-
* console.log("Order status:", data.
|
|
3376
|
-
* console.log("Total amount:", data.
|
|
3330
|
+
* console.log("Order details:", data.order);
|
|
3331
|
+
* console.log("Order status:", data.order.status);
|
|
3332
|
+
* console.log("Total amount:", data.order.grand_total);
|
|
3377
3333
|
* }
|
|
3378
3334
|
* ```
|
|
3379
3335
|
*/
|
|
@@ -3414,9 +3370,9 @@ var OrderClient = class extends StorefrontAPIClient {
|
|
|
3414
3370
|
* if (error) {
|
|
3415
3371
|
* console.error("Failed to create order:", error.message);
|
|
3416
3372
|
* } else {
|
|
3417
|
-
* console.log("Order created:", data.
|
|
3418
|
-
* console.log("Payment required:", data.
|
|
3419
|
-
* console.log("Payment info:", data.
|
|
3373
|
+
* console.log("Order created:", data.order.id);
|
|
3374
|
+
* console.log("Payment required:", data.payment_required);
|
|
3375
|
+
* console.log("Payment info:", data.payment_info);
|
|
3420
3376
|
* }
|
|
3421
3377
|
* ```
|
|
3422
3378
|
*/
|
|
@@ -3447,10 +3403,10 @@ var OrderClient = class extends StorefrontAPIClient {
|
|
|
3447
3403
|
* if (error) {
|
|
3448
3404
|
* console.error("Failed to list orders:", error.message);
|
|
3449
3405
|
* } else {
|
|
3450
|
-
* console.log("Orders found:", data.
|
|
3451
|
-
* console.log("Pagination:", data.
|
|
3406
|
+
* console.log("Orders found:", data.orders?.length || 0);
|
|
3407
|
+
* console.log("Pagination:", data.pagination);
|
|
3452
3408
|
*
|
|
3453
|
-
* data.
|
|
3409
|
+
* data.orders?.forEach(order => {
|
|
3454
3410
|
* console.log(`Order ${order.order_number}: ${order.status}`);
|
|
3455
3411
|
* });
|
|
3456
3412
|
* }
|
|
@@ -3471,10 +3427,10 @@ var OrderClient = class extends StorefrontAPIClient {
|
|
|
3471
3427
|
* if (error) {
|
|
3472
3428
|
* console.error("Failed to get payment status:", error.message);
|
|
3473
3429
|
* } else {
|
|
3474
|
-
* console.log("Payment status:", data.
|
|
3475
|
-
* console.log("Amount paid:", data.
|
|
3476
|
-
* console.log("Amount unpaid:", data.
|
|
3477
|
-
* console.log("Retry available:", data.
|
|
3430
|
+
* console.log("Payment status:", data.status);
|
|
3431
|
+
* console.log("Amount paid:", data.amount_paid);
|
|
3432
|
+
* console.log("Amount unpaid:", data.amount_unpaid);
|
|
3433
|
+
* console.log("Retry available:", data.is_retry_available);
|
|
3478
3434
|
* }
|
|
3479
3435
|
* ```
|
|
3480
3436
|
*/
|
|
@@ -3495,9 +3451,9 @@ var OrderClient = class extends StorefrontAPIClient {
|
|
|
3495
3451
|
* if (error) {
|
|
3496
3452
|
* console.error("Failed to get order shipments:", error.message);
|
|
3497
3453
|
* } else {
|
|
3498
|
-
* console.log("Shipments found:", data.
|
|
3454
|
+
* console.log("Shipments found:", data.shipments?.length || 0);
|
|
3499
3455
|
*
|
|
3500
|
-
* data.
|
|
3456
|
+
* data.shipments?.forEach(shipment => {
|
|
3501
3457
|
* console.log(`Shipment ${shipment.id}: ${shipment.status}`);
|
|
3502
3458
|
* console.log("Tracking number:", shipment.tracking_number);
|
|
3503
3459
|
* console.log("Carrier:", shipment.carrier);
|
|
@@ -3522,9 +3478,9 @@ var OrderClient = class extends StorefrontAPIClient {
|
|
|
3522
3478
|
* if (error) {
|
|
3523
3479
|
* console.error("Failed to get order payments:", error.message);
|
|
3524
3480
|
* } else {
|
|
3525
|
-
* console.log("Payments found:", data.
|
|
3481
|
+
* console.log("Payments found:", data.payments?.length || 0);
|
|
3526
3482
|
*
|
|
3527
|
-
* data.
|
|
3483
|
+
* data.payments?.forEach(payment => {
|
|
3528
3484
|
* console.log(`Payment ${payment.id}: ${payment.status}`);
|
|
3529
3485
|
* console.log("Amount:", payment.amount);
|
|
3530
3486
|
* console.log("Gateway:", payment.payment_gateway);
|
|
@@ -3550,13 +3506,13 @@ var OrderClient = class extends StorefrontAPIClient {
|
|
|
3550
3506
|
* if (error) {
|
|
3551
3507
|
* console.error("Failed to get order refunds:", error.message);
|
|
3552
3508
|
* } else {
|
|
3553
|
-
* console.log("Refunds found:", data.
|
|
3509
|
+
* console.log("Refunds found:", data.refunds?.length || 0);
|
|
3554
3510
|
*
|
|
3555
|
-
* data.
|
|
3511
|
+
* data.refunds?.forEach(refund => {
|
|
3556
3512
|
* console.log(`Refund ${refund.id}: ${refund.status}`);
|
|
3557
|
-
* console.log("Amount:", refund.
|
|
3558
|
-
* console.log("Reason:", refund.
|
|
3559
|
-
* console.log("Processed at:", refund.
|
|
3513
|
+
* console.log("Amount:", refund.refund_amount);
|
|
3514
|
+
* console.log("Reason:", refund.refund_remarks);
|
|
3515
|
+
* console.log("Processed at:", refund.refund_date);
|
|
3560
3516
|
* });
|
|
3561
3517
|
* }
|
|
3562
3518
|
* ```
|
|
@@ -3585,8 +3541,8 @@ var OrderClient = class extends StorefrontAPIClient {
|
|
|
3585
3541
|
* console.error("Failed to cancel order:", error.message);
|
|
3586
3542
|
* } else {
|
|
3587
3543
|
* console.log("Order cancelled successfully");
|
|
3588
|
-
* console.log("Updated order status:", data.
|
|
3589
|
-
* console.log("Cancellation reason:", data.
|
|
3544
|
+
* console.log("Updated order status:", data.order?.status);
|
|
3545
|
+
* console.log("Cancellation reason:", data.order?.cancellation_reason);
|
|
3590
3546
|
* }
|
|
3591
3547
|
* ```
|
|
3592
3548
|
*/
|
|
@@ -3634,8 +3590,8 @@ var OrderClient = class extends StorefrontAPIClient {
|
|
|
3634
3590
|
* console.error("Failed to retry payment:", error.message);
|
|
3635
3591
|
* } else {
|
|
3636
3592
|
* console.log("Payment retry initiated");
|
|
3637
|
-
* console.log("Payment info:", data.
|
|
3638
|
-
* console.log("Transaction ID:", data.
|
|
3593
|
+
* console.log("Payment info:", data.payment_info);
|
|
3594
|
+
* console.log("Transaction ID:", data.payment_info.transaction_id);
|
|
3639
3595
|
* }
|
|
3640
3596
|
* ```
|
|
3641
3597
|
*/
|
|
@@ -3668,10 +3624,10 @@ var ShippingClient = class extends StorefrontAPIClient {
|
|
|
3668
3624
|
* if (error) {
|
|
3669
3625
|
* console.error("Failed to get shipping methods:", error.message);
|
|
3670
3626
|
* } else {
|
|
3671
|
-
* console.log("Is serviceable:", data.
|
|
3672
|
-
* console.log("Available shipping methods:", data.
|
|
3627
|
+
* console.log("Is serviceable:", data.is_serviceable);
|
|
3628
|
+
* console.log("Available shipping methods:", data.shipping_methods?.length || 0);
|
|
3673
3629
|
*
|
|
3674
|
-
* data.
|
|
3630
|
+
* data.shipping_methods?.forEach(method => {
|
|
3675
3631
|
* console.log(`Method: ${method.name} (${method.shipping_type})`);
|
|
3676
3632
|
* console.log(`Shipping cost: ${method.shipping_amount}`);
|
|
3677
3633
|
* console.log(`Estimated delivery: ${method.estimated_delivery_days} days`);
|
|
@@ -3701,9 +3657,9 @@ var ShippingClient = class extends StorefrontAPIClient {
|
|
|
3701
3657
|
* if (error) {
|
|
3702
3658
|
* console.error("Failed to check pincode serviceability:", error.message);
|
|
3703
3659
|
* } else {
|
|
3704
|
-
* console.log("Pincode serviceable:", data.
|
|
3660
|
+
* console.log("Pincode serviceable:", data.is_serviceable);
|
|
3705
3661
|
*
|
|
3706
|
-
* if (data.
|
|
3662
|
+
* if (data.is_serviceable) {
|
|
3707
3663
|
* console.log("Delivery is available to this pincode");
|
|
3708
3664
|
* } else {
|
|
3709
3665
|
* console.log("Delivery is not available to this pincode");
|