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