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