Skip to content

Commit 5889365

Browse files
feat(api): api update
1 parent 70de3e2 commit 5889365

30 files changed

Lines changed: 1062 additions & 43 deletions

File tree

.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 29
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-adab8df19dce27396e4a0e698287f083e1f932e63b85fd8dd4d54f80f0e0b5a8.yml
3-
openapi_spec_hash: 717fea46f446ff97bad627f200963fd7
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-ecf38e27f0c2544a8965f6cee827927343a926e1ab511aa7b34e8aa7d1866c8e.yml
3+
openapi_spec_hash: c5767791a19b95c52ef073902fa5da77
44
config_hash: ff35e224e809656528c44163aa41bebd

src/Monitors/MonitorCreateParams/Webhook.php

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,32 @@
88
use ContextDev\Core\Attributes\Required;
99
use ContextDev\Core\Concerns\SdkModel;
1010
use ContextDev\Core\Contracts\BaseModel;
11+
use ContextDev\Monitors\MonitorCreateParams\Webhook\Event;
1112

1213
/**
13-
* @phpstan-type WebhookShape = array{url: string, secret?: string|null}
14+
* @phpstan-type WebhookShape = array{
15+
* url: string, events?: list<Event|value-of<Event>>|null, secret?: string|null
16+
* }
1417
*/
1518
final class Webhook implements BaseModel
1619
{
1720
/** @use SdkModel<WebhookShape> */
1821
use SdkModel;
1922

2023
/**
21-
* Webhook URL called when a change is detected.
24+
* Webhook URL events are delivered to.
2225
*/
2326
#[Required]
2427
public string $url;
2528

29+
/**
30+
* Events delivered to this endpoint. `change.detected` fires only when a run detects a change; `run.completed` fires on every completed run — including runs that detected no change — and embeds the change when one was detected. Defaults to `["change.detected"]` when omitted.
31+
*
32+
* @var list<value-of<Event>>|null $events
33+
*/
34+
#[Optional(list: Event::class)]
35+
public ?array $events;
36+
2637
/**
2738
* Signing secret used to verify webhook authenticity. Each delivery includes an `X-Context-Signature: t=<unix>,v1=<hmac>` header, where the HMAC is SHA-256 over `"{t}.{rawRequestBody}"` keyed by this secret. Recompute it with a constant-time compare and reject stale timestamps to prevent replay. Generated by the API; cannot be set by clients.
2839
*/
@@ -52,20 +63,26 @@ public function __construct()
5263
* Construct an instance from the required parameters.
5364
*
5465
* You must use named parameters to construct any parameters with a default value.
66+
*
67+
* @param list<Event|value-of<Event>>|null $events
5568
*/
56-
public static function with(string $url, ?string $secret = null): self
57-
{
69+
public static function with(
70+
string $url,
71+
?array $events = null,
72+
?string $secret = null
73+
): self {
5874
$self = new self;
5975

6076
$self['url'] = $url;
6177

78+
null !== $events && $self['events'] = $events;
6279
null !== $secret && $self['secret'] = $secret;
6380

6481
return $self;
6582
}
6683

6784
/**
68-
* Webhook URL called when a change is detected.
85+
* Webhook URL events are delivered to.
6986
*/
7087
public function withURL(string $url): self
7188
{
@@ -75,6 +92,19 @@ public function withURL(string $url): self
7592
return $self;
7693
}
7794

95+
/**
96+
* Events delivered to this endpoint. `change.detected` fires only when a run detects a change; `run.completed` fires on every completed run — including runs that detected no change — and embeds the change when one was detected. Defaults to `["change.detected"]` when omitted.
97+
*
98+
* @param list<Event|value-of<Event>> $events
99+
*/
100+
public function withEvents(array $events): self
101+
{
102+
$self = clone $this;
103+
$self['events'] = $events;
104+
105+
return $self;
106+
}
107+
78108
/**
79109
* Signing secret used to verify webhook authenticity. Each delivery includes an `X-Context-Signature: t=<unix>,v1=<hmac>` header, where the HMAC is SHA-256 over `"{t}.{rawRequestBody}"` keyed by this secret. Recompute it with a constant-time compare and reject stale timestamps to prevent replay. Generated by the API; cannot be set by clients.
80110
*/
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace ContextDev\Monitors\MonitorCreateParams\Webhook;
6+
7+
enum Event: string
8+
{
9+
case CHANGE_DETECTED = 'change.detected';
10+
11+
case RUN_COMPLETED = 'run.completed';
12+
}

src/Monitors/MonitorGetResponse/Webhook.php

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,32 @@
88
use ContextDev\Core\Attributes\Required;
99
use ContextDev\Core\Concerns\SdkModel;
1010
use ContextDev\Core\Contracts\BaseModel;
11+
use ContextDev\Monitors\MonitorGetResponse\Webhook\Event;
1112

1213
/**
13-
* @phpstan-type WebhookShape = array{url: string, secret?: string|null}
14+
* @phpstan-type WebhookShape = array{
15+
* url: string, events?: list<Event|value-of<Event>>|null, secret?: string|null
16+
* }
1417
*/
1518
final class Webhook implements BaseModel
1619
{
1720
/** @use SdkModel<WebhookShape> */
1821
use SdkModel;
1922

2023
/**
21-
* Webhook URL called when a change is detected.
24+
* Webhook URL events are delivered to.
2225
*/
2326
#[Required]
2427
public string $url;
2528

29+
/**
30+
* Events delivered to this endpoint. `change.detected` fires only when a run detects a change; `run.completed` fires on every completed run — including runs that detected no change — and embeds the change when one was detected. Defaults to `["change.detected"]` when omitted.
31+
*
32+
* @var list<value-of<Event>>|null $events
33+
*/
34+
#[Optional(list: Event::class)]
35+
public ?array $events;
36+
2637
/**
2738
* Signing secret used to verify webhook authenticity. Each delivery includes an `X-Context-Signature: t=<unix>,v1=<hmac>` header, where the HMAC is SHA-256 over `"{t}.{rawRequestBody}"` keyed by this secret. Recompute it with a constant-time compare and reject stale timestamps to prevent replay. Generated by the API; cannot be set by clients.
2839
*/
@@ -52,20 +63,26 @@ public function __construct()
5263
* Construct an instance from the required parameters.
5364
*
5465
* You must use named parameters to construct any parameters with a default value.
66+
*
67+
* @param list<Event|value-of<Event>>|null $events
5568
*/
56-
public static function with(string $url, ?string $secret = null): self
57-
{
69+
public static function with(
70+
string $url,
71+
?array $events = null,
72+
?string $secret = null
73+
): self {
5874
$self = new self;
5975

6076
$self['url'] = $url;
6177

78+
null !== $events && $self['events'] = $events;
6279
null !== $secret && $self['secret'] = $secret;
6380

6481
return $self;
6582
}
6683

6784
/**
68-
* Webhook URL called when a change is detected.
85+
* Webhook URL events are delivered to.
6986
*/
7087
public function withURL(string $url): self
7188
{
@@ -75,6 +92,19 @@ public function withURL(string $url): self
7592
return $self;
7693
}
7794

95+
/**
96+
* Events delivered to this endpoint. `change.detected` fires only when a run detects a change; `run.completed` fires on every completed run — including runs that detected no change — and embeds the change when one was detected. Defaults to `["change.detected"]` when omitted.
97+
*
98+
* @param list<Event|value-of<Event>> $events
99+
*/
100+
public function withEvents(array $events): self
101+
{
102+
$self = clone $this;
103+
$self['events'] = $events;
104+
105+
return $self;
106+
}
107+
78108
/**
79109
* Signing secret used to verify webhook authenticity. Each delivery includes an `X-Context-Signature: t=<unix>,v1=<hmac>` header, where the HMAC is SHA-256 over `"{t}.{rawRequestBody}"` keyed by this secret. Recompute it with a constant-time compare and reject stale timestamps to prevent replay. Generated by the API; cannot be set by clients.
80110
*/
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace ContextDev\Monitors\MonitorGetResponse\Webhook;
6+
7+
enum Event: string
8+
{
9+
case CHANGE_DETECTED = 'change.detected';
10+
11+
case RUN_COMPLETED = 'run.completed';
12+
}

src/Monitors/MonitorListAccountRunsResponse/Data.php

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
use ContextDev\Monitors\MonitorListAccountRunsResponse\Data\Status;
1616
use ContextDev\Monitors\MonitorListAccountRunsResponse\Data\TargetType;
1717
use ContextDev\Monitors\MonitorListAccountRunsResponse\Data\WebhookDelivery;
18+
use ContextDev\Monitors\MonitorListAccountRunsResponse\Data\WebhookDelivery1;
1819

1920
/**
2021
* @phpstan-import-type ErrorShape from \ContextDev\Monitors\MonitorListAccountRunsResponse\Data\Error
22+
* @phpstan-import-type WebhookDelivery1Shape from \ContextDev\Monitors\MonitorListAccountRunsResponse\Data\WebhookDelivery1
2123
* @phpstan-import-type WebhookDeliveryShape from \ContextDev\Monitors\MonitorListAccountRunsResponse\Data\WebhookDelivery
2224
*
2325
* @phpstan-type DataShape = array{
@@ -35,6 +37,7 @@
3537
* error?: null|Error|ErrorShape,
3638
* skipReason?: null|SkipReason|value-of<SkipReason>,
3739
* startedAt?: \DateTimeInterface|null,
40+
* webhookDeliveries?: list<WebhookDelivery1|WebhookDelivery1Shape>|null,
3841
* webhookDelivery?: null|WebhookDelivery|WebhookDeliveryShape,
3942
* }
4043
*/
@@ -109,7 +112,17 @@ final class Data implements BaseModel
109112
public ?\DateTimeInterface $startedAt;
110113

111114
/**
112-
* The webhook delivery attempted for a change detected by this run. Omitted when no webhook was attempted, including historical runs created before delivery tracking was added.
115+
* All webhook deliveries attempted by this run — one per subscribed event that fired. Omitted when no webhook was attempted, including runs created before event selection was added.
116+
*
117+
* @var list<WebhookDelivery1>|null $webhookDeliveries
118+
*/
119+
#[Optional('webhook_deliveries', list: WebhookDelivery1::class)]
120+
public ?array $webhookDeliveries;
121+
122+
/**
123+
* @deprecated
124+
*
125+
* Deprecated: use `webhook_deliveries`, which records every attempt now that a run can deliver multiple events. Omitted when no webhook was attempted, including historical runs created before delivery tracking was added.
113126
*/
114127
#[Optional('webhook_delivery')]
115128
public ?WebhookDelivery $webhookDelivery;
@@ -163,6 +176,7 @@ public function __construct()
163176
* @param TargetType|value-of<TargetType> $targetType
164177
* @param Error|ErrorShape|null $error
165178
* @param SkipReason|value-of<SkipReason>|null $skipReason
179+
* @param list<WebhookDelivery1|WebhookDelivery1Shape>|null $webhookDeliveries
166180
* @param WebhookDelivery|WebhookDeliveryShape|null $webhookDelivery
167181
*/
168182
public static function with(
@@ -180,6 +194,7 @@ public static function with(
180194
Error|array|null $error = null,
181195
SkipReason|string|null $skipReason = null,
182196
?\DateTimeInterface $startedAt = null,
197+
?array $webhookDeliveries = null,
183198
WebhookDelivery|array|null $webhookDelivery = null,
184199
): self {
185200
$self = new self;
@@ -199,6 +214,7 @@ public static function with(
199214
null !== $error && $self['error'] = $error;
200215
null !== $skipReason && $self['skipReason'] = $skipReason;
201216
null !== $startedAt && $self['startedAt'] = $startedAt;
217+
null !== $webhookDeliveries && $self['webhookDeliveries'] = $webhookDeliveries;
202218
null !== $webhookDelivery && $self['webhookDelivery'] = $webhookDelivery;
203219

204220
return $self;
@@ -348,7 +364,20 @@ public function withStartedAt(?\DateTimeInterface $startedAt): self
348364
}
349365

350366
/**
351-
* The webhook delivery attempted for a change detected by this run. Omitted when no webhook was attempted, including historical runs created before delivery tracking was added.
367+
* All webhook deliveries attempted by this run — one per subscribed event that fired. Omitted when no webhook was attempted, including runs created before event selection was added.
368+
*
369+
* @param list<WebhookDelivery1|WebhookDelivery1Shape> $webhookDeliveries
370+
*/
371+
public function withWebhookDeliveries(array $webhookDeliveries): self
372+
{
373+
$self = clone $this;
374+
$self['webhookDeliveries'] = $webhookDeliveries;
375+
376+
return $self;
377+
}
378+
379+
/**
380+
* Deprecated: use `webhook_deliveries`, which records every attempt now that a run can deliver multiple events. Omitted when no webhook was attempted, including historical runs created before delivery tracking was added.
352381
*
353382
* @param WebhookDelivery|WebhookDeliveryShape $webhookDelivery
354383
*/

src/Monitors/MonitorListAccountRunsResponse/Data/WebhookDelivery.php

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,20 @@
88
use ContextDev\Core\Concerns\SdkModel;
99
use ContextDev\Core\Contracts\BaseModel;
1010
use ContextDev\Monitors\MonitorListAccountRunsResponse\Data\WebhookDelivery\Error;
11+
use ContextDev\Monitors\MonitorListAccountRunsResponse\Data\WebhookDelivery\Event;
1112
use ContextDev\Monitors\MonitorListAccountRunsResponse\Data\WebhookDelivery\Status;
1213

1314
/**
14-
* The webhook delivery attempted for a change detected by this run. Omitted when no webhook was attempted, including historical runs created before delivery tracking was added.
15+
* Deprecated: use `webhook_deliveries`, which records every attempt now that a run can deliver multiple events. Omitted when no webhook was attempted, including historical runs created before delivery tracking was added.
16+
*
17+
* @deprecated
1518
*
1619
* @phpstan-import-type ErrorShape from \ContextDev\Monitors\MonitorListAccountRunsResponse\Data\WebhookDelivery\Error
1720
*
1821
* @phpstan-type WebhookDeliveryShape = array{
1922
* attemptedAt: \DateTimeInterface,
2023
* error: null|\ContextDev\Monitors\MonitorListAccountRunsResponse\Data\WebhookDelivery\Error|ErrorShape,
24+
* event: Event|value-of<Event>,
2125
* eventID: string,
2226
* httpStatus: int|null,
2327
* status: \ContextDev\Monitors\MonitorListAccountRunsResponse\Data\WebhookDelivery\Status|value-of<\ContextDev\Monitors\MonitorListAccountRunsResponse\Data\WebhookDelivery\Status>,
@@ -34,6 +38,14 @@ final class WebhookDelivery implements BaseModel
3438
#[Required]
3539
public ?Error $error;
3640

41+
/**
42+
* The event this delivery carried. Deliveries recorded before event selection existed report change.detected.
43+
*
44+
* @var value-of<Event> $event
45+
*/
46+
#[Required(enum: Event::class)]
47+
public string $event;
48+
3749
/**
3850
* Identifier sent in the X-Context-Id header.
3951
*/
@@ -62,7 +74,12 @@ enum: Status::class,
6274
* To enforce required parameters use
6375
* ```
6476
* WebhookDelivery::with(
65-
* attemptedAt: ..., error: ..., eventID: ..., httpStatus: ..., status: ...
77+
* attemptedAt: ...,
78+
* error: ...,
79+
* event: ...,
80+
* eventID: ...,
81+
* httpStatus: ...,
82+
* status: ...,
6683
* )
6784
* ```
6885
*
@@ -72,6 +89,7 @@ enum: Status::class,
7289
* (new WebhookDelivery)
7390
* ->withAttemptedAt(...)
7491
* ->withError(...)
92+
* ->withEvent(...)
7593
* ->withEventID(...)
7694
* ->withHTTPStatus(...)
7795
* ->withStatus(...)
@@ -88,11 +106,13 @@ public function __construct()
88106
* You must use named parameters to construct any parameters with a default value.
89107
*
90108
* @param Error|ErrorShape|null $error
109+
* @param Event|value-of<Event> $event
91110
* @param Status|value-of<Status> $status
92111
*/
93112
public static function with(
94113
\DateTimeInterface $attemptedAt,
95114
Error|array|null $error,
115+
Event|string $event,
96116
string $eventID,
97117
?int $httpStatus,
98118
Status|string $status,
@@ -101,6 +121,7 @@ public static function with(
101121

102122
$self['attemptedAt'] = $attemptedAt;
103123
$self['error'] = $error;
124+
$self['event'] = $event;
104125
$self['eventID'] = $eventID;
105126
$self['httpStatus'] = $httpStatus;
106127
$self['status'] = $status;
@@ -128,6 +149,19 @@ public function withError(
128149
return $self;
129150
}
130151

152+
/**
153+
* The event this delivery carried. Deliveries recorded before event selection existed report change.detected.
154+
*
155+
* @param Event|value-of<Event> $event
156+
*/
157+
public function withEvent(Event|string $event): self
158+
{
159+
$self = clone $this;
160+
$self['event'] = $event;
161+
162+
return $self;
163+
}
164+
131165
/**
132166
* Identifier sent in the X-Context-Id header.
133167
*/

0 commit comments

Comments
 (0)