@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/extraction/index.d.mts +25 -1
- package/dist/extraction/index.d.ts +25 -1
- package/dist/extraction/index.js +22 -0
- package/dist/extraction/index.js.map +1 -1
- package/dist/extraction/index.mjs +22 -0
- package/dist/extraction/index.mjs.map +1 -1
- package/dist/index.d.mts +696 -22
- package/dist/index.d.ts +696 -22
- package/dist/index.js +615 -18
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +615 -18
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2496,6 +2496,28 @@ var Extraction = class {
|
|
|
2496
2496
|
const response = await this.http.get(`/webdata/usage${query ? `?${query}` : ""}`);
|
|
2497
2497
|
return this.convertUsageDates(response);
|
|
2498
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
|
+
}
|
|
2499
2521
|
// ==========================================================================
|
|
2500
2522
|
// HELPERS
|
|
2501
2523
|
// ==========================================================================
|
|
@@ -3428,41 +3450,150 @@ var Integrations = class {
|
|
|
3428
3450
|
// ============================================================================
|
|
3429
3451
|
/**
|
|
3430
3452
|
* List all connections
|
|
3453
|
+
*
|
|
3454
|
+
* @example
|
|
3455
|
+
* ```typescript
|
|
3456
|
+
* const { connections } = await integrations.listConnections({
|
|
3457
|
+
* environment: 'production',
|
|
3458
|
+
* status: 'connected',
|
|
3459
|
+
* });
|
|
3460
|
+
* ```
|
|
3431
3461
|
*/
|
|
3432
|
-
async listConnections(
|
|
3462
|
+
async listConnections(request) {
|
|
3433
3463
|
const params = new URLSearchParams();
|
|
3434
|
-
if (
|
|
3435
|
-
if (
|
|
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());
|
|
3436
3469
|
const queryString = params.toString();
|
|
3437
|
-
|
|
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
|
+
};
|
|
3438
3477
|
}
|
|
3439
3478
|
/**
|
|
3440
3479
|
* Get a specific connection
|
|
3441
3480
|
*/
|
|
3442
|
-
async getConnection(
|
|
3443
|
-
|
|
3481
|
+
async getConnection(connectionId) {
|
|
3482
|
+
const response = await this.http.get(`/integrations/connections/${connectionId}`);
|
|
3483
|
+
return this.convertConnectionDetailsDates(response);
|
|
3444
3484
|
}
|
|
3445
3485
|
/**
|
|
3446
|
-
*
|
|
3447
|
-
*
|
|
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
|
+
* ```
|
|
3448
3497
|
*/
|
|
3449
|
-
async
|
|
3450
|
-
return this.http.post("/integrations/connections",
|
|
3451
|
-
|
|
3452
|
-
|
|
3453
|
-
|
|
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);
|
|
3454
3523
|
}
|
|
3455
3524
|
/**
|
|
3456
3525
|
* Delete a connection
|
|
3457
3526
|
*/
|
|
3458
|
-
async deleteConnection(
|
|
3459
|
-
return this.http.delete(`/integrations/connections/${
|
|
3527
|
+
async deleteConnection(connectionId) {
|
|
3528
|
+
return this.http.delete(`/integrations/connections/${connectionId}`);
|
|
3460
3529
|
}
|
|
3461
3530
|
/**
|
|
3462
|
-
*
|
|
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
|
+
* ```
|
|
3557
|
+
*/
|
|
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
|
+
* ```
|
|
3463
3579
|
*/
|
|
3464
|
-
async
|
|
3465
|
-
|
|
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
|
+
};
|
|
3466
3597
|
}
|
|
3467
3598
|
// ============================================================================
|
|
3468
3599
|
// PASSTHROUGH
|
|
@@ -3473,6 +3604,45 @@ var Integrations = class {
|
|
|
3473
3604
|
async passthrough(request) {
|
|
3474
3605
|
return this.http.post("/integrations/passthrough", request);
|
|
3475
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
|
+
}
|
|
3476
3646
|
};
|
|
3477
3647
|
|
|
3478
3648
|
// src/marketing/client.ts
|
|
@@ -3528,6 +3698,22 @@ var Marketing = class {
|
|
|
3528
3698
|
const response = await this.http.get(`/marketing/trends/${trendId}`);
|
|
3529
3699
|
return this.convertTrendDates(response);
|
|
3530
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
|
+
}
|
|
3531
3717
|
// ============================================================================
|
|
3532
3718
|
// Opportunities
|
|
3533
3719
|
// ============================================================================
|
|
@@ -3736,6 +3922,54 @@ var Marketing = class {
|
|
|
3736
3922
|
const response = await this.http.get(`/marketing/scripts/${scriptId}`);
|
|
3737
3923
|
return this.convertScriptDates(response);
|
|
3738
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
|
+
}
|
|
3739
3973
|
// ============================================================================
|
|
3740
3974
|
// Analytics
|
|
3741
3975
|
// ============================================================================
|
|
@@ -3783,6 +4017,318 @@ var Marketing = class {
|
|
|
3783
4017
|
});
|
|
3784
4018
|
return this.http.get(`/marketing/analytics/performance?${params.toString()}`);
|
|
3785
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
|
+
}
|
|
3786
4332
|
// ============================================================================
|
|
3787
4333
|
// Date Conversion Helpers
|
|
3788
4334
|
// ============================================================================
|
|
@@ -3834,6 +4380,57 @@ var Marketing = class {
|
|
|
3834
4380
|
}
|
|
3835
4381
|
return script;
|
|
3836
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
|
+
}
|
|
3837
4434
|
};
|
|
3838
4435
|
|
|
3839
4436
|
// src/index.ts
|