cloudflare/cloudflare-typescript
Publicmirrored from https://github.com/cloudflare/cloudflare-typescriptAvailable
src/resources/cache/cache-reserve.ts
288lines · modecode
| 1 | // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
| 2 | |
| 3 | import { APIResource } from '../../core/resource'; |
| 4 | import { APIPromise } from '../../core/api-promise'; |
| 5 | import { RequestOptions } from '../../internal/request-options'; |
| 6 | import { path } from '../../internal/utils/path'; |
| 7 | |
| 8 | export class BaseCacheReserveResource extends APIResource { |
| 9 | static override readonly _key: readonly ['cache', 'cacheReserve'] = Object.freeze([ |
| 10 | 'cache', |
| 11 | 'cacheReserve', |
| 12 | ] as const); |
| 13 | |
| 14 | /** |
| 15 | * You can use Cache Reserve Clear to clear your Cache Reserve, but you must first |
| 16 | * disable Cache Reserve. In most cases, this will be accomplished within 24 hours. |
| 17 | * You cannot re-enable Cache Reserve while this process is ongoing. Keep in mind |
| 18 | * that you cannot undo or cancel this operation. |
| 19 | * |
| 20 | * @example |
| 21 | * ```ts |
| 22 | * const response = await client.cache.cacheReserve.clear({ |
| 23 | * zone_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 24 | * body: {}, |
| 25 | * }); |
| 26 | * ``` |
| 27 | */ |
| 28 | clear(params: CacheReserveClearParams, options?: RequestOptions): APIPromise<CacheReserveClearResponse> { |
| 29 | const { zone_id, body } = params; |
| 30 | return ( |
| 31 | this._client.post(path`/zones/${zone_id}/cache/cache_reserve_clear`, { |
| 32 | body: body, |
| 33 | ...options, |
| 34 | }) as APIPromise<{ result: CacheReserveClearResponse }> |
| 35 | )._thenUnwrap((obj) => obj.result); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Increase cache lifetimes by automatically storing all cacheable files into |
| 40 | * Cloudflare's persistent object storage buckets. Requires Cache Reserve |
| 41 | * subscription. Note: using Tiered Cache with Cache Reserve is highly recommended |
| 42 | * to reduce Reserve operations costs. See the |
| 43 | * [developer docs](https://developers.cloudflare.com/cache/about/cache-reserve) |
| 44 | * for more information. |
| 45 | * |
| 46 | * @example |
| 47 | * ```ts |
| 48 | * const response = await client.cache.cacheReserve.edit({ |
| 49 | * zone_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 50 | * value: 'on', |
| 51 | * }); |
| 52 | * ``` |
| 53 | */ |
| 54 | edit(params: CacheReserveEditParams, options?: RequestOptions): APIPromise<CacheReserveEditResponse> { |
| 55 | const { zone_id, ...body } = params; |
| 56 | return ( |
| 57 | this._client.patch(path`/zones/${zone_id}/cache/cache_reserve`, { body, ...options }) as APIPromise<{ |
| 58 | result: CacheReserveEditResponse; |
| 59 | }> |
| 60 | )._thenUnwrap((obj) => obj.result); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Increase cache lifetimes by automatically storing all cacheable files into |
| 65 | * Cloudflare's persistent object storage buckets. Requires Cache Reserve |
| 66 | * subscription. Note: using Tiered Cache with Cache Reserve is highly recommended |
| 67 | * to reduce Reserve operations costs. See the |
| 68 | * [developer docs](https://developers.cloudflare.com/cache/about/cache-reserve) |
| 69 | * for more information. |
| 70 | * |
| 71 | * @example |
| 72 | * ```ts |
| 73 | * const cacheReserve = await client.cache.cacheReserve.get({ |
| 74 | * zone_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 75 | * }); |
| 76 | * ``` |
| 77 | */ |
| 78 | get(params: CacheReserveGetParams, options?: RequestOptions): APIPromise<CacheReserveGetResponse> { |
| 79 | const { zone_id } = params; |
| 80 | return ( |
| 81 | this._client.get(path`/zones/${zone_id}/cache/cache_reserve`, options) as APIPromise<{ |
| 82 | result: CacheReserveGetResponse; |
| 83 | }> |
| 84 | )._thenUnwrap((obj) => obj.result); |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * You can use Cache Reserve Clear to clear your Cache Reserve, but you must first |
| 89 | * disable Cache Reserve. In most cases, this will be accomplished within 24 hours. |
| 90 | * You cannot re-enable Cache Reserve while this process is ongoing. Keep in mind |
| 91 | * that you cannot undo or cancel this operation. |
| 92 | * |
| 93 | * @example |
| 94 | * ```ts |
| 95 | * const response = await client.cache.cacheReserve.status({ |
| 96 | * zone_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 97 | * }); |
| 98 | * ``` |
| 99 | */ |
| 100 | status(params: CacheReserveStatusParams, options?: RequestOptions): APIPromise<CacheReserveStatusResponse> { |
| 101 | const { zone_id } = params; |
| 102 | return ( |
| 103 | this._client.get(path`/zones/${zone_id}/cache/cache_reserve_clear`, options) as APIPromise<{ |
| 104 | result: CacheReserveStatusResponse; |
| 105 | }> |
| 106 | )._thenUnwrap((obj) => obj.result); |
| 107 | } |
| 108 | } |
| 109 | export class CacheReserveResource extends BaseCacheReserveResource {} |
| 110 | |
| 111 | /** |
| 112 | * The identifier of the caching setting. |
| 113 | */ |
| 114 | export type CacheReserve = 'cache_reserve'; |
| 115 | |
| 116 | /** |
| 117 | * ID of the zone setting. |
| 118 | */ |
| 119 | export type CacheReserveClear = 'cache_reserve_clear'; |
| 120 | |
| 121 | /** |
| 122 | * The current state of the Cache Reserve Clear operation. |
| 123 | */ |
| 124 | export type State = 'In-progress' | 'Completed'; |
| 125 | |
| 126 | /** |
| 127 | * You can use Cache Reserve Clear to clear your Cache Reserve, but you must first |
| 128 | * disable Cache Reserve. In most cases, this will be accomplished within 24 hours. |
| 129 | * You cannot re-enable Cache Reserve while this process is ongoing. Keep in mind |
| 130 | * that you cannot undo or cancel this operation. |
| 131 | */ |
| 132 | export interface CacheReserveClearResponse { |
| 133 | /** |
| 134 | * ID of the zone setting. |
| 135 | */ |
| 136 | id: CacheReserveClear; |
| 137 | |
| 138 | /** |
| 139 | * The time that the latest Cache Reserve Clear operation started. |
| 140 | */ |
| 141 | start_ts: string; |
| 142 | |
| 143 | /** |
| 144 | * The current state of the Cache Reserve Clear operation. |
| 145 | */ |
| 146 | state: State; |
| 147 | |
| 148 | /** |
| 149 | * The time that the latest Cache Reserve Clear operation completed. |
| 150 | */ |
| 151 | end_ts?: string; |
| 152 | |
| 153 | /** |
| 154 | * Last time this setting was modified. |
| 155 | */ |
| 156 | modified_on?: string | null; |
| 157 | } |
| 158 | |
| 159 | export interface CacheReserveEditResponse { |
| 160 | /** |
| 161 | * The identifier of the caching setting. |
| 162 | */ |
| 163 | id: CacheReserve; |
| 164 | |
| 165 | /** |
| 166 | * Whether the setting is editable. |
| 167 | */ |
| 168 | editable: boolean; |
| 169 | |
| 170 | /** |
| 171 | * Value of the Cache Reserve zone setting. |
| 172 | */ |
| 173 | value: 'on' | 'off'; |
| 174 | |
| 175 | /** |
| 176 | * Last time this setting was modified. |
| 177 | */ |
| 178 | modified_on?: string | null; |
| 179 | } |
| 180 | |
| 181 | export interface CacheReserveGetResponse { |
| 182 | /** |
| 183 | * The identifier of the caching setting. |
| 184 | */ |
| 185 | id: CacheReserve; |
| 186 | |
| 187 | /** |
| 188 | * Whether the setting is editable. |
| 189 | */ |
| 190 | editable: boolean; |
| 191 | |
| 192 | /** |
| 193 | * Value of the Cache Reserve zone setting. |
| 194 | */ |
| 195 | value: 'on' | 'off'; |
| 196 | |
| 197 | /** |
| 198 | * Last time this setting was modified. |
| 199 | */ |
| 200 | modified_on?: string | null; |
| 201 | } |
| 202 | |
| 203 | /** |
| 204 | * You can use Cache Reserve Clear to clear your Cache Reserve, but you must first |
| 205 | * disable Cache Reserve. In most cases, this will be accomplished within 24 hours. |
| 206 | * You cannot re-enable Cache Reserve while this process is ongoing. Keep in mind |
| 207 | * that you cannot undo or cancel this operation. |
| 208 | */ |
| 209 | export interface CacheReserveStatusResponse { |
| 210 | /** |
| 211 | * ID of the zone setting. |
| 212 | */ |
| 213 | id: CacheReserveClear; |
| 214 | |
| 215 | /** |
| 216 | * The time that the latest Cache Reserve Clear operation started. |
| 217 | */ |
| 218 | start_ts: string; |
| 219 | |
| 220 | /** |
| 221 | * The current state of the Cache Reserve Clear operation. |
| 222 | */ |
| 223 | state: State; |
| 224 | |
| 225 | /** |
| 226 | * The time that the latest Cache Reserve Clear operation completed. |
| 227 | */ |
| 228 | end_ts?: string; |
| 229 | |
| 230 | /** |
| 231 | * Last time this setting was modified. |
| 232 | */ |
| 233 | modified_on?: string | null; |
| 234 | } |
| 235 | |
| 236 | export interface CacheReserveClearParams { |
| 237 | /** |
| 238 | * Path param: Identifier. |
| 239 | */ |
| 240 | zone_id: string; |
| 241 | |
| 242 | /** |
| 243 | * Body param |
| 244 | */ |
| 245 | body: unknown; |
| 246 | } |
| 247 | |
| 248 | export interface CacheReserveEditParams { |
| 249 | /** |
| 250 | * Path param: Identifier. |
| 251 | */ |
| 252 | zone_id: string; |
| 253 | |
| 254 | /** |
| 255 | * Body param: Value of the Cache Reserve zone setting. |
| 256 | */ |
| 257 | value: 'on' | 'off'; |
| 258 | } |
| 259 | |
| 260 | export interface CacheReserveGetParams { |
| 261 | /** |
| 262 | * Identifier. |
| 263 | */ |
| 264 | zone_id: string; |
| 265 | } |
| 266 | |
| 267 | export interface CacheReserveStatusParams { |
| 268 | /** |
| 269 | * Identifier. |
| 270 | */ |
| 271 | zone_id: string; |
| 272 | } |
| 273 | |
| 274 | export declare namespace CacheReserveResource { |
| 275 | export { |
| 276 | type CacheReserve as CacheReserve, |
| 277 | type CacheReserveClear as CacheReserveClear, |
| 278 | type State as State, |
| 279 | type CacheReserveClearResponse as CacheReserveClearResponse, |
| 280 | type CacheReserveEditResponse as CacheReserveEditResponse, |
| 281 | type CacheReserveGetResponse as CacheReserveGetResponse, |
| 282 | type CacheReserveStatusResponse as CacheReserveStatusResponse, |
| 283 | type CacheReserveClearParams as CacheReserveClearParams, |
| 284 | type CacheReserveEditParams as CacheReserveEditParams, |
| 285 | type CacheReserveGetParams as CacheReserveGetParams, |
| 286 | type CacheReserveStatusParams as CacheReserveStatusParams, |
| 287 | }; |
| 288 | } |
| 289 | |