Skip to content

Commit 9571fea

Browse files
committed
feat(zones): add CT alerting sub-resource
1 parent fe4c286 commit 9571fea

8 files changed

Lines changed: 236 additions & 0 deletions

File tree

src/resources/zones/api.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,17 @@ Types:
165165
Methods:
166166

167167
- <code title="get /zones/{zone_id}/available_rate_plans">client.zones.ratePlans.<a href="./src/resources/zones/rate-plans.ts">get</a>({ ...params }) -> RatePlanGetResponsesSinglePage</code>
168+
169+
## CT
170+
171+
### Alerting
172+
173+
Types:
174+
175+
- <code><a href="./src/resources/zones/ct/alerting.ts">AlertingEditResponse</a></code>
176+
- <code><a href="./src/resources/zones/ct/alerting.ts">AlertingGetResponse</a></code>
177+
178+
Methods:
179+
180+
- <code title="patch /zones/{zone_id}/ct/alerting">client.zones.ct.alerting.<a href="./src/resources/zones/ct/alerting.ts">edit</a>({ ...params }) -> AlertingEditResponse</code>
181+
- <code title="get /zones/{zone_id}/ct/alerting">client.zones.ct.alerting.<a href="./src/resources/zones/ct/alerting.ts">get</a>({ ...params }) -> AlertingGetResponse</code>

src/resources/zones/ct.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
export * from './ct/index';

src/resources/zones/ct/alerting.ts

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
import { APIResource } from '../../../resource';
4+
import * as Core from '../../../core';
5+
6+
export class Alerting extends APIResource {
7+
/**
8+
* Create or update the Certificate Transparency alerting subscription for a zone.
9+
* Enables or disables email notifications when certificates are issued for the
10+
* zone's domains. For Free and Pro zones, the subscription is toggled on or off
11+
* using the enabled field. Notification emails are sent to all users with SSL
12+
* permissions on the zone. For Business and Enterprise zones, the emails field is
13+
* required and controls which addresses receive alerts. Setting emails to an empty
14+
* list disables the subscription regardless of the enabled field. A maximum of 10
15+
* email addresses may be configured.
16+
*
17+
* @example
18+
* ```ts
19+
* const response = await client.zones.ct.alerting.edit({
20+
* zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
21+
* enabled: true,
22+
* });
23+
* ```
24+
*/
25+
edit(params: AlertingEditParams, options?: Core.RequestOptions): Core.APIPromise<AlertingEditResponse> {
26+
const { zone_id, ...body } = params;
27+
return (
28+
this._client.patch(`/zones/${zone_id}/ct/alerting`, { body, ...options }) as Core.APIPromise<{
29+
result: AlertingEditResponse;
30+
}>
31+
)._thenUnwrap((obj) => obj.result);
32+
}
33+
34+
/**
35+
* Retrieve the Certificate Transparency alerting subscription settings for a zone.
36+
* Returns whether CT monitoring is enabled and, for Business and Enterprise zones,
37+
* the list of email addresses that receive alerts.
38+
*
39+
* @example
40+
* ```ts
41+
* const alerting = await client.zones.ct.alerting.get({
42+
* zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
43+
* });
44+
* ```
45+
*/
46+
get(params: AlertingGetParams, options?: Core.RequestOptions): Core.APIPromise<AlertingGetResponse> {
47+
const { zone_id } = params;
48+
return (
49+
this._client.get(`/zones/${zone_id}/ct/alerting`, options) as Core.APIPromise<{
50+
result: AlertingGetResponse;
51+
}>
52+
)._thenUnwrap((obj) => obj.result);
53+
}
54+
}
55+
56+
/**
57+
* Certificate Transparency alerting subscription settings for a zone.
58+
*/
59+
export interface AlertingEditResponse {
60+
/**
61+
* Whether CT alerting is enabled for the zone.
62+
*/
63+
enabled: boolean;
64+
65+
/**
66+
* Email addresses that receive CT alert notifications. Only present and
67+
* configurable for Business and Enterprise zones. Maximum of 10 addresses. For
68+
* Free and Pro zones, notifications are sent to all users with SSL permissions on
69+
* the zone.
70+
*/
71+
emails?: Array<string>;
72+
}
73+
74+
/**
75+
* Certificate Transparency alerting subscription settings for a zone.
76+
*/
77+
export interface AlertingGetResponse {
78+
/**
79+
* Whether CT alerting is enabled for the zone.
80+
*/
81+
enabled: boolean;
82+
83+
/**
84+
* Email addresses that receive CT alert notifications. Only present and
85+
* configurable for Business and Enterprise zones. Maximum of 10 addresses. For
86+
* Free and Pro zones, notifications are sent to all users with SSL permissions on
87+
* the zone.
88+
*/
89+
emails?: Array<string>;
90+
}
91+
92+
export interface AlertingEditParams {
93+
/**
94+
* Path param: Identifier.
95+
*/
96+
zone_id: string;
97+
98+
/**
99+
* Body param: Whether CT alerting is enabled for the zone.
100+
*/
101+
enabled: boolean;
102+
103+
/**
104+
* Body param: Email addresses that receive CT alert notifications. Only present
105+
* and configurable for Business and Enterprise zones. Maximum of 10 addresses. For
106+
* Free and Pro zones, notifications are sent to all users with SSL permissions on
107+
* the zone.
108+
*/
109+
emails?: Array<string>;
110+
}
111+
112+
export interface AlertingGetParams {
113+
/**
114+
* Identifier.
115+
*/
116+
zone_id: string;
117+
}
118+
119+
export declare namespace Alerting {
120+
export {
121+
type AlertingEditResponse as AlertingEditResponse,
122+
type AlertingGetResponse as AlertingGetResponse,
123+
type AlertingEditParams as AlertingEditParams,
124+
type AlertingGetParams as AlertingGetParams,
125+
};
126+
}

src/resources/zones/ct/ct.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
import { APIResource } from '../../../resource';
4+
import * as AlertingAPI from './alerting';
5+
import {
6+
Alerting,
7+
AlertingEditParams,
8+
AlertingEditResponse,
9+
AlertingGetParams,
10+
AlertingGetResponse,
11+
} from './alerting';
12+
13+
export class CT extends APIResource {
14+
alerting: AlertingAPI.Alerting = new AlertingAPI.Alerting(this._client);
15+
}
16+
17+
CT.Alerting = Alerting;
18+
19+
export declare namespace CT {
20+
export {
21+
Alerting as Alerting,
22+
type AlertingEditResponse as AlertingEditResponse,
23+
type AlertingGetResponse as AlertingGetResponse,
24+
type AlertingEditParams as AlertingEditParams,
25+
type AlertingGetParams as AlertingGetParams,
26+
};
27+
}

src/resources/zones/ct/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
export {
4+
Alerting,
5+
type AlertingEditResponse,
6+
type AlertingGetResponse,
7+
type AlertingEditParams,
8+
type AlertingGetParams,
9+
} from './alerting';
10+
export { CT } from './ct';

src/resources/zones/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export {
1212
type PlanListParams,
1313
type PlanGetParams,
1414
} from './plans';
15+
export { CT } from './ct/index';
1516
export {
1617
CustomNameserverUpdateResponsesSinglePage,
1718
CustomNameservers,

src/resources/zones/zones.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ import {
119119
SubscriptionUpdateResponse,
120120
Subscriptions,
121121
} from './subscriptions';
122+
import * as CTAPI from './ct/ct';
123+
import { CT } from './ct/ct';
122124
import { V4PagePaginationArray, type V4PagePaginationArrayParams } from '../../pagination';
123125

124126
export class Zones extends APIResource {
@@ -132,6 +134,7 @@ export class Zones extends APIResource {
132134
subscriptions: SubscriptionsAPI.Subscriptions = new SubscriptionsAPI.Subscriptions(this._client);
133135
plans: PlansAPI.Plans = new PlansAPI.Plans(this._client);
134136
ratePlans: RatePlansAPI.RatePlans = new RatePlansAPI.RatePlans(this._client);
137+
ct: CTAPI.CT = new CTAPI.CT(this._client);
135138

136139
/**
137140
* Create Zone
@@ -694,6 +697,7 @@ Zones.Plans = Plans;
694697
Zones.AvailableRatePlansSinglePage = AvailableRatePlansSinglePage;
695698
Zones.RatePlans = RatePlans;
696699
Zones.RatePlanGetResponsesSinglePage = RatePlanGetResponsesSinglePage;
700+
Zones.CT = CT;
697701

698702
export declare namespace Zones {
699703
export {
@@ -830,4 +834,6 @@ export declare namespace Zones {
830834
RatePlanGetResponsesSinglePage as RatePlanGetResponsesSinglePage,
831835
type RatePlanGetParams as RatePlanGetParams,
832836
};
837+
838+
export { CT as CT };
833839
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
import Cloudflare from 'cloudflare';
4+
import { Response } from 'node-fetch';
5+
6+
const client = new Cloudflare({
7+
apiKey: '144c9defac04969c7bfad8efaa8ea194',
8+
apiEmail: 'user@example.com',
9+
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
10+
});
11+
12+
describe('resource alerting', () => {
13+
test('edit: only required params', async () => {
14+
const responsePromise = client.zones.ct.alerting.edit({
15+
zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
16+
enabled: true,
17+
});
18+
const rawResponse = await responsePromise.asResponse();
19+
expect(rawResponse).toBeInstanceOf(Response);
20+
const response = await responsePromise;
21+
expect(response).not.toBeInstanceOf(Response);
22+
const dataAndResponse = await responsePromise.withResponse();
23+
expect(dataAndResponse.data).toBe(response);
24+
expect(dataAndResponse.response).toBe(rawResponse);
25+
});
26+
27+
test('edit: required and optional params', async () => {
28+
const response = await client.zones.ct.alerting.edit({
29+
zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
30+
enabled: true,
31+
emails: ['security@example.com', 'admin@example.com'],
32+
});
33+
});
34+
35+
test('get: only required params', async () => {
36+
const responsePromise = client.zones.ct.alerting.get({ zone_id: '023e105f4ecef8ad9ca31a8372d0c353' });
37+
const rawResponse = await responsePromise.asResponse();
38+
expect(rawResponse).toBeInstanceOf(Response);
39+
const response = await responsePromise;
40+
expect(response).not.toBeInstanceOf(Response);
41+
const dataAndResponse = await responsePromise.withResponse();
42+
expect(dataAndResponse.data).toBe(response);
43+
expect(dataAndResponse.response).toBe(rawResponse);
44+
});
45+
46+
test('get: required and optional params', async () => {
47+
const response = await client.zones.ct.alerting.get({ zone_id: '023e105f4ecef8ad9ca31a8372d0c353' });
48+
});
49+
});

0 commit comments

Comments
 (0)