🌐 AI搜索 & 代理 主页
Skip to content

Commit 803fd0e

Browse files
stainless-app[bot]meorphis
authored andcommitted
feat(r2_bucket): add cors support (#2178)
1 parent cddc5fd commit 803fd0e

File tree

6 files changed

+371
-1
lines changed

6 files changed

+371
-1
lines changed

.stats.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
configured_endpoints: 1448
1+
configured_endpoints: 1451
22
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-4acaaed718bd08d16e3866d5ad032fbf2bbfeb978df2cf5164edb81fe41e4f89.yml

api.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4013,6 +4013,20 @@ Methods:
40134013
- <code title="put /accounts/{account_id}/r2/buckets/{bucket_name}/lifecycle">client.r2.buckets.lifecycle.<a href="./src/resources/r2/buckets/lifecycle.ts">update</a>(bucketName, { ...params }) -> LifecycleUpdateResponse</code>
40144014
- <code title="get /accounts/{account_id}/r2/buckets/{bucket_name}/lifecycle">client.r2.buckets.lifecycle.<a href="./src/resources/r2/buckets/lifecycle.ts">get</a>(bucketName, { ...params }) -> LifecycleGetResponse</code>
40154015

4016+
### CORS
4017+
4018+
Types:
4019+
4020+
- <code><a href="./src/resources/r2/buckets/cors.ts">CORSUpdateResponse</a></code>
4021+
- <code><a href="./src/resources/r2/buckets/cors.ts">CORSDeleteResponse</a></code>
4022+
- <code><a href="./src/resources/r2/buckets/cors.ts">CORSGetResponse</a></code>
4023+
4024+
Methods:
4025+
4026+
- <code title="put /accounts/{account_id}/r2/buckets/{bucket_name}/cors">client.r2.buckets.cors.<a href="./src/resources/r2/buckets/cors.ts">update</a>(bucketName, { ...params }) -> CORSUpdateResponse</code>
4027+
- <code title="delete /accounts/{account_id}/r2/buckets/{bucket_name}/cors">client.r2.buckets.cors.<a href="./src/resources/r2/buckets/cors.ts">delete</a>(bucketName, { ...params }) -> CORSDeleteResponse</code>
4028+
- <code title="get /accounts/{account_id}/r2/buckets/{bucket_name}/cors">client.r2.buckets.cors.<a href="./src/resources/r2/buckets/cors.ts">get</a>(bucketName, { ...params }) -> CORSGetResponse</code>
4029+
40164030
### Domains
40174031

40184032
#### Custom

src/resources/r2/buckets/buckets.ts

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

33
import { APIResource } from '../../../resource';
44
import * as Core from '../../../core';
5+
import * as CORSAPI from './cors';
6+
import {
7+
CORS,
8+
CORSDeleteParams,
9+
CORSDeleteResponse,
10+
CORSGetParams,
11+
CORSGetResponse,
12+
CORSUpdateParams,
13+
CORSUpdateResponse,
14+
} from './cors';
515
import * as LifecycleAPI from './lifecycle';
616
import {
717
Lifecycle,
@@ -27,6 +37,7 @@ import { EventNotifications } from './event-notifications/event-notifications';
2737

2838
export class Buckets extends APIResource {
2939
lifecycle: LifecycleAPI.Lifecycle = new LifecycleAPI.Lifecycle(this._client);
40+
cors: CORSAPI.CORS = new CORSAPI.CORS(this._client);
3041
domains: DomainsAPI.Domains = new DomainsAPI.Domains(this._client);
3142
eventNotifications: EventNotificationsAPI.EventNotifications = new EventNotificationsAPI.EventNotifications(
3243
this._client,
@@ -241,6 +252,7 @@ export interface BucketGetParams {
241252
}
242253

243254
Buckets.Lifecycle = Lifecycle;
255+
Buckets.CORS = CORS;
244256
Buckets.Domains = Domains;
245257
Buckets.EventNotifications = EventNotifications;
246258
Buckets.SippyResource = SippyResource;
@@ -264,6 +276,16 @@ export declare namespace Buckets {
264276
type LifecycleGetParams as LifecycleGetParams,
265277
};
266278

279+
export {
280+
CORS as CORS,
281+
type CORSUpdateResponse as CORSUpdateResponse,
282+
type CORSDeleteResponse as CORSDeleteResponse,
283+
type CORSGetResponse as CORSGetResponse,
284+
type CORSUpdateParams as CORSUpdateParams,
285+
type CORSDeleteParams as CORSDeleteParams,
286+
type CORSGetParams as CORSGetParams,
287+
};
288+
267289
export { Domains as Domains };
268290

269291
export { EventNotifications as EventNotifications };

src/resources/r2/buckets/cors.ts

Lines changed: 245 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,245 @@
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 CORS extends APIResource {
7+
/**
8+
* Set the CORS policy for a bucket
9+
*/
10+
update(
11+
bucketName: string,
12+
params: CORSUpdateParams,
13+
options?: Core.RequestOptions,
14+
): Core.APIPromise<CORSUpdateResponse> {
15+
const { account_id, 'cf-r2-jurisdiction': cfR2Jurisdiction, ...body } = params;
16+
return (
17+
this._client.put(`/accounts/${account_id}/r2/buckets/${bucketName}/cors`, {
18+
body,
19+
...options,
20+
headers: {
21+
...(cfR2Jurisdiction?.toString() != null ?
22+
{ 'cf-r2-jurisdiction': cfR2Jurisdiction?.toString() }
23+
: undefined),
24+
...options?.headers,
25+
},
26+
}) as Core.APIPromise<{ result: CORSUpdateResponse }>
27+
)._thenUnwrap((obj) => obj.result);
28+
}
29+
30+
/**
31+
* Delete the CORS policy for a bucket
32+
*/
33+
delete(
34+
bucketName: string,
35+
params: CORSDeleteParams,
36+
options?: Core.RequestOptions,
37+
): Core.APIPromise<CORSDeleteResponse> {
38+
const { account_id, 'cf-r2-jurisdiction': cfR2Jurisdiction } = params;
39+
return (
40+
this._client.delete(`/accounts/${account_id}/r2/buckets/${bucketName}/cors`, {
41+
...options,
42+
headers: {
43+
...(cfR2Jurisdiction?.toString() != null ?
44+
{ 'cf-r2-jurisdiction': cfR2Jurisdiction?.toString() }
45+
: undefined),
46+
...options?.headers,
47+
},
48+
}) as Core.APIPromise<{ result: CORSDeleteResponse }>
49+
)._thenUnwrap((obj) => obj.result);
50+
}
51+
52+
/**
53+
* Get the CORS policy for a bucket
54+
*/
55+
get(
56+
bucketName: string,
57+
params: CORSGetParams,
58+
options?: Core.RequestOptions,
59+
): Core.APIPromise<CORSGetResponse> {
60+
const { account_id, 'cf-r2-jurisdiction': cfR2Jurisdiction } = params;
61+
return (
62+
this._client.get(`/accounts/${account_id}/r2/buckets/${bucketName}/cors`, {
63+
...options,
64+
headers: {
65+
...(cfR2Jurisdiction?.toString() != null ?
66+
{ 'cf-r2-jurisdiction': cfR2Jurisdiction?.toString() }
67+
: undefined),
68+
...options?.headers,
69+
},
70+
}) as Core.APIPromise<{ result: CORSGetResponse }>
71+
)._thenUnwrap((obj) => obj.result);
72+
}
73+
}
74+
75+
export type CORSUpdateResponse = unknown;
76+
77+
export type CORSDeleteResponse = unknown;
78+
79+
export interface CORSGetResponse {
80+
rules?: Array<CORSGetResponse.Rule>;
81+
}
82+
83+
export namespace CORSGetResponse {
84+
export interface Rule {
85+
/**
86+
* Object specifying allowed origins, methods and headers for this CORS rule.
87+
*/
88+
allowed: Rule.Allowed;
89+
90+
/**
91+
* Identifier for this rule
92+
*/
93+
id?: string;
94+
95+
/**
96+
* Specifies the headers that can be exposed back, and accessed by, the JavaScript
97+
* making the cross-origin request. If you need to access headers beyond the
98+
* safelisted response headers, such as Content-Encoding or cf-cache-status, you
99+
* must specify it here.
100+
*/
101+
exposeHeaders?: Array<string>;
102+
103+
/**
104+
* Specifies the amount of time (in seconds) browsers are allowed to cache CORS
105+
* preflight responses. Browsers may limit this to 2 hours or less, even if the
106+
* maximum value (86400) is specified.
107+
*/
108+
maxAgeSeconds?: number;
109+
}
110+
111+
export namespace Rule {
112+
/**
113+
* Object specifying allowed origins, methods and headers for this CORS rule.
114+
*/
115+
export interface Allowed {
116+
/**
117+
* Specifies the value for the Access-Control-Allow-Methods header R2 sets when
118+
* requesting objects in a bucket from a browser.
119+
*/
120+
methods: Array<'GET' | 'PUT' | 'POST' | 'DELETE' | 'HEAD'>;
121+
122+
/**
123+
* Specifies the value for the Access-Control-Allow-Origin header R2 sets when
124+
* requesting objects in a bucket from a browser.
125+
*/
126+
origins: Array<string>;
127+
128+
/**
129+
* Specifies the value for the Access-Control-Allow-Headers header R2 sets when
130+
* requesting objects in this bucket from a browser. Cross-origin requests that
131+
* include custom headers (e.g. x-user-id) should specify these headers as
132+
* AllowedHeaders.
133+
*/
134+
headers?: Array<string>;
135+
}
136+
}
137+
}
138+
139+
export interface CORSUpdateParams {
140+
/**
141+
* Path param: Account ID
142+
*/
143+
account_id: string;
144+
145+
/**
146+
* Body param:
147+
*/
148+
rules?: Array<CORSUpdateParams.Rule>;
149+
150+
/**
151+
* Header param: The bucket jurisdiction
152+
*/
153+
'cf-r2-jurisdiction'?: 'default' | 'eu' | 'fedramp';
154+
}
155+
156+
export namespace CORSUpdateParams {
157+
export interface Rule {
158+
/**
159+
* Object specifying allowed origins, methods and headers for this CORS rule.
160+
*/
161+
allowed: Rule.Allowed;
162+
163+
/**
164+
* Identifier for this rule
165+
*/
166+
id?: string;
167+
168+
/**
169+
* Specifies the headers that can be exposed back, and accessed by, the JavaScript
170+
* making the cross-origin request. If you need to access headers beyond the
171+
* safelisted response headers, such as Content-Encoding or cf-cache-status, you
172+
* must specify it here.
173+
*/
174+
exposeHeaders?: Array<string>;
175+
176+
/**
177+
* Specifies the amount of time (in seconds) browsers are allowed to cache CORS
178+
* preflight responses. Browsers may limit this to 2 hours or less, even if the
179+
* maximum value (86400) is specified.
180+
*/
181+
maxAgeSeconds?: number;
182+
}
183+
184+
export namespace Rule {
185+
/**
186+
* Object specifying allowed origins, methods and headers for this CORS rule.
187+
*/
188+
export interface Allowed {
189+
/**
190+
* Specifies the value for the Access-Control-Allow-Methods header R2 sets when
191+
* requesting objects in a bucket from a browser.
192+
*/
193+
methods: Array<'GET' | 'PUT' | 'POST' | 'DELETE' | 'HEAD'>;
194+
195+
/**
196+
* Specifies the value for the Access-Control-Allow-Origin header R2 sets when
197+
* requesting objects in a bucket from a browser.
198+
*/
199+
origins: Array<string>;
200+
201+
/**
202+
* Specifies the value for the Access-Control-Allow-Headers header R2 sets when
203+
* requesting objects in this bucket from a browser. Cross-origin requests that
204+
* include custom headers (e.g. x-user-id) should specify these headers as
205+
* AllowedHeaders.
206+
*/
207+
headers?: Array<string>;
208+
}
209+
}
210+
}
211+
212+
export interface CORSDeleteParams {
213+
/**
214+
* Path param: Account ID
215+
*/
216+
account_id: string;
217+
218+
/**
219+
* Header param: The bucket jurisdiction
220+
*/
221+
'cf-r2-jurisdiction'?: 'default' | 'eu' | 'fedramp';
222+
}
223+
224+
export interface CORSGetParams {
225+
/**
226+
* Path param: Account ID
227+
*/
228+
account_id: string;
229+
230+
/**
231+
* Header param: The bucket jurisdiction
232+
*/
233+
'cf-r2-jurisdiction'?: 'default' | 'eu' | 'fedramp';
234+
}
235+
236+
export declare namespace CORS {
237+
export {
238+
type CORSUpdateResponse as CORSUpdateResponse,
239+
type CORSDeleteResponse as CORSDeleteResponse,
240+
type CORSGetResponse as CORSGetResponse,
241+
type CORSUpdateParams as CORSUpdateParams,
242+
type CORSDeleteParams as CORSDeleteParams,
243+
type CORSGetParams as CORSGetParams,
244+
};
245+
}

src/resources/r2/buckets/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ export {
1010
type BucketDeleteParams,
1111
type BucketGetParams,
1212
} from './buckets';
13+
export {
14+
CORS,
15+
type CORSUpdateResponse,
16+
type CORSDeleteResponse,
17+
type CORSGetResponse,
18+
type CORSUpdateParams,
19+
type CORSDeleteParams,
20+
type CORSGetParams,
21+
} from './cors';
1322
export { Domains } from './domains/index';
1423
export { EventNotifications } from './event-notifications/index';
1524
export {

0 commit comments

Comments
 (0)