@stack0/sdk 0.5.2 → 0.5.4

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
@@ -2278,6 +2496,28 @@ var Extraction = class {
2278
2496
  const response = await this.http.get(`/webdata/usage${query ? `?${query}` : ""}`);
2279
2497
  return this.convertUsageDates(response);
2280
2498
  }
2499
+ /**
2500
+ * Get daily usage breakdown
2501
+ *
2502
+ * @example
2503
+ * ```typescript
2504
+ * const { days } = await extraction.getUsageDaily({
2505
+ * periodStart: '2024-01-01T00:00:00Z',
2506
+ * periodEnd: '2024-01-31T23:59:59Z',
2507
+ * });
2508
+ * days.forEach(day => {
2509
+ * console.log(`${day.date}: ${day.screenshots} screenshots, ${day.extractions} extractions`);
2510
+ * });
2511
+ * ```
2512
+ */
2513
+ async getUsageDaily(request = {}) {
2514
+ const params = new URLSearchParams();
2515
+ if (request.environment) params.set("environment", request.environment);
2516
+ if (request.periodStart) params.set("periodStart", request.periodStart);
2517
+ if (request.periodEnd) params.set("periodEnd", request.periodEnd);
2518
+ const query = params.toString();
2519
+ return this.http.get(`/webdata/usage/daily${query ? `?${query}` : ""}`);
2520
+ }
2281
2521
  // ==========================================================================
2282
2522
  // HELPERS
2283
2523
  // ==========================================================================
@@ -3210,41 +3450,150 @@ var Integrations = class {
3210
3450
  // ============================================================================
3211
3451
  /**
3212
3452
  * List all connections
3453
+ *
3454
+ * @example
3455
+ * ```typescript
3456
+ * const { connections } = await integrations.listConnections({
3457
+ * environment: 'production',
3458
+ * status: 'connected',
3459
+ * });
3460
+ * ```
3213
3461
  */
3214
- async listConnections(options) {
3462
+ async listConnections(request) {
3215
3463
  const params = new URLSearchParams();
3216
- if (options?.connectorId) params.set("connectorId", options.connectorId);
3217
- if (options?.status) params.set("status", options.status);
3464
+ if (request?.projectId) params.set("projectId", request.projectId);
3465
+ if (request?.environment) params.set("environment", request.environment);
3466
+ if (request?.connectorSlug) params.set("connectorSlug", request.connectorSlug);
3467
+ if (request?.status) params.set("status", request.status);
3468
+ if (request?.limit) params.set("limit", request.limit.toString());
3218
3469
  const queryString = params.toString();
3219
- return this.http.get(`/integrations/connections${queryString ? `?${queryString}` : ""}`);
3470
+ const response = await this.http.get(
3471
+ `/integrations/connections${queryString ? `?${queryString}` : ""}`
3472
+ );
3473
+ return {
3474
+ ...response,
3475
+ connections: response.connections.map((c) => this.convertConnectionDates(c))
3476
+ };
3220
3477
  }
3221
3478
  /**
3222
3479
  * Get a specific connection
3223
3480
  */
3224
- async getConnection(id) {
3225
- return this.http.get(`/integrations/connections/${id}`);
3481
+ async getConnection(connectionId) {
3482
+ const response = await this.http.get(`/integrations/connections/${connectionId}`);
3483
+ return this.convertConnectionDetailsDates(response);
3226
3484
  }
3227
3485
  /**
3228
- * Create a new connection (initiates OAuth flow)
3229
- * Returns the OAuth authorization URL to redirect the user to
3486
+ * Initiate OAuth flow for a connector
3487
+ *
3488
+ * @example
3489
+ * ```typescript
3490
+ * const { authUrl, connectionId, state } = await integrations.initiateOAuth({
3491
+ * connectorSlug: 'hubspot',
3492
+ * redirectUrl: 'https://yourapp.com/oauth/callback',
3493
+ * name: 'My HubSpot Connection',
3494
+ * });
3495
+ * // Redirect user to authUrl
3496
+ * ```
3230
3497
  */
3231
- async createConnection(connectorSlug, options) {
3232
- return this.http.post("/integrations/connections", {
3233
- connectorSlug,
3234
- ...options
3235
- });
3498
+ async initiateOAuth(request) {
3499
+ return this.http.post("/integrations/connections/oauth/initiate", request);
3500
+ }
3501
+ /**
3502
+ * Complete OAuth flow with callback data
3503
+ *
3504
+ * @example
3505
+ * ```typescript
3506
+ * const result = await integrations.completeOAuth({
3507
+ * code: 'auth_code_from_callback',
3508
+ * state: 'state_from_initiate',
3509
+ * redirectUrl: 'https://yourapp.com/oauth/callback',
3510
+ * });
3511
+ * console.log(`Connected to: ${result.externalAccountName}`);
3512
+ * ```
3513
+ */
3514
+ async completeOAuth(request) {
3515
+ return this.http.post("/integrations/connections/oauth/callback", request);
3516
+ }
3517
+ /**
3518
+ * Update a connection
3519
+ */
3520
+ async updateConnection(request) {
3521
+ const { connectionId, ...data } = request;
3522
+ return this.http.patch(`/integrations/connections/${connectionId}`, data);
3236
3523
  }
3237
3524
  /**
3238
3525
  * Delete a connection
3239
3526
  */
3240
- async deleteConnection(id) {
3241
- return this.http.delete(`/integrations/connections/${id}`);
3527
+ async deleteConnection(connectionId) {
3528
+ return this.http.delete(`/integrations/connections/${connectionId}`);
3242
3529
  }
3243
3530
  /**
3244
- * Test a connection's credentials
3531
+ * Reconnect an expired or errored connection
3532
+ *
3533
+ * @example
3534
+ * ```typescript
3535
+ * const { authUrl, state } = await integrations.reconnectConnection({
3536
+ * connectionId: 'conn_123',
3537
+ * redirectUrl: 'https://yourapp.com/oauth/callback',
3538
+ * });
3539
+ * // Redirect user to authUrl
3540
+ * ```
3541
+ */
3542
+ async reconnectConnection(request) {
3543
+ return this.http.post(
3544
+ `/integrations/connections/${request.connectionId}/reconnect`,
3545
+ { redirectUrl: request.redirectUrl }
3546
+ );
3547
+ }
3548
+ /**
3549
+ * Get integration statistics
3550
+ *
3551
+ * @example
3552
+ * ```typescript
3553
+ * const stats = await integrations.getStats({ environment: 'production' });
3554
+ * console.log(`Active connections: ${stats.activeConnections}`);
3555
+ * console.log(`API calls last 30 days: ${stats.apiCallsLast30Days}`);
3556
+ * ```
3245
3557
  */
3246
- async testConnection(id) {
3247
- return this.http.post(`/integrations/connections/${id}/test`, {});
3558
+ async getStats(request) {
3559
+ const params = new URLSearchParams();
3560
+ if (request?.environment) params.set("environment", request.environment);
3561
+ const queryString = params.toString();
3562
+ return this.http.get(
3563
+ `/integrations/connections/stats${queryString ? `?${queryString}` : ""}`
3564
+ );
3565
+ }
3566
+ // ============================================================================
3567
+ // LOGS
3568
+ // ============================================================================
3569
+ /**
3570
+ * List API logs
3571
+ *
3572
+ * @example
3573
+ * ```typescript
3574
+ * const { logs } = await integrations.listLogs({
3575
+ * connectionId: 'conn_123',
3576
+ * limit: 50,
3577
+ * });
3578
+ * ```
3579
+ */
3580
+ async listLogs(request) {
3581
+ const params = new URLSearchParams();
3582
+ if (request?.connectionId) params.set("connectionId", request.connectionId);
3583
+ if (request?.connectorSlug) params.set("connectorSlug", request.connectorSlug);
3584
+ if (request?.statusCode) params.set("statusCode", request.statusCode.toString());
3585
+ if (request?.method) params.set("method", request.method);
3586
+ if (request?.search) params.set("search", request.search);
3587
+ if (request?.limit) params.set("limit", request.limit.toString());
3588
+ if (request?.cursor) params.set("cursor", request.cursor);
3589
+ const queryString = params.toString();
3590
+ const response = await this.http.get(
3591
+ `/integrations/logs${queryString ? `?${queryString}` : ""}`
3592
+ );
3593
+ return {
3594
+ ...response,
3595
+ logs: response.logs.map((log) => this.convertLogDates(log))
3596
+ };
3248
3597
  }
3249
3598
  // ============================================================================
3250
3599
  // PASSTHROUGH
@@ -3255,6 +3604,45 @@ var Integrations = class {
3255
3604
  async passthrough(request) {
3256
3605
  return this.http.post("/integrations/passthrough", request);
3257
3606
  }
3607
+ // ============================================================================
3608
+ // Date Conversion Helpers
3609
+ // ============================================================================
3610
+ convertConnectionDates(connection) {
3611
+ if (connection.connectedAt && typeof connection.connectedAt === "string") {
3612
+ connection.connectedAt = new Date(connection.connectedAt);
3613
+ }
3614
+ if (connection.lastUsedAt && typeof connection.lastUsedAt === "string") {
3615
+ connection.lastUsedAt = new Date(connection.lastUsedAt);
3616
+ }
3617
+ if (connection.createdAt && typeof connection.createdAt === "string") {
3618
+ connection.createdAt = new Date(connection.createdAt);
3619
+ }
3620
+ return connection;
3621
+ }
3622
+ convertConnectionDetailsDates(connection) {
3623
+ if (connection.connectedAt && typeof connection.connectedAt === "string") {
3624
+ connection.connectedAt = new Date(connection.connectedAt);
3625
+ }
3626
+ if (connection.lastUsedAt && typeof connection.lastUsedAt === "string") {
3627
+ connection.lastUsedAt = new Date(connection.lastUsedAt);
3628
+ }
3629
+ if (connection.lastErrorAt && typeof connection.lastErrorAt === "string") {
3630
+ connection.lastErrorAt = new Date(connection.lastErrorAt);
3631
+ }
3632
+ if (connection.createdAt && typeof connection.createdAt === "string") {
3633
+ connection.createdAt = new Date(connection.createdAt);
3634
+ }
3635
+ if (connection.updatedAt && typeof connection.updatedAt === "string") {
3636
+ connection.updatedAt = new Date(connection.updatedAt);
3637
+ }
3638
+ return connection;
3639
+ }
3640
+ convertLogDates(log) {
3641
+ if (typeof log.createdAt === "string") {
3642
+ log.createdAt = new Date(log.createdAt);
3643
+ }
3644
+ return log;
3645
+ }
3258
3646
  };
3259
3647
 
3260
3648
  // src/marketing/client.ts
@@ -3310,6 +3698,22 @@ var Marketing = class {
3310
3698
  const response = await this.http.get(`/marketing/trends/${trendId}`);
3311
3699
  return this.convertTrendDates(response);
3312
3700
  }
3701
+ /**
3702
+ * Update trend status
3703
+ *
3704
+ * @example
3705
+ * ```typescript
3706
+ * await marketing.updateTrendStatus({
3707
+ * trendId: 'trend-id',
3708
+ * status: 'active',
3709
+ * });
3710
+ * ```
3711
+ */
3712
+ async updateTrendStatus(request) {
3713
+ return this.http.patch(`/marketing/trends/${request.trendId}/status`, {
3714
+ status: request.status
3715
+ });
3716
+ }
3313
3717
  // ============================================================================
3314
3718
  // Opportunities
3315
3719
  // ============================================================================
@@ -3518,6 +3922,54 @@ var Marketing = class {
3518
3922
  const response = await this.http.get(`/marketing/scripts/${scriptId}`);
3519
3923
  return this.convertScriptDates(response);
3520
3924
  }
3925
+ /**
3926
+ * Update a script
3927
+ *
3928
+ * @example
3929
+ * ```typescript
3930
+ * const updated = await marketing.updateScript({
3931
+ * scriptId: 'script-id',
3932
+ * hook: 'Updated hook line',
3933
+ * cta: 'New call to action!',
3934
+ * });
3935
+ * ```
3936
+ */
3937
+ async updateScript(request) {
3938
+ const { scriptId, ...data } = request;
3939
+ const response = await this.http.patch(`/marketing/scripts/${scriptId}`, data);
3940
+ return this.convertScriptDates(response);
3941
+ }
3942
+ /**
3943
+ * Create a new version of a script
3944
+ *
3945
+ * @example
3946
+ * ```typescript
3947
+ * const newVersion = await marketing.createScriptVersion({
3948
+ * scriptId: 'script-id',
3949
+ * hook: 'Updated hook for v2',
3950
+ * slides: [...],
3951
+ * cta: 'Updated CTA',
3952
+ * });
3953
+ * ```
3954
+ */
3955
+ async createScriptVersion(request) {
3956
+ const { scriptId, ...data } = request;
3957
+ const response = await this.http.post(`/marketing/scripts/${scriptId}/versions`, data);
3958
+ return this.convertScriptDates(response);
3959
+ }
3960
+ /**
3961
+ * Get all versions of a script
3962
+ */
3963
+ async getScriptVersions(scriptId) {
3964
+ const response = await this.http.get(`/marketing/scripts/${scriptId}/versions`);
3965
+ return response.map((s) => this.convertScriptDates(s));
3966
+ }
3967
+ /**
3968
+ * Delete a script
3969
+ */
3970
+ async deleteScript(scriptId) {
3971
+ return this.http.delete(`/marketing/scripts/${scriptId}`);
3972
+ }
3521
3973
  // ============================================================================
3522
3974
  // Analytics
3523
3975
  // ============================================================================
@@ -3565,6 +4017,318 @@ var Marketing = class {
3565
4017
  });
3566
4018
  return this.http.get(`/marketing/analytics/performance?${params.toString()}`);
3567
4019
  }
4020
+ /**
4021
+ * Get trend discovery analytics
4022
+ *
4023
+ * @example
4024
+ * ```typescript
4025
+ * const trendStats = await marketing.getTrendAnalytics({
4026
+ * projectSlug: 'my-project',
4027
+ * environment: 'production',
4028
+ * });
4029
+ * console.log(`Total trends: ${trendStats.totalTrends}`);
4030
+ * ```
4031
+ */
4032
+ async getTrendAnalytics(request) {
4033
+ const params = new URLSearchParams({
4034
+ projectSlug: request.projectSlug,
4035
+ ...request.environment && { environment: request.environment },
4036
+ ...request.startDate && { startDate: request.startDate.toISOString() },
4037
+ ...request.endDate && { endDate: request.endDate.toISOString() }
4038
+ });
4039
+ return this.http.get(`/marketing/analytics/trends?${params.toString()}`);
4040
+ }
4041
+ /**
4042
+ * Get opportunity conversion analytics
4043
+ *
4044
+ * @example
4045
+ * ```typescript
4046
+ * const conversion = await marketing.getOpportunityConversion({
4047
+ * projectSlug: 'my-project',
4048
+ * environment: 'production',
4049
+ * });
4050
+ * console.log(`Conversion rate: ${conversion.conversionRate}%`);
4051
+ * ```
4052
+ */
4053
+ async getOpportunityConversion(request) {
4054
+ const params = new URLSearchParams({
4055
+ projectSlug: request.projectSlug,
4056
+ ...request.environment && { environment: request.environment },
4057
+ ...request.startDate && { startDate: request.startDate.toISOString() },
4058
+ ...request.endDate && { endDate: request.endDate.toISOString() }
4059
+ });
4060
+ return this.http.get(`/marketing/analytics/conversion?${params.toString()}`);
4061
+ }
4062
+ // ============================================================================
4063
+ // Calendar
4064
+ // ============================================================================
4065
+ /**
4066
+ * Schedule content for publishing
4067
+ *
4068
+ * @example
4069
+ * ```typescript
4070
+ * const entry = await marketing.scheduleContent({
4071
+ * projectSlug: 'my-project',
4072
+ * contentId: 'content-id',
4073
+ * scheduledFor: new Date('2024-12-25T10:00:00Z'),
4074
+ * autoPublish: true,
4075
+ * });
4076
+ * ```
4077
+ */
4078
+ async scheduleContent(request) {
4079
+ const response = await this.http.post("/marketing/calendar/schedule", {
4080
+ ...request,
4081
+ scheduledFor: request.scheduledFor.toISOString()
4082
+ });
4083
+ return this.convertCalendarEntryDates(response);
4084
+ }
4085
+ /**
4086
+ * List scheduled content
4087
+ *
4088
+ * @example
4089
+ * ```typescript
4090
+ * const entries = await marketing.listCalendarEntries({
4091
+ * projectSlug: 'my-project',
4092
+ * startDate: new Date('2024-12-01'),
4093
+ * endDate: new Date('2024-12-31'),
4094
+ * });
4095
+ * ```
4096
+ */
4097
+ async listCalendarEntries(request) {
4098
+ const params = new URLSearchParams({
4099
+ projectSlug: request.projectSlug,
4100
+ ...request.environment && { environment: request.environment },
4101
+ ...request.startDate && { startDate: request.startDate.toISOString() },
4102
+ ...request.endDate && { endDate: request.endDate.toISOString() },
4103
+ ...request.limit && { limit: request.limit.toString() },
4104
+ ...request.offset && { offset: request.offset.toString() }
4105
+ });
4106
+ const response = await this.http.get(`/marketing/calendar?${params.toString()}`);
4107
+ return response.map((e) => this.convertCalendarEntryDates(e));
4108
+ }
4109
+ /**
4110
+ * Get a single calendar entry by ID
4111
+ */
4112
+ async getCalendarEntry(entryId) {
4113
+ const response = await this.http.get(`/marketing/calendar/${entryId}`);
4114
+ return this.convertCalendarEntryDates(response);
4115
+ }
4116
+ /**
4117
+ * Update a calendar entry
4118
+ *
4119
+ * @example
4120
+ * ```typescript
4121
+ * const updated = await marketing.updateCalendarEntry({
4122
+ * entryId: 'entry-id',
4123
+ * scheduledFor: new Date('2024-12-26T10:00:00Z'),
4124
+ * });
4125
+ * ```
4126
+ */
4127
+ async updateCalendarEntry(request) {
4128
+ const { entryId, ...data } = request;
4129
+ const response = await this.http.patch(`/marketing/calendar/${entryId}`, {
4130
+ ...data,
4131
+ ...data.scheduledFor && { scheduledFor: data.scheduledFor.toISOString() }
4132
+ });
4133
+ return this.convertCalendarEntryDates(response);
4134
+ }
4135
+ /**
4136
+ * Cancel a scheduled calendar entry
4137
+ */
4138
+ async cancelCalendarEntry(entryId) {
4139
+ return this.http.post(`/marketing/calendar/${entryId}/cancel`, {});
4140
+ }
4141
+ /**
4142
+ * Mark content as published
4143
+ */
4144
+ async markContentPublished(request) {
4145
+ const response = await this.http.post(`/marketing/calendar/${request.entryId}/published`, {
4146
+ ...request.publishedAt && { publishedAt: request.publishedAt.toISOString() }
4147
+ });
4148
+ return this.convertCalendarEntryDates(response);
4149
+ }
4150
+ // ============================================================================
4151
+ // Assets (Asset Jobs)
4152
+ // ============================================================================
4153
+ /**
4154
+ * Create an asset generation job
4155
+ *
4156
+ * @example
4157
+ * ```typescript
4158
+ * const job = await marketing.createAssetJob({
4159
+ * projectSlug: 'my-project',
4160
+ * contentId: 'content-id',
4161
+ * jobType: 'slide_generation',
4162
+ * input: { style: 'modern' },
4163
+ * });
4164
+ * ```
4165
+ */
4166
+ async createAssetJob(request) {
4167
+ const response = await this.http.post("/marketing/assets/jobs", request);
4168
+ return this.convertAssetJobDates(response);
4169
+ }
4170
+ /**
4171
+ * List asset jobs
4172
+ *
4173
+ * @example
4174
+ * ```typescript
4175
+ * const jobs = await marketing.listAssetJobs({
4176
+ * projectSlug: 'my-project',
4177
+ * status: 'processing',
4178
+ * });
4179
+ * ```
4180
+ */
4181
+ async listAssetJobs(request) {
4182
+ const params = new URLSearchParams({
4183
+ projectSlug: request.projectSlug,
4184
+ ...request.contentId && { contentId: request.contentId },
4185
+ ...request.status && { status: request.status },
4186
+ ...request.jobType && { jobType: request.jobType },
4187
+ ...request.limit && { limit: request.limit.toString() },
4188
+ ...request.offset && { offset: request.offset.toString() }
4189
+ });
4190
+ const response = await this.http.get(`/marketing/assets/jobs?${params.toString()}`);
4191
+ return response.map((j) => this.convertAssetJobDates(j));
4192
+ }
4193
+ /**
4194
+ * Get an asset job by ID
4195
+ */
4196
+ async getAssetJob(jobId) {
4197
+ const response = await this.http.get(`/marketing/assets/jobs/${jobId}`);
4198
+ return this.convertAssetJobDates(response);
4199
+ }
4200
+ /**
4201
+ * Update asset job status
4202
+ */
4203
+ async updateAssetJobStatus(request) {
4204
+ const { jobId, ...data } = request;
4205
+ const response = await this.http.patch(`/marketing/assets/jobs/${jobId}/status`, data);
4206
+ return this.convertAssetJobDates(response);
4207
+ }
4208
+ /**
4209
+ * Retry a failed asset job
4210
+ */
4211
+ async retryAssetJob(jobId) {
4212
+ const response = await this.http.post(`/marketing/assets/jobs/${jobId}/retry`, {});
4213
+ return this.convertAssetJobDates(response);
4214
+ }
4215
+ /**
4216
+ * Cancel an asset job
4217
+ */
4218
+ async cancelAssetJob(jobId) {
4219
+ const response = await this.http.post(`/marketing/assets/jobs/${jobId}/cancel`, {});
4220
+ return this.convertAssetJobDates(response);
4221
+ }
4222
+ // ============================================================================
4223
+ // Settings
4224
+ // ============================================================================
4225
+ /**
4226
+ * Get marketing settings for a project
4227
+ *
4228
+ * @example
4229
+ * ```typescript
4230
+ * const settings = await marketing.getSettings({
4231
+ * projectSlug: 'my-project',
4232
+ * environment: 'production',
4233
+ * });
4234
+ * console.log(`Brand voice: ${settings.brandVoice}`);
4235
+ * ```
4236
+ */
4237
+ async getSettings(request) {
4238
+ const params = new URLSearchParams({
4239
+ projectSlug: request.projectSlug,
4240
+ ...request.environment && { environment: request.environment }
4241
+ });
4242
+ return this.http.get(`/marketing/settings?${params.toString()}`);
4243
+ }
4244
+ /**
4245
+ * Update marketing settings
4246
+ *
4247
+ * @example
4248
+ * ```typescript
4249
+ * await marketing.updateSettings({
4250
+ * projectSlug: 'my-project',
4251
+ * brandVoice: 'Professional yet approachable',
4252
+ * monitoredKeywords: ['AI', 'startup', 'tech'],
4253
+ * });
4254
+ * ```
4255
+ */
4256
+ async updateSettings(request) {
4257
+ return this.http.post("/marketing/settings", request);
4258
+ }
4259
+ // ============================================================================
4260
+ // Usage
4261
+ // ============================================================================
4262
+ /**
4263
+ * Get current period usage
4264
+ *
4265
+ * @example
4266
+ * ```typescript
4267
+ * const usage = await marketing.getCurrentUsage({
4268
+ * projectSlug: 'my-project',
4269
+ * environment: 'production',
4270
+ * });
4271
+ * console.log(`AI tokens used: ${usage.aiTokensUsed}`);
4272
+ * ```
4273
+ */
4274
+ async getCurrentUsage(request) {
4275
+ const params = new URLSearchParams({
4276
+ projectSlug: request.projectSlug,
4277
+ ...request.environment && { environment: request.environment }
4278
+ });
4279
+ const response = await this.http.get(`/marketing/usage/current?${params.toString()}`);
4280
+ return this.convertUsageDates(response);
4281
+ }
4282
+ /**
4283
+ * Get usage history
4284
+ *
4285
+ * @example
4286
+ * ```typescript
4287
+ * const history = await marketing.getUsageHistory({
4288
+ * projectSlug: 'my-project',
4289
+ * limit: 6, // Last 6 months
4290
+ * });
4291
+ * ```
4292
+ */
4293
+ async getUsageHistory(request) {
4294
+ const params = new URLSearchParams({
4295
+ projectSlug: request.projectSlug,
4296
+ ...request.environment && { environment: request.environment },
4297
+ ...request.startDate && { startDate: request.startDate.toISOString() },
4298
+ ...request.endDate && { endDate: request.endDate.toISOString() },
4299
+ ...request.limit && { limit: request.limit.toString() }
4300
+ });
4301
+ const response = await this.http.get(`/marketing/usage/history?${params.toString()}`);
4302
+ return response.map((u) => this.convertMarketingUsageDates(u));
4303
+ }
4304
+ /**
4305
+ * Get total usage across all periods
4306
+ *
4307
+ * @example
4308
+ * ```typescript
4309
+ * const totals = await marketing.getTotalUsage({
4310
+ * projectSlug: 'my-project',
4311
+ * startDate: new Date('2024-01-01'),
4312
+ * });
4313
+ * console.log(`Total content generated: ${totals.contentGenerated}`);
4314
+ * ```
4315
+ */
4316
+ async getTotalUsage(request) {
4317
+ const params = new URLSearchParams({
4318
+ projectSlug: request.projectSlug,
4319
+ ...request.environment && { environment: request.environment },
4320
+ ...request.startDate && { startDate: request.startDate.toISOString() },
4321
+ ...request.endDate && { endDate: request.endDate.toISOString() }
4322
+ });
4323
+ return this.http.get(`/marketing/usage/total?${params.toString()}`);
4324
+ }
4325
+ /**
4326
+ * Record usage (typically called internally)
4327
+ */
4328
+ async recordUsage(request) {
4329
+ const response = await this.http.post("/marketing/usage/record", request);
4330
+ return this.convertMarketingUsageDates(response);
4331
+ }
3568
4332
  // ============================================================================
3569
4333
  // Date Conversion Helpers
3570
4334
  // ============================================================================
@@ -3616,6 +4380,57 @@ var Marketing = class {
3616
4380
  }
3617
4381
  return script;
3618
4382
  }
4383
+ convertCalendarEntryDates(entry) {
4384
+ if (typeof entry.scheduledFor === "string") {
4385
+ entry.scheduledFor = new Date(entry.scheduledFor);
4386
+ }
4387
+ if (typeof entry.createdAt === "string") {
4388
+ entry.createdAt = new Date(entry.createdAt);
4389
+ }
4390
+ if (entry.updatedAt && typeof entry.updatedAt === "string") {
4391
+ entry.updatedAt = new Date(entry.updatedAt);
4392
+ }
4393
+ if (entry.publishedAt && typeof entry.publishedAt === "string") {
4394
+ entry.publishedAt = new Date(entry.publishedAt);
4395
+ }
4396
+ return entry;
4397
+ }
4398
+ convertAssetJobDates(job) {
4399
+ if (typeof job.createdAt === "string") {
4400
+ job.createdAt = new Date(job.createdAt);
4401
+ }
4402
+ if (job.startedAt && typeof job.startedAt === "string") {
4403
+ job.startedAt = new Date(job.startedAt);
4404
+ }
4405
+ if (job.completedAt && typeof job.completedAt === "string") {
4406
+ job.completedAt = new Date(job.completedAt);
4407
+ }
4408
+ return job;
4409
+ }
4410
+ convertUsageDates(usage) {
4411
+ if (typeof usage.periodStart === "string") {
4412
+ usage.periodStart = new Date(usage.periodStart);
4413
+ }
4414
+ if (typeof usage.periodEnd === "string") {
4415
+ usage.periodEnd = new Date(usage.periodEnd);
4416
+ }
4417
+ return usage;
4418
+ }
4419
+ convertMarketingUsageDates(usage) {
4420
+ if (typeof usage.periodStart === "string") {
4421
+ usage.periodStart = new Date(usage.periodStart);
4422
+ }
4423
+ if (typeof usage.periodEnd === "string") {
4424
+ usage.periodEnd = new Date(usage.periodEnd);
4425
+ }
4426
+ if (typeof usage.createdAt === "string") {
4427
+ usage.createdAt = new Date(usage.createdAt);
4428
+ }
4429
+ if (usage.updatedAt && typeof usage.updatedAt === "string") {
4430
+ usage.updatedAt = new Date(usage.updatedAt);
4431
+ }
4432
+ return usage;
4433
+ }
3619
4434
  };
3620
4435
 
3621
4436
  // src/index.ts