@stack0/sdk 0.5.2 → 0.5.3

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.js CHANGED
@@ -1602,6 +1602,224 @@ var CDN = class {
1602
1602
  }
1603
1603
  return bundle;
1604
1604
  }
1605
+ // ============================================================================
1606
+ // Usage Methods
1607
+ // ============================================================================
1608
+ /**
1609
+ * Get current usage stats for the billing period
1610
+ *
1611
+ * @example
1612
+ * ```typescript
1613
+ * const usage = await cdn.getUsage({
1614
+ * projectSlug: 'my-project',
1615
+ * });
1616
+ * console.log(`Bandwidth: ${usage.bandwidthFormatted}`);
1617
+ * console.log(`Estimated cost: ${usage.estimatedCostFormatted}`);
1618
+ * ```
1619
+ */
1620
+ async getUsage(request = {}) {
1621
+ const params = new URLSearchParams();
1622
+ if (request.projectSlug) params.set("projectSlug", request.projectSlug);
1623
+ if (request.environment) params.set("environment", request.environment);
1624
+ if (request.periodStart) {
1625
+ const date = request.periodStart instanceof Date ? request.periodStart.toISOString() : request.periodStart;
1626
+ params.set("periodStart", date);
1627
+ }
1628
+ if (request.periodEnd) {
1629
+ const date = request.periodEnd instanceof Date ? request.periodEnd.toISOString() : request.periodEnd;
1630
+ params.set("periodEnd", date);
1631
+ }
1632
+ const query = params.toString();
1633
+ const response = await this.http.get(`/cdn/usage${query ? `?${query}` : ""}`);
1634
+ return this.convertUsageDates(response);
1635
+ }
1636
+ /**
1637
+ * Get usage history (time series data for charts)
1638
+ *
1639
+ * @example
1640
+ * ```typescript
1641
+ * const history = await cdn.getUsageHistory({
1642
+ * projectSlug: 'my-project',
1643
+ * days: 30,
1644
+ * });
1645
+ * console.log(`Total requests: ${history.totals.requests}`);
1646
+ * ```
1647
+ */
1648
+ async getUsageHistory(request = {}) {
1649
+ const params = new URLSearchParams();
1650
+ if (request.projectSlug) params.set("projectSlug", request.projectSlug);
1651
+ if (request.environment) params.set("environment", request.environment);
1652
+ if (request.days) params.set("days", request.days.toString());
1653
+ if (request.granularity) params.set("granularity", request.granularity);
1654
+ const query = params.toString();
1655
+ const response = await this.http.get(`/cdn/usage/history${query ? `?${query}` : ""}`);
1656
+ return {
1657
+ ...response,
1658
+ data: response.data.map((point) => this.convertUsageDataPointDates(point))
1659
+ };
1660
+ }
1661
+ /**
1662
+ * Get storage breakdown by type or folder
1663
+ *
1664
+ * @example
1665
+ * ```typescript
1666
+ * const breakdown = await cdn.getStorageBreakdown({
1667
+ * projectSlug: 'my-project',
1668
+ * groupBy: 'type',
1669
+ * });
1670
+ * breakdown.items.forEach(item => {
1671
+ * console.log(`${item.key}: ${item.sizeFormatted} (${item.percentage}%)`);
1672
+ * });
1673
+ * ```
1674
+ */
1675
+ async getStorageBreakdown(request = {}) {
1676
+ const params = new URLSearchParams();
1677
+ if (request.projectSlug) params.set("projectSlug", request.projectSlug);
1678
+ if (request.environment) params.set("environment", request.environment);
1679
+ if (request.groupBy) params.set("groupBy", request.groupBy);
1680
+ const query = params.toString();
1681
+ return this.http.get(`/cdn/usage/storage-breakdown${query ? `?${query}` : ""}`);
1682
+ }
1683
+ convertUsageDates(usage) {
1684
+ if (typeof usage.periodStart === "string") {
1685
+ usage.periodStart = new Date(usage.periodStart);
1686
+ }
1687
+ if (typeof usage.periodEnd === "string") {
1688
+ usage.periodEnd = new Date(usage.periodEnd);
1689
+ }
1690
+ return usage;
1691
+ }
1692
+ convertUsageDataPointDates(point) {
1693
+ if (typeof point.timestamp === "string") {
1694
+ point.timestamp = new Date(point.timestamp);
1695
+ }
1696
+ return point;
1697
+ }
1698
+ // ============================================================================
1699
+ // Additional Folder Methods
1700
+ // ============================================================================
1701
+ /**
1702
+ * Get a folder by ID
1703
+ *
1704
+ * @example
1705
+ * ```typescript
1706
+ * const folder = await cdn.getFolder('folder-id');
1707
+ * console.log(`Folder: ${folder.name}, Assets: ${folder.assetCount}`);
1708
+ * ```
1709
+ */
1710
+ async getFolder(id) {
1711
+ const response = await this.http.get(`/cdn/folders/${id}`);
1712
+ return this.convertFolderDates(response);
1713
+ }
1714
+ /**
1715
+ * Get a folder by its path
1716
+ *
1717
+ * @example
1718
+ * ```typescript
1719
+ * const folder = await cdn.getFolderByPath('/images/avatars');
1720
+ * ```
1721
+ */
1722
+ async getFolderByPath(path) {
1723
+ const encodedPath = encodeURIComponent(path);
1724
+ const response = await this.http.get(`/cdn/folders/path/${encodedPath}`);
1725
+ return this.convertFolderDates(response);
1726
+ }
1727
+ /**
1728
+ * Update a folder's name
1729
+ *
1730
+ * @example
1731
+ * ```typescript
1732
+ * const folder = await cdn.updateFolder({
1733
+ * id: 'folder-id',
1734
+ * name: 'New Folder Name',
1735
+ * });
1736
+ * ```
1737
+ */
1738
+ async updateFolder(request) {
1739
+ const { id, ...data } = request;
1740
+ const response = await this.http.patch(`/cdn/folders/${id}`, data);
1741
+ return this.convertFolderDates(response);
1742
+ }
1743
+ /**
1744
+ * List folders with optional filters
1745
+ *
1746
+ * @example
1747
+ * ```typescript
1748
+ * const { folders, total } = await cdn.listFolders({
1749
+ * parentId: null, // root level
1750
+ * limit: 50,
1751
+ * });
1752
+ * ```
1753
+ */
1754
+ async listFolders(request = {}) {
1755
+ const params = new URLSearchParams();
1756
+ if (request.parentId !== void 0) params.set("parentId", request.parentId ?? "");
1757
+ if (request.limit) params.set("limit", request.limit.toString());
1758
+ if (request.offset) params.set("offset", request.offset.toString());
1759
+ if (request.search) params.set("search", request.search);
1760
+ const query = params.toString();
1761
+ const response = await this.http.get(`/cdn/folders${query ? `?${query}` : ""}`);
1762
+ return {
1763
+ ...response,
1764
+ folders: response.folders.map((folder) => this.convertFolderListItemDates(folder))
1765
+ };
1766
+ }
1767
+ /**
1768
+ * Move a folder to a new parent
1769
+ *
1770
+ * @example
1771
+ * ```typescript
1772
+ * await cdn.moveFolder({
1773
+ * id: 'folder-id',
1774
+ * newParentId: 'new-parent-id', // or null for root
1775
+ * });
1776
+ * ```
1777
+ */
1778
+ async moveFolder(request) {
1779
+ return this.http.post("/cdn/folders/move", request);
1780
+ }
1781
+ convertFolderListItemDates(folder) {
1782
+ if (typeof folder.createdAt === "string") {
1783
+ folder.createdAt = new Date(folder.createdAt);
1784
+ }
1785
+ return folder;
1786
+ }
1787
+ // ============================================================================
1788
+ // Additional Video Methods
1789
+ // ============================================================================
1790
+ /**
1791
+ * List all thumbnails for a video asset
1792
+ *
1793
+ * @example
1794
+ * ```typescript
1795
+ * const { thumbnails } = await cdn.listThumbnails('video-asset-id');
1796
+ * thumbnails.forEach(thumb => {
1797
+ * console.log(`${thumb.timestamp}s: ${thumb.url}`);
1798
+ * });
1799
+ * ```
1800
+ */
1801
+ async listThumbnails(assetId) {
1802
+ const response = await this.http.get(`/cdn/video/${assetId}/thumbnails`);
1803
+ return response;
1804
+ }
1805
+ // ============================================================================
1806
+ // Additional Private Files Methods
1807
+ // ============================================================================
1808
+ /**
1809
+ * Move private files to a different folder
1810
+ *
1811
+ * @example
1812
+ * ```typescript
1813
+ * const result = await cdn.movePrivateFiles({
1814
+ * fileIds: ['file-1', 'file-2'],
1815
+ * folder: '/confidential/archive',
1816
+ * });
1817
+ * console.log(`Moved ${result.movedCount} files`);
1818
+ * ```
1819
+ */
1820
+ async movePrivateFiles(request) {
1821
+ return this.http.post("/cdn/private/move", request);
1822
+ }
1605
1823
  };
1606
1824
 
1607
1825
  // src/screenshots/client.ts