cloudflare/cloudflare-typescript
Publicmirrored fromhttps://github.com/cloudflare/cloudflare-typescriptAvailable
src/resources/api-gateway/configurations.ts
187lines · modecode
| 1 | // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
| 2 | |
| 3 | import { APIResource } from '../../resource'; |
| 4 | import { isRequestOptions } from '../../core'; |
| 5 | import * as Core from '../../core'; |
| 6 | |
| 7 | export class Configurations extends APIResource { |
| 8 | /** |
| 9 | * Updates API Shield configuration settings for a zone. Can modify validation |
| 10 | * strictness, enforcement mode, and other global settings. |
| 11 | * |
| 12 | * @example |
| 13 | * ```ts |
| 14 | * const configuration = |
| 15 | * await client.apiGateway.configurations.update({ |
| 16 | * zone_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 17 | * auth_id_characteristics: [ |
| 18 | * { name: 'authorization', type: 'header' }, |
| 19 | * ], |
| 20 | * }); |
| 21 | * ``` |
| 22 | */ |
| 23 | update(params: ConfigurationUpdateParams, options?: Core.RequestOptions): Core.APIPromise<Configuration> { |
| 24 | const { zone_id = this._client.zoneId, normalize, ...body } = params; |
| 25 | return ( |
| 26 | this._client.put(`/zones/${zone_id}/api_gateway/configuration`, { |
| 27 | query: { normalize }, |
| 28 | body, |
| 29 | ...options, |
| 30 | }) as Core.APIPromise<{ result: Configuration }> |
| 31 | )._thenUnwrap((obj) => obj.result); |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Gets the current API Shield configuration settings for a zone, including |
| 36 | * validation behavior and enforcement mode. |
| 37 | * |
| 38 | * @example |
| 39 | * ```ts |
| 40 | * const configuration = |
| 41 | * await client.apiGateway.configurations.get({ |
| 42 | * zone_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 43 | * }); |
| 44 | * ``` |
| 45 | */ |
| 46 | get(params?: ConfigurationGetParams, options?: Core.RequestOptions): Core.APIPromise<Configuration>; |
| 47 | get(options?: Core.RequestOptions): Core.APIPromise<Configuration>; |
| 48 | get( |
| 49 | params: ConfigurationGetParams | Core.RequestOptions = {}, |
| 50 | options?: Core.RequestOptions, |
| 51 | ): Core.APIPromise<Configuration> { |
| 52 | if (isRequestOptions(params)) { |
| 53 | return this.get({}, params); |
| 54 | } |
| 55 | const { zone_id = this._client.zoneId, ...query } = params; |
| 56 | return ( |
| 57 | this._client.get(`/zones/${zone_id}/api_gateway/configuration`, { |
| 58 | query, |
| 59 | ...options, |
| 60 | }) as Core.APIPromise<{ result: Configuration }> |
| 61 | )._thenUnwrap((obj) => obj.result); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | export interface Configuration { |
| 66 | auth_id_characteristics: Array< |
| 67 | Configuration.APIShieldAuthIDCharacteristic | Configuration.APIShieldAuthIDCharacteristicJWTClaim |
| 68 | >; |
| 69 | } |
| 70 | |
| 71 | export namespace Configuration { |
| 72 | /** |
| 73 | * Auth ID Characteristic |
| 74 | */ |
| 75 | export interface APIShieldAuthIDCharacteristic { |
| 76 | /** |
| 77 | * The name of the characteristic field, i.e., the header or cookie name. |
| 78 | */ |
| 79 | name: string; |
| 80 | |
| 81 | /** |
| 82 | * The type of characteristic. |
| 83 | */ |
| 84 | type: 'header' | 'cookie'; |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Auth ID Characteristic extracted from JWT Token Claims |
| 89 | */ |
| 90 | export interface APIShieldAuthIDCharacteristicJWTClaim { |
| 91 | /** |
| 92 | * Claim location expressed as `$(token_config_id):$(json_path)`, where |
| 93 | * `token_config_id` is the ID of the token configuration used in validating the |
| 94 | * JWT, and `json_path` is a RFC 9535 JSONPath |
| 95 | * (https://goessner.net/articles/JsonPath/, |
| 96 | * https://www.rfc-editor.org/rfc/rfc9535.html). The JSONPath expression may be in |
| 97 | * dot or bracket notation, may only specify literal keys or array indexes, and |
| 98 | * must return a singleton value, which will be interpreted as a string. |
| 99 | */ |
| 100 | name: string; |
| 101 | |
| 102 | /** |
| 103 | * The type of characteristic. |
| 104 | */ |
| 105 | type: 'jwt'; |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | export interface ConfigurationUpdateParams { |
| 110 | /** |
| 111 | * Path param: Identifier. |
| 112 | */ |
| 113 | zone_id?: string; |
| 114 | |
| 115 | /** |
| 116 | * Body param |
| 117 | */ |
| 118 | auth_id_characteristics: Array< |
| 119 | | ConfigurationUpdateParams.APIShieldAuthIDCharacteristic |
| 120 | | ConfigurationUpdateParams.APIShieldAuthIDCharacteristicJWTClaim |
| 121 | >; |
| 122 | |
| 123 | /** |
| 124 | * Query param: Ensures that the configuration is written or retrieved in |
| 125 | * normalized fashion |
| 126 | */ |
| 127 | normalize?: boolean; |
| 128 | } |
| 129 | |
| 130 | export namespace ConfigurationUpdateParams { |
| 131 | /** |
| 132 | * Auth ID Characteristic |
| 133 | */ |
| 134 | export interface APIShieldAuthIDCharacteristic { |
| 135 | /** |
| 136 | * The name of the characteristic field, i.e., the header or cookie name. |
| 137 | */ |
| 138 | name: string; |
| 139 | |
| 140 | /** |
| 141 | * The type of characteristic. |
| 142 | */ |
| 143 | type: 'header' | 'cookie'; |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * Auth ID Characteristic extracted from JWT Token Claims |
| 148 | */ |
| 149 | export interface APIShieldAuthIDCharacteristicJWTClaim { |
| 150 | /** |
| 151 | * Claim location expressed as `$(token_config_id):$(json_path)`, where |
| 152 | * `token_config_id` is the ID of the token configuration used in validating the |
| 153 | * JWT, and `json_path` is a RFC 9535 JSONPath |
| 154 | * (https://goessner.net/articles/JsonPath/, |
| 155 | * https://www.rfc-editor.org/rfc/rfc9535.html). The JSONPath expression may be in |
| 156 | * dot or bracket notation, may only specify literal keys or array indexes, and |
| 157 | * must return a singleton value, which will be interpreted as a string. |
| 158 | */ |
| 159 | name: string; |
| 160 | |
| 161 | /** |
| 162 | * The type of characteristic. |
| 163 | */ |
| 164 | type: 'jwt'; |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | export interface ConfigurationGetParams { |
| 169 | /** |
| 170 | * Path param: Identifier. |
| 171 | */ |
| 172 | zone_id?: string; |
| 173 | |
| 174 | /** |
| 175 | * Query param: Ensures that the configuration is written or retrieved in |
| 176 | * normalized fashion |
| 177 | */ |
| 178 | normalize?: boolean; |
| 179 | } |
| 180 | |
| 181 | export declare namespace Configurations { |
| 182 | export { |
| 183 | type Configuration as Configuration, |
| 184 | type ConfigurationUpdateParams as ConfigurationUpdateParams, |
| 185 | type ConfigurationGetParams as ConfigurationGetParams, |
| 186 | }; |
| 187 | } |
| 188 | |