Skip to content

Commit 454ad3d

Browse files
feat: feat(abuse_reports): Expose new abuse report endpoints. GET and LIST.
* feat(abuse_reports): Expose new abuse report endpoints. GET and LIST. * feat(abuse_reports): Expose new abuse report endpoints
1 parent 6e4418f commit 454ad3d

File tree

4 files changed

+278
-2
lines changed

4 files changed

+278
-2
lines changed

.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
configured_endpoints: 1887
1+
configured_endpoints: 1889
22
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-fe5f9f74ec7fae587b81aa6c4405a2129bbe6c146d36a6a8eee6cbc184dceb01.yml
33
openapi_spec_hash: ad2c2470332035b5d92e2a94faefe5a6
4-
config_hash: 47bfb436213622df92afdda8ce4f077f
4+
config_hash: f02bc3ad56bdede6c515f996ca86012c

api.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8742,10 +8742,14 @@ Methods:
87428742
Types:
87438743

87448744
- <code><a href="./src/resources/abuse-reports.ts">AbuseReportCreateResponse</a></code>
8745+
- <code><a href="./src/resources/abuse-reports.ts">AbuseReportListResponse</a></code>
8746+
- <code><a href="./src/resources/abuse-reports.ts">AbuseReportGetResponse</a></code>
87458747

87468748
Methods:
87478749

87488750
- <code title="post /accounts/{account_id}/abuse-reports/{report_param}">client.abuseReports.<a href="./src/resources/abuse-reports.ts">create</a>(reportParam, { ...params }) -> AbuseReportCreateResponse</code>
8751+
- <code title="get /accounts/{account_id}/abuse-reports">client.abuseReports.<a href="./src/resources/abuse-reports.ts">list</a>({ ...params }) -> AbuseReportListResponsesV4PagePagination</code>
8752+
- <code title="get /accounts/{account_id}/abuse-reports/{report_param}">client.abuseReports.<a href="./src/resources/abuse-reports.ts">get</a>(reportParam, { ...params }) -> AbuseReportGetResponse</code>
87498753

87508754
# AI
87518755

src/resources/abuse-reports.ts

Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import { APIResource } from '../resource';
44
import * as Core from '../core';
5+
import { V4PagePagination, type V4PagePaginationParams } from '../pagination';
56

67
export class AbuseReports extends APIResource {
78
/**
@@ -20,13 +21,182 @@ export class AbuseReports extends APIResource {
2021
}) as Core.APIPromise<{ result: AbuseReportCreateResponse }>
2122
)._thenUnwrap((obj) => obj.result);
2223
}
24+
25+
/**
26+
* List the abuse reports for a given account.
27+
*/
28+
list(
29+
params: AbuseReportListParams,
30+
options?: Core.RequestOptions,
31+
): Core.PagePromise<AbuseReportListResponsesV4PagePagination, AbuseReportListResponse> {
32+
const { account_id, ...query } = params;
33+
return this._client.getAPIList(
34+
`/accounts/${account_id}/abuse-reports`,
35+
AbuseReportListResponsesV4PagePagination,
36+
{ query, ...options },
37+
);
38+
}
39+
40+
/**
41+
* Retrieve an abuse report.
42+
*/
43+
get(
44+
reportParam: string,
45+
params: AbuseReportGetParams,
46+
options?: Core.RequestOptions,
47+
): Core.APIPromise<AbuseReportGetResponse> {
48+
const { account_id } = params;
49+
return (
50+
this._client.get(`/accounts/${account_id}/abuse-reports/${reportParam}`, options) as Core.APIPromise<{
51+
result: AbuseReportGetResponse;
52+
}>
53+
)._thenUnwrap((obj) => obj.result);
54+
}
2355
}
2456

57+
export class AbuseReportListResponsesV4PagePagination extends V4PagePagination<AbuseReportListResponse> {}
58+
2559
/**
2660
* The result should be 'success' for successful response
2761
*/
2862
export type AbuseReportCreateResponse = string;
2963

64+
export interface AbuseReportListResponse {
65+
reports: Array<AbuseReportListResponse.Report>;
66+
}
67+
68+
export namespace AbuseReportListResponse {
69+
export interface Report {
70+
/**
71+
* Public facing ID of abuse report, aka abuse_rand.
72+
*/
73+
id: string;
74+
75+
/**
76+
* Creation date of report. Time in RFC 3339 format
77+
* (https://www.rfc-editor.org/rfc/rfc3339.html)
78+
*/
79+
cdate: string;
80+
81+
/**
82+
* Domain that relates to the report.
83+
*/
84+
domain: string;
85+
86+
/**
87+
* A summary of the mitigations related to this report.
88+
*/
89+
mitigation_summary: Report.MitigationSummary;
90+
91+
/**
92+
* An enum value that represents the status of an abuse record
93+
*/
94+
status: 'accepted' | 'in_review';
95+
96+
/**
97+
* The abuse report type
98+
*/
99+
type: 'PHISH' | 'GEN' | 'THREAT' | 'DMCA' | 'EMER' | 'TM' | 'REG_WHO' | 'NCSEI' | 'NETWORK';
100+
}
101+
102+
export namespace Report {
103+
/**
104+
* A summary of the mitigations related to this report.
105+
*/
106+
export interface MitigationSummary {
107+
/**
108+
* How many of the reported URLs were confirmed as abusive.
109+
*/
110+
accepted_url_count: number;
111+
112+
/**
113+
* How many mitigations are active.
114+
*/
115+
active_count: number;
116+
117+
/**
118+
* Whether the report has been forwarded to an external hosting provider.
119+
*/
120+
external_host_notified: boolean;
121+
122+
/**
123+
* How many mitigations are under review.
124+
*/
125+
in_review_count: number;
126+
127+
/**
128+
* How many mitigations are pending their effective date.
129+
*/
130+
pending_count: number;
131+
}
132+
}
133+
}
134+
135+
export interface AbuseReportGetResponse {
136+
/**
137+
* Public facing ID of abuse report, aka abuse_rand.
138+
*/
139+
id: string;
140+
141+
/**
142+
* Creation date of report. Time in RFC 3339 format
143+
* (https://www.rfc-editor.org/rfc/rfc3339.html)
144+
*/
145+
cdate: string;
146+
147+
/**
148+
* Domain that relates to the report.
149+
*/
150+
domain: string;
151+
152+
/**
153+
* A summary of the mitigations related to this report.
154+
*/
155+
mitigation_summary: AbuseReportGetResponse.MitigationSummary;
156+
157+
/**
158+
* An enum value that represents the status of an abuse record
159+
*/
160+
status: 'accepted' | 'in_review';
161+
162+
/**
163+
* The abuse report type
164+
*/
165+
type: 'PHISH' | 'GEN' | 'THREAT' | 'DMCA' | 'EMER' | 'TM' | 'REG_WHO' | 'NCSEI' | 'NETWORK';
166+
}
167+
168+
export namespace AbuseReportGetResponse {
169+
/**
170+
* A summary of the mitigations related to this report.
171+
*/
172+
export interface MitigationSummary {
173+
/**
174+
* How many of the reported URLs were confirmed as abusive.
175+
*/
176+
accepted_url_count: number;
177+
178+
/**
179+
* How many mitigations are active.
180+
*/
181+
active_count: number;
182+
183+
/**
184+
* Whether the report has been forwarded to an external hosting provider.
185+
*/
186+
external_host_notified: boolean;
187+
188+
/**
189+
* How many mitigations are under review.
190+
*/
191+
in_review_count: number;
192+
193+
/**
194+
* How many mitigations are pending their effective date.
195+
*/
196+
pending_count: number;
197+
}
198+
}
199+
30200
export type AbuseReportCreateParams =
31201
| AbuseReportCreateParams.AbuseReportsDmcaReport
32202
| AbuseReportCreateParams.AbuseReportsTrademarkReport
@@ -881,9 +1051,66 @@ export declare namespace AbuseReportCreateParams {
8811051
}
8821052
}
8831053

1054+
export interface AbuseReportListParams extends V4PagePaginationParams {
1055+
/**
1056+
* Path param: Cloudflare Account ID
1057+
*/
1058+
account_id: string;
1059+
1060+
/**
1061+
* Query param: Returns reports created after the specified date
1062+
*/
1063+
created_after?: string;
1064+
1065+
/**
1066+
* Query param: Returns reports created before the specified date
1067+
*/
1068+
created_before?: string;
1069+
1070+
/**
1071+
* Query param: Filter by domain name related to the abuse report
1072+
*/
1073+
domain?: string;
1074+
1075+
/**
1076+
* Query param: Filter reports that have any mitigations in the given status.
1077+
*/
1078+
mitigation_status?: 'pending' | 'active' | 'in_review' | 'cancelled' | 'removed';
1079+
1080+
/**
1081+
* Query param: A property to sort by, followed by the order (id, cdate, domain,
1082+
* type, status)
1083+
*/
1084+
sort?: string;
1085+
1086+
/**
1087+
* Query param: Filter by the status of the report.
1088+
*/
1089+
status?: 'accepted' | 'in_review';
1090+
1091+
/**
1092+
* Query param: Filter by the type of the report.
1093+
*/
1094+
type?: 'PHISH' | 'GEN' | 'THREAT' | 'DMCA' | 'EMER' | 'TM' | 'REG_WHO' | 'NCSEI' | 'NETWORK';
1095+
}
1096+
1097+
export interface AbuseReportGetParams {
1098+
/**
1099+
* Cloudflare Account ID
1100+
*/
1101+
account_id: string;
1102+
}
1103+
1104+
AbuseReports.AbuseReportListResponsesV4PagePagination = AbuseReportListResponsesV4PagePagination;
1105+
8841106
export declare namespace AbuseReports {
8851107
export {
8861108
type AbuseReportCreateResponse as AbuseReportCreateResponse,
1109+
type AbuseReportListResponse as AbuseReportListResponse,
1110+
type AbuseReportGetResponse as AbuseReportGetResponse,
1111+
AbuseReportListResponsesV4PagePagination as AbuseReportListResponsesV4PagePagination,
8871112
type AbuseReportCreateParams as AbuseReportCreateParams,
1113+
type AbuseReportListParams as AbuseReportListParams,
1114+
type AbuseReportGetParams as AbuseReportGetParams,
8881115
};
8891116
}

tests/api-resources/abuse-reports.test.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,49 @@ describe('resource abuseReports', () => {
6666
title: 'x',
6767
});
6868
});
69+
70+
test('list: only required params', async () => {
71+
const responsePromise = client.abuseReports.list({ account_id: '023e105f4ecef8ad9ca31a8372d0c353' });
72+
const rawResponse = await responsePromise.asResponse();
73+
expect(rawResponse).toBeInstanceOf(Response);
74+
const response = await responsePromise;
75+
expect(response).not.toBeInstanceOf(Response);
76+
const dataAndResponse = await responsePromise.withResponse();
77+
expect(dataAndResponse.data).toBe(response);
78+
expect(dataAndResponse.response).toBe(rawResponse);
79+
});
80+
81+
test('list: required and optional params', async () => {
82+
const response = await client.abuseReports.list({
83+
account_id: '023e105f4ecef8ad9ca31a8372d0c353',
84+
created_after: '2009-11-10T23:00:00Z',
85+
created_before: '2009-11-10T23:00:00Z',
86+
domain: 'domain',
87+
mitigation_status: 'pending',
88+
page: 0,
89+
per_page: 0,
90+
sort: 'sort',
91+
status: 'accepted',
92+
type: 'PHISH',
93+
});
94+
});
95+
96+
test('get: only required params', async () => {
97+
const responsePromise = client.abuseReports.get('report_param', {
98+
account_id: '023e105f4ecef8ad9ca31a8372d0c353',
99+
});
100+
const rawResponse = await responsePromise.asResponse();
101+
expect(rawResponse).toBeInstanceOf(Response);
102+
const response = await responsePromise;
103+
expect(response).not.toBeInstanceOf(Response);
104+
const dataAndResponse = await responsePromise.withResponse();
105+
expect(dataAndResponse.data).toBe(response);
106+
expect(dataAndResponse.response).toBe(rawResponse);
107+
});
108+
109+
test('get: required and optional params', async () => {
110+
const response = await client.abuseReports.get('report_param', {
111+
account_id: '023e105f4ecef8ad9ca31a8372d0c353',
112+
});
113+
});
69114
});

0 commit comments

Comments
 (0)