@fonderie/client 0.24.0 → 0.26.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.
@@ -226,6 +226,7 @@ new BillingClient(http: HttpClient, tokens: TokenStore): BillingClient
226
226
  interface IConfigAdminClientOptions {
227
227
  baseUrl: string;
228
228
  adminToken: string;
229
+ prefix?: string;
229
230
  actor?: string;
230
231
  }
231
232
 
@@ -283,9 +284,31 @@ new AdminClient(opts: IAdminClientOptions): AdminClient
283
284
  .tokens(): Promise<IApiResponse<IAdminTokensReport>>
284
285
  .adminLog(query?: IAdminLogQuery): Promise<IApiResponse<IAdminLogPage>>
285
286
 
287
+ interface IAuthAdminClientOptions {
288
+ baseUrl: string;
289
+ adminToken: string;
290
+ prefix?: string;
291
+ actor?: string;
292
+ }
293
+
294
+ interface IAdminLoginHistoryQuery {
295
+ limit?: number;
296
+ cursor?: string;
297
+ }
298
+
299
+ new AuthAdminClient(opts: IAuthAdminClientOptions): AuthAdminClient
300
+ .findUser(email: string): Promise<IApiResponse<IAdminUserDTO>>
301
+ .getUser(id: string): Promise<IApiResponse<IAdminUserDTO>>
302
+ .listUserSessions(id: string): Promise<IApiResponse<ISessionDTO[]>>
303
+ .revokeUserSessions(id: string): Promise<IApiResponse<undefined>>
304
+ .userLoginHistory(id: string, query?: IAdminLoginHistoryQuery): Promise<IApiResponse<ILoginHistoryPageResult>>
305
+ .suspendUser(id: string): Promise<IApiResponse<IAdminUserDTO>>
306
+ .unsuspendUser(id: string): Promise<IApiResponse<IAdminUserDTO>>
307
+
286
308
  interface ICourierAdminClientOptions {
287
309
  baseUrl: string;
288
310
  adminToken: string;
311
+ prefix?: string;
289
312
  actor?: string;
290
313
  }
291
314
 
@@ -736,6 +759,10 @@ interface IAdminTokensReport {
736
759
  }>;
737
760
  }
738
761
 
762
+ interface IAdminUserDTO extends IUserDTO {
763
+ deletedAt: string | null;
764
+ }
765
+
739
766
  interface IConfigEntry {
740
767
  key: string;
741
768
  value: unknown;
package/dist/index.cjs CHANGED
@@ -22,6 +22,7 @@ var index_exports = {};
22
22
  __export(index_exports, {
23
23
  AdminClient: () => AdminClient,
24
24
  AuditClient: () => AuditClient,
25
+ AuthAdminClient: () => AuthAdminClient,
25
26
  AuthClient: () => AuthClient,
26
27
  BillingClient: () => BillingClient,
27
28
  ConfigAdminClient: () => ConfigAdminClient,
@@ -1590,116 +1591,150 @@ function envQuery(environment) {
1590
1591
  var ConfigAdminClient = class {
1591
1592
  http;
1592
1593
  adminToken;
1594
+ prefix;
1593
1595
  actorHeaders;
1594
1596
  constructor(opts) {
1595
1597
  this.http = new HttpClient(opts.baseUrl);
1596
1598
  this.adminToken = opts.adminToken;
1599
+ this.prefix = opts.prefix?.replace(/\/+$/, "");
1597
1600
  this.actorHeaders = opts.actor ? { "X-Actor": opts.actor } : void 0;
1598
1601
  }
1602
+ // The path literals stay on the legacy '/admin/...' so the route table and
1603
+ // the coverage gate read them; the prefix is applied here at request time.
1604
+ rebase(opts) {
1605
+ if (!this.prefix) return opts;
1606
+ return { ...opts, path: opts.path.replace(/^\/admin(?=\/|\?|$)/, this.prefix) };
1607
+ }
1599
1608
  // ── Config ───────────────────────────────────────────────────────────────
1600
1609
  listConfig(environment) {
1601
- return this.http.request({
1602
- method: "GET",
1603
- path: `/admin/config${envQuery(environment)}`,
1604
- token: this.adminToken
1605
- });
1610
+ return this.http.request(
1611
+ this.rebase({
1612
+ method: "GET",
1613
+ path: `/admin/config${envQuery(environment)}`,
1614
+ token: this.adminToken
1615
+ })
1616
+ );
1606
1617
  }
1607
1618
  getConfig(key, environment) {
1608
- return this.http.request({
1609
- method: "GET",
1610
- path: `/admin/config/${encodeURIComponent(key)}${envQuery(environment)}`,
1611
- token: this.adminToken
1612
- });
1619
+ return this.http.request(
1620
+ this.rebase({
1621
+ method: "GET",
1622
+ path: `/admin/config/${encodeURIComponent(key)}${envQuery(environment)}`,
1623
+ token: this.adminToken
1624
+ })
1625
+ );
1613
1626
  }
1614
1627
  setConfig(key, input, environment) {
1615
- return this.http.request({
1616
- method: "PUT",
1617
- path: `/admin/config/${encodeURIComponent(key)}${envQuery(environment)}`,
1618
- body: input,
1619
- token: this.adminToken,
1620
- headers: this.actorHeaders
1621
- });
1628
+ return this.http.request(
1629
+ this.rebase({
1630
+ method: "PUT",
1631
+ path: `/admin/config/${encodeURIComponent(key)}${envQuery(environment)}`,
1632
+ body: input,
1633
+ token: this.adminToken,
1634
+ headers: this.actorHeaders
1635
+ })
1636
+ );
1622
1637
  }
1623
1638
  deleteConfig(key, environment) {
1624
- return this.http.request({
1625
- method: "DELETE",
1626
- path: `/admin/config/${encodeURIComponent(key)}${envQuery(environment)}`,
1627
- token: this.adminToken,
1628
- headers: this.actorHeaders
1629
- });
1639
+ return this.http.request(
1640
+ this.rebase({
1641
+ method: "DELETE",
1642
+ path: `/admin/config/${encodeURIComponent(key)}${envQuery(environment)}`,
1643
+ token: this.adminToken,
1644
+ headers: this.actorHeaders
1645
+ })
1646
+ );
1630
1647
  }
1631
1648
  listConfigRevisions(key, environment) {
1632
- return this.http.request({
1633
- method: "GET",
1634
- path: `/admin/config/${encodeURIComponent(key)}/revisions${envQuery(environment)}`,
1635
- token: this.adminToken
1636
- });
1649
+ return this.http.request(
1650
+ this.rebase({
1651
+ method: "GET",
1652
+ path: `/admin/config/${encodeURIComponent(key)}/revisions${envQuery(environment)}`,
1653
+ token: this.adminToken
1654
+ })
1655
+ );
1637
1656
  }
1638
1657
  rollbackConfig(key, input, environment) {
1639
- return this.http.request({
1640
- method: "POST",
1641
- path: `/admin/config/${encodeURIComponent(key)}/rollback${envQuery(environment)}`,
1642
- body: input,
1643
- token: this.adminToken,
1644
- headers: this.actorHeaders
1645
- });
1658
+ return this.http.request(
1659
+ this.rebase({
1660
+ method: "POST",
1661
+ path: `/admin/config/${encodeURIComponent(key)}/rollback${envQuery(environment)}`,
1662
+ body: input,
1663
+ token: this.adminToken,
1664
+ headers: this.actorHeaders
1665
+ })
1666
+ );
1646
1667
  }
1647
1668
  // ── Secrets (masked) ─────────────────────────────────────────────────────
1648
1669
  listSecrets(environment) {
1649
- return this.http.request({
1650
- method: "GET",
1651
- path: `/admin/secrets${envQuery(environment)}`,
1652
- token: this.adminToken
1653
- });
1670
+ return this.http.request(
1671
+ this.rebase({
1672
+ method: "GET",
1673
+ path: `/admin/secrets${envQuery(environment)}`,
1674
+ token: this.adminToken
1675
+ })
1676
+ );
1654
1677
  }
1655
1678
  getSecret(key, environment) {
1656
- return this.http.request({
1657
- method: "GET",
1658
- path: `/admin/secrets/${encodeURIComponent(key)}${envQuery(environment)}`,
1659
- token: this.adminToken
1660
- });
1679
+ return this.http.request(
1680
+ this.rebase({
1681
+ method: "GET",
1682
+ path: `/admin/secrets/${encodeURIComponent(key)}${envQuery(environment)}`,
1683
+ token: this.adminToken
1684
+ })
1685
+ );
1661
1686
  }
1662
1687
  setSecret(key, input, environment) {
1663
- return this.http.request({
1664
- method: "PUT",
1665
- path: `/admin/secrets/${encodeURIComponent(key)}${envQuery(environment)}`,
1666
- body: input,
1667
- token: this.adminToken,
1668
- headers: this.actorHeaders
1669
- });
1688
+ return this.http.request(
1689
+ this.rebase({
1690
+ method: "PUT",
1691
+ path: `/admin/secrets/${encodeURIComponent(key)}${envQuery(environment)}`,
1692
+ body: input,
1693
+ token: this.adminToken,
1694
+ headers: this.actorHeaders
1695
+ })
1696
+ );
1670
1697
  }
1671
1698
  deleteSecret(key, environment) {
1672
- return this.http.request({
1673
- method: "DELETE",
1674
- path: `/admin/secrets/${encodeURIComponent(key)}${envQuery(environment)}`,
1675
- token: this.adminToken,
1676
- headers: this.actorHeaders
1677
- });
1699
+ return this.http.request(
1700
+ this.rebase({
1701
+ method: "DELETE",
1702
+ path: `/admin/secrets/${encodeURIComponent(key)}${envQuery(environment)}`,
1703
+ token: this.adminToken,
1704
+ headers: this.actorHeaders
1705
+ })
1706
+ );
1678
1707
  }
1679
1708
  listSecretRevisions(key, environment) {
1680
- return this.http.request({
1681
- method: "GET",
1682
- path: `/admin/secrets/${encodeURIComponent(key)}/revisions${envQuery(environment)}`,
1683
- token: this.adminToken
1684
- });
1709
+ return this.http.request(
1710
+ this.rebase({
1711
+ method: "GET",
1712
+ path: `/admin/secrets/${encodeURIComponent(key)}/revisions${envQuery(environment)}`,
1713
+ token: this.adminToken
1714
+ })
1715
+ );
1685
1716
  }
1686
1717
  rollbackSecret(key, input, environment) {
1687
- return this.http.request({
1688
- method: "POST",
1689
- path: `/admin/secrets/${encodeURIComponent(key)}/rollback${envQuery(environment)}`,
1690
- body: input,
1691
- token: this.adminToken,
1692
- headers: this.actorHeaders
1693
- });
1718
+ return this.http.request(
1719
+ this.rebase({
1720
+ method: "POST",
1721
+ path: `/admin/secrets/${encodeURIComponent(key)}/rollback${envQuery(environment)}`,
1722
+ body: input,
1723
+ token: this.adminToken,
1724
+ headers: this.actorHeaders
1725
+ })
1726
+ );
1694
1727
  }
1695
1728
  // POST (not GET) so the decrypted value never lands in a URL or access log.
1696
1729
  revealSecret(key, environment) {
1697
- return this.http.request({
1698
- method: "POST",
1699
- path: `/admin/secrets/${encodeURIComponent(key)}/reveal${envQuery(environment)}`,
1700
- token: this.adminToken,
1701
- headers: this.actorHeaders
1702
- });
1730
+ return this.http.request(
1731
+ this.rebase({
1732
+ method: "POST",
1733
+ path: `/admin/secrets/${encodeURIComponent(key)}/reveal${envQuery(environment)}`,
1734
+ token: this.adminToken,
1735
+ headers: this.actorHeaders
1736
+ })
1737
+ );
1703
1738
  }
1704
1739
  };
1705
1740
 
@@ -1750,67 +1785,138 @@ var AdminClient = class {
1750
1785
  }
1751
1786
  };
1752
1787
 
1788
+ // src/modules/auth-admin.ts
1789
+ var AuthAdminClient = class {
1790
+ http;
1791
+ adminToken;
1792
+ prefix;
1793
+ actorHeaders;
1794
+ constructor(opts) {
1795
+ this.http = new HttpClient(opts.baseUrl);
1796
+ this.adminToken = opts.adminToken;
1797
+ this.prefix = (opts.prefix ?? "/_admin").replace(/\/+$/, "");
1798
+ this.actorHeaders = opts.actor ? { "X-Actor": opts.actor } : void 0;
1799
+ }
1800
+ call(method, suffix) {
1801
+ return this.http.request({
1802
+ method,
1803
+ path: `${this.prefix}/users${suffix}`,
1804
+ token: this.adminToken,
1805
+ headers: this.actorHeaders
1806
+ });
1807
+ }
1808
+ findUser(email) {
1809
+ return this.call("GET", `?email=${encodeURIComponent(email)}`);
1810
+ }
1811
+ getUser(id) {
1812
+ return this.call("GET", `/${encodeURIComponent(id)}`);
1813
+ }
1814
+ listUserSessions(id) {
1815
+ return this.call("GET", `/${encodeURIComponent(id)}/sessions`);
1816
+ }
1817
+ // Signs the user out everywhere.
1818
+ revokeUserSessions(id) {
1819
+ return this.call("DELETE", `/${encodeURIComponent(id)}/sessions`);
1820
+ }
1821
+ userLoginHistory(id, query = {}) {
1822
+ const q = new URLSearchParams();
1823
+ if (query.limit) q.set("limit", String(query.limit));
1824
+ if (query.cursor) q.set("cursor", query.cursor);
1825
+ const qs = q.toString();
1826
+ return this.call(
1827
+ "GET",
1828
+ `/${encodeURIComponent(id)}/login-history${qs ? `?${qs}` : ""}`
1829
+ );
1830
+ }
1831
+ suspendUser(id) {
1832
+ return this.call("POST", `/${encodeURIComponent(id)}/suspend`);
1833
+ }
1834
+ unsuspendUser(id) {
1835
+ return this.call("POST", `/${encodeURIComponent(id)}/unsuspend`);
1836
+ }
1837
+ };
1838
+
1753
1839
  // src/modules/courier-admin.ts
1754
1840
  var CourierAdminClient = class {
1755
1841
  http;
1756
1842
  adminToken;
1843
+ prefix;
1757
1844
  actorHeaders;
1758
1845
  constructor(opts) {
1759
1846
  this.http = new HttpClient(opts.baseUrl);
1760
1847
  this.adminToken = opts.adminToken;
1848
+ this.prefix = opts.prefix?.replace(/\/+$/, "");
1761
1849
  this.actorHeaders = opts.actor ? { "X-Actor": opts.actor } : void 0;
1762
1850
  }
1851
+ // The path literals stay on the legacy '/admin/...' so the route table and
1852
+ // the coverage gate read them; the prefix is applied here at request time.
1853
+ rebase(opts) {
1854
+ if (!this.prefix) return opts;
1855
+ return { ...opts, path: opts.path.replace(/^\/admin(?=\/|\?|$)/, this.prefix) };
1856
+ }
1763
1857
  listTemplates() {
1764
- return this.http.request({
1765
- method: "GET",
1766
- path: "/admin/templates",
1767
- token: this.adminToken
1768
- });
1858
+ return this.http.request(
1859
+ this.rebase({
1860
+ method: "GET",
1861
+ path: "/admin/templates",
1862
+ token: this.adminToken
1863
+ })
1864
+ );
1769
1865
  }
1770
1866
  getTemplate(type, locale) {
1771
1867
  const q = locale ? `?locale=${encodeURIComponent(locale)}` : "";
1772
- return this.http.request({
1773
- method: "GET",
1774
- path: `/admin/templates/${encodeURIComponent(type)}${q}`,
1775
- token: this.adminToken
1776
- });
1868
+ return this.http.request(
1869
+ this.rebase({
1870
+ method: "GET",
1871
+ path: `/admin/templates/${encodeURIComponent(type)}${q}`,
1872
+ token: this.adminToken
1873
+ })
1874
+ );
1777
1875
  }
1778
1876
  setTemplate(type, input, locale) {
1779
1877
  const q = locale ? `?locale=${encodeURIComponent(locale)}` : "";
1780
- return this.http.request({
1781
- method: "PUT",
1782
- path: `/admin/templates/${encodeURIComponent(type)}${q}`,
1783
- body: input,
1784
- token: this.adminToken,
1785
- headers: this.actorHeaders
1786
- });
1878
+ return this.http.request(
1879
+ this.rebase({
1880
+ method: "PUT",
1881
+ path: `/admin/templates/${encodeURIComponent(type)}${q}`,
1882
+ body: input,
1883
+ token: this.adminToken,
1884
+ headers: this.actorHeaders
1885
+ })
1886
+ );
1787
1887
  }
1788
1888
  deleteTemplate(type, locale) {
1789
1889
  const q = locale ? `?locale=${encodeURIComponent(locale)}` : "";
1790
- return this.http.request({
1791
- method: "DELETE",
1792
- path: `/admin/templates/${encodeURIComponent(type)}${q}`,
1793
- token: this.adminToken,
1794
- headers: this.actorHeaders
1795
- });
1890
+ return this.http.request(
1891
+ this.rebase({
1892
+ method: "DELETE",
1893
+ path: `/admin/templates/${encodeURIComponent(type)}${q}`,
1894
+ token: this.adminToken,
1895
+ headers: this.actorHeaders
1896
+ })
1897
+ );
1796
1898
  }
1797
1899
  listRevisions(type, locale) {
1798
1900
  const q = locale ? `?locale=${encodeURIComponent(locale)}` : "";
1799
- return this.http.request({
1800
- method: "GET",
1801
- path: `/admin/templates/${encodeURIComponent(type)}/revisions${q}`,
1802
- token: this.adminToken
1803
- });
1901
+ return this.http.request(
1902
+ this.rebase({
1903
+ method: "GET",
1904
+ path: `/admin/templates/${encodeURIComponent(type)}/revisions${q}`,
1905
+ token: this.adminToken
1906
+ })
1907
+ );
1804
1908
  }
1805
1909
  rollback(type, input, locale) {
1806
1910
  const q = locale ? `?locale=${encodeURIComponent(locale)}` : "";
1807
- return this.http.request({
1808
- method: "POST",
1809
- path: `/admin/templates/${encodeURIComponent(type)}/rollback${q}`,
1810
- body: input,
1811
- token: this.adminToken,
1812
- headers: this.actorHeaders
1813
- });
1911
+ return this.http.request(
1912
+ this.rebase({
1913
+ method: "POST",
1914
+ path: `/admin/templates/${encodeURIComponent(type)}/rollback${q}`,
1915
+ body: input,
1916
+ token: this.adminToken,
1917
+ headers: this.actorHeaders
1918
+ })
1919
+ );
1814
1920
  }
1815
1921
  };
1816
1922
 
@@ -1822,6 +1928,7 @@ function isMfaRequired(result) {
1822
1928
  0 && (module.exports = {
1823
1929
  AdminClient,
1824
1930
  AuditClient,
1931
+ AuthAdminClient,
1825
1932
  AuthClient,
1826
1933
  BillingClient,
1827
1934
  ConfigAdminClient,