|
| 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 | +} |
0 commit comments