@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.iife.js
CHANGED
|
@@ -809,6 +809,21 @@ var CE_SDK = (() => {
|
|
|
809
809
|
function createAuthMiddleware(config) {
|
|
810
810
|
let isRefreshing = false;
|
|
811
811
|
let refreshPromise = null;
|
|
812
|
+
let hasAssessedTokens = false;
|
|
813
|
+
const assessTokenStateOnce = async () => {
|
|
814
|
+
if (hasAssessedTokens) return;
|
|
815
|
+
hasAssessedTokens = true;
|
|
816
|
+
try {
|
|
817
|
+
const accessToken = await config.tokenStorage.getAccessToken();
|
|
818
|
+
const refreshToken = await config.tokenStorage.getRefreshToken();
|
|
819
|
+
if (!accessToken && refreshToken) {
|
|
820
|
+
await config.tokenStorage.clearTokens();
|
|
821
|
+
console.info("Cleaned up orphaned refresh token");
|
|
822
|
+
}
|
|
823
|
+
} catch (error) {
|
|
824
|
+
console.warn("Token state assessment failed:", error);
|
|
825
|
+
}
|
|
826
|
+
};
|
|
812
827
|
const refreshTokens = async () => {
|
|
813
828
|
if (isRefreshing && refreshPromise) {
|
|
814
829
|
return refreshPromise;
|
|
@@ -885,17 +900,55 @@ var CE_SDK = (() => {
|
|
|
885
900
|
return {
|
|
886
901
|
async onRequest({ request }) {
|
|
887
902
|
const pathname = getPathnameFromUrl(request.url);
|
|
903
|
+
await assessTokenStateOnce();
|
|
888
904
|
if (isAnonymousAuthEndpoint(pathname)) {
|
|
889
905
|
if (config.apiKey) {
|
|
890
906
|
request.headers.set("X-Api-Key", config.apiKey);
|
|
891
907
|
}
|
|
892
908
|
const existingToken = await config.tokenStorage.getAccessToken();
|
|
909
|
+
if (existingToken && !isTokenExpired(existingToken) && isUserLoggedIn(existingToken)) {
|
|
910
|
+
return new Response(
|
|
911
|
+
JSON.stringify({
|
|
912
|
+
message: "Cannot create anonymous session while authenticated",
|
|
913
|
+
success: false,
|
|
914
|
+
code: "USER_ALREADY_AUTHENTICATED"
|
|
915
|
+
}),
|
|
916
|
+
{
|
|
917
|
+
status: 400,
|
|
918
|
+
headers: { "Content-Type": "application/json" }
|
|
919
|
+
}
|
|
920
|
+
);
|
|
921
|
+
}
|
|
893
922
|
if (existingToken) {
|
|
894
923
|
request.headers.set("Authorization", `Bearer ${existingToken}`);
|
|
895
924
|
}
|
|
896
925
|
return request;
|
|
897
926
|
}
|
|
898
927
|
let accessToken = await config.tokenStorage.getAccessToken();
|
|
928
|
+
if (!accessToken) {
|
|
929
|
+
try {
|
|
930
|
+
const response = await fetch(`${config.baseUrl}/auth/anonymous`, {
|
|
931
|
+
method: "POST",
|
|
932
|
+
headers: {
|
|
933
|
+
"Content-Type": "application/json",
|
|
934
|
+
...config.apiKey && { "X-Api-Key": config.apiKey }
|
|
935
|
+
}
|
|
936
|
+
});
|
|
937
|
+
if (response.ok) {
|
|
938
|
+
const data = await response.json();
|
|
939
|
+
const tokens = data.content;
|
|
940
|
+
if (tokens?.access_token && tokens?.refresh_token) {
|
|
941
|
+
await config.tokenStorage.setAccessToken(tokens.access_token);
|
|
942
|
+
await config.tokenStorage.setRefreshToken(tokens.refresh_token);
|
|
943
|
+
accessToken = tokens.access_token;
|
|
944
|
+
config.onTokensUpdated?.(tokens.access_token, tokens.refresh_token);
|
|
945
|
+
console.info("Automatically created anonymous session for first API request");
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
} catch (error) {
|
|
949
|
+
console.warn("Failed to automatically create anonymous tokens:", error);
|
|
950
|
+
}
|
|
951
|
+
}
|
|
899
952
|
if (accessToken && isTokenExpired(accessToken)) {
|
|
900
953
|
try {
|
|
901
954
|
await refreshTokens();
|
|
@@ -1456,6 +1509,50 @@ var CE_SDK = (() => {
|
|
|
1456
1509
|
* @param options - Optional query parameters
|
|
1457
1510
|
* @param headers - Optional header parameters (customer_group_id, etc.)
|
|
1458
1511
|
* @returns Promise with products and pagination info
|
|
1512
|
+
*
|
|
1513
|
+
* @example
|
|
1514
|
+
* ```typescript
|
|
1515
|
+
* // Basic product listing
|
|
1516
|
+
* const { data, error } = await sdk.catalog.listProducts();
|
|
1517
|
+
*
|
|
1518
|
+
* if (error) {
|
|
1519
|
+
* console.error("Failed to list products:", error);
|
|
1520
|
+
* return;
|
|
1521
|
+
* }
|
|
1522
|
+
*
|
|
1523
|
+
* console.log("Products found:", data.products?.length || 0);
|
|
1524
|
+
* console.log("Pagination:", data.pagination);
|
|
1525
|
+
*
|
|
1526
|
+
* // With filtering and pagination
|
|
1527
|
+
* const { data: filteredData, error: filteredError } = await sdk.catalog.listProducts({
|
|
1528
|
+
* page: 1,
|
|
1529
|
+
* limit: 20,
|
|
1530
|
+
* sort_by: JSON.stringify({ "created_at": "desc" }),
|
|
1531
|
+
* category_slug: ["electronics", "smartphones"]
|
|
1532
|
+
* });
|
|
1533
|
+
*
|
|
1534
|
+
* // Override customer group ID for this specific request
|
|
1535
|
+
* const { data: overrideData, error: overrideError } = await sdk.catalog.listProducts(
|
|
1536
|
+
* {
|
|
1537
|
+
* page: 1,
|
|
1538
|
+
* limit: 20,
|
|
1539
|
+
* sort_by: JSON.stringify({ "created_at": "desc" }),
|
|
1540
|
+
* category_slug: ["electronics", "smartphones"]
|
|
1541
|
+
* },
|
|
1542
|
+
* {
|
|
1543
|
+
* "x-customer-group-id": "01H9XYZ12345USERID" // Override default SDK config
|
|
1544
|
+
* }
|
|
1545
|
+
* );
|
|
1546
|
+
*
|
|
1547
|
+
* if (filteredError) {
|
|
1548
|
+
* console.error("Failed to get filtered products:", filteredError);
|
|
1549
|
+
* return;
|
|
1550
|
+
* }
|
|
1551
|
+
*
|
|
1552
|
+
* filteredData.products?.forEach(product => {
|
|
1553
|
+
* console.log(`Product: ${product.name} - ${product.price}`);
|
|
1554
|
+
* });
|
|
1555
|
+
* ```
|
|
1459
1556
|
*/
|
|
1460
1557
|
async listProducts(options, headers) {
|
|
1461
1558
|
const mergedHeaders = this.mergeHeaders(headers);
|
|
@@ -1474,6 +1571,46 @@ var CE_SDK = (() => {
|
|
|
1474
1571
|
* @param options - Optional query parameters
|
|
1475
1572
|
* @param headers - Optional header parameters (customer_group_id, etc.)
|
|
1476
1573
|
* @returns Promise with skus and pagination info
|
|
1574
|
+
*
|
|
1575
|
+
* @example
|
|
1576
|
+
* ```typescript
|
|
1577
|
+
* // Basic SKU listing
|
|
1578
|
+
* const { data, error } = await sdk.catalog.listSkus();
|
|
1579
|
+
*
|
|
1580
|
+
* if (error) {
|
|
1581
|
+
* console.error("Failed to list SKUs:", error);
|
|
1582
|
+
* return;
|
|
1583
|
+
* }
|
|
1584
|
+
*
|
|
1585
|
+
* console.log("SKUs found:", data.skus?.length || 0);
|
|
1586
|
+
* console.log("Pagination:", data.pagination);
|
|
1587
|
+
*
|
|
1588
|
+
* // With pagination
|
|
1589
|
+
* const { data: skuData, error: skuError } = await sdk.catalog.listSkus({
|
|
1590
|
+
* page: 1,
|
|
1591
|
+
* limit: 50
|
|
1592
|
+
* });
|
|
1593
|
+
*
|
|
1594
|
+
* // Override customer group ID for this specific request
|
|
1595
|
+
* const { data: overrideData, error: overrideError } = await sdk.catalog.listSkus(
|
|
1596
|
+
* {
|
|
1597
|
+
* page: 1,
|
|
1598
|
+
* limit: 50
|
|
1599
|
+
* },
|
|
1600
|
+
* {
|
|
1601
|
+
* "x-customer-group-id": "01H9XYZ12345USERID" // Override default SDK config
|
|
1602
|
+
* }
|
|
1603
|
+
* );
|
|
1604
|
+
*
|
|
1605
|
+
* if (skuError) {
|
|
1606
|
+
* console.error("Failed to get SKUs:", skuError);
|
|
1607
|
+
* return;
|
|
1608
|
+
* }
|
|
1609
|
+
*
|
|
1610
|
+
* skuData.skus?.forEach(sku => {
|
|
1611
|
+
* console.log(`SKU: ${sku.sku} - Price: ${sku.price}`);
|
|
1612
|
+
* });
|
|
1613
|
+
* ```
|
|
1477
1614
|
*/
|
|
1478
1615
|
async listSkus(options, headers) {
|
|
1479
1616
|
const mergedHeaders = this.mergeHeaders(headers);
|
|
@@ -1492,6 +1629,43 @@ var CE_SDK = (() => {
|
|
|
1492
1629
|
* @param pathParams - The path parameters (product ID or slug)
|
|
1493
1630
|
* @param headers - Optional header parameters (customer_group_id, etc.)
|
|
1494
1631
|
* @returns Promise with product details
|
|
1632
|
+
*
|
|
1633
|
+
* @example
|
|
1634
|
+
* ```typescript
|
|
1635
|
+
* // Get product by ID
|
|
1636
|
+
* const { data, error } = await sdk.catalog.getProductDetail(
|
|
1637
|
+
* { product_id_or_slug: "prod_123" }
|
|
1638
|
+
* );
|
|
1639
|
+
*
|
|
1640
|
+
* if (error) {
|
|
1641
|
+
* console.error("Failed to get product details:", error);
|
|
1642
|
+
* return;
|
|
1643
|
+
* }
|
|
1644
|
+
*
|
|
1645
|
+
* console.log("Product:", data.product.name);
|
|
1646
|
+
* console.log("Price:", data.product.price);
|
|
1647
|
+
* console.log("Description:", data.product.description);
|
|
1648
|
+
*
|
|
1649
|
+
* // Get product by slug
|
|
1650
|
+
* const { data: slugData, error: slugError } = await sdk.catalog.getProductDetail({
|
|
1651
|
+
* product_id_or_slug: "detox-candy"
|
|
1652
|
+
* });
|
|
1653
|
+
*
|
|
1654
|
+
* // Override customer group ID for this specific request
|
|
1655
|
+
* const { data: overrideData, error: overrideError } = await sdk.catalog.getProductDetail(
|
|
1656
|
+
* { product_id_or_slug: "detox-candy" },
|
|
1657
|
+
* {
|
|
1658
|
+
* "x-customer-group-id": "premium_customers" // Override default SDK config
|
|
1659
|
+
* }
|
|
1660
|
+
* );
|
|
1661
|
+
*
|
|
1662
|
+
* if (slugError) {
|
|
1663
|
+
* console.error("Failed to get product by slug:", slugError);
|
|
1664
|
+
* return;
|
|
1665
|
+
* }
|
|
1666
|
+
*
|
|
1667
|
+
* console.log("Product with custom pricing:", slugData.product.price);
|
|
1668
|
+
* ```
|
|
1495
1669
|
*/
|
|
1496
1670
|
async getProductDetail(pathParams, headers) {
|
|
1497
1671
|
const mergedHeaders = this.mergeHeaders(headers);
|
|
@@ -1505,11 +1679,37 @@ var CE_SDK = (() => {
|
|
|
1505
1679
|
);
|
|
1506
1680
|
}
|
|
1507
1681
|
/**
|
|
1508
|
-
* List variants for a specific product
|
|
1682
|
+
* List all variants for a specific product
|
|
1509
1683
|
*
|
|
1510
1684
|
* @param pathParams - The path parameters (product ID)
|
|
1511
1685
|
* @param headers - Optional header parameters (customer_group_id, etc.)
|
|
1512
|
-
* @returns Promise with variants
|
|
1686
|
+
* @returns Promise with product variants and pagination info
|
|
1687
|
+
*
|
|
1688
|
+
* @example
|
|
1689
|
+
* ```typescript
|
|
1690
|
+
* const { data, error } = await sdk.catalog.listProductVariants(
|
|
1691
|
+
* { product_id: "prod_123" }
|
|
1692
|
+
* );
|
|
1693
|
+
*
|
|
1694
|
+
* if (error) {
|
|
1695
|
+
* console.error("Failed to list product variants:", error);
|
|
1696
|
+
* return;
|
|
1697
|
+
* }
|
|
1698
|
+
*
|
|
1699
|
+
* console.log("Variants found:", data.variants?.length || 0);
|
|
1700
|
+
*
|
|
1701
|
+
* data.variants?.forEach(variant => {
|
|
1702
|
+
* console.log(`Variant: ${variant.name} - SKU: ${variant.sku} - Price: ${variant.price}`);
|
|
1703
|
+
* });
|
|
1704
|
+
*
|
|
1705
|
+
* // Override customer group ID for this specific request
|
|
1706
|
+
* const { data: overrideData, error: overrideError } = await sdk.catalog.listProductVariants(
|
|
1707
|
+
* { product_id: "prod_123" },
|
|
1708
|
+
* {
|
|
1709
|
+
* "x-customer-group-id": "wholesale_customers" // Override default SDK config
|
|
1710
|
+
* }
|
|
1711
|
+
* );
|
|
1712
|
+
* ```
|
|
1513
1713
|
*/
|
|
1514
1714
|
async listProductVariants(pathParams, headers) {
|
|
1515
1715
|
const mergedHeaders = this.mergeHeaders(headers);
|
|
@@ -1523,11 +1723,31 @@ var CE_SDK = (() => {
|
|
|
1523
1723
|
);
|
|
1524
1724
|
}
|
|
1525
1725
|
/**
|
|
1526
|
-
* Get details for a specific variant
|
|
1726
|
+
* Get details for a specific product variant
|
|
1527
1727
|
*
|
|
1528
1728
|
* @param pathParams - The path parameters (product ID and variant ID)
|
|
1529
1729
|
* @param headers - Optional header parameters (customer_group_id, etc.)
|
|
1530
1730
|
* @returns Promise with variant details
|
|
1731
|
+
*
|
|
1732
|
+
* @example
|
|
1733
|
+
* ```typescript
|
|
1734
|
+
* const { data, error } = await sdk.catalog.getVariantDetail(
|
|
1735
|
+
* {
|
|
1736
|
+
* product_id: "prod_123",
|
|
1737
|
+
* variant_id: "var_456"
|
|
1738
|
+
* }
|
|
1739
|
+
* );
|
|
1740
|
+
*
|
|
1741
|
+
* if (error) {
|
|
1742
|
+
* console.error("Failed to get variant details:", error);
|
|
1743
|
+
* return;
|
|
1744
|
+
* }
|
|
1745
|
+
*
|
|
1746
|
+
* console.log("Variant:", data.variant.name);
|
|
1747
|
+
* console.log("SKU:", data.variant.sku);
|
|
1748
|
+
* console.log("Price:", data.variant.price);
|
|
1749
|
+
* console.log("Stock:", data.variant.stock);
|
|
1750
|
+
* ```
|
|
1531
1751
|
*/
|
|
1532
1752
|
async getVariantDetail(pathParams, headers) {
|
|
1533
1753
|
const mergedHeaders = this.mergeHeaders(headers);
|
|
@@ -1541,24 +1761,77 @@ var CE_SDK = (() => {
|
|
|
1541
1761
|
);
|
|
1542
1762
|
}
|
|
1543
1763
|
/**
|
|
1544
|
-
* List all categories
|
|
1764
|
+
* List all product categories
|
|
1545
1765
|
*
|
|
1546
1766
|
* @param options - Optional query parameters
|
|
1547
1767
|
* @returns Promise with categories and pagination info
|
|
1768
|
+
*
|
|
1769
|
+
* @example
|
|
1770
|
+
* ```typescript
|
|
1771
|
+
* // Basic category listing
|
|
1772
|
+
* const { data, error } = await sdk.catalog.listCategories();
|
|
1773
|
+
*
|
|
1774
|
+
* if (error) {
|
|
1775
|
+
* console.error("Failed to list categories:", error);
|
|
1776
|
+
* return;
|
|
1777
|
+
* }
|
|
1778
|
+
*
|
|
1779
|
+
* console.log("Categories found:", data.categories?.length || 0);
|
|
1780
|
+
*
|
|
1781
|
+
* data.categories?.forEach(category => {
|
|
1782
|
+
* console.log(`Category: ${category.name} - ${category.description}`);
|
|
1783
|
+
* });
|
|
1784
|
+
*
|
|
1785
|
+
* // With pagination
|
|
1786
|
+
* const { data: catData, error: catError } = await sdk.catalog.listCategories({
|
|
1787
|
+
* page: 1,
|
|
1788
|
+
* limit: 10
|
|
1789
|
+
* });
|
|
1790
|
+
* ```
|
|
1548
1791
|
*/
|
|
1549
1792
|
async listCategories(options) {
|
|
1550
1793
|
return this.executeRequest(
|
|
1551
1794
|
() => this.client.GET("/catalog/categories", {
|
|
1552
|
-
params: {
|
|
1795
|
+
params: {
|
|
1796
|
+
query: options
|
|
1797
|
+
}
|
|
1553
1798
|
})
|
|
1554
1799
|
);
|
|
1555
1800
|
}
|
|
1556
1801
|
/**
|
|
1557
|
-
* List reviews for a specific product
|
|
1802
|
+
* List all reviews for a specific product
|
|
1558
1803
|
*
|
|
1559
1804
|
* @param pathParams - The path parameters (product ID)
|
|
1560
1805
|
* @param queryParams - Optional query parameters
|
|
1561
|
-
* @returns Promise with reviews and pagination info
|
|
1806
|
+
* @returns Promise with product reviews and pagination info
|
|
1807
|
+
*
|
|
1808
|
+
* @example
|
|
1809
|
+
* ```typescript
|
|
1810
|
+
* const { data, error } = await sdk.catalog.listProductReviews(
|
|
1811
|
+
* { product_id: "prod_123" }
|
|
1812
|
+
* );
|
|
1813
|
+
*
|
|
1814
|
+
* if (error) {
|
|
1815
|
+
* console.error("Failed to list product reviews:", error);
|
|
1816
|
+
* return;
|
|
1817
|
+
* }
|
|
1818
|
+
*
|
|
1819
|
+
* console.log("Reviews found:", data.reviews?.length || 0);
|
|
1820
|
+
*
|
|
1821
|
+
* data.reviews?.forEach(review => {
|
|
1822
|
+
* console.log(`Review by ${review.customer_name}: ${review.rating}/5`);
|
|
1823
|
+
* console.log("Comment:", review.comment);
|
|
1824
|
+
* });
|
|
1825
|
+
*
|
|
1826
|
+
* // With pagination
|
|
1827
|
+
* const { data: reviewData, error: reviewError } = await sdk.catalog.listProductReviews(
|
|
1828
|
+
* { product_id: "prod_123" },
|
|
1829
|
+
* {
|
|
1830
|
+
* page: 1,
|
|
1831
|
+
* limit: 5
|
|
1832
|
+
* }
|
|
1833
|
+
* );
|
|
1834
|
+
* ```
|
|
1562
1835
|
*/
|
|
1563
1836
|
async listProductReviews(pathParams, queryParams) {
|
|
1564
1837
|
return this.executeRequest(
|
|
@@ -1571,11 +1844,33 @@ var CE_SDK = (() => {
|
|
|
1571
1844
|
);
|
|
1572
1845
|
}
|
|
1573
1846
|
/**
|
|
1574
|
-
* Create a review
|
|
1847
|
+
* Create a product review
|
|
1575
1848
|
*
|
|
1576
1849
|
* @param pathParams - The path parameters (product ID)
|
|
1577
|
-
* @param formData - The review data
|
|
1578
|
-
* @returns Promise
|
|
1850
|
+
* @param formData - The review data including rating, comment, and optional images
|
|
1851
|
+
* @returns Promise with review creation response
|
|
1852
|
+
*
|
|
1853
|
+
* @example
|
|
1854
|
+
* ```typescript
|
|
1855
|
+
* const { data, error } = await sdk.catalog.createProductReview(
|
|
1856
|
+
* { product_id: "prod_123" },
|
|
1857
|
+
* {
|
|
1858
|
+
* rating: 5,
|
|
1859
|
+
* comment: "Excellent product! Highly recommended.",
|
|
1860
|
+
* images: [
|
|
1861
|
+
* new File(["image data"], "review1.jpg", { type: "image/jpeg" }),
|
|
1862
|
+
* new File(["image data"], "review2.jpg", { type: "image/jpeg" })
|
|
1863
|
+
* ]
|
|
1864
|
+
* }
|
|
1865
|
+
* );
|
|
1866
|
+
*
|
|
1867
|
+
* if (error) {
|
|
1868
|
+
* console.error("Failed to create review:", error);
|
|
1869
|
+
* return;
|
|
1870
|
+
* }
|
|
1871
|
+
*
|
|
1872
|
+
* console.log("Review created successfully:", data.message);
|
|
1873
|
+
* ```
|
|
1579
1874
|
*/
|
|
1580
1875
|
async createProductReview(pathParams, formData) {
|
|
1581
1876
|
return this.executeRequest(
|
|
@@ -1603,24 +1898,103 @@ var CE_SDK = (() => {
|
|
|
1603
1898
|
/**
|
|
1604
1899
|
* Search for products
|
|
1605
1900
|
*
|
|
1606
|
-
* @param searchData - The search
|
|
1607
|
-
* @
|
|
1901
|
+
* @param searchData - The search query and filters
|
|
1902
|
+
* @param headers - Optional header parameters (customer_group_id, etc.)
|
|
1903
|
+
* @returns Promise with search results including products, facets, and pagination
|
|
1904
|
+
*
|
|
1905
|
+
* @example
|
|
1906
|
+
* ```typescript
|
|
1907
|
+
* const { data, error } = await sdk.catalog.searchProducts({
|
|
1908
|
+
* query: "smartphone",
|
|
1909
|
+
* filters: {
|
|
1910
|
+
* category: ["electronics", "mobile"],
|
|
1911
|
+
* price_range: { min: 100, max: 1000 },
|
|
1912
|
+
* brand: ["Apple", "Samsung"] // facet names depend on product configuration
|
|
1913
|
+
* },
|
|
1914
|
+
* page: 1,
|
|
1915
|
+
* limit: 20
|
|
1916
|
+
* });
|
|
1917
|
+
*
|
|
1918
|
+
* if (error) {
|
|
1919
|
+
* console.error("Failed to search products:", error);
|
|
1920
|
+
* return;
|
|
1921
|
+
* }
|
|
1922
|
+
*
|
|
1923
|
+
* console.log("Search results:", data.skus?.length || 0, "products found");
|
|
1924
|
+
* console.log("Facet distribution:", data.facet_distribution);
|
|
1925
|
+
* console.log("Price range:", data.facet_stats.price_range);
|
|
1926
|
+
*
|
|
1927
|
+
* data.skus?.forEach(sku => {
|
|
1928
|
+
* console.log(`Found: ${sku.name} - ${sku.price}`);
|
|
1929
|
+
* });
|
|
1930
|
+
*
|
|
1931
|
+
* // Override customer group ID for this specific request
|
|
1932
|
+
* const { data: overrideData, error: overrideError } = await sdk.catalog.searchProducts(
|
|
1933
|
+
* {
|
|
1934
|
+
* query: "laptop",
|
|
1935
|
+
* filters: { category: ["computers"] }
|
|
1936
|
+
* },
|
|
1937
|
+
* {
|
|
1938
|
+
* "x-customer-group-id": "01H9XYZ12345USERID" // Override default SDK config
|
|
1939
|
+
* }
|
|
1940
|
+
* );
|
|
1941
|
+
* ```
|
|
1608
1942
|
*/
|
|
1609
1943
|
async searchProducts(searchData, headers) {
|
|
1610
1944
|
const mergedHeaders = this.mergeHeaders(headers);
|
|
1611
1945
|
return this.executeRequest(
|
|
1612
1946
|
() => this.client.POST("/catalog/products/search", {
|
|
1613
|
-
|
|
1614
|
-
|
|
1947
|
+
params: {
|
|
1948
|
+
header: mergedHeaders
|
|
1949
|
+
},
|
|
1950
|
+
body: searchData
|
|
1615
1951
|
})
|
|
1616
1952
|
);
|
|
1617
1953
|
}
|
|
1618
1954
|
/**
|
|
1619
1955
|
* List cross-sell products
|
|
1620
1956
|
*
|
|
1621
|
-
* @param options - Optional query parameters
|
|
1957
|
+
* @param options - Optional query parameters for filtering and pagination
|
|
1622
1958
|
* @param headers - Optional header parameters (customer_group_id, etc.)
|
|
1623
1959
|
* @returns Promise with cross-sell products
|
|
1960
|
+
* @example
|
|
1961
|
+
* ```typescript
|
|
1962
|
+
* // Basic usage - get cross-sell products for cart items
|
|
1963
|
+
* const { data, error } = await sdk.catalog.listCrossSellProducts({
|
|
1964
|
+
* product_id: ["prod_01H9XYZ12345ABCDE", "prod_01H9ABC67890FGHIJ"]
|
|
1965
|
+
* });
|
|
1966
|
+
*
|
|
1967
|
+
* // Advanced usage with pagination and custom sorting
|
|
1968
|
+
* const { data, error } = await sdk.catalog.listCrossSellProducts({
|
|
1969
|
+
* product_id: ["prod_01H9XYZ12345ABCDE"],
|
|
1970
|
+
* page: 1,
|
|
1971
|
+
* limit: 10,
|
|
1972
|
+
* sort_by: '{"price":"asc"}'
|
|
1973
|
+
* });
|
|
1974
|
+
*
|
|
1975
|
+
* // Override customer group ID for this specific request
|
|
1976
|
+
* const { data, error } = await sdk.catalog.listCrossSellProducts(
|
|
1977
|
+
* {
|
|
1978
|
+
* product_id: ["prod_01H9XYZ12345ABCDE"],
|
|
1979
|
+
* page: 1,
|
|
1980
|
+
* limit: 10
|
|
1981
|
+
* },
|
|
1982
|
+
* {
|
|
1983
|
+
* "x-customer-group-id": "01H9XYZ12345USERID" // Override default SDK config
|
|
1984
|
+
* }
|
|
1985
|
+
* );
|
|
1986
|
+
*
|
|
1987
|
+
* if (error) {
|
|
1988
|
+
* console.error("Failed to get cross-sell products:", error.message);
|
|
1989
|
+
* } else {
|
|
1990
|
+
* console.log("Cross-sell products found:", data.content.products.length);
|
|
1991
|
+
* console.log("Pagination:", data.content.pagination);
|
|
1992
|
+
*
|
|
1993
|
+
* data.content.products.forEach(product => {
|
|
1994
|
+
* console.log(`Product: ${product.name} - ${product.price}`);
|
|
1995
|
+
* });
|
|
1996
|
+
* }
|
|
1997
|
+
* ```
|
|
1624
1998
|
*/
|
|
1625
1999
|
async listCrossSellProducts(options, headers) {
|
|
1626
2000
|
const mergedHeaders = this.mergeHeaders(headers);
|
|
@@ -1636,9 +2010,47 @@ var CE_SDK = (() => {
|
|
|
1636
2010
|
/**
|
|
1637
2011
|
* List up-sell products
|
|
1638
2012
|
*
|
|
1639
|
-
* @param options - Optional query parameters
|
|
2013
|
+
* @param options - Optional query parameters for filtering and pagination
|
|
1640
2014
|
* @param headers - Optional header parameters (customer_group_id, etc.)
|
|
1641
2015
|
* @returns Promise with up-sell products
|
|
2016
|
+
* @example
|
|
2017
|
+
* ```typescript
|
|
2018
|
+
* // Basic usage - get up-sell products for cart items
|
|
2019
|
+
* const { data, error } = await sdk.catalog.listUpSellProducts({
|
|
2020
|
+
* product_id: ["prod_01H9XYZ12345ABCDE"]
|
|
2021
|
+
* });
|
|
2022
|
+
*
|
|
2023
|
+
* // Advanced usage with pagination and custom sorting
|
|
2024
|
+
* const { data, error } = await sdk.catalog.listUpSellProducts({
|
|
2025
|
+
* product_id: ["prod_01H9XYZ12345ABCDE"],
|
|
2026
|
+
* page: 1,
|
|
2027
|
+
* limit: 15,
|
|
2028
|
+
* sort_by: '{"relevance":"desc"}'
|
|
2029
|
+
* });
|
|
2030
|
+
*
|
|
2031
|
+
* // Override customer group ID for this specific request
|
|
2032
|
+
* const { data, error } = await sdk.catalog.listUpSellProducts(
|
|
2033
|
+
* {
|
|
2034
|
+
* product_id: ["prod_01H9XYZ12345ABCDE"],
|
|
2035
|
+
* page: 1,
|
|
2036
|
+
* limit: 15
|
|
2037
|
+
* },
|
|
2038
|
+
* {
|
|
2039
|
+
* "x-customer-group-id": "01H9XYZ12345USERID" // Override default SDK config
|
|
2040
|
+
* }
|
|
2041
|
+
* );
|
|
2042
|
+
*
|
|
2043
|
+
* if (error) {
|
|
2044
|
+
* console.error("Failed to get up-sell products:", error.message);
|
|
2045
|
+
* } else {
|
|
2046
|
+
* console.log("Up-sell products found:", data.content.products.length);
|
|
2047
|
+
* console.log("Pagination:", data.content.pagination);
|
|
2048
|
+
*
|
|
2049
|
+
* data.content.products.forEach(product => {
|
|
2050
|
+
* console.log(`Up-sell: ${product.name} - ${product.price}`);
|
|
2051
|
+
* });
|
|
2052
|
+
* }
|
|
2053
|
+
* ```
|
|
1642
2054
|
*/
|
|
1643
2055
|
async listUpSellProducts(options, headers) {
|
|
1644
2056
|
const mergedHeaders = this.mergeHeaders(headers);
|
|
@@ -1654,9 +2066,47 @@ var CE_SDK = (() => {
|
|
|
1654
2066
|
/**
|
|
1655
2067
|
* List similar products
|
|
1656
2068
|
*
|
|
1657
|
-
* @param options - Optional query parameters
|
|
2069
|
+
* @param options - Optional query parameters for filtering and pagination
|
|
1658
2070
|
* @param headers - Optional header parameters (customer_group_id, etc.)
|
|
1659
2071
|
* @returns Promise with similar products
|
|
2072
|
+
* @example
|
|
2073
|
+
* ```typescript
|
|
2074
|
+
* // Basic usage - get similar products for a specific product
|
|
2075
|
+
* const { data, error } = await sdk.catalog.listSimilarProducts({
|
|
2076
|
+
* product_id: ["prod_01H9XYZ12345ABCDE"]
|
|
2077
|
+
* });
|
|
2078
|
+
*
|
|
2079
|
+
* // Advanced usage with pagination and custom sorting
|
|
2080
|
+
* const { data, error } = await sdk.catalog.listSimilarProducts({
|
|
2081
|
+
* product_id: ["prod_01H9XYZ12345ABCDE"],
|
|
2082
|
+
* page: 1,
|
|
2083
|
+
* limit: 20,
|
|
2084
|
+
* sort_by: '{"relevance":"desc"}'
|
|
2085
|
+
* });
|
|
2086
|
+
*
|
|
2087
|
+
* // Override customer group ID for this specific request
|
|
2088
|
+
* const { data, error } = await sdk.catalog.listSimilarProducts(
|
|
2089
|
+
* {
|
|
2090
|
+
* product_id: ["prod_01H9XYZ12345ABCDE"],
|
|
2091
|
+
* page: 1,
|
|
2092
|
+
* limit: 20
|
|
2093
|
+
* },
|
|
2094
|
+
* {
|
|
2095
|
+
* "x-customer-group-id": "01H9XYZ12345USERID" // Override default SDK config
|
|
2096
|
+
* }
|
|
2097
|
+
* );
|
|
2098
|
+
*
|
|
2099
|
+
* if (error) {
|
|
2100
|
+
* console.error("Failed to get similar products:", error.message);
|
|
2101
|
+
* } else {
|
|
2102
|
+
* console.log("Similar products found:", data.content.products.length);
|
|
2103
|
+
* console.log("Pagination:", data.content.pagination);
|
|
2104
|
+
*
|
|
2105
|
+
* data.content.products.forEach(product => {
|
|
2106
|
+
* console.log(`Similar: ${product.name} - ${product.price}`);
|
|
2107
|
+
* });
|
|
2108
|
+
* }
|
|
2109
|
+
* ```
|
|
1660
2110
|
*/
|
|
1661
2111
|
async listSimilarProducts(options, headers) {
|
|
1662
2112
|
const mergedHeaders = this.mergeHeaders(headers);
|
|
@@ -1678,6 +2128,33 @@ var CE_SDK = (() => {
|
|
|
1678
2128
|
*
|
|
1679
2129
|
* @param payload - Object containing the items to add to the cart
|
|
1680
2130
|
* @returns Promise with the created cart
|
|
2131
|
+
* @example
|
|
2132
|
+
* ```typescript
|
|
2133
|
+
* const { data, error } = await sdk.cart.createCart({
|
|
2134
|
+
* items: [
|
|
2135
|
+
* {
|
|
2136
|
+
* product_id: "01H9XYZ12345ABCDE",
|
|
2137
|
+
* variant_id: null,
|
|
2138
|
+
* quantity: 2
|
|
2139
|
+
* },
|
|
2140
|
+
* {
|
|
2141
|
+
* product_id: "01H9ABC67890FGHIJ",
|
|
2142
|
+
* variant_id: "01H9XYZ67890KLMNO",
|
|
2143
|
+
* quantity: 1
|
|
2144
|
+
* }
|
|
2145
|
+
* ],
|
|
2146
|
+
* metadata: {
|
|
2147
|
+
* "source": "web",
|
|
2148
|
+
* "campaign": "summer_sale"
|
|
2149
|
+
* }
|
|
2150
|
+
* });
|
|
2151
|
+
*
|
|
2152
|
+
* if (error) {
|
|
2153
|
+
* console.error("Failed to create cart:", error.message);
|
|
2154
|
+
* } else {
|
|
2155
|
+
* console.log("Cart created:", data.cart.id);
|
|
2156
|
+
* }
|
|
2157
|
+
* ```
|
|
1681
2158
|
*/
|
|
1682
2159
|
async createCart(payload) {
|
|
1683
2160
|
return this.executeRequest(
|
|
@@ -1691,6 +2168,20 @@ var CE_SDK = (() => {
|
|
|
1691
2168
|
*
|
|
1692
2169
|
* @param cartId - The ID of the cart
|
|
1693
2170
|
* @returns Promise with cart details
|
|
2171
|
+
* @example
|
|
2172
|
+
* ```typescript
|
|
2173
|
+
* const { data, error } = await sdk.cart.getCart({
|
|
2174
|
+
* id: "01H9CART12345ABCDE"
|
|
2175
|
+
* });
|
|
2176
|
+
*
|
|
2177
|
+
* if (error) {
|
|
2178
|
+
* console.error("Failed to get cart:", error.message);
|
|
2179
|
+
* } else {
|
|
2180
|
+
* const cart = data.cart;
|
|
2181
|
+
* console.log("Cart total:", cart.total_amount);
|
|
2182
|
+
* console.log("Items count:", cart.items.length);
|
|
2183
|
+
* }
|
|
2184
|
+
* ```
|
|
1694
2185
|
*/
|
|
1695
2186
|
async getCart(cartId) {
|
|
1696
2187
|
return this.executeRequest(
|
|
@@ -1706,6 +2197,18 @@ var CE_SDK = (() => {
|
|
|
1706
2197
|
*
|
|
1707
2198
|
* @param cartId - The ID of the cart
|
|
1708
2199
|
* @returns Promise that resolves when the cart is deleted
|
|
2200
|
+
* @example
|
|
2201
|
+
* ```typescript
|
|
2202
|
+
* const { data, error } = await sdk.cart.deleteCart({
|
|
2203
|
+
* id: "01H9CART12345ABCDE"
|
|
2204
|
+
* });
|
|
2205
|
+
*
|
|
2206
|
+
* if (error) {
|
|
2207
|
+
* console.error("Failed to delete cart:", error.message);
|
|
2208
|
+
* } else {
|
|
2209
|
+
* console.log("Cart deleted:", data.message);
|
|
2210
|
+
* }
|
|
2211
|
+
* ```
|
|
1709
2212
|
*/
|
|
1710
2213
|
async deleteCart(cartId) {
|
|
1711
2214
|
return this.executeRequest(
|
|
@@ -1722,6 +2225,34 @@ var CE_SDK = (() => {
|
|
|
1722
2225
|
* @param cartId - The cart id
|
|
1723
2226
|
* @param body - The body of the request
|
|
1724
2227
|
* @returns Promise with updated cart
|
|
2228
|
+
* @example
|
|
2229
|
+
* ```typescript
|
|
2230
|
+
* // Add item to cart
|
|
2231
|
+
* const { data, error } = await sdk.cart.addDeleteCartItem(
|
|
2232
|
+
* { id: "01H9CART12345ABCDE" },
|
|
2233
|
+
* {
|
|
2234
|
+
* product_id: "01H9XYZ12345ABCDE",
|
|
2235
|
+
* variant_id: null,
|
|
2236
|
+
* quantity: 3
|
|
2237
|
+
* }
|
|
2238
|
+
* );
|
|
2239
|
+
*
|
|
2240
|
+
* if (error) {
|
|
2241
|
+
* console.error("Failed to update cart:", error.message);
|
|
2242
|
+
* } else {
|
|
2243
|
+
* console.log("Cart updated:", data.cart.items.length);
|
|
2244
|
+
* }
|
|
2245
|
+
*
|
|
2246
|
+
* // Remove item from cart (set quantity to 0)
|
|
2247
|
+
* const { data: removeData, error: removeError } = await sdk.cart.addDeleteCartItem(
|
|
2248
|
+
* { id: "01H9CART12345ABCDE" },
|
|
2249
|
+
* {
|
|
2250
|
+
* product_id: "01H9XYZ12345ABCDE",
|
|
2251
|
+
* variant_id: null,
|
|
2252
|
+
* quantity: 0
|
|
2253
|
+
* }
|
|
2254
|
+
* );
|
|
2255
|
+
* ```
|
|
1725
2256
|
*/
|
|
1726
2257
|
async addDeleteCartItem(cartId, body) {
|
|
1727
2258
|
return this.executeRequest(
|
|
@@ -1738,6 +2269,19 @@ var CE_SDK = (() => {
|
|
|
1738
2269
|
*
|
|
1739
2270
|
* @param userId - The ID of the user
|
|
1740
2271
|
* @returns Promise with cart details
|
|
2272
|
+
* @example
|
|
2273
|
+
* ```typescript
|
|
2274
|
+
* const { data, error } = await sdk.cart.getUserCart({
|
|
2275
|
+
* user_id: "01H9USER12345ABCDE"
|
|
2276
|
+
* });
|
|
2277
|
+
*
|
|
2278
|
+
* if (error) {
|
|
2279
|
+
* console.error("Failed to get user cart:", error.message);
|
|
2280
|
+
* } else {
|
|
2281
|
+
* console.log("User cart ID:", data.cart.id);
|
|
2282
|
+
* console.log("Cart value:", data.cart.subtotal_amount);
|
|
2283
|
+
* }
|
|
2284
|
+
* ```
|
|
1741
2285
|
*/
|
|
1742
2286
|
async getUserCart(userId) {
|
|
1743
2287
|
return this.executeRequest(
|
|
@@ -1753,6 +2297,18 @@ var CE_SDK = (() => {
|
|
|
1753
2297
|
*
|
|
1754
2298
|
* @param userId - The ID of the user
|
|
1755
2299
|
* @returns Promise that resolves when the cart is deleted
|
|
2300
|
+
* @example
|
|
2301
|
+
* ```typescript
|
|
2302
|
+
* const { data, error } = await sdk.cart.deleteUserCart({
|
|
2303
|
+
* user_id: "01H9USER12345ABCDE"
|
|
2304
|
+
* });
|
|
2305
|
+
*
|
|
2306
|
+
* if (error) {
|
|
2307
|
+
* console.error("Failed to delete user cart:", error.message);
|
|
2308
|
+
* } else {
|
|
2309
|
+
* console.log("User cart cleared:", data.message);
|
|
2310
|
+
* }
|
|
2311
|
+
* ```
|
|
1756
2312
|
*/
|
|
1757
2313
|
async deleteUserCart(userId) {
|
|
1758
2314
|
return this.executeRequest(
|
|
@@ -1770,6 +2326,62 @@ var CE_SDK = (() => {
|
|
|
1770
2326
|
* @param cartId - The ID of the cart
|
|
1771
2327
|
* @param addressData - The address data
|
|
1772
2328
|
* @returns Promise with updated cart
|
|
2329
|
+
* @example
|
|
2330
|
+
* ```typescript
|
|
2331
|
+
* // For registered users with saved addresses
|
|
2332
|
+
* const { data, error } = await sdk.cart.updateCartAddress(
|
|
2333
|
+
* { id: "01H9CART12345ABCDE" },
|
|
2334
|
+
* {
|
|
2335
|
+
* billing_address_id: "01H9ADDR12345BILL",
|
|
2336
|
+
* shipping_address_id: "01H9ADDR12345SHIP"
|
|
2337
|
+
* }
|
|
2338
|
+
* );
|
|
2339
|
+
*
|
|
2340
|
+
* if (error) {
|
|
2341
|
+
* console.error("Failed to update cart address:", error.message);
|
|
2342
|
+
* } else {
|
|
2343
|
+
* console.log("Addresses updated:", data.message);
|
|
2344
|
+
* }
|
|
2345
|
+
*
|
|
2346
|
+
* // For guest checkout with new addresses
|
|
2347
|
+
* const { data: guestData, error: guestError } = await sdk.cart.updateCartAddress(
|
|
2348
|
+
* { id: "01H9CART12345ABCDE" },
|
|
2349
|
+
* {
|
|
2350
|
+
* billing_address: {
|
|
2351
|
+
* first_name: "John",
|
|
2352
|
+
* last_name: "Doe",
|
|
2353
|
+
* email: "john@example.com",
|
|
2354
|
+
* phone: "9876543210",
|
|
2355
|
+
* country_code: "+91",
|
|
2356
|
+
* address_line1: "123 Main Street",
|
|
2357
|
+
* address_line2: "Apt 4B",
|
|
2358
|
+
* city: "Mumbai",
|
|
2359
|
+
* state: "Maharashtra",
|
|
2360
|
+
* pincode: "400001",
|
|
2361
|
+
* country: "India",
|
|
2362
|
+
* landmark: "Near Station",
|
|
2363
|
+
* tax_identification_number: null,
|
|
2364
|
+
* business_name: null
|
|
2365
|
+
* },
|
|
2366
|
+
* shipping_address: {
|
|
2367
|
+
* first_name: "John",
|
|
2368
|
+
* last_name: "Doe",
|
|
2369
|
+
* email: "john@example.com",
|
|
2370
|
+
* phone: "9876543210",
|
|
2371
|
+
* country_code: "+91",
|
|
2372
|
+
* address_line1: "456 Oak Avenue",
|
|
2373
|
+
* address_line2: null,
|
|
2374
|
+
* city: "Pune",
|
|
2375
|
+
* state: "Maharashtra",
|
|
2376
|
+
* pincode: "411001",
|
|
2377
|
+
* country: "India",
|
|
2378
|
+
* landmark: "Near Mall",
|
|
2379
|
+
* tax_identification_number: null,
|
|
2380
|
+
* business_name: null
|
|
2381
|
+
* }
|
|
2382
|
+
* }
|
|
2383
|
+
* );
|
|
2384
|
+
* ```
|
|
1773
2385
|
*/
|
|
1774
2386
|
async updateCartAddress(cartId, addressData) {
|
|
1775
2387
|
return this.executeRequest(
|
|
@@ -1787,6 +2399,20 @@ var CE_SDK = (() => {
|
|
|
1787
2399
|
* @param cartId - The ID of the cart
|
|
1788
2400
|
* @param couponCode - The coupon code
|
|
1789
2401
|
* @returns Promise with updated cart
|
|
2402
|
+
* @example
|
|
2403
|
+
* ```typescript
|
|
2404
|
+
* const { data, error } = await sdk.cart.applyCoupon(
|
|
2405
|
+
* { id: "01H9CART12345ABCDE" },
|
|
2406
|
+
* { coupon_code: "FLAT100OFF" }
|
|
2407
|
+
* );
|
|
2408
|
+
*
|
|
2409
|
+
* if (error) {
|
|
2410
|
+
* console.error("Failed to apply coupon:", error.message);
|
|
2411
|
+
* } else {
|
|
2412
|
+
* console.log("Coupon applied, new total:", data.cart.total_amount);
|
|
2413
|
+
* console.log("Discount amount:", data.cart.coupon_discount_amount);
|
|
2414
|
+
* }
|
|
2415
|
+
* ```
|
|
1790
2416
|
*/
|
|
1791
2417
|
async applyCoupon(cartId, couponCode) {
|
|
1792
2418
|
return this.executeRequest(
|
|
@@ -1803,6 +2429,18 @@ var CE_SDK = (() => {
|
|
|
1803
2429
|
*
|
|
1804
2430
|
* @param cartId - The ID of the cart
|
|
1805
2431
|
* @returns Promise with updated cart
|
|
2432
|
+
* @example
|
|
2433
|
+
* ```typescript
|
|
2434
|
+
* const { data, error } = await sdk.cart.removeCoupon({
|
|
2435
|
+
* id: "01H9CART12345ABCDE"
|
|
2436
|
+
* });
|
|
2437
|
+
*
|
|
2438
|
+
* if (error) {
|
|
2439
|
+
* console.error("Failed to remove coupon:", error.message);
|
|
2440
|
+
* } else {
|
|
2441
|
+
* console.log("Coupon removed, new total:", data.cart.total_amount);
|
|
2442
|
+
* }
|
|
2443
|
+
* ```
|
|
1806
2444
|
*/
|
|
1807
2445
|
async removeCoupon(cartId) {
|
|
1808
2446
|
return this.executeRequest(
|
|
@@ -1820,6 +2458,20 @@ var CE_SDK = (() => {
|
|
|
1820
2458
|
* @param cartId - The ID of the cart
|
|
1821
2459
|
* @param points - The number of points to redeem
|
|
1822
2460
|
* @returns Promise with updated cart
|
|
2461
|
+
* @example
|
|
2462
|
+
* ```typescript
|
|
2463
|
+
* const { data, error } = await sdk.cart.redeemLoyaltyPoints(
|
|
2464
|
+
* { id: "01H9CART12345ABCDE" },
|
|
2465
|
+
* { points: 500 }
|
|
2466
|
+
* );
|
|
2467
|
+
*
|
|
2468
|
+
* if (error) {
|
|
2469
|
+
* console.error("Failed to redeem loyalty points:", error.message);
|
|
2470
|
+
* } else {
|
|
2471
|
+
* console.log("Points redeemed, new total:", data.cart.total_amount);
|
|
2472
|
+
* console.log("Points discount:", data.cart.loyalty_points_discount_amount);
|
|
2473
|
+
* }
|
|
2474
|
+
* ```
|
|
1823
2475
|
*/
|
|
1824
2476
|
async redeemLoyaltyPoints(cartId, points) {
|
|
1825
2477
|
return this.executeRequest(
|
|
@@ -1836,6 +2488,18 @@ var CE_SDK = (() => {
|
|
|
1836
2488
|
*
|
|
1837
2489
|
* @param cartId - The ID of the cart
|
|
1838
2490
|
* @returns Promise with updated cart
|
|
2491
|
+
* @example
|
|
2492
|
+
* ```typescript
|
|
2493
|
+
* const { data, error } = await sdk.cart.removeLoyaltyPoints({
|
|
2494
|
+
* id: "01H9CART12345ABCDE"
|
|
2495
|
+
* });
|
|
2496
|
+
*
|
|
2497
|
+
* if (error) {
|
|
2498
|
+
* console.error("Failed to remove loyalty points:", error.message);
|
|
2499
|
+
* } else {
|
|
2500
|
+
* console.log("Loyalty points removed, new total:", data.cart.total_amount);
|
|
2501
|
+
* }
|
|
2502
|
+
* ```
|
|
1839
2503
|
*/
|
|
1840
2504
|
async removeLoyaltyPoints(cartId) {
|
|
1841
2505
|
return this.executeRequest(
|
|
@@ -1853,6 +2517,23 @@ var CE_SDK = (() => {
|
|
|
1853
2517
|
* @param cartId - The ID of the cart
|
|
1854
2518
|
* @param body - The body of the request
|
|
1855
2519
|
* @returns Promise with updated cart
|
|
2520
|
+
* @example
|
|
2521
|
+
* ```typescript
|
|
2522
|
+
* const { data, error } = await sdk.cart.updateShippingMethod(
|
|
2523
|
+
* { id: "01H9CART12345ABCDE" },
|
|
2524
|
+
* {
|
|
2525
|
+
* shipping_method_id: "01H9SHIP12345FAST",
|
|
2526
|
+
* estimated_delivery_date: "2024-01-15"
|
|
2527
|
+
* }
|
|
2528
|
+
* );
|
|
2529
|
+
*
|
|
2530
|
+
* if (error) {
|
|
2531
|
+
* console.error("Failed to update shipping method:", error.message);
|
|
2532
|
+
* } else {
|
|
2533
|
+
* console.log("Shipping method updated:", data.cart.shipping_method?.name);
|
|
2534
|
+
* console.log("Shipping cost:", data.cart.shipping_cost);
|
|
2535
|
+
* }
|
|
2536
|
+
* ```
|
|
1856
2537
|
*/
|
|
1857
2538
|
async updateShippingMethod(cartId, body) {
|
|
1858
2539
|
return this.executeRequest(
|
|
@@ -1870,6 +2551,20 @@ var CE_SDK = (() => {
|
|
|
1870
2551
|
* @param cartId - The ID of the cart
|
|
1871
2552
|
* @param body - The body of the request
|
|
1872
2553
|
* @returns Promise with updated cart
|
|
2554
|
+
* @example
|
|
2555
|
+
* ```typescript
|
|
2556
|
+
* const { data, error } = await sdk.cart.redeemCreditBalance(
|
|
2557
|
+
* { id: "01H9CART12345ABCDE" },
|
|
2558
|
+
* { amount: 250.00 }
|
|
2559
|
+
* );
|
|
2560
|
+
*
|
|
2561
|
+
* if (error) {
|
|
2562
|
+
* console.error("Failed to redeem credit balance:", error.message);
|
|
2563
|
+
* } else {
|
|
2564
|
+
* console.log("Credit applied, new total:", data.cart.total_amount);
|
|
2565
|
+
* console.log("Credit discount:", data.cart.credit_balance_discount_amount);
|
|
2566
|
+
* }
|
|
2567
|
+
* ```
|
|
1873
2568
|
*/
|
|
1874
2569
|
async redeemCreditBalance(cartId, body) {
|
|
1875
2570
|
return this.executeRequest(
|
|
@@ -1886,6 +2581,18 @@ var CE_SDK = (() => {
|
|
|
1886
2581
|
*
|
|
1887
2582
|
* @param cartId - The ID of the cart
|
|
1888
2583
|
* @returns Promise with updated cart
|
|
2584
|
+
* @example
|
|
2585
|
+
* ```typescript
|
|
2586
|
+
* const { data, error } = await sdk.cart.removeCreditBalance({
|
|
2587
|
+
* id: "01H9CART12345ABCDE"
|
|
2588
|
+
* });
|
|
2589
|
+
*
|
|
2590
|
+
* if (error) {
|
|
2591
|
+
* console.error("Failed to remove credit balance:", error.message);
|
|
2592
|
+
* } else {
|
|
2593
|
+
* console.log("Credit balance removed, new total:", data.cart.total_amount);
|
|
2594
|
+
* }
|
|
2595
|
+
* ```
|
|
1889
2596
|
*/
|
|
1890
2597
|
async removeCreditBalance(cartId) {
|
|
1891
2598
|
return this.executeRequest(
|
|
@@ -1903,6 +2610,23 @@ var CE_SDK = (() => {
|
|
|
1903
2610
|
* @param cartId - The ID of the cart
|
|
1904
2611
|
* @param body - The body of the request
|
|
1905
2612
|
* @returns Promise with updated cart
|
|
2613
|
+
* @example
|
|
2614
|
+
* ```typescript
|
|
2615
|
+
* const { data, error } = await sdk.cart.redeemGiftCard(
|
|
2616
|
+
* { id: "01H9CART12345ABCDE" },
|
|
2617
|
+
* {
|
|
2618
|
+
* gift_card_code: "GIFT2024-ABCD-1234",
|
|
2619
|
+
* amount: 100.00
|
|
2620
|
+
* }
|
|
2621
|
+
* );
|
|
2622
|
+
*
|
|
2623
|
+
* if (error) {
|
|
2624
|
+
* console.error("Failed to redeem gift card:", error.message);
|
|
2625
|
+
* } else {
|
|
2626
|
+
* console.log("Gift card applied, new total:", data.cart.total_amount);
|
|
2627
|
+
* console.log("Gift card discount:", data.cart.gift_card_discount_amount);
|
|
2628
|
+
* }
|
|
2629
|
+
* ```
|
|
1906
2630
|
*/
|
|
1907
2631
|
async redeemGiftCard(cartId, body) {
|
|
1908
2632
|
return this.executeRequest(
|
|
@@ -1919,6 +2643,18 @@ var CE_SDK = (() => {
|
|
|
1919
2643
|
*
|
|
1920
2644
|
* @param cartId - The ID of the cart
|
|
1921
2645
|
* @returns Promise with updated cart
|
|
2646
|
+
* @example
|
|
2647
|
+
* ```typescript
|
|
2648
|
+
* const { data, error } = await sdk.cart.removeGiftCard({
|
|
2649
|
+
* id: "01H9CART12345ABCDE"
|
|
2650
|
+
* });
|
|
2651
|
+
*
|
|
2652
|
+
* if (error) {
|
|
2653
|
+
* console.error("Failed to remove gift card:", error.message);
|
|
2654
|
+
* } else {
|
|
2655
|
+
* console.log("Gift card removed, new total:", data.cart.total_amount);
|
|
2656
|
+
* }
|
|
2657
|
+
* ```
|
|
1922
2658
|
*/
|
|
1923
2659
|
async removeGiftCard(cartId) {
|
|
1924
2660
|
return this.executeRequest(
|
|
@@ -1935,6 +2671,22 @@ var CE_SDK = (() => {
|
|
|
1935
2671
|
*
|
|
1936
2672
|
* @param userId - The ID of the user
|
|
1937
2673
|
* @returns Promise with wishlist items
|
|
2674
|
+
* @example
|
|
2675
|
+
* ```typescript
|
|
2676
|
+
* const { data, error } = await sdk.cart.getWishlist({
|
|
2677
|
+
* user_id: "01H9USER12345ABCDE"
|
|
2678
|
+
* });
|
|
2679
|
+
*
|
|
2680
|
+
* if (error) {
|
|
2681
|
+
* console.error("Failed to get wishlist:", error.message);
|
|
2682
|
+
* } else {
|
|
2683
|
+
* const products = data.products;
|
|
2684
|
+
* console.log("Wishlist items:", products.length);
|
|
2685
|
+
* products.forEach(product => {
|
|
2686
|
+
* console.log("Product:", product.name, "Price:", product.price);
|
|
2687
|
+
* });
|
|
2688
|
+
* }
|
|
2689
|
+
* ```
|
|
1938
2690
|
*/
|
|
1939
2691
|
async getWishlist(userId) {
|
|
1940
2692
|
return this.executeRequest(
|
|
@@ -1951,6 +2703,23 @@ var CE_SDK = (() => {
|
|
|
1951
2703
|
* @param userId - The ID of the user
|
|
1952
2704
|
* @param itemId - The ID of the item
|
|
1953
2705
|
* @returns Promise with updated wishlist
|
|
2706
|
+
* @example
|
|
2707
|
+
* ```typescript
|
|
2708
|
+
* const { data, error } = await sdk.cart.addToWishlist(
|
|
2709
|
+
* { user_id: "01H9USER12345ABCDE" },
|
|
2710
|
+
* {
|
|
2711
|
+
* product_id: "01F3Z7KG06J4ACWH1C4926KJEC",
|
|
2712
|
+
* variant_id: null
|
|
2713
|
+
* }
|
|
2714
|
+
* );
|
|
2715
|
+
*
|
|
2716
|
+
* if (error) {
|
|
2717
|
+
* console.error("Failed to add to wishlist:", error.message);
|
|
2718
|
+
* } else {
|
|
2719
|
+
* const products = data.products;
|
|
2720
|
+
* console.log("Item added to wishlist, total items:", products.length);
|
|
2721
|
+
* }
|
|
2722
|
+
* ```
|
|
1954
2723
|
*/
|
|
1955
2724
|
async addToWishlist(userId, itemId) {
|
|
1956
2725
|
return this.executeRequest(
|
|
@@ -1966,8 +2735,25 @@ var CE_SDK = (() => {
|
|
|
1966
2735
|
* Remove item from wishlist
|
|
1967
2736
|
*
|
|
1968
2737
|
* @param userId - The ID of the user
|
|
1969
|
-
* @param
|
|
2738
|
+
* @param body - The body containing product details to remove
|
|
1970
2739
|
* @returns Promise with updated wishlist
|
|
2740
|
+
* @example
|
|
2741
|
+
* ```typescript
|
|
2742
|
+
* const { data, error } = await sdk.cart.removeFromWishlist(
|
|
2743
|
+
* { user_id: "01H9USER12345ABCDE" },
|
|
2744
|
+
* {
|
|
2745
|
+
* product_id: "01F3Z7KG06J4ACWH1C4926KJEC",
|
|
2746
|
+
* variant_id: null
|
|
2747
|
+
* }
|
|
2748
|
+
* );
|
|
2749
|
+
*
|
|
2750
|
+
* if (error) {
|
|
2751
|
+
* console.error("Failed to remove from wishlist:", error.message);
|
|
2752
|
+
* } else {
|
|
2753
|
+
* const products = data.products;
|
|
2754
|
+
* console.log("Item removed from wishlist, remaining items:", products.length);
|
|
2755
|
+
* }
|
|
2756
|
+
* ```
|
|
1971
2757
|
*/
|
|
1972
2758
|
async removeFromWishlist(userId, body) {
|
|
1973
2759
|
return this.executeRequest(
|
|
@@ -1984,6 +2770,26 @@ var CE_SDK = (() => {
|
|
|
1984
2770
|
*
|
|
1985
2771
|
* @param headers - Optional header parameters (customer_group_id, etc.)
|
|
1986
2772
|
* @returns Promise with all available coupons
|
|
2773
|
+
* @example
|
|
2774
|
+
* ```typescript
|
|
2775
|
+
* // Get all available coupons
|
|
2776
|
+
* const { data, error } = await sdk.cart.getAvailableCoupons();
|
|
2777
|
+
*
|
|
2778
|
+
* if (error) {
|
|
2779
|
+
* console.error("Failed to get available coupons:", error.message);
|
|
2780
|
+
* } else {
|
|
2781
|
+
* const coupons = data.coupons || [];
|
|
2782
|
+
* console.log("Available coupons:", coupons.length);
|
|
2783
|
+
* coupons.forEach(coupon => {
|
|
2784
|
+
* console.log("Coupon:", coupon.code, "Discount:", coupon.discount_amount);
|
|
2785
|
+
* });
|
|
2786
|
+
* }
|
|
2787
|
+
*
|
|
2788
|
+
* // Override customer group ID for this specific request
|
|
2789
|
+
* const { data: overrideData, error: overrideError } = await sdk.cart.getAvailableCoupons({
|
|
2790
|
+
* "x-customer-group-id": "01H9GROUP12345ABC" // Override default SDK config
|
|
2791
|
+
* });
|
|
2792
|
+
* ```
|
|
1987
2793
|
*/
|
|
1988
2794
|
async getAvailableCoupons(headers) {
|
|
1989
2795
|
const mergedHeaders = this.mergeHeaders(headers);
|
|
@@ -2000,6 +2806,26 @@ var CE_SDK = (() => {
|
|
|
2000
2806
|
*
|
|
2001
2807
|
* @param headers - Optional header parameters (customer_group_id, etc.)
|
|
2002
2808
|
* @returns Promise with all available promotions
|
|
2809
|
+
* @example
|
|
2810
|
+
* ```typescript
|
|
2811
|
+
* // Get all available promotions
|
|
2812
|
+
* const { data, error } = await sdk.cart.getAvailablePromotions();
|
|
2813
|
+
*
|
|
2814
|
+
* if (error) {
|
|
2815
|
+
* console.error("Failed to get available promotions:", error.message);
|
|
2816
|
+
* } else {
|
|
2817
|
+
* const promotions = data.promotions || [];
|
|
2818
|
+
* console.log("Available promotions:", promotions.length);
|
|
2819
|
+
* promotions.forEach(promotion => {
|
|
2820
|
+
* console.log("Promotion:", promotion.name, "Type:", promotion.promotion_type);
|
|
2821
|
+
* });
|
|
2822
|
+
* }
|
|
2823
|
+
*
|
|
2824
|
+
* // Override customer group ID for this specific request
|
|
2825
|
+
* const { data: overrideData, error: overrideError } = await sdk.cart.getAvailablePromotions({
|
|
2826
|
+
* "x-customer-group-id": "01H9GROUP12345ABC" // Override default SDK config
|
|
2827
|
+
* });
|
|
2828
|
+
* ```
|
|
2003
2829
|
*/
|
|
2004
2830
|
async getAvailablePromotions(headers) {
|
|
2005
2831
|
const mergedHeaders = this.mergeHeaders(headers);
|
|
@@ -2016,6 +2842,29 @@ var CE_SDK = (() => {
|
|
|
2016
2842
|
*
|
|
2017
2843
|
* @param cartId - The ID of the cart
|
|
2018
2844
|
* @returns Promise with evaluated promotions
|
|
2845
|
+
* @example
|
|
2846
|
+
* ```typescript
|
|
2847
|
+
* const { data, error } = await sdk.cart.evaluatePromotions({
|
|
2848
|
+
* id: "01H9CART12345ABCDE"
|
|
2849
|
+
* });
|
|
2850
|
+
*
|
|
2851
|
+
* if (error) {
|
|
2852
|
+
* console.error("Failed to evaluate promotions:", error.message);
|
|
2853
|
+
* } else {
|
|
2854
|
+
* const applicable = data.applicable_promotions || [];
|
|
2855
|
+
* const inapplicable = data.inapplicable_promotions || [];
|
|
2856
|
+
*
|
|
2857
|
+
* console.log("Applicable promotions:", applicable.length);
|
|
2858
|
+
* applicable.forEach(promo => {
|
|
2859
|
+
* console.log(`- ${promo.name}: ${promo.savings_message}`);
|
|
2860
|
+
* });
|
|
2861
|
+
*
|
|
2862
|
+
* console.log("Inapplicable promotions:", inapplicable.length);
|
|
2863
|
+
* inapplicable.forEach(promo => {
|
|
2864
|
+
* console.log(`- ${promo.name}: ${promo.reason}`);
|
|
2865
|
+
* });
|
|
2866
|
+
* }
|
|
2867
|
+
* ```
|
|
2019
2868
|
*/
|
|
2020
2869
|
async evaluatePromotions(cartId) {
|
|
2021
2870
|
return this.executeRequest(
|
|
@@ -2031,6 +2880,29 @@ var CE_SDK = (() => {
|
|
|
2031
2880
|
*
|
|
2032
2881
|
* @param cartId - The ID of the cart
|
|
2033
2882
|
* @returns Promise with evaluated coupons
|
|
2883
|
+
* @example
|
|
2884
|
+
* ```typescript
|
|
2885
|
+
* const { data, error } = await sdk.cart.evaluateCoupons({
|
|
2886
|
+
* id: "01H9CART12345ABCDE"
|
|
2887
|
+
* });
|
|
2888
|
+
*
|
|
2889
|
+
* if (error) {
|
|
2890
|
+
* console.error("Failed to evaluate coupons:", error.message);
|
|
2891
|
+
* } else {
|
|
2892
|
+
* const applicable = data.applicable_coupons || [];
|
|
2893
|
+
* const inapplicable = data.inapplicable_coupons || [];
|
|
2894
|
+
*
|
|
2895
|
+
* console.log("Applicable coupons:", applicable.length);
|
|
2896
|
+
* applicable.forEach(coupon => {
|
|
2897
|
+
* console.log(`- ${coupon.code}: Save $${coupon.estimated_discount}`);
|
|
2898
|
+
* });
|
|
2899
|
+
*
|
|
2900
|
+
* console.log("Inapplicable coupons:", inapplicable.length);
|
|
2901
|
+
* inapplicable.forEach(coupon => {
|
|
2902
|
+
* console.log(`- ${coupon.code}: ${coupon.reason}`);
|
|
2903
|
+
* });
|
|
2904
|
+
* }
|
|
2905
|
+
* ```
|
|
2034
2906
|
*/
|
|
2035
2907
|
async evaluateCoupons(cartId) {
|
|
2036
2908
|
return this.executeRequest(
|
|
@@ -2047,19 +2919,45 @@ var CE_SDK = (() => {
|
|
|
2047
2919
|
var AuthClient = class extends StorefrontAPIClient {
|
|
2048
2920
|
/**
|
|
2049
2921
|
* Get anonymous token for guest users
|
|
2922
|
+
*
|
|
2923
|
+
* @example
|
|
2924
|
+
* ```typescript
|
|
2925
|
+
* // Get token for guest browsing
|
|
2926
|
+
* const { data, error } = await sdk.auth.getAnonymousToken();
|
|
2927
|
+
*
|
|
2928
|
+
* if (error) {
|
|
2929
|
+
* console.error("Failed to get anonymous token:", error.message);
|
|
2930
|
+
* } else {
|
|
2931
|
+
* console.log("Anonymous token:", data.access_token);
|
|
2932
|
+
* // Store token or proceed with guest operations
|
|
2933
|
+
* }
|
|
2934
|
+
* ```
|
|
2050
2935
|
*/
|
|
2051
2936
|
async getAnonymousToken() {
|
|
2052
|
-
return this.executeRequest(
|
|
2053
|
-
() => this.client.POST("/auth/anonymous")
|
|
2054
|
-
);
|
|
2937
|
+
return this.executeRequest(() => this.client.POST("/auth/anonymous"));
|
|
2055
2938
|
}
|
|
2056
2939
|
/**
|
|
2057
2940
|
* Login with phone number
|
|
2058
2941
|
*
|
|
2059
|
-
* @param
|
|
2060
|
-
* @
|
|
2061
|
-
* @
|
|
2062
|
-
*
|
|
2942
|
+
* @param body - Login request body containing phone number and options
|
|
2943
|
+
* @returns Promise with OTP token and action
|
|
2944
|
+
* @example
|
|
2945
|
+
* ```typescript
|
|
2946
|
+
* // Login with phone number
|
|
2947
|
+
* const { data, error } = await sdk.auth.loginWithPhone({
|
|
2948
|
+
* phoneNumber: "9876543210",
|
|
2949
|
+
* countryCode: "+91",
|
|
2950
|
+
* registerIfNotExists: true
|
|
2951
|
+
* });
|
|
2952
|
+
*
|
|
2953
|
+
* if (error) {
|
|
2954
|
+
* console.error("Login failed:", error.message);
|
|
2955
|
+
* } else {
|
|
2956
|
+
* console.log("OTP sent. Token:", data.otpToken);
|
|
2957
|
+
* console.log("Action:", data.action); // "login" or "register"
|
|
2958
|
+
* // Redirect user to OTP verification screen
|
|
2959
|
+
* }
|
|
2960
|
+
* ```
|
|
2063
2961
|
*/
|
|
2064
2962
|
async loginWithPhone(body) {
|
|
2065
2963
|
return this.executeRequest(
|
|
@@ -2071,10 +2969,24 @@ var CE_SDK = (() => {
|
|
|
2071
2969
|
/**
|
|
2072
2970
|
* Login with WhatsApp
|
|
2073
2971
|
*
|
|
2074
|
-
* @param
|
|
2075
|
-
* @param countryCode - Country code (defaults to +91)
|
|
2076
|
-
* @param registerIfNotExists - Whether to register if user doesn't exist
|
|
2972
|
+
* @param body - Login request body containing phone number and options
|
|
2077
2973
|
* @returns Promise with OTP token and action
|
|
2974
|
+
* @example
|
|
2975
|
+
* ```typescript
|
|
2976
|
+
* // Login with WhatsApp number
|
|
2977
|
+
* const { data, error } = await sdk.auth.loginWithWhatsApp({
|
|
2978
|
+
* phone: "9876543210",
|
|
2979
|
+
* country_code: "+91",
|
|
2980
|
+
* register_if_not_exists: true
|
|
2981
|
+
* });
|
|
2982
|
+
*
|
|
2983
|
+
* if (error) {
|
|
2984
|
+
* console.error("WhatsApp login failed:", error.message);
|
|
2985
|
+
* } else {
|
|
2986
|
+
* console.log("OTP sent to WhatsApp. Token:", data.otp_token);
|
|
2987
|
+
* console.log("Action:", data.otp_action); // "login" or "register"
|
|
2988
|
+
* }
|
|
2989
|
+
* ```
|
|
2078
2990
|
*/
|
|
2079
2991
|
async loginWithWhatsApp(body) {
|
|
2080
2992
|
return this.executeRequest(
|
|
@@ -2086,9 +2998,24 @@ var CE_SDK = (() => {
|
|
|
2086
2998
|
/**
|
|
2087
2999
|
* Login with email
|
|
2088
3000
|
*
|
|
2089
|
-
* @param
|
|
2090
|
-
* @param registerIfNotExists - Whether to register if user doesn't exist
|
|
3001
|
+
* @param body - Login request body containing email and options
|
|
2091
3002
|
* @returns Promise with OTP token and action
|
|
3003
|
+
* @example
|
|
3004
|
+
* ```typescript
|
|
3005
|
+
* // Login with email address
|
|
3006
|
+
* const { data, error } = await sdk.auth.loginWithEmail({
|
|
3007
|
+
* email: "customer@example.com",
|
|
3008
|
+
* registerIfNotExists: true
|
|
3009
|
+
* });
|
|
3010
|
+
*
|
|
3011
|
+
* if (error) {
|
|
3012
|
+
* console.error("Email login failed:", error.message);
|
|
3013
|
+
* } else {
|
|
3014
|
+
* console.log("OTP sent to email. Token:", data.otpToken);
|
|
3015
|
+
* console.log("Action:", data.action); // "login" or "register"
|
|
3016
|
+
* // Show OTP input form
|
|
3017
|
+
* }
|
|
3018
|
+
* ```
|
|
2092
3019
|
*/
|
|
2093
3020
|
async loginWithEmail(body) {
|
|
2094
3021
|
return this.executeRequest(
|
|
@@ -2100,8 +3027,23 @@ var CE_SDK = (() => {
|
|
|
2100
3027
|
/**
|
|
2101
3028
|
* Login with password
|
|
2102
3029
|
*
|
|
2103
|
-
* @param
|
|
3030
|
+
* @param body - Login credentials containing email/phone and password
|
|
2104
3031
|
* @returns Promise with user info and tokens
|
|
3032
|
+
* @example
|
|
3033
|
+
* ```typescript
|
|
3034
|
+
* // Login with email and password
|
|
3035
|
+
* const { data, error } = await sdk.auth.loginWithPassword({
|
|
3036
|
+
* email: "customer@example.com",
|
|
3037
|
+
* password: "securePassword123"
|
|
3038
|
+
* });
|
|
3039
|
+
*
|
|
3040
|
+
* if (error) {
|
|
3041
|
+
* console.error("Password login failed:", error.message);
|
|
3042
|
+
* } else {
|
|
3043
|
+
* console.log("Login successful:", data.user.email);
|
|
3044
|
+
* console.log("Access token:", data.access_token);
|
|
3045
|
+
* }
|
|
3046
|
+
* ```
|
|
2105
3047
|
*/
|
|
2106
3048
|
async loginWithPassword(body) {
|
|
2107
3049
|
return this.executeRequest(
|
|
@@ -2113,8 +3055,22 @@ var CE_SDK = (() => {
|
|
|
2113
3055
|
/**
|
|
2114
3056
|
* Forgot password
|
|
2115
3057
|
*
|
|
2116
|
-
* @param
|
|
2117
|
-
* @returns Promise with
|
|
3058
|
+
* @param body - Request body containing email address
|
|
3059
|
+
* @returns Promise with password reset information
|
|
3060
|
+
* @example
|
|
3061
|
+
* ```typescript
|
|
3062
|
+
* // Send password reset email
|
|
3063
|
+
* const { data, error } = await sdk.auth.forgotPassword({
|
|
3064
|
+
* email: "customer@example.com"
|
|
3065
|
+
* });
|
|
3066
|
+
*
|
|
3067
|
+
* if (error) {
|
|
3068
|
+
* console.error("Password reset failed:", error.message);
|
|
3069
|
+
* } else {
|
|
3070
|
+
* console.log("Reset email sent successfully");
|
|
3071
|
+
* // Show confirmation message to user
|
|
3072
|
+
* }
|
|
3073
|
+
* ```
|
|
2118
3074
|
*/
|
|
2119
3075
|
async forgotPassword(body) {
|
|
2120
3076
|
return this.executeRequest(
|
|
@@ -2126,8 +3082,24 @@ var CE_SDK = (() => {
|
|
|
2126
3082
|
/**
|
|
2127
3083
|
* Reset password
|
|
2128
3084
|
*
|
|
2129
|
-
* @param
|
|
2130
|
-
* @returns Promise with
|
|
3085
|
+
* @param body - Reset password request body containing new password and OTP token
|
|
3086
|
+
* @returns Promise with new access and refresh tokens
|
|
3087
|
+
* @example
|
|
3088
|
+
* ```typescript
|
|
3089
|
+
* // Reset password with OTP token from forgot password flow
|
|
3090
|
+
* const { data, error } = await sdk.auth.resetPassword({
|
|
3091
|
+
* new_password: "newSecurePassword123",
|
|
3092
|
+
* confirm_password: "newSecurePassword123",
|
|
3093
|
+
* otp_token: "abc123otptoken"
|
|
3094
|
+
* });
|
|
3095
|
+
*
|
|
3096
|
+
* if (error) {
|
|
3097
|
+
* console.error("Password reset failed:", error.message);
|
|
3098
|
+
* } else {
|
|
3099
|
+
* console.log("Password reset successful");
|
|
3100
|
+
* console.log("New access token:", data.access_token);
|
|
3101
|
+
* }
|
|
3102
|
+
* ```
|
|
2131
3103
|
*/
|
|
2132
3104
|
async resetPassword(body) {
|
|
2133
3105
|
return this.executeRequest(
|
|
@@ -2139,10 +3111,24 @@ var CE_SDK = (() => {
|
|
|
2139
3111
|
/**
|
|
2140
3112
|
* Change password
|
|
2141
3113
|
*
|
|
2142
|
-
* @param
|
|
2143
|
-
* @
|
|
2144
|
-
* @
|
|
2145
|
-
*
|
|
3114
|
+
* @param body - Change password request body containing old and new passwords
|
|
3115
|
+
* @returns Promise with new access and refresh tokens
|
|
3116
|
+
* @example
|
|
3117
|
+
* ```typescript
|
|
3118
|
+
* // Change user's password
|
|
3119
|
+
* const { data, error } = await sdk.auth.changePassword({
|
|
3120
|
+
* old_password: "currentPassword123",
|
|
3121
|
+
* new_password: "newSecurePassword456",
|
|
3122
|
+
* confirm_password: "newSecurePassword456"
|
|
3123
|
+
* });
|
|
3124
|
+
*
|
|
3125
|
+
* if (error) {
|
|
3126
|
+
* console.error("Password change failed:", error.message);
|
|
3127
|
+
* } else {
|
|
3128
|
+
* console.log("Password changed successfully");
|
|
3129
|
+
* console.log("New access token:", data.access_token);
|
|
3130
|
+
* }
|
|
3131
|
+
* ```
|
|
2146
3132
|
*/
|
|
2147
3133
|
async changePassword(body) {
|
|
2148
3134
|
return this.executeRequest(
|
|
@@ -2154,10 +3140,25 @@ var CE_SDK = (() => {
|
|
|
2154
3140
|
/**
|
|
2155
3141
|
* Verify OTP
|
|
2156
3142
|
*
|
|
2157
|
-
* @param
|
|
2158
|
-
* @param otpToken - OTP token from login request
|
|
2159
|
-
* @param otpAction - OTP action from login request
|
|
3143
|
+
* @param body - OTP verification data including code and tokens
|
|
2160
3144
|
* @returns Promise with user info and tokens
|
|
3145
|
+
* @example
|
|
3146
|
+
* ```typescript
|
|
3147
|
+
* // Verify OTP after login attempt
|
|
3148
|
+
* const { data, error } = await sdk.auth.verifyOtp({
|
|
3149
|
+
* otp: "1234",
|
|
3150
|
+
* otpToken: "56895455",
|
|
3151
|
+
* otpAction: "login" // or "register"
|
|
3152
|
+
* });
|
|
3153
|
+
*
|
|
3154
|
+
* if (error) {
|
|
3155
|
+
* console.error("OTP verification failed:", error.message);
|
|
3156
|
+
* // Show error message, allow retry
|
|
3157
|
+
* } else {
|
|
3158
|
+
* console.log("Login successful:", data.user.email);
|
|
3159
|
+
* console.log("User ID:", data.user.id);
|
|
3160
|
+
* }
|
|
3161
|
+
* ```
|
|
2161
3162
|
*/
|
|
2162
3163
|
async verifyOtp(body) {
|
|
2163
3164
|
return this.executeRequest(
|
|
@@ -2169,8 +3170,27 @@ var CE_SDK = (() => {
|
|
|
2169
3170
|
/**
|
|
2170
3171
|
* Register with phone
|
|
2171
3172
|
*
|
|
2172
|
-
* @param
|
|
3173
|
+
* @param body - Registration details including phone number and user information
|
|
2173
3174
|
* @returns Promise with user info and tokens
|
|
3175
|
+
* @example
|
|
3176
|
+
* ```typescript
|
|
3177
|
+
* // Register a new user with phone number
|
|
3178
|
+
* const { data, error } = await sdk.auth.registerWithPhone({
|
|
3179
|
+
* phone: "9876543210",
|
|
3180
|
+
* country_code: "+91",
|
|
3181
|
+
* first_name: "John",
|
|
3182
|
+
* last_name: "Doe",
|
|
3183
|
+
* email: "john.doe@example.com"
|
|
3184
|
+
* });
|
|
3185
|
+
*
|
|
3186
|
+
* if (error) {
|
|
3187
|
+
* console.error("Phone registration failed:", error.message);
|
|
3188
|
+
* } else {
|
|
3189
|
+
* console.log("Registration successful:", data.user.first_name);
|
|
3190
|
+
* console.log("User ID:", data.user.id);
|
|
3191
|
+
* console.log("Access token:", data.access_token);
|
|
3192
|
+
* }
|
|
3193
|
+
* ```
|
|
2174
3194
|
*/
|
|
2175
3195
|
async registerWithPhone(body) {
|
|
2176
3196
|
return this.executeRequest(
|
|
@@ -2182,8 +3202,26 @@ var CE_SDK = (() => {
|
|
|
2182
3202
|
/**
|
|
2183
3203
|
* Register with email
|
|
2184
3204
|
*
|
|
2185
|
-
* @param
|
|
3205
|
+
* @param body - Registration details including email and user information
|
|
2186
3206
|
* @returns Promise with user info and tokens
|
|
3207
|
+
* @example
|
|
3208
|
+
* ```typescript
|
|
3209
|
+
* // Register a new user with email address
|
|
3210
|
+
* const { data, error } = await sdk.auth.registerWithEmail({
|
|
3211
|
+
* email: "jane.smith@example.com",
|
|
3212
|
+
* first_name: "Jane",
|
|
3213
|
+
* last_name: "Smith",
|
|
3214
|
+
* phone: "9876543210"
|
|
3215
|
+
* });
|
|
3216
|
+
*
|
|
3217
|
+
* if (error) {
|
|
3218
|
+
* console.error("Email registration failed:", error.message);
|
|
3219
|
+
* } else {
|
|
3220
|
+
* console.log("Registration successful:", data.user.email);
|
|
3221
|
+
* console.log("User ID:", data.user.id);
|
|
3222
|
+
* console.log("Access token:", data.access_token);
|
|
3223
|
+
* }
|
|
3224
|
+
* ```
|
|
2187
3225
|
*/
|
|
2188
3226
|
async registerWithEmail(body) {
|
|
2189
3227
|
return this.executeRequest(
|
|
@@ -2194,8 +3232,24 @@ var CE_SDK = (() => {
|
|
|
2194
3232
|
}
|
|
2195
3233
|
/**
|
|
2196
3234
|
* Refresh the access token using a refresh token
|
|
2197
|
-
* @param
|
|
3235
|
+
* @param body - Request body containing the refresh token
|
|
2198
3236
|
* @returns Promise with the new access token and refresh token
|
|
3237
|
+
* @example
|
|
3238
|
+
* ```typescript
|
|
3239
|
+
* // Refresh access token when it expires
|
|
3240
|
+
* const { data, error } = await sdk.auth.refreshToken({
|
|
3241
|
+
* refresh_token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
|
|
3242
|
+
* });
|
|
3243
|
+
*
|
|
3244
|
+
* if (error) {
|
|
3245
|
+
* console.error("Token refresh failed:", error.message);
|
|
3246
|
+
* // Redirect to login
|
|
3247
|
+
* } else {
|
|
3248
|
+
* console.log("Token refreshed successfully");
|
|
3249
|
+
* console.log("New access token:", data.access_token);
|
|
3250
|
+
* console.log("New refresh token:", data.refresh_token);
|
|
3251
|
+
* }
|
|
3252
|
+
* ```
|
|
2199
3253
|
*/
|
|
2200
3254
|
async refreshToken(body) {
|
|
2201
3255
|
return this.executeRequest(
|
|
@@ -2208,17 +3262,43 @@ var CE_SDK = (() => {
|
|
|
2208
3262
|
* Logout
|
|
2209
3263
|
*
|
|
2210
3264
|
* @returns Promise that resolves when logout is complete
|
|
3265
|
+
* @example
|
|
3266
|
+
* ```typescript
|
|
3267
|
+
* // Logout current user
|
|
3268
|
+
* const { data, error } = await sdk.auth.logout();
|
|
3269
|
+
*
|
|
3270
|
+
* if (error) {
|
|
3271
|
+
* console.error("Logout failed:", error.message);
|
|
3272
|
+
* } else {
|
|
3273
|
+
* console.log("Logout successful");
|
|
3274
|
+
* console.log("Session ended for user:", data.user.email);
|
|
3275
|
+
* }
|
|
3276
|
+
* ```
|
|
2211
3277
|
*/
|
|
2212
3278
|
async logout() {
|
|
2213
|
-
return this.executeRequest(
|
|
2214
|
-
() => this.client.POST("/auth/logout")
|
|
2215
|
-
);
|
|
3279
|
+
return this.executeRequest(() => this.client.POST("/auth/logout"));
|
|
2216
3280
|
}
|
|
2217
3281
|
/**
|
|
2218
3282
|
* Get user details
|
|
2219
3283
|
*
|
|
2220
|
-
* @param
|
|
3284
|
+
* @param pathParams - Path parameters containing user ID
|
|
2221
3285
|
* @returns Promise with user details
|
|
3286
|
+
* @example
|
|
3287
|
+
* ```typescript
|
|
3288
|
+
* // Get details for a specific user
|
|
3289
|
+
* const { data, error } = await sdk.auth.getUserDetails({
|
|
3290
|
+
* id: "01H9XYZ12345USERID"
|
|
3291
|
+
* });
|
|
3292
|
+
*
|
|
3293
|
+
* if (error) {
|
|
3294
|
+
* console.error("Failed to get user details:", error.message);
|
|
3295
|
+
* } else {
|
|
3296
|
+
* console.log("User details:", data.user);
|
|
3297
|
+
* console.log("Email:", data.user.email);
|
|
3298
|
+
* console.log("Phone:", data.user.phoneNumber);
|
|
3299
|
+
* console.log("Created:", data.user.createdAt);
|
|
3300
|
+
* }
|
|
3301
|
+
* ```
|
|
2222
3302
|
*/
|
|
2223
3303
|
async getUserDetails(pathParams) {
|
|
2224
3304
|
return this.executeRequest(
|
|
@@ -2232,8 +3312,29 @@ var CE_SDK = (() => {
|
|
|
2232
3312
|
/**
|
|
2233
3313
|
* Update user details
|
|
2234
3314
|
*
|
|
2235
|
-
* @param
|
|
2236
|
-
* @
|
|
3315
|
+
* @param pathParams - Path parameters containing user ID
|
|
3316
|
+
* @param body - Updated user information
|
|
3317
|
+
* @returns Promise with updated user details
|
|
3318
|
+
* @example
|
|
3319
|
+
* ```typescript
|
|
3320
|
+
* // Update user profile information
|
|
3321
|
+
* const { data, error } = await sdk.auth.updateUserDetails(
|
|
3322
|
+
* { id: "01H9XYZ12345USERID" },
|
|
3323
|
+
* {
|
|
3324
|
+
* first_name: "John",
|
|
3325
|
+
* last_name: "Doe",
|
|
3326
|
+
* email: "john.doe@example.com",
|
|
3327
|
+
* phone: "9876543210",
|
|
3328
|
+
* country_code: "+91"
|
|
3329
|
+
* }
|
|
3330
|
+
* );
|
|
3331
|
+
*
|
|
3332
|
+
* if (error) {
|
|
3333
|
+
* console.error("Failed to update user:", error.message);
|
|
3334
|
+
* } else {
|
|
3335
|
+
* console.log("User updated successfully:", data.user.first_name);
|
|
3336
|
+
* }
|
|
3337
|
+
* ```
|
|
2237
3338
|
*/
|
|
2238
3339
|
async updateUserDetails(pathParams, body) {
|
|
2239
3340
|
return this.executeRequest(
|
|
@@ -2248,8 +3349,25 @@ var CE_SDK = (() => {
|
|
|
2248
3349
|
/**
|
|
2249
3350
|
* Add profile image
|
|
2250
3351
|
*
|
|
2251
|
-
* @param
|
|
2252
|
-
* @
|
|
3352
|
+
* @param pathParams - Path parameters containing user ID
|
|
3353
|
+
* @param formData - Form data containing the image file
|
|
3354
|
+
* @returns Promise with profile image URL
|
|
3355
|
+
* @example
|
|
3356
|
+
* ```typescript
|
|
3357
|
+
* // Add profile image for a user
|
|
3358
|
+
* const imageFile = document.getElementById('file-input').files[0];
|
|
3359
|
+
* const { data, error } = await sdk.auth.addProfileImage(
|
|
3360
|
+
* { id: "01H9XYZ12345USERID" },
|
|
3361
|
+
* { image: imageFile }
|
|
3362
|
+
* );
|
|
3363
|
+
*
|
|
3364
|
+
* if (error) {
|
|
3365
|
+
* console.error("Failed to add profile image:", error.message);
|
|
3366
|
+
* } else {
|
|
3367
|
+
* console.log("Profile image added successfully");
|
|
3368
|
+
* console.log("Image URL:", data.profile_image_url);
|
|
3369
|
+
* }
|
|
3370
|
+
* ```
|
|
2253
3371
|
*/
|
|
2254
3372
|
async addProfileImage(pathParams, formData) {
|
|
2255
3373
|
return this.executeRequest(
|
|
@@ -2273,8 +3391,25 @@ var CE_SDK = (() => {
|
|
|
2273
3391
|
/**
|
|
2274
3392
|
* Update profile image
|
|
2275
3393
|
*
|
|
2276
|
-
* @param
|
|
2277
|
-
* @
|
|
3394
|
+
* @param pathParams - Path parameters containing user ID
|
|
3395
|
+
* @param formData - Form data containing the new image file
|
|
3396
|
+
* @returns Promise with updated profile image URL
|
|
3397
|
+
* @example
|
|
3398
|
+
* ```typescript
|
|
3399
|
+
* // Update existing profile image
|
|
3400
|
+
* const newImageFile = document.getElementById('file-input').files[0];
|
|
3401
|
+
* const { data, error } = await sdk.auth.updateProfileImage(
|
|
3402
|
+
* { id: "01H9XYZ12345USERID" },
|
|
3403
|
+
* { image: newImageFile }
|
|
3404
|
+
* );
|
|
3405
|
+
*
|
|
3406
|
+
* if (error) {
|
|
3407
|
+
* console.error("Failed to update profile image:", error.message);
|
|
3408
|
+
* } else {
|
|
3409
|
+
* console.log("Profile image updated successfully");
|
|
3410
|
+
* console.log("New image URL:", data.profile_image_url);
|
|
3411
|
+
* }
|
|
3412
|
+
* ```
|
|
2278
3413
|
*/
|
|
2279
3414
|
async updateProfileImage(pathParams, formData) {
|
|
2280
3415
|
return this.executeRequest(
|
|
@@ -2298,8 +3433,22 @@ var CE_SDK = (() => {
|
|
|
2298
3433
|
/**
|
|
2299
3434
|
* Delete profile image
|
|
2300
3435
|
*
|
|
2301
|
-
* @param
|
|
2302
|
-
* @returns Promise with
|
|
3436
|
+
* @param pathParams - Path parameters containing user ID
|
|
3437
|
+
* @returns Promise with deletion confirmation
|
|
3438
|
+
* @example
|
|
3439
|
+
* ```typescript
|
|
3440
|
+
* // Delete user's profile image
|
|
3441
|
+
* const { data, error } = await sdk.auth.deleteProfileImage({
|
|
3442
|
+
* id: "01H9XYZ12345USERID"
|
|
3443
|
+
* });
|
|
3444
|
+
*
|
|
3445
|
+
* if (error) {
|
|
3446
|
+
* console.error("Failed to delete profile image:", error.message);
|
|
3447
|
+
* } else {
|
|
3448
|
+
* console.log("Profile image deleted successfully");
|
|
3449
|
+
* console.log("Success:", data.success);
|
|
3450
|
+
* }
|
|
3451
|
+
* ```
|
|
2303
3452
|
*/
|
|
2304
3453
|
async deleteProfileImage(pathParams) {
|
|
2305
3454
|
return this.executeRequest(
|
|
@@ -2313,8 +3462,21 @@ var CE_SDK = (() => {
|
|
|
2313
3462
|
/**
|
|
2314
3463
|
* Get profile image
|
|
2315
3464
|
*
|
|
2316
|
-
* @param
|
|
2317
|
-
* @returns Promise with
|
|
3465
|
+
* @param pathParams - Path parameters containing user ID
|
|
3466
|
+
* @returns Promise with profile image URL
|
|
3467
|
+
* @example
|
|
3468
|
+
* ```typescript
|
|
3469
|
+
* // Get user's profile image URL
|
|
3470
|
+
* const { data, error } = await sdk.auth.getProfileImage({
|
|
3471
|
+
* id: "01H9XYZ12345USERID"
|
|
3472
|
+
* });
|
|
3473
|
+
*
|
|
3474
|
+
* if (error) {
|
|
3475
|
+
* console.error("Failed to get profile image:", error.message);
|
|
3476
|
+
* } else {
|
|
3477
|
+
* console.log("Profile image URL:", data.profile_image_url);
|
|
3478
|
+
* }
|
|
3479
|
+
* ```
|
|
2318
3480
|
*/
|
|
2319
3481
|
async getProfileImage(pathParams) {
|
|
2320
3482
|
return this.executeRequest(
|
|
@@ -2328,8 +3490,22 @@ var CE_SDK = (() => {
|
|
|
2328
3490
|
/**
|
|
2329
3491
|
* Deactivate user account
|
|
2330
3492
|
*
|
|
2331
|
-
* @param
|
|
2332
|
-
* @returns Promise with
|
|
3493
|
+
* @param pathParams - Path parameters containing user ID
|
|
3494
|
+
* @returns Promise with deactivation confirmation
|
|
3495
|
+
* @example
|
|
3496
|
+
* ```typescript
|
|
3497
|
+
* // Deactivate a user account
|
|
3498
|
+
* const { data, error } = await sdk.auth.deactivateUserAccount({
|
|
3499
|
+
* id: "01H9XYZ12345USERID"
|
|
3500
|
+
* });
|
|
3501
|
+
*
|
|
3502
|
+
* if (error) {
|
|
3503
|
+
* console.error("Failed to deactivate account:", error.message);
|
|
3504
|
+
* } else {
|
|
3505
|
+
* console.log("Account deactivated successfully");
|
|
3506
|
+
* console.log("Success:", data.success);
|
|
3507
|
+
* }
|
|
3508
|
+
* ```
|
|
2333
3509
|
*/
|
|
2334
3510
|
async deactivateUserAccount(pathParams) {
|
|
2335
3511
|
return this.executeRequest(
|
|
@@ -2343,8 +3519,21 @@ var CE_SDK = (() => {
|
|
|
2343
3519
|
/**
|
|
2344
3520
|
* Get user notification preferences
|
|
2345
3521
|
*
|
|
2346
|
-
* @param
|
|
2347
|
-
* @returns Promise with user
|
|
3522
|
+
* @param pathParams - Path parameters containing user ID
|
|
3523
|
+
* @returns Promise with user's notification preferences
|
|
3524
|
+
* @example
|
|
3525
|
+
* ```typescript
|
|
3526
|
+
* // Get user's notification preferences
|
|
3527
|
+
* const { data, error } = await sdk.auth.getUserNotificationPreferences({
|
|
3528
|
+
* id: "01H9XYZ12345USERID"
|
|
3529
|
+
* });
|
|
3530
|
+
*
|
|
3531
|
+
* if (error) {
|
|
3532
|
+
* console.error("Failed to get preferences:", error.message);
|
|
3533
|
+
* } else {
|
|
3534
|
+
* console.log("Notification preferences:", data.notification_preferences);
|
|
3535
|
+
* }
|
|
3536
|
+
* ```
|
|
2348
3537
|
*/
|
|
2349
3538
|
async getUserNotificationPreferences(pathParams) {
|
|
2350
3539
|
return this.executeRequest(
|
|
@@ -2358,8 +3547,27 @@ var CE_SDK = (() => {
|
|
|
2358
3547
|
/**
|
|
2359
3548
|
* Update user notification preferences
|
|
2360
3549
|
*
|
|
2361
|
-
* @param
|
|
2362
|
-
* @
|
|
3550
|
+
* @param pathParams - Path parameters containing user ID
|
|
3551
|
+
* @param body - Updated notification preferences
|
|
3552
|
+
* @returns Promise with updated notification preferences
|
|
3553
|
+
* @example
|
|
3554
|
+
* ```typescript
|
|
3555
|
+
* // Update user's notification preferences
|
|
3556
|
+
* const { data, error } = await sdk.auth.updateUserNotificationPreferences(
|
|
3557
|
+
* { id: "01H9XYZ12345USERID" },
|
|
3558
|
+
* {
|
|
3559
|
+
* email_notifications: true,
|
|
3560
|
+
* sms_notifications: false,
|
|
3561
|
+
* push_notifications: true
|
|
3562
|
+
* }
|
|
3563
|
+
* );
|
|
3564
|
+
*
|
|
3565
|
+
* if (error) {
|
|
3566
|
+
* console.error("Failed to update preferences:", error.message);
|
|
3567
|
+
* } else {
|
|
3568
|
+
* console.log("Preferences updated successfully");
|
|
3569
|
+
* }
|
|
3570
|
+
* ```
|
|
2363
3571
|
*/
|
|
2364
3572
|
async updateUserNotificationPreferences(pathParams, body) {
|
|
2365
3573
|
return this.executeRequest(
|
|
@@ -2374,8 +3582,27 @@ var CE_SDK = (() => {
|
|
|
2374
3582
|
/**
|
|
2375
3583
|
* Create user notification preference
|
|
2376
3584
|
*
|
|
2377
|
-
* @param
|
|
2378
|
-
* @
|
|
3585
|
+
* @param pathParams - Path parameters containing user ID
|
|
3586
|
+
* @param body - Notification preferences to create
|
|
3587
|
+
* @returns Promise with created notification preferences
|
|
3588
|
+
* @example
|
|
3589
|
+
* ```typescript
|
|
3590
|
+
* // Create notification preferences for a user
|
|
3591
|
+
* const { data, error } = await sdk.auth.createUserNotificationPreference(
|
|
3592
|
+
* { id: "01H9XYZ12345USERID" },
|
|
3593
|
+
* {
|
|
3594
|
+
* email_notifications: true,
|
|
3595
|
+
* sms_notifications: true,
|
|
3596
|
+
* push_notifications: false
|
|
3597
|
+
* }
|
|
3598
|
+
* );
|
|
3599
|
+
*
|
|
3600
|
+
* if (error) {
|
|
3601
|
+
* console.error("Failed to create preferences:", error.message);
|
|
3602
|
+
* } else {
|
|
3603
|
+
* console.log("Preferences created successfully");
|
|
3604
|
+
* }
|
|
3605
|
+
* ```
|
|
2379
3606
|
*/
|
|
2380
3607
|
async createUserNotificationPreference(pathParams, body) {
|
|
2381
3608
|
return this.executeRequest(
|
|
@@ -2389,9 +3616,25 @@ var CE_SDK = (() => {
|
|
|
2389
3616
|
}
|
|
2390
3617
|
/**
|
|
2391
3618
|
* Generate OTP
|
|
2392
|
-
*
|
|
2393
|
-
* @param body - OTP generation body
|
|
2394
|
-
* @returns Promise with OTP
|
|
3619
|
+
*
|
|
3620
|
+
* @param body - OTP generation body (phone or email)
|
|
3621
|
+
* @returns Promise with OTP token and action
|
|
3622
|
+
* @example
|
|
3623
|
+
* ```typescript
|
|
3624
|
+
* // Generate OTP for phone number
|
|
3625
|
+
* const { data, error } = await sdk.auth.generateOtp({
|
|
3626
|
+
* phone: "9876543210",
|
|
3627
|
+
* country_code: "+91"
|
|
3628
|
+
* });
|
|
3629
|
+
*
|
|
3630
|
+
* if (error) {
|
|
3631
|
+
* console.error("OTP generation failed:", error.message);
|
|
3632
|
+
* } else {
|
|
3633
|
+
* console.log("OTP sent successfully");
|
|
3634
|
+
* console.log("OTP token:", data.otp_token);
|
|
3635
|
+
* console.log("Action:", data.otp_action);
|
|
3636
|
+
* }
|
|
3637
|
+
* ```
|
|
2395
3638
|
*/
|
|
2396
3639
|
async generateOtp(body) {
|
|
2397
3640
|
return this.executeRequest(
|
|
@@ -2403,8 +3646,23 @@ var CE_SDK = (() => {
|
|
|
2403
3646
|
/**
|
|
2404
3647
|
* Check whether email or phone is already verified
|
|
2405
3648
|
*
|
|
2406
|
-
* @param body -
|
|
2407
|
-
* @returns Promise with
|
|
3649
|
+
* @param body - Request body containing phone numbers or email addresses to verify
|
|
3650
|
+
* @returns Promise with verification status for provided contacts
|
|
3651
|
+
* @example
|
|
3652
|
+
* ```typescript
|
|
3653
|
+
* // Check verification status for multiple contacts
|
|
3654
|
+
* const { data, error } = await sdk.auth.checkEmailOrPhoneIsVerified({
|
|
3655
|
+
* phone: ["9876543210", "9123456789"],
|
|
3656
|
+
* email: ["user1@example.com", "user2@example.com"]
|
|
3657
|
+
* });
|
|
3658
|
+
*
|
|
3659
|
+
* if (error) {
|
|
3660
|
+
* console.error("Verification check failed:", error.message);
|
|
3661
|
+
* } else {
|
|
3662
|
+
* console.log("Verified phones:", data.verified_phone);
|
|
3663
|
+
* console.log("Verified emails:", data.verified_email);
|
|
3664
|
+
* }
|
|
3665
|
+
* ```
|
|
2408
3666
|
*/
|
|
2409
3667
|
async checkEmailOrPhoneIsVerified(body) {
|
|
2410
3668
|
return this.executeRequest(
|
|
@@ -2422,6 +3680,20 @@ var CE_SDK = (() => {
|
|
|
2422
3680
|
*
|
|
2423
3681
|
* @param orderNumber - Order number
|
|
2424
3682
|
* @returns Promise with order details
|
|
3683
|
+
* @example
|
|
3684
|
+
* ```typescript
|
|
3685
|
+
* const { data, error } = await sdk.order.getOrderDetails({
|
|
3686
|
+
* order_number: "ORD-2024-001"
|
|
3687
|
+
* });
|
|
3688
|
+
*
|
|
3689
|
+
* if (error) {
|
|
3690
|
+
* console.error("Failed to get order details:", error.message);
|
|
3691
|
+
* } else {
|
|
3692
|
+
* console.log("Order details:", data.content.order);
|
|
3693
|
+
* console.log("Order status:", data.content.order.status);
|
|
3694
|
+
* console.log("Total amount:", data.content.order.total_amount);
|
|
3695
|
+
* }
|
|
3696
|
+
* ```
|
|
2425
3697
|
*/
|
|
2426
3698
|
async getOrderDetails(pathParams) {
|
|
2427
3699
|
return this.executeRequest(
|
|
@@ -2435,10 +3707,42 @@ var CE_SDK = (() => {
|
|
|
2435
3707
|
/**
|
|
2436
3708
|
* Create order
|
|
2437
3709
|
*
|
|
2438
|
-
* @param
|
|
2439
|
-
* @param paymentGateway - Payment gateway
|
|
2440
|
-
* @param paymentGatewayParams - Params for the selected payment gateway
|
|
3710
|
+
* @param body - Order creation request body
|
|
2441
3711
|
* @returns Promise with order details
|
|
3712
|
+
* @example
|
|
3713
|
+
* ```typescript
|
|
3714
|
+
* // Example with PayU payment gateway
|
|
3715
|
+
* const { data, error } = await sdk.order.createOrder({
|
|
3716
|
+
* cart_id: "cart_01H9XYZ12345ABCDE",
|
|
3717
|
+
* payment_gateway: "PAYU",
|
|
3718
|
+
* payment_gateway_params: {
|
|
3719
|
+
* payment_gateway: "PAYU",
|
|
3720
|
+
* furl: "https://yourapp.com/payment/failure",
|
|
3721
|
+
* surl: "https://yourapp.com/payment/success"
|
|
3722
|
+
* }
|
|
3723
|
+
* });
|
|
3724
|
+
*
|
|
3725
|
+
* // Example with Juspay payment gateway
|
|
3726
|
+
* const { data, error } = await sdk.order.createOrder({
|
|
3727
|
+
* cart_id: "cart_01H9XYZ12345ABCDE",
|
|
3728
|
+
* payment_gateway: "JUSPAY",
|
|
3729
|
+
* payment_gateway_params: {
|
|
3730
|
+
* payment_gateway: "JUSPAY",
|
|
3731
|
+
* action: "paymentPage",
|
|
3732
|
+
* integration_type: "hyper-checkout",
|
|
3733
|
+
* return_url: "https://yourapp.com/payment/return",
|
|
3734
|
+
* gateway_reference_id: "juspay_gateway_ref_123"
|
|
3735
|
+
* }
|
|
3736
|
+
* });
|
|
3737
|
+
*
|
|
3738
|
+
* if (error) {
|
|
3739
|
+
* console.error("Failed to create order:", error.message);
|
|
3740
|
+
* } else {
|
|
3741
|
+
* console.log("Order created:", data.content.order.id);
|
|
3742
|
+
* console.log("Payment required:", data.content.payment_required);
|
|
3743
|
+
* console.log("Payment info:", data.content.payment_info);
|
|
3744
|
+
* }
|
|
3745
|
+
* ```
|
|
2442
3746
|
*/
|
|
2443
3747
|
async createOrder(body) {
|
|
2444
3748
|
return this.executeRequest(
|
|
@@ -2450,8 +3754,35 @@ var CE_SDK = (() => {
|
|
|
2450
3754
|
/**
|
|
2451
3755
|
* List all orders
|
|
2452
3756
|
*
|
|
2453
|
-
* @param queryParams - Query parameters
|
|
2454
|
-
* @returns Promise with order
|
|
3757
|
+
* @param queryParams - Query parameters for filtering and pagination
|
|
3758
|
+
* @returns Promise with order list
|
|
3759
|
+
* @example
|
|
3760
|
+
* ```typescript
|
|
3761
|
+
* // Basic usage - only required parameter
|
|
3762
|
+
* const { data, error } = await sdk.order.listOrders({
|
|
3763
|
+
* user_id: "user_01H9XYZ12345ABCDE"
|
|
3764
|
+
* });
|
|
3765
|
+
*
|
|
3766
|
+
* // Advanced usage with optional parameters
|
|
3767
|
+
* const { data, error } = await sdk.order.listOrders({
|
|
3768
|
+
* user_id: "user_01H9XYZ12345ABCDE",
|
|
3769
|
+
* page: 1,
|
|
3770
|
+
* limit: 20,
|
|
3771
|
+
* sort_by: '{"created_at":"desc"}',
|
|
3772
|
+
* status: ["confirmed", "shipped", "delivered"]
|
|
3773
|
+
* });
|
|
3774
|
+
*
|
|
3775
|
+
* if (error) {
|
|
3776
|
+
* console.error("Failed to list orders:", error.message);
|
|
3777
|
+
* } else {
|
|
3778
|
+
* console.log("Orders found:", data.content.orders?.length || 0);
|
|
3779
|
+
* console.log("Pagination:", data.content.pagination);
|
|
3780
|
+
*
|
|
3781
|
+
* data.content.orders?.forEach(order => {
|
|
3782
|
+
* console.log(`Order ${order.order_number}: ${order.status}`);
|
|
3783
|
+
* });
|
|
3784
|
+
* }
|
|
3785
|
+
* ```
|
|
2455
3786
|
*/
|
|
2456
3787
|
async listOrders(queryParams) {
|
|
2457
3788
|
return this.executeRequest(
|
|
@@ -2467,6 +3798,19 @@ var CE_SDK = (() => {
|
|
|
2467
3798
|
*
|
|
2468
3799
|
* @param orderNumber - Order number
|
|
2469
3800
|
* @returns Promise with payment status
|
|
3801
|
+
* @example
|
|
3802
|
+
* ```typescript
|
|
3803
|
+
* const { data, error } = await sdk.order.getPaymentStatus("ORD-2024-001");
|
|
3804
|
+
*
|
|
3805
|
+
* if (error) {
|
|
3806
|
+
* console.error("Failed to get payment status:", error.message);
|
|
3807
|
+
* } else {
|
|
3808
|
+
* console.log("Payment status:", data.content.status);
|
|
3809
|
+
* console.log("Amount paid:", data.content.amount_paid);
|
|
3810
|
+
* console.log("Amount unpaid:", data.content.amount_unpaid);
|
|
3811
|
+
* console.log("Retry available:", data.content.is_retry_available);
|
|
3812
|
+
* }
|
|
3813
|
+
* ```
|
|
2470
3814
|
*/
|
|
2471
3815
|
async getPaymentStatus(orderNumber) {
|
|
2472
3816
|
return this.executeRequest(
|
|
@@ -2480,8 +3824,26 @@ var CE_SDK = (() => {
|
|
|
2480
3824
|
/**
|
|
2481
3825
|
* Get all shipments for an order
|
|
2482
3826
|
*
|
|
2483
|
-
* @param
|
|
3827
|
+
* @param pathParams - Order number path parameters
|
|
2484
3828
|
* @returns Promise with shipments
|
|
3829
|
+
* @example
|
|
3830
|
+
* ```typescript
|
|
3831
|
+
* const { data, error } = await sdk.order.listOrderShipments({
|
|
3832
|
+
* order_number: "ORD-2024-001"
|
|
3833
|
+
* });
|
|
3834
|
+
*
|
|
3835
|
+
* if (error) {
|
|
3836
|
+
* console.error("Failed to get order shipments:", error.message);
|
|
3837
|
+
* } else {
|
|
3838
|
+
* console.log("Shipments found:", data.content.shipments?.length || 0);
|
|
3839
|
+
*
|
|
3840
|
+
* data.content.shipments?.forEach(shipment => {
|
|
3841
|
+
* console.log(`Shipment ${shipment.id}: ${shipment.status}`);
|
|
3842
|
+
* console.log("Tracking number:", shipment.tracking_number);
|
|
3843
|
+
* console.log("Carrier:", shipment.carrier);
|
|
3844
|
+
* });
|
|
3845
|
+
* }
|
|
3846
|
+
* ```
|
|
2485
3847
|
*/
|
|
2486
3848
|
async listOrderShipments(pathParams) {
|
|
2487
3849
|
return this.executeRequest(
|
|
@@ -2495,8 +3857,27 @@ var CE_SDK = (() => {
|
|
|
2495
3857
|
/**
|
|
2496
3858
|
* List order payments
|
|
2497
3859
|
*
|
|
2498
|
-
* @param
|
|
3860
|
+
* @param pathParams - Order number path parameters
|
|
2499
3861
|
* @returns Promise with payments
|
|
3862
|
+
* @example
|
|
3863
|
+
* ```typescript
|
|
3864
|
+
* const { data, error } = await sdk.order.listOrderPayments({
|
|
3865
|
+
* order_number: "ORD-2024-001"
|
|
3866
|
+
* });
|
|
3867
|
+
*
|
|
3868
|
+
* if (error) {
|
|
3869
|
+
* console.error("Failed to get order payments:", error.message);
|
|
3870
|
+
* } else {
|
|
3871
|
+
* console.log("Payments found:", data.content.payments?.length || 0);
|
|
3872
|
+
*
|
|
3873
|
+
* data.content.payments?.forEach(payment => {
|
|
3874
|
+
* console.log(`Payment ${payment.id}: ${payment.status}`);
|
|
3875
|
+
* console.log("Amount:", payment.amount);
|
|
3876
|
+
* console.log("Gateway:", payment.payment_gateway);
|
|
3877
|
+
* console.log("Transaction ID:", payment.transaction_id);
|
|
3878
|
+
* });
|
|
3879
|
+
* }
|
|
3880
|
+
* ```
|
|
2500
3881
|
*/
|
|
2501
3882
|
async listOrderPayments(pathParams) {
|
|
2502
3883
|
return this.executeRequest(
|
|
@@ -2510,8 +3891,27 @@ var CE_SDK = (() => {
|
|
|
2510
3891
|
/**
|
|
2511
3892
|
* List order refunds
|
|
2512
3893
|
*
|
|
2513
|
-
* @param
|
|
3894
|
+
* @param pathParams - Order number path parameters
|
|
2514
3895
|
* @returns Promise with refunds
|
|
3896
|
+
* @example
|
|
3897
|
+
* ```typescript
|
|
3898
|
+
* const { data, error } = await sdk.order.listOrderRefunds({
|
|
3899
|
+
* order_number: "ORD-2024-001"
|
|
3900
|
+
* });
|
|
3901
|
+
*
|
|
3902
|
+
* if (error) {
|
|
3903
|
+
* console.error("Failed to get order refunds:", error.message);
|
|
3904
|
+
* } else {
|
|
3905
|
+
* console.log("Refunds found:", data.content.refunds?.length || 0);
|
|
3906
|
+
*
|
|
3907
|
+
* data.content.refunds?.forEach(refund => {
|
|
3908
|
+
* console.log(`Refund ${refund.id}: ${refund.status}`);
|
|
3909
|
+
* console.log("Amount:", refund.amount);
|
|
3910
|
+
* console.log("Reason:", refund.reason);
|
|
3911
|
+
* console.log("Processed at:", refund.processed_at);
|
|
3912
|
+
* });
|
|
3913
|
+
* }
|
|
3914
|
+
* ```
|
|
2515
3915
|
*/
|
|
2516
3916
|
async listOrderRefunds(pathParams) {
|
|
2517
3917
|
return this.executeRequest(
|
|
@@ -2525,8 +3925,28 @@ var CE_SDK = (() => {
|
|
|
2525
3925
|
/**
|
|
2526
3926
|
* Cancel an order
|
|
2527
3927
|
*
|
|
2528
|
-
* @param
|
|
3928
|
+
* @param pathParams - Order number path parameters
|
|
3929
|
+
* @param body - Cancellation request body
|
|
2529
3930
|
* @returns Promise with order details
|
|
3931
|
+
* @example
|
|
3932
|
+
* ```typescript
|
|
3933
|
+
* const { data, error } = await sdk.order.cancelOrder(
|
|
3934
|
+
* { order_number: "ORD-2024-001" },
|
|
3935
|
+
* {
|
|
3936
|
+
* cancellation_reason: "Customer requested cancellation",
|
|
3937
|
+
* refund_mode: "original_payment_mode",
|
|
3938
|
+
* feedback: "Customer changed their mind about the purchase"
|
|
3939
|
+
* }
|
|
3940
|
+
* );
|
|
3941
|
+
*
|
|
3942
|
+
* if (error) {
|
|
3943
|
+
* console.error("Failed to cancel order:", error.message);
|
|
3944
|
+
* } else {
|
|
3945
|
+
* console.log("Order cancelled successfully");
|
|
3946
|
+
* console.log("Updated order status:", data.content.order?.status);
|
|
3947
|
+
* console.log("Cancellation reason:", data.content.order?.cancellation_reason);
|
|
3948
|
+
* }
|
|
3949
|
+
* ```
|
|
2530
3950
|
*/
|
|
2531
3951
|
async cancelOrder(pathParams, body) {
|
|
2532
3952
|
return this.executeRequest(
|
|
@@ -2541,8 +3961,45 @@ var CE_SDK = (() => {
|
|
|
2541
3961
|
/**
|
|
2542
3962
|
* Retry payment for an order
|
|
2543
3963
|
*
|
|
2544
|
-
* @param
|
|
2545
|
-
* @
|
|
3964
|
+
* @param pathParams - Order number path parameters
|
|
3965
|
+
* @param body - Payment retry request body
|
|
3966
|
+
* @returns Promise with payment information
|
|
3967
|
+
* @example
|
|
3968
|
+
* ```typescript
|
|
3969
|
+
* // Example with PayU payment gateway
|
|
3970
|
+
* const { data, error } = await sdk.order.retryOrderPayment(
|
|
3971
|
+
* { order_number: "ORD-2024-001" },
|
|
3972
|
+
* {
|
|
3973
|
+
* payment_gateway_params: {
|
|
3974
|
+
* payment_gateway: "PAYU",
|
|
3975
|
+
* furl: "https://yourapp.com/payment/failure",
|
|
3976
|
+
* surl: "https://yourapp.com/payment/success"
|
|
3977
|
+
* }
|
|
3978
|
+
* }
|
|
3979
|
+
* );
|
|
3980
|
+
*
|
|
3981
|
+
* // Example with Juspay payment gateway
|
|
3982
|
+
* const { data, error } = await sdk.order.retryOrderPayment(
|
|
3983
|
+
* { order_number: "ORD-2024-001" },
|
|
3984
|
+
* {
|
|
3985
|
+
* payment_gateway_params: {
|
|
3986
|
+
* payment_gateway: "JUSPAY",
|
|
3987
|
+
* action: "paymentPage",
|
|
3988
|
+
* integration_type: "hyper-checkout",
|
|
3989
|
+
* return_url: "https://yourapp.com/payment/return",
|
|
3990
|
+
* gateway_reference_id: "juspay_gateway_ref_123"
|
|
3991
|
+
* }
|
|
3992
|
+
* }
|
|
3993
|
+
* );
|
|
3994
|
+
*
|
|
3995
|
+
* if (error) {
|
|
3996
|
+
* console.error("Failed to retry payment:", error.message);
|
|
3997
|
+
* } else {
|
|
3998
|
+
* console.log("Payment retry initiated");
|
|
3999
|
+
* console.log("Payment info:", data.content.payment_info);
|
|
4000
|
+
* console.log("Transaction ID:", data.content.payment_info.transaction_id);
|
|
4001
|
+
* }
|
|
4002
|
+
* ```
|
|
2546
4003
|
*/
|
|
2547
4004
|
async retryOrderPayment(pathParams, body) {
|
|
2548
4005
|
return this.executeRequest(
|
|
@@ -2563,6 +4020,31 @@ var CE_SDK = (() => {
|
|
|
2563
4020
|
*
|
|
2564
4021
|
* @param body - Shipping methods body
|
|
2565
4022
|
* @returns Promise with shipping options
|
|
4023
|
+
* @example
|
|
4024
|
+
* ```typescript
|
|
4025
|
+
* const { data, error } = await sdk.shipping.getShippingMethods({
|
|
4026
|
+
* delivery_pincode: "400001",
|
|
4027
|
+
* cart_id: "cart_01H9XYZ12345ABCDE"
|
|
4028
|
+
* });
|
|
4029
|
+
*
|
|
4030
|
+
* if (error) {
|
|
4031
|
+
* console.error("Failed to get shipping methods:", error.message);
|
|
4032
|
+
* } else {
|
|
4033
|
+
* console.log("Is serviceable:", data.content.is_serviceable);
|
|
4034
|
+
* console.log("Available shipping methods:", data.content.shipping_methods?.length || 0);
|
|
4035
|
+
*
|
|
4036
|
+
* data.content.shipping_methods?.forEach(method => {
|
|
4037
|
+
* console.log(`Method: ${method.name} (${method.shipping_type})`);
|
|
4038
|
+
* console.log(`Shipping cost: ${method.shipping_amount}`);
|
|
4039
|
+
* console.log(`Estimated delivery: ${method.estimated_delivery_days} days`);
|
|
4040
|
+
*
|
|
4041
|
+
* method.courier_companies?.forEach(courier => {
|
|
4042
|
+
* console.log(` - ${courier.name}: ${courier.shipping_amount} (${courier.mode})`);
|
|
4043
|
+
* console.log(` Rating: ${courier.rating}/5, Recommended: ${courier.is_recommended}`);
|
|
4044
|
+
* });
|
|
4045
|
+
* });
|
|
4046
|
+
* }
|
|
4047
|
+
* ```
|
|
2566
4048
|
*/
|
|
2567
4049
|
async getShippingMethods(body) {
|
|
2568
4050
|
return this.executeRequest(
|
|
@@ -2576,6 +4058,24 @@ var CE_SDK = (() => {
|
|
|
2576
4058
|
*
|
|
2577
4059
|
* @param pathParams - Path parameters
|
|
2578
4060
|
* @returns Promise with pincode deliverability result
|
|
4061
|
+
* @example
|
|
4062
|
+
* ```typescript
|
|
4063
|
+
* const { data, error } = await sdk.shipping.checkPincodeDeliverability({
|
|
4064
|
+
* pincode: "400001"
|
|
4065
|
+
* });
|
|
4066
|
+
*
|
|
4067
|
+
* if (error) {
|
|
4068
|
+
* console.error("Failed to check pincode serviceability:", error.message);
|
|
4069
|
+
* } else {
|
|
4070
|
+
* console.log("Pincode serviceable:", data.content.is_serviceable);
|
|
4071
|
+
*
|
|
4072
|
+
* if (data.content.is_serviceable) {
|
|
4073
|
+
* console.log("Delivery is available to this pincode");
|
|
4074
|
+
* } else {
|
|
4075
|
+
* console.log("Delivery is not available to this pincode");
|
|
4076
|
+
* }
|
|
4077
|
+
* }
|
|
4078
|
+
* ```
|
|
2579
4079
|
*/
|
|
2580
4080
|
async checkPincodeDeliverability(pathParams) {
|
|
2581
4081
|
return this.executeRequest(
|
|
@@ -2594,17 +4094,64 @@ var CE_SDK = (() => {
|
|
|
2594
4094
|
* Get a list of countries
|
|
2595
4095
|
*
|
|
2596
4096
|
* @returns Promise with countries
|
|
4097
|
+
*
|
|
4098
|
+
* @example
|
|
4099
|
+
* ```typescript
|
|
4100
|
+
* const { data, error } = await sdk.helpers.listCountries();
|
|
4101
|
+
*
|
|
4102
|
+
* if (error) {
|
|
4103
|
+
* console.error("Failed to get countries:", error);
|
|
4104
|
+
* return;
|
|
4105
|
+
* }
|
|
4106
|
+
*
|
|
4107
|
+
* console.log("Countries found:", data.countries?.length || 0);
|
|
4108
|
+
*
|
|
4109
|
+
* data.countries?.forEach(country => {
|
|
4110
|
+
* console.log(`Country: ${country.name} (${country.iso_code})`);
|
|
4111
|
+
* console.log("Phone code:", country.phone_code);
|
|
4112
|
+
* console.log("Currency:", country.currency?.code);
|
|
4113
|
+
* });
|
|
4114
|
+
* ```
|
|
2597
4115
|
*/
|
|
2598
4116
|
async listCountries() {
|
|
2599
|
-
return this.executeRequest(
|
|
2600
|
-
() => this.client.GET("/common/countries", {})
|
|
2601
|
-
);
|
|
4117
|
+
return this.executeRequest(() => this.client.GET("/common/countries", {}));
|
|
2602
4118
|
}
|
|
2603
4119
|
/**
|
|
2604
|
-
*
|
|
4120
|
+
* Get a list of states for a country
|
|
2605
4121
|
*
|
|
2606
4122
|
* @param pathParams - Path parameters
|
|
2607
4123
|
* @returns Promise with states
|
|
4124
|
+
*
|
|
4125
|
+
* @example
|
|
4126
|
+
* ```typescript
|
|
4127
|
+
* const { data, error } = await sdk.helpers.listCountryStates({
|
|
4128
|
+
* country_iso_code: "IN"
|
|
4129
|
+
* });
|
|
4130
|
+
*
|
|
4131
|
+
* if (error) {
|
|
4132
|
+
* console.error("Failed to get states:", error);
|
|
4133
|
+
* return;
|
|
4134
|
+
* }
|
|
4135
|
+
*
|
|
4136
|
+
* console.log("States found:", data.states?.length || 0);
|
|
4137
|
+
*
|
|
4138
|
+
* data.states?.forEach(state => {
|
|
4139
|
+
* console.log(`State: ${state.name} (${state.iso_code})`);
|
|
4140
|
+
* console.log("Type:", state.type);
|
|
4141
|
+
* });
|
|
4142
|
+
*
|
|
4143
|
+
* // Get states for different country
|
|
4144
|
+
* const { data: usStates, error: usError } = await sdk.helpers.listCountryStates({
|
|
4145
|
+
* country_iso_code: "US"
|
|
4146
|
+
* });
|
|
4147
|
+
*
|
|
4148
|
+
* if (usError) {
|
|
4149
|
+
* console.error("Failed to get US states:", usError);
|
|
4150
|
+
* return;
|
|
4151
|
+
* }
|
|
4152
|
+
*
|
|
4153
|
+
* console.log("US States:", usStates.states?.map(s => s.name).join(", "));
|
|
4154
|
+
* ```
|
|
2608
4155
|
*/
|
|
2609
4156
|
async listCountryStates(pathParams) {
|
|
2610
4157
|
return this.executeRequest(
|
|
@@ -2620,6 +4167,38 @@ var CE_SDK = (() => {
|
|
|
2620
4167
|
*
|
|
2621
4168
|
* @param pathParams - Path parameters
|
|
2622
4169
|
* @returns Promise with pincodes
|
|
4170
|
+
*
|
|
4171
|
+
* @example
|
|
4172
|
+
* ```typescript
|
|
4173
|
+
* const { data, error } = await sdk.helpers.listCountryPincodes({
|
|
4174
|
+
* country_iso_code: "IN"
|
|
4175
|
+
* });
|
|
4176
|
+
*
|
|
4177
|
+
* if (error) {
|
|
4178
|
+
* console.error("Failed to get pincodes:", error);
|
|
4179
|
+
* return;
|
|
4180
|
+
* }
|
|
4181
|
+
*
|
|
4182
|
+
* console.log("Pincodes found:", data.pincodes?.length || 0);
|
|
4183
|
+
*
|
|
4184
|
+
* data.pincodes?.forEach(pincode => {
|
|
4185
|
+
* console.log(`Pincode: ${pincode.pincode} - ${pincode.city}, ${pincode.state}`);
|
|
4186
|
+
* console.log("District:", pincode.district);
|
|
4187
|
+
* console.log("Area:", pincode.area);
|
|
4188
|
+
* });
|
|
4189
|
+
*
|
|
4190
|
+
* // Get pincodes for different country
|
|
4191
|
+
* const { data: usPincodes, error: usError } = await sdk.helpers.listCountryPincodes({
|
|
4192
|
+
* country_iso_code: "US"
|
|
4193
|
+
* });
|
|
4194
|
+
*
|
|
4195
|
+
* if (usError) {
|
|
4196
|
+
* console.error("Failed to get US pincodes:", usError);
|
|
4197
|
+
* return;
|
|
4198
|
+
* }
|
|
4199
|
+
*
|
|
4200
|
+
* console.log("US Pincodes:", usPincodes.pincodes?.map(p => p.pincode).join(", "));
|
|
4201
|
+
* ```
|
|
2623
4202
|
*/
|
|
2624
4203
|
async listCountryPincodes(pathParams) {
|
|
2625
4204
|
return this.executeRequest(
|
|
@@ -2639,6 +4218,24 @@ var CE_SDK = (() => {
|
|
|
2639
4218
|
*
|
|
2640
4219
|
* @param body - Customer creation body
|
|
2641
4220
|
* @returns Promise with customer details
|
|
4221
|
+
*
|
|
4222
|
+
* @example
|
|
4223
|
+
* ```typescript
|
|
4224
|
+
* const { data, error } = await sdk.customer.createCustomer({
|
|
4225
|
+
* first_name: "John",
|
|
4226
|
+
* last_name: "Doe",
|
|
4227
|
+
* email: "john.doe@example.com",
|
|
4228
|
+
* phone: "+1234567890",
|
|
4229
|
+
* password: "securePassword123"
|
|
4230
|
+
* });
|
|
4231
|
+
*
|
|
4232
|
+
* if (error) {
|
|
4233
|
+
* console.error("Failed to create customer:", error);
|
|
4234
|
+
* return;
|
|
4235
|
+
* }
|
|
4236
|
+
*
|
|
4237
|
+
* console.log("Customer created:", data.customer_detail);
|
|
4238
|
+
* ```
|
|
2642
4239
|
*/
|
|
2643
4240
|
async createCustomer(body) {
|
|
2644
4241
|
return this.executeRequest(
|
|
@@ -2652,6 +4249,20 @@ var CE_SDK = (() => {
|
|
|
2652
4249
|
*
|
|
2653
4250
|
* @param pathParams - Path parameters
|
|
2654
4251
|
* @returns Promise with customer details
|
|
4252
|
+
*
|
|
4253
|
+
* @example
|
|
4254
|
+
* ```typescript
|
|
4255
|
+
* const { data, error } = await sdk.customer.getCustomer({
|
|
4256
|
+
* id: "customer_123"
|
|
4257
|
+
* });
|
|
4258
|
+
*
|
|
4259
|
+
* if (error) {
|
|
4260
|
+
* console.error("Failed to get customer:", error);
|
|
4261
|
+
* return;
|
|
4262
|
+
* }
|
|
4263
|
+
*
|
|
4264
|
+
* console.log("Customer details:", data.customer_detail);
|
|
4265
|
+
* ```
|
|
2655
4266
|
*/
|
|
2656
4267
|
async getCustomer(pathParams) {
|
|
2657
4268
|
return this.executeRequest(
|
|
@@ -2668,6 +4279,25 @@ var CE_SDK = (() => {
|
|
|
2668
4279
|
* @param pathParams - Path parameters
|
|
2669
4280
|
* @param body - Customer update body
|
|
2670
4281
|
* @returns Promise with customer details
|
|
4282
|
+
*
|
|
4283
|
+
* @example
|
|
4284
|
+
* ```typescript
|
|
4285
|
+
* const { data, error } = await sdk.customer.updateCustomer(
|
|
4286
|
+
* { id: "customer_123" },
|
|
4287
|
+
* {
|
|
4288
|
+
* first_name: "John",
|
|
4289
|
+
* last_name: "Smith",
|
|
4290
|
+
* email: "john.smith@example.com"
|
|
4291
|
+
* }
|
|
4292
|
+
* );
|
|
4293
|
+
*
|
|
4294
|
+
* if (error) {
|
|
4295
|
+
* console.error("Failed to update customer:", error);
|
|
4296
|
+
* return;
|
|
4297
|
+
* }
|
|
4298
|
+
*
|
|
4299
|
+
* console.log("Customer updated:", data.customer_detail);
|
|
4300
|
+
* ```
|
|
2671
4301
|
*/
|
|
2672
4302
|
async updateCustomer(pathParams, body) {
|
|
2673
4303
|
return this.executeRequest(
|
|
@@ -2684,6 +4314,28 @@ var CE_SDK = (() => {
|
|
|
2684
4314
|
*
|
|
2685
4315
|
* @param pathParams - Path parameters
|
|
2686
4316
|
* @returns Promise with addresses
|
|
4317
|
+
*
|
|
4318
|
+
* @example
|
|
4319
|
+
* ```typescript
|
|
4320
|
+
* const { data, error } = await sdk.customer.listAddresses({
|
|
4321
|
+
* user_id: "user_456"
|
|
4322
|
+
* });
|
|
4323
|
+
*
|
|
4324
|
+
* if (error) {
|
|
4325
|
+
* console.error("Failed to list addresses:", error);
|
|
4326
|
+
* return;
|
|
4327
|
+
* }
|
|
4328
|
+
*
|
|
4329
|
+
* console.log("Addresses:", data.addresses);
|
|
4330
|
+
* console.log("Pagination:", data.pagination);
|
|
4331
|
+
*
|
|
4332
|
+
* // With pagination
|
|
4333
|
+
* const { data: page2, error: page2Error } = await sdk.customer.listAddresses({
|
|
4334
|
+
* user_id: "user_456",
|
|
4335
|
+
* page: 2,
|
|
4336
|
+
* limit: 10
|
|
4337
|
+
* });
|
|
4338
|
+
* ```
|
|
2687
4339
|
*/
|
|
2688
4340
|
async listAddresses(pathParams) {
|
|
2689
4341
|
return this.executeRequest(
|
|
@@ -2700,6 +4352,30 @@ var CE_SDK = (() => {
|
|
|
2700
4352
|
* @param pathParams - Path parameters
|
|
2701
4353
|
* @param body - Address creation body
|
|
2702
4354
|
* @returns Promise with address details
|
|
4355
|
+
*
|
|
4356
|
+
* @example
|
|
4357
|
+
* ```typescript
|
|
4358
|
+
* const { data, error } = await sdk.customer.createAddress(
|
|
4359
|
+
* { user_id: "user_456" },
|
|
4360
|
+
* {
|
|
4361
|
+
* address_line1: "123 Main Street",
|
|
4362
|
+
* address_line2: "Apt 4B",
|
|
4363
|
+
* city: "New York",
|
|
4364
|
+
* state: "NY",
|
|
4365
|
+
* country: "US",
|
|
4366
|
+
* pincode: "10001",
|
|
4367
|
+
* is_default_billing: true,
|
|
4368
|
+
* is_default_shipping: false
|
|
4369
|
+
* }
|
|
4370
|
+
* );
|
|
4371
|
+
*
|
|
4372
|
+
* if (error) {
|
|
4373
|
+
* console.error("Failed to create address:", error);
|
|
4374
|
+
* return;
|
|
4375
|
+
* }
|
|
4376
|
+
*
|
|
4377
|
+
* console.log("Address created:", data.address);
|
|
4378
|
+
* ```
|
|
2703
4379
|
*/
|
|
2704
4380
|
async createAddress(pathParams, body) {
|
|
2705
4381
|
return this.executeRequest(
|
|
@@ -2716,6 +4392,21 @@ var CE_SDK = (() => {
|
|
|
2716
4392
|
*
|
|
2717
4393
|
* @param pathParams - Path parameters
|
|
2718
4394
|
* @returns Promise with address details
|
|
4395
|
+
*
|
|
4396
|
+
* @example
|
|
4397
|
+
* ```typescript
|
|
4398
|
+
* const { data, error } = await sdk.customer.getAddress({
|
|
4399
|
+
* user_id: "user_456",
|
|
4400
|
+
* address_id: "addr_789"
|
|
4401
|
+
* });
|
|
4402
|
+
*
|
|
4403
|
+
* if (error) {
|
|
4404
|
+
* console.error("Failed to get address:", error);
|
|
4405
|
+
* return;
|
|
4406
|
+
* }
|
|
4407
|
+
*
|
|
4408
|
+
* console.log("Address details:", data.address);
|
|
4409
|
+
* ```
|
|
2719
4410
|
*/
|
|
2720
4411
|
async getAddress(pathParams) {
|
|
2721
4412
|
return this.executeRequest(
|
|
@@ -2732,6 +4423,29 @@ var CE_SDK = (() => {
|
|
|
2732
4423
|
* @param pathParams - Path parameters
|
|
2733
4424
|
* @param body - Address update body
|
|
2734
4425
|
* @returns Promise with address details
|
|
4426
|
+
*
|
|
4427
|
+
* @example
|
|
4428
|
+
* ```typescript
|
|
4429
|
+
* const { data, error } = await sdk.customer.updateAddress(
|
|
4430
|
+
* {
|
|
4431
|
+
* user_id: "user_456",
|
|
4432
|
+
* address_id: "addr_789"
|
|
4433
|
+
* },
|
|
4434
|
+
* {
|
|
4435
|
+
* address_line1: "456 Oak Avenue",
|
|
4436
|
+
* city: "Los Angeles",
|
|
4437
|
+
* state: "CA",
|
|
4438
|
+
* pincode: "90210"
|
|
4439
|
+
* }
|
|
4440
|
+
* );
|
|
4441
|
+
*
|
|
4442
|
+
* if (error) {
|
|
4443
|
+
* console.error("Failed to update address:", error);
|
|
4444
|
+
* return;
|
|
4445
|
+
* }
|
|
4446
|
+
*
|
|
4447
|
+
* console.log("Address updated:", data.address);
|
|
4448
|
+
* ```
|
|
2735
4449
|
*/
|
|
2736
4450
|
async updateAddress(pathParams, body) {
|
|
2737
4451
|
return this.executeRequest(
|
|
@@ -2747,7 +4461,22 @@ var CE_SDK = (() => {
|
|
|
2747
4461
|
* Delete an address for a customer
|
|
2748
4462
|
*
|
|
2749
4463
|
* @param pathParams - Path parameters
|
|
2750
|
-
* @returns Promise with
|
|
4464
|
+
* @returns Promise with deletion response
|
|
4465
|
+
*
|
|
4466
|
+
* @example
|
|
4467
|
+
* ```typescript
|
|
4468
|
+
* const { data, error } = await sdk.customer.deleteAddress({
|
|
4469
|
+
* user_id: "user_456",
|
|
4470
|
+
* address_id: "addr_789"
|
|
4471
|
+
* });
|
|
4472
|
+
*
|
|
4473
|
+
* if (error) {
|
|
4474
|
+
* console.error("Failed to delete address:", error);
|
|
4475
|
+
* return;
|
|
4476
|
+
* }
|
|
4477
|
+
*
|
|
4478
|
+
* console.log("Address deleted:", data.message);
|
|
4479
|
+
* ```
|
|
2751
4480
|
*/
|
|
2752
4481
|
async deleteAddress(pathParams) {
|
|
2753
4482
|
return this.executeRequest(
|
|
@@ -2763,6 +4492,21 @@ var CE_SDK = (() => {
|
|
|
2763
4492
|
*
|
|
2764
4493
|
* @param pathParams - Path parameters
|
|
2765
4494
|
* @returns Promise with loyalty details
|
|
4495
|
+
*
|
|
4496
|
+
* @example
|
|
4497
|
+
* ```typescript
|
|
4498
|
+
* const { data, error } = await sdk.customer.getLoyaltyDetails({
|
|
4499
|
+
* user_id: "user_456"
|
|
4500
|
+
* });
|
|
4501
|
+
*
|
|
4502
|
+
* if (error) {
|
|
4503
|
+
* console.error("Failed to get loyalty details:", error);
|
|
4504
|
+
* return;
|
|
4505
|
+
* }
|
|
4506
|
+
*
|
|
4507
|
+
* console.log("Loyalty info:", data.loyalty);
|
|
4508
|
+
* console.log("Points balance:", data.loyalty_point_balance);
|
|
4509
|
+
* ```
|
|
2766
4510
|
*/
|
|
2767
4511
|
async getLoyaltyDetails(pathParams) {
|
|
2768
4512
|
return this.executeRequest(
|
|
@@ -2778,6 +4522,28 @@ var CE_SDK = (() => {
|
|
|
2778
4522
|
*
|
|
2779
4523
|
* @param pathParams - Path parameters
|
|
2780
4524
|
* @returns Promise with loyalty points activity
|
|
4525
|
+
*
|
|
4526
|
+
* @example
|
|
4527
|
+
* ```typescript
|
|
4528
|
+
* const { data, error } = await sdk.customer.listLoyaltyPointsActivity({
|
|
4529
|
+
* user_id: "user_456"
|
|
4530
|
+
* });
|
|
4531
|
+
*
|
|
4532
|
+
* if (error) {
|
|
4533
|
+
* console.error("Failed to get loyalty activity:", error);
|
|
4534
|
+
* return;
|
|
4535
|
+
* }
|
|
4536
|
+
*
|
|
4537
|
+
* console.log("Loyalty activity:", data.loyalty_points_activity);
|
|
4538
|
+
*
|
|
4539
|
+
* // With pagination and sorting
|
|
4540
|
+
* const { data: sortedData, error: sortedError } = await sdk.customer.listLoyaltyPointsActivity({
|
|
4541
|
+
* user_id: "user_456",
|
|
4542
|
+
* page: 1,
|
|
4543
|
+
* limit: 20,
|
|
4544
|
+
* sort_by: JSON.stringify({ "created_at": "desc" })
|
|
4545
|
+
* });
|
|
4546
|
+
* ```
|
|
2781
4547
|
*/
|
|
2782
4548
|
async listLoyaltyPointsActivity(pathParams) {
|
|
2783
4549
|
return this.executeRequest(
|
|
@@ -2793,6 +4559,21 @@ var CE_SDK = (() => {
|
|
|
2793
4559
|
*
|
|
2794
4560
|
* @param pathParams - Path parameters
|
|
2795
4561
|
* @returns Promise with reviews
|
|
4562
|
+
*
|
|
4563
|
+
* @example
|
|
4564
|
+
* ```typescript
|
|
4565
|
+
* const { data, error } = await sdk.customer.listCustomerReviews({
|
|
4566
|
+
* user_id: "user_456"
|
|
4567
|
+
* });
|
|
4568
|
+
*
|
|
4569
|
+
* if (error) {
|
|
4570
|
+
* console.error("Failed to get customer reviews:", error);
|
|
4571
|
+
* return;
|
|
4572
|
+
* }
|
|
4573
|
+
*
|
|
4574
|
+
* console.log("Customer reviews:", data.reviews);
|
|
4575
|
+
* console.log("Ready for review:", data.ready_for_review);
|
|
4576
|
+
* ```
|
|
2796
4577
|
*/
|
|
2797
4578
|
async listCustomerReviews(pathParams) {
|
|
2798
4579
|
return this.executeRequest(
|
|
@@ -2809,6 +4590,25 @@ var CE_SDK = (() => {
|
|
|
2809
4590
|
var StoreConfigClient = class extends StorefrontAPIClient {
|
|
2810
4591
|
/**
|
|
2811
4592
|
* Get store config
|
|
4593
|
+
*
|
|
4594
|
+
* @returns Promise with store configuration data
|
|
4595
|
+
*
|
|
4596
|
+
* @example
|
|
4597
|
+
* ```typescript
|
|
4598
|
+
* const { data, error } = await sdk.storeConfig.getStoreConfig();
|
|
4599
|
+
*
|
|
4600
|
+
* if (error) {
|
|
4601
|
+
* console.error('Failed to get store config:', error.message);
|
|
4602
|
+
* return;
|
|
4603
|
+
* }
|
|
4604
|
+
*
|
|
4605
|
+
* // Access store configuration data
|
|
4606
|
+
* const storeConfig = data.store_config;
|
|
4607
|
+
* console.log('Store brand:', storeConfig.brand.name);
|
|
4608
|
+
* console.log('Currency:', storeConfig.currency.code);
|
|
4609
|
+
* console.log('KYC enabled:', storeConfig.is_kyc_enabled);
|
|
4610
|
+
* console.log('Customer groups enabled:', storeConfig.is_customer_group_enabled);
|
|
4611
|
+
* ```
|
|
2812
4612
|
*/
|
|
2813
4613
|
async getStoreConfig() {
|
|
2814
4614
|
return this.executeRequest(() => this.client.GET("/store/config"));
|