perspectapi-ts-sdk 2.8.3 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +46 -114
- package/dist/index.d.ts +46 -114
- package/dist/index.js +74 -112
- package/dist/index.mjs +74 -112
- package/package.json +1 -1
- package/src/client/auth-client.ts +3 -51
- package/src/client/categories-client.ts +126 -107
- package/src/types/index.ts +4 -19
package/dist/index.js
CHANGED
|
@@ -716,43 +716,6 @@ var AuthClient = class extends BaseClient {
|
|
|
716
716
|
async getCsrfToken() {
|
|
717
717
|
return this.http.get(this.buildPath("/csrf"));
|
|
718
718
|
}
|
|
719
|
-
/**
|
|
720
|
-
* Sign up a new user
|
|
721
|
-
*/
|
|
722
|
-
async signUp(data) {
|
|
723
|
-
return this.create("/signup", data);
|
|
724
|
-
}
|
|
725
|
-
/**
|
|
726
|
-
* Sign in user
|
|
727
|
-
*/
|
|
728
|
-
async signIn(data) {
|
|
729
|
-
const response = await this.create("/authenticate", data);
|
|
730
|
-
if (response.data && "token" in response.data && response.data.token) {
|
|
731
|
-
this.http.setAuth(response.data.token);
|
|
732
|
-
}
|
|
733
|
-
return response;
|
|
734
|
-
}
|
|
735
|
-
/**
|
|
736
|
-
* Activate user account
|
|
737
|
-
*/
|
|
738
|
-
async activateAccount(activationKey) {
|
|
739
|
-
return this.getSingle(`/activate/${activationKey}`);
|
|
740
|
-
}
|
|
741
|
-
/**
|
|
742
|
-
* Request password reset
|
|
743
|
-
*/
|
|
744
|
-
async forgotPassword(email) {
|
|
745
|
-
return this.create("/forgotpassword", { email });
|
|
746
|
-
}
|
|
747
|
-
/**
|
|
748
|
-
* Reset password with token
|
|
749
|
-
*/
|
|
750
|
-
async resetPassword(resetToken, password) {
|
|
751
|
-
return this.create(
|
|
752
|
-
`/passwordreset/${resetToken}`,
|
|
753
|
-
{ password }
|
|
754
|
-
);
|
|
755
|
-
}
|
|
756
719
|
/**
|
|
757
720
|
* Get current user profile
|
|
758
721
|
*/
|
|
@@ -1589,115 +1552,114 @@ var CategoriesClient = class extends BaseClient {
|
|
|
1589
1552
|
super(http, "/api/v1", cache);
|
|
1590
1553
|
}
|
|
1591
1554
|
/**
|
|
1592
|
-
* Get all categories
|
|
1555
|
+
* Get all categories for a site
|
|
1593
1556
|
*/
|
|
1594
|
-
async getCategories(params) {
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
* Get category by slug
|
|
1605
|
-
*/
|
|
1606
|
-
async getCategoryBySlug(slug) {
|
|
1607
|
-
return this.getSingle(`/categories/slug/${slug}`);
|
|
1557
|
+
async getCategories(siteName, params, cachePolicy) {
|
|
1558
|
+
const endpoint = this.siteScopedEndpoint(siteName, "/categories", { includeSitesSegment: false });
|
|
1559
|
+
const path = this.buildPath(endpoint);
|
|
1560
|
+
return this.fetchWithCache(
|
|
1561
|
+
endpoint,
|
|
1562
|
+
params,
|
|
1563
|
+
this.buildCategoryTags(siteName),
|
|
1564
|
+
cachePolicy,
|
|
1565
|
+
() => this.http.get(path, params)
|
|
1566
|
+
);
|
|
1608
1567
|
}
|
|
1609
1568
|
/**
|
|
1610
|
-
* Get
|
|
1569
|
+
* Get category by ID (validates it belongs to the site)
|
|
1611
1570
|
*/
|
|
1612
|
-
async
|
|
1613
|
-
const endpoint = this.siteScopedEndpoint(
|
|
1614
|
-
siteName,
|
|
1615
|
-
`/product_category/slug/${encodeURIComponent(slug)}`,
|
|
1616
|
-
{ includeSitesSegment: false }
|
|
1617
|
-
);
|
|
1571
|
+
async getCategoryById(siteName, id, cachePolicy) {
|
|
1572
|
+
const endpoint = this.siteScopedEndpoint(siteName, `/categories/${id}`, { includeSitesSegment: false });
|
|
1618
1573
|
const path = this.buildPath(endpoint);
|
|
1619
1574
|
return this.fetchWithCache(
|
|
1620
1575
|
endpoint,
|
|
1621
1576
|
void 0,
|
|
1622
|
-
this.buildCategoryTags(siteName,
|
|
1577
|
+
this.buildCategoryTags(siteName, `categories:id:${id}`),
|
|
1623
1578
|
cachePolicy,
|
|
1624
1579
|
() => this.http.get(path)
|
|
1625
1580
|
);
|
|
1626
1581
|
}
|
|
1627
1582
|
/**
|
|
1628
|
-
*
|
|
1583
|
+
* Get product categories for a site
|
|
1629
1584
|
*/
|
|
1630
|
-
async
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
* Delete category
|
|
1641
|
-
*/
|
|
1642
|
-
async deleteCategory(id) {
|
|
1643
|
-
return this.delete(`/categories/${id}`);
|
|
1644
|
-
}
|
|
1645
|
-
/**
|
|
1646
|
-
* Get category tree (hierarchical structure)
|
|
1647
|
-
*/
|
|
1648
|
-
async getCategoryTree(rootId) {
|
|
1649
|
-
const endpoint = rootId ? `/categories/tree/${rootId}` : "/categories/tree";
|
|
1650
|
-
return this.getSingle(endpoint);
|
|
1651
|
-
}
|
|
1652
|
-
/**
|
|
1653
|
-
* Get category children
|
|
1654
|
-
*/
|
|
1655
|
-
async getCategoryChildren(id) {
|
|
1656
|
-
return this.getSingle(`/categories/${id}/children`);
|
|
1657
|
-
}
|
|
1658
|
-
/**
|
|
1659
|
-
* Get category parent
|
|
1660
|
-
*/
|
|
1661
|
-
async getCategoryParent(id) {
|
|
1662
|
-
return this.getSingle(`/categories/${id}/parent`);
|
|
1585
|
+
async getProductCategories(siteName, params, cachePolicy) {
|
|
1586
|
+
const endpoint = this.siteScopedEndpoint(siteName, "/categories/product", { includeSitesSegment: false });
|
|
1587
|
+
const path = this.buildPath(endpoint);
|
|
1588
|
+
return this.fetchWithCache(
|
|
1589
|
+
endpoint,
|
|
1590
|
+
params,
|
|
1591
|
+
this.buildCategoryTags(siteName, "categories:product"),
|
|
1592
|
+
cachePolicy,
|
|
1593
|
+
() => this.http.get(path, params)
|
|
1594
|
+
);
|
|
1663
1595
|
}
|
|
1664
1596
|
/**
|
|
1665
|
-
*
|
|
1597
|
+
* Create new category for a site
|
|
1666
1598
|
*/
|
|
1667
|
-
async
|
|
1668
|
-
|
|
1599
|
+
async createCategory(siteName, data, csrfToken) {
|
|
1600
|
+
const endpoint = this.siteScopedEndpoint(siteName, "/categories", { includeSitesSegment: false });
|
|
1601
|
+
const path = this.buildPath(endpoint);
|
|
1602
|
+
const result = await this.http.post(path, data, { csrfToken });
|
|
1603
|
+
if (this.cache) {
|
|
1604
|
+
await this.cache.invalidate({ tags: this.buildCategoryTags(siteName) });
|
|
1605
|
+
}
|
|
1606
|
+
return result;
|
|
1669
1607
|
}
|
|
1670
1608
|
/**
|
|
1671
|
-
*
|
|
1609
|
+
* Create new product category for a site
|
|
1672
1610
|
*/
|
|
1673
|
-
async
|
|
1674
|
-
|
|
1611
|
+
async createProductCategory(siteName, data, csrfToken) {
|
|
1612
|
+
const endpoint = this.siteScopedEndpoint(siteName, "/categories/product", { includeSitesSegment: false });
|
|
1613
|
+
const path = this.buildPath(endpoint);
|
|
1614
|
+
const result = await this.http.post(path, data, { csrfToken });
|
|
1615
|
+
if (this.cache) {
|
|
1616
|
+
await this.cache.invalidate({ tags: this.buildCategoryTags(siteName, "categories:product") });
|
|
1617
|
+
}
|
|
1618
|
+
return result;
|
|
1675
1619
|
}
|
|
1676
1620
|
/**
|
|
1677
|
-
*
|
|
1621
|
+
* Update category (validates it belongs to the site)
|
|
1678
1622
|
*/
|
|
1679
|
-
async
|
|
1680
|
-
|
|
1623
|
+
async updateCategory(siteName, id, data, csrfToken) {
|
|
1624
|
+
const endpoint = this.siteScopedEndpoint(siteName, `/categories/${id}`, { includeSitesSegment: false });
|
|
1625
|
+
const path = this.buildPath(endpoint);
|
|
1626
|
+
const result = await this.http.put(path, data, { csrfToken });
|
|
1627
|
+
if (this.cache) {
|
|
1628
|
+
await this.cache.invalidate({ tags: this.buildCategoryTags(siteName, `categories:id:${id}`) });
|
|
1629
|
+
}
|
|
1630
|
+
return result;
|
|
1681
1631
|
}
|
|
1682
1632
|
/**
|
|
1683
|
-
*
|
|
1633
|
+
* Delete category (validates it belongs to the site)
|
|
1684
1634
|
*/
|
|
1685
|
-
async
|
|
1686
|
-
|
|
1635
|
+
async deleteCategory(siteName, id, csrfToken) {
|
|
1636
|
+
const endpoint = this.siteScopedEndpoint(siteName, `/categories/${id}`, { includeSitesSegment: false });
|
|
1637
|
+
const path = this.buildPath(endpoint);
|
|
1638
|
+
const result = await this.http.delete(path, { csrfToken });
|
|
1639
|
+
if (this.cache) {
|
|
1640
|
+
await this.cache.invalidate({ tags: this.buildCategoryTags(siteName) });
|
|
1641
|
+
}
|
|
1642
|
+
return result;
|
|
1687
1643
|
}
|
|
1688
1644
|
/**
|
|
1689
|
-
*
|
|
1645
|
+
* Associate pages or products with categories
|
|
1690
1646
|
*/
|
|
1691
|
-
async
|
|
1692
|
-
|
|
1647
|
+
async associateCategories(siteName, data, csrfToken) {
|
|
1648
|
+
const endpoint = this.siteScopedEndpoint(siteName, "/categories/associate", { includeSitesSegment: false });
|
|
1649
|
+
const path = this.buildPath(endpoint);
|
|
1650
|
+
const result = await this.http.post(path, data, { csrfToken });
|
|
1651
|
+
if (this.cache) {
|
|
1652
|
+
await this.cache.invalidate({ tags: this.buildCategoryTags(siteName) });
|
|
1653
|
+
}
|
|
1654
|
+
return result;
|
|
1693
1655
|
}
|
|
1694
|
-
buildCategoryTags(siteName,
|
|
1656
|
+
buildCategoryTags(siteName, extraTag) {
|
|
1695
1657
|
const tags = /* @__PURE__ */ new Set(["categories"]);
|
|
1696
1658
|
if (siteName) {
|
|
1697
1659
|
tags.add(`categories:site:${siteName}`);
|
|
1698
1660
|
}
|
|
1699
|
-
if (
|
|
1700
|
-
tags.add(
|
|
1661
|
+
if (extraTag) {
|
|
1662
|
+
tags.add(extraTag);
|
|
1701
1663
|
}
|
|
1702
1664
|
return Array.from(tags.values());
|
|
1703
1665
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -654,43 +654,6 @@ var AuthClient = class extends BaseClient {
|
|
|
654
654
|
async getCsrfToken() {
|
|
655
655
|
return this.http.get(this.buildPath("/csrf"));
|
|
656
656
|
}
|
|
657
|
-
/**
|
|
658
|
-
* Sign up a new user
|
|
659
|
-
*/
|
|
660
|
-
async signUp(data) {
|
|
661
|
-
return this.create("/signup", data);
|
|
662
|
-
}
|
|
663
|
-
/**
|
|
664
|
-
* Sign in user
|
|
665
|
-
*/
|
|
666
|
-
async signIn(data) {
|
|
667
|
-
const response = await this.create("/authenticate", data);
|
|
668
|
-
if (response.data && "token" in response.data && response.data.token) {
|
|
669
|
-
this.http.setAuth(response.data.token);
|
|
670
|
-
}
|
|
671
|
-
return response;
|
|
672
|
-
}
|
|
673
|
-
/**
|
|
674
|
-
* Activate user account
|
|
675
|
-
*/
|
|
676
|
-
async activateAccount(activationKey) {
|
|
677
|
-
return this.getSingle(`/activate/${activationKey}`);
|
|
678
|
-
}
|
|
679
|
-
/**
|
|
680
|
-
* Request password reset
|
|
681
|
-
*/
|
|
682
|
-
async forgotPassword(email) {
|
|
683
|
-
return this.create("/forgotpassword", { email });
|
|
684
|
-
}
|
|
685
|
-
/**
|
|
686
|
-
* Reset password with token
|
|
687
|
-
*/
|
|
688
|
-
async resetPassword(resetToken, password) {
|
|
689
|
-
return this.create(
|
|
690
|
-
`/passwordreset/${resetToken}`,
|
|
691
|
-
{ password }
|
|
692
|
-
);
|
|
693
|
-
}
|
|
694
657
|
/**
|
|
695
658
|
* Get current user profile
|
|
696
659
|
*/
|
|
@@ -1527,115 +1490,114 @@ var CategoriesClient = class extends BaseClient {
|
|
|
1527
1490
|
super(http, "/api/v1", cache);
|
|
1528
1491
|
}
|
|
1529
1492
|
/**
|
|
1530
|
-
* Get all categories
|
|
1493
|
+
* Get all categories for a site
|
|
1531
1494
|
*/
|
|
1532
|
-
async getCategories(params) {
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
* Get category by slug
|
|
1543
|
-
*/
|
|
1544
|
-
async getCategoryBySlug(slug) {
|
|
1545
|
-
return this.getSingle(`/categories/slug/${slug}`);
|
|
1495
|
+
async getCategories(siteName, params, cachePolicy) {
|
|
1496
|
+
const endpoint = this.siteScopedEndpoint(siteName, "/categories", { includeSitesSegment: false });
|
|
1497
|
+
const path = this.buildPath(endpoint);
|
|
1498
|
+
return this.fetchWithCache(
|
|
1499
|
+
endpoint,
|
|
1500
|
+
params,
|
|
1501
|
+
this.buildCategoryTags(siteName),
|
|
1502
|
+
cachePolicy,
|
|
1503
|
+
() => this.http.get(path, params)
|
|
1504
|
+
);
|
|
1546
1505
|
}
|
|
1547
1506
|
/**
|
|
1548
|
-
* Get
|
|
1507
|
+
* Get category by ID (validates it belongs to the site)
|
|
1549
1508
|
*/
|
|
1550
|
-
async
|
|
1551
|
-
const endpoint = this.siteScopedEndpoint(
|
|
1552
|
-
siteName,
|
|
1553
|
-
`/product_category/slug/${encodeURIComponent(slug)}`,
|
|
1554
|
-
{ includeSitesSegment: false }
|
|
1555
|
-
);
|
|
1509
|
+
async getCategoryById(siteName, id, cachePolicy) {
|
|
1510
|
+
const endpoint = this.siteScopedEndpoint(siteName, `/categories/${id}`, { includeSitesSegment: false });
|
|
1556
1511
|
const path = this.buildPath(endpoint);
|
|
1557
1512
|
return this.fetchWithCache(
|
|
1558
1513
|
endpoint,
|
|
1559
1514
|
void 0,
|
|
1560
|
-
this.buildCategoryTags(siteName,
|
|
1515
|
+
this.buildCategoryTags(siteName, `categories:id:${id}`),
|
|
1561
1516
|
cachePolicy,
|
|
1562
1517
|
() => this.http.get(path)
|
|
1563
1518
|
);
|
|
1564
1519
|
}
|
|
1565
1520
|
/**
|
|
1566
|
-
*
|
|
1521
|
+
* Get product categories for a site
|
|
1567
1522
|
*/
|
|
1568
|
-
async
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
* Delete category
|
|
1579
|
-
*/
|
|
1580
|
-
async deleteCategory(id) {
|
|
1581
|
-
return this.delete(`/categories/${id}`);
|
|
1582
|
-
}
|
|
1583
|
-
/**
|
|
1584
|
-
* Get category tree (hierarchical structure)
|
|
1585
|
-
*/
|
|
1586
|
-
async getCategoryTree(rootId) {
|
|
1587
|
-
const endpoint = rootId ? `/categories/tree/${rootId}` : "/categories/tree";
|
|
1588
|
-
return this.getSingle(endpoint);
|
|
1589
|
-
}
|
|
1590
|
-
/**
|
|
1591
|
-
* Get category children
|
|
1592
|
-
*/
|
|
1593
|
-
async getCategoryChildren(id) {
|
|
1594
|
-
return this.getSingle(`/categories/${id}/children`);
|
|
1595
|
-
}
|
|
1596
|
-
/**
|
|
1597
|
-
* Get category parent
|
|
1598
|
-
*/
|
|
1599
|
-
async getCategoryParent(id) {
|
|
1600
|
-
return this.getSingle(`/categories/${id}/parent`);
|
|
1523
|
+
async getProductCategories(siteName, params, cachePolicy) {
|
|
1524
|
+
const endpoint = this.siteScopedEndpoint(siteName, "/categories/product", { includeSitesSegment: false });
|
|
1525
|
+
const path = this.buildPath(endpoint);
|
|
1526
|
+
return this.fetchWithCache(
|
|
1527
|
+
endpoint,
|
|
1528
|
+
params,
|
|
1529
|
+
this.buildCategoryTags(siteName, "categories:product"),
|
|
1530
|
+
cachePolicy,
|
|
1531
|
+
() => this.http.get(path, params)
|
|
1532
|
+
);
|
|
1601
1533
|
}
|
|
1602
1534
|
/**
|
|
1603
|
-
*
|
|
1535
|
+
* Create new category for a site
|
|
1604
1536
|
*/
|
|
1605
|
-
async
|
|
1606
|
-
|
|
1537
|
+
async createCategory(siteName, data, csrfToken) {
|
|
1538
|
+
const endpoint = this.siteScopedEndpoint(siteName, "/categories", { includeSitesSegment: false });
|
|
1539
|
+
const path = this.buildPath(endpoint);
|
|
1540
|
+
const result = await this.http.post(path, data, { csrfToken });
|
|
1541
|
+
if (this.cache) {
|
|
1542
|
+
await this.cache.invalidate({ tags: this.buildCategoryTags(siteName) });
|
|
1543
|
+
}
|
|
1544
|
+
return result;
|
|
1607
1545
|
}
|
|
1608
1546
|
/**
|
|
1609
|
-
*
|
|
1547
|
+
* Create new product category for a site
|
|
1610
1548
|
*/
|
|
1611
|
-
async
|
|
1612
|
-
|
|
1549
|
+
async createProductCategory(siteName, data, csrfToken) {
|
|
1550
|
+
const endpoint = this.siteScopedEndpoint(siteName, "/categories/product", { includeSitesSegment: false });
|
|
1551
|
+
const path = this.buildPath(endpoint);
|
|
1552
|
+
const result = await this.http.post(path, data, { csrfToken });
|
|
1553
|
+
if (this.cache) {
|
|
1554
|
+
await this.cache.invalidate({ tags: this.buildCategoryTags(siteName, "categories:product") });
|
|
1555
|
+
}
|
|
1556
|
+
return result;
|
|
1613
1557
|
}
|
|
1614
1558
|
/**
|
|
1615
|
-
*
|
|
1559
|
+
* Update category (validates it belongs to the site)
|
|
1616
1560
|
*/
|
|
1617
|
-
async
|
|
1618
|
-
|
|
1561
|
+
async updateCategory(siteName, id, data, csrfToken) {
|
|
1562
|
+
const endpoint = this.siteScopedEndpoint(siteName, `/categories/${id}`, { includeSitesSegment: false });
|
|
1563
|
+
const path = this.buildPath(endpoint);
|
|
1564
|
+
const result = await this.http.put(path, data, { csrfToken });
|
|
1565
|
+
if (this.cache) {
|
|
1566
|
+
await this.cache.invalidate({ tags: this.buildCategoryTags(siteName, `categories:id:${id}`) });
|
|
1567
|
+
}
|
|
1568
|
+
return result;
|
|
1619
1569
|
}
|
|
1620
1570
|
/**
|
|
1621
|
-
*
|
|
1571
|
+
* Delete category (validates it belongs to the site)
|
|
1622
1572
|
*/
|
|
1623
|
-
async
|
|
1624
|
-
|
|
1573
|
+
async deleteCategory(siteName, id, csrfToken) {
|
|
1574
|
+
const endpoint = this.siteScopedEndpoint(siteName, `/categories/${id}`, { includeSitesSegment: false });
|
|
1575
|
+
const path = this.buildPath(endpoint);
|
|
1576
|
+
const result = await this.http.delete(path, { csrfToken });
|
|
1577
|
+
if (this.cache) {
|
|
1578
|
+
await this.cache.invalidate({ tags: this.buildCategoryTags(siteName) });
|
|
1579
|
+
}
|
|
1580
|
+
return result;
|
|
1625
1581
|
}
|
|
1626
1582
|
/**
|
|
1627
|
-
*
|
|
1583
|
+
* Associate pages or products with categories
|
|
1628
1584
|
*/
|
|
1629
|
-
async
|
|
1630
|
-
|
|
1585
|
+
async associateCategories(siteName, data, csrfToken) {
|
|
1586
|
+
const endpoint = this.siteScopedEndpoint(siteName, "/categories/associate", { includeSitesSegment: false });
|
|
1587
|
+
const path = this.buildPath(endpoint);
|
|
1588
|
+
const result = await this.http.post(path, data, { csrfToken });
|
|
1589
|
+
if (this.cache) {
|
|
1590
|
+
await this.cache.invalidate({ tags: this.buildCategoryTags(siteName) });
|
|
1591
|
+
}
|
|
1592
|
+
return result;
|
|
1631
1593
|
}
|
|
1632
|
-
buildCategoryTags(siteName,
|
|
1594
|
+
buildCategoryTags(siteName, extraTag) {
|
|
1633
1595
|
const tags = /* @__PURE__ */ new Set(["categories"]);
|
|
1634
1596
|
if (siteName) {
|
|
1635
1597
|
tags.add(`categories:site:${siteName}`);
|
|
1636
1598
|
}
|
|
1637
|
-
if (
|
|
1638
|
-
tags.add(
|
|
1599
|
+
if (extraTag) {
|
|
1600
|
+
tags.add(extraTag);
|
|
1639
1601
|
}
|
|
1640
1602
|
return Array.from(tags.values());
|
|
1641
1603
|
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Authentication client for PerspectAPI SDK
|
|
3
|
+
*
|
|
4
|
+
* Admin and site user authentication is OTP-based.
|
|
5
|
+
* Site user OTP methods are on SiteUsersClient.
|
|
3
6
|
*/
|
|
4
7
|
|
|
5
8
|
import { BaseClient } from './base-client';
|
|
6
9
|
import type { CacheManager } from '../cache/cache-manager';
|
|
7
10
|
import type {
|
|
8
|
-
SignUpRequest,
|
|
9
|
-
SignInRequest,
|
|
10
|
-
AuthResponse,
|
|
11
11
|
User,
|
|
12
12
|
ApiResponse,
|
|
13
13
|
} from '../types';
|
|
@@ -24,54 +24,6 @@ export class AuthClient extends BaseClient {
|
|
|
24
24
|
return this.http.get<{ token: string }>(this.buildPath('/csrf'));
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
/**
|
|
28
|
-
* Sign up a new user
|
|
29
|
-
*/
|
|
30
|
-
async signUp(data: SignUpRequest): Promise<ApiResponse<{ message: string; userId: string }>> {
|
|
31
|
-
return this.create<SignUpRequest, { message: string; userId: string }>('/signup', data);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Sign in user
|
|
36
|
-
*/
|
|
37
|
-
async signIn(data: SignInRequest): Promise<ApiResponse<AuthResponse>> {
|
|
38
|
-
const response = await this.create<SignInRequest, AuthResponse>('/authenticate', data);
|
|
39
|
-
|
|
40
|
-
// Update HTTP client with JWT if provided
|
|
41
|
-
if (response.data && 'token' in response.data && response.data.token) {
|
|
42
|
-
this.http.setAuth(response.data.token);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return response;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Activate user account
|
|
50
|
-
*/
|
|
51
|
-
async activateAccount(activationKey: string): Promise<ApiResponse<{ message: string }>> {
|
|
52
|
-
return this.getSingle<{ message: string }>(`/activate/${activationKey}`);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Request password reset
|
|
57
|
-
*/
|
|
58
|
-
async forgotPassword(email: string): Promise<ApiResponse<{ message: string }>> {
|
|
59
|
-
return this.create<{ email: string }, { message: string }>('/forgotpassword', { email });
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Reset password with token
|
|
64
|
-
*/
|
|
65
|
-
async resetPassword(
|
|
66
|
-
resetToken: string,
|
|
67
|
-
password: string
|
|
68
|
-
): Promise<ApiResponse<{ message: string }>> {
|
|
69
|
-
return this.create<{ password: string }, { message: string }>(
|
|
70
|
-
`/passwordreset/${resetToken}`,
|
|
71
|
-
{ password }
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
27
|
/**
|
|
76
28
|
* Get current user profile
|
|
77
29
|
*/
|