UNPKG

cloudflare

Version:

The official TypeScript library for the Cloudflare API

590 lines (509 loc) • 12.4 kB
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { APIResource } from '../../../core/resource'; import * as CredentialsAPI from './credentials'; import { BaseCredentials, CredentialEditParams, CredentialEditResponse, CredentialUpdateParams, CredentialUpdateResponse, Credentials as CredentialsAPICredentials, } from './credentials'; import { APIPromise } from '../../../core/api-promise'; import { PagePromise, V4PagePaginationArray, type V4PagePaginationArrayParams, } from '../../../core/pagination'; import { RequestOptions } from '../../../internal/request-options'; import { path } from '../../../internal/utils/path'; export class BaseConfiguration extends APIResource { static override readonly _key: readonly ['tokenValidation', 'configuration'] = Object.freeze([ 'tokenValidation', 'configuration', ] as const); /** * Creates a JWT validation configuration for the zone. * * @example * ```ts * const tokenConfig = * await client.tokenValidation.configuration.create({ * zone_id: '023e105f4ecef8ad9ca31a8372d0c353', * credentials: { * keys: [ * { * alg: 'RS256', * e: 'e', * kid: 'kid', * kty: 'RSA', * n: 'n', * }, * ], * }, * description: * 'Long description for Token Validation Configuration', * title: 'Example Token Validation Configuration', * token_sources: [ * 'http.request.headers["x-auth"][0]', * 'http.request.cookies["Authorization"][0]', * ], * token_type: 'JWT', * }); * ``` */ create(params: ConfigurationCreateParams, options?: RequestOptions): APIPromise<TokenConfig> { const { zone_id, ...body } = params; return ( this._client.post(path`/zones/${zone_id}/token_validation/config`, { body, ...options }) as APIPromise<{ result: TokenConfig; }> )._thenUnwrap((obj) => obj.result); } /** * Lists the JWT validation configurations defined for the zone. * * @example * ```ts * // Automatically fetches more pages as needed. * for await (const tokenConfig of client.tokenValidation.configuration.list( * { zone_id: '023e105f4ecef8ad9ca31a8372d0c353' }, * )) { * // ... * } * ``` */ list( params: ConfigurationListParams, options?: RequestOptions, ): PagePromise<TokenConfigsV4PagePaginationArray, TokenConfig> { const { zone_id, ...query } = params; return this._client.getAPIList( path`/zones/${zone_id}/token_validation/config`, V4PagePaginationArray<TokenConfig>, { query, ...options }, ); } /** * Deletes a JWT validation configuration from the zone. * * @example * ```ts * const configuration = * await client.tokenValidation.configuration.delete( * '4a7ee8d3-dd63-4ceb-9d5f-c27831854ce7', * { zone_id: '023e105f4ecef8ad9ca31a8372d0c353' }, * ); * ``` */ delete( configID: string, params: ConfigurationDeleteParams, options?: RequestOptions, ): APIPromise<ConfigurationDeleteResponse> { const { zone_id } = params; return ( this._client.delete( path`/zones/${zone_id}/token_validation/config/${configID}`, options, ) as APIPromise<{ result: ConfigurationDeleteResponse }> )._thenUnwrap((obj) => obj.result); } /** * Updates only the supplied fields on a JWT validation configuration. * * @example * ```ts * const response = * await client.tokenValidation.configuration.edit( * '4a7ee8d3-dd63-4ceb-9d5f-c27831854ce7', * { zone_id: '023e105f4ecef8ad9ca31a8372d0c353' }, * ); * ``` */ edit( configID: string, params: ConfigurationEditParams, options?: RequestOptions, ): APIPromise<ConfigurationEditResponse> { const { zone_id, ...body } = params; return ( this._client.patch(path`/zones/${zone_id}/token_validation/config/${configID}`, { body, ...options, }) as APIPromise<{ result: ConfigurationEditResponse }> )._thenUnwrap((obj) => obj.result); } /** * Returns a JWT validation configuration by ID. * * @example * ```ts * const tokenConfig = * await client.tokenValidation.configuration.get( * '4a7ee8d3-dd63-4ceb-9d5f-c27831854ce7', * { zone_id: '023e105f4ecef8ad9ca31a8372d0c353' }, * ); * ``` */ get(configID: string, params: ConfigurationGetParams, options?: RequestOptions): APIPromise<TokenConfig> { const { zone_id } = params; return ( this._client.get(path`/zones/${zone_id}/token_validation/config/${configID}`, options) as APIPromise<{ result: TokenConfig; }> )._thenUnwrap((obj) => obj.result); } } export class Configuration extends BaseConfiguration { credentials: CredentialsAPI.Credentials = new CredentialsAPI.Credentials(this._client); } export type TokenConfigsV4PagePaginationArray = V4PagePaginationArray<TokenConfig>; export interface TokenConfig { /** * UUID. */ id: string; created_at: string; credentials: TokenConfig.Credentials; description: string; last_updated: string; title: string; token_sources: Array<string>; token_type: 'JWT'; } export namespace TokenConfig { export interface Credentials { keys: Array< | Credentials.APIShieldCredentialsJWTKeyRSA | Credentials.APIShieldCredentialsJWTKeyEcEs256 | Credentials.APIShieldCredentialsJWTKeyEcEs384 | Credentials.APIShieldCredentialsJWTKeyOctResponse >; } export namespace Credentials { /** * JSON representation of an RSA key. */ export interface APIShieldCredentialsJWTKeyRSA { /** * Algorithm */ alg: 'RS256' | 'RS384' | 'RS512' | 'PS256' | 'PS384' | 'PS512'; /** * RSA exponent */ e: string; /** * Key ID */ kid: string; /** * Key Type */ kty: 'RSA'; /** * RSA modulus */ n: string; } /** * JSON representation of an ES256 key */ export interface APIShieldCredentialsJWTKeyEcEs256 { /** * Algorithm */ alg: 'ES256'; /** * Curve */ crv: 'P-256'; /** * Key ID */ kid: string; /** * Key Type */ kty: 'EC'; /** * X EC coordinate */ x: string; /** * Y EC coordinate */ y: string; } /** * JSON representation of an ES384 key */ export interface APIShieldCredentialsJWTKeyEcEs384 { /** * Algorithm */ alg: 'ES384'; /** * Curve */ crv: 'P-384'; /** * Key ID */ kid: string; /** * Key Type */ kty: 'EC'; /** * X EC coordinate */ x: string; /** * Y EC coordinate */ y: string; } /** * JSON representation of a symmetric verification key in API responses (secret * material is redacted). */ export interface APIShieldCredentialsJWTKeyOctResponse { /** * Algorithm */ alg: 'HS256' | 'HS384' | 'HS512'; /** * Key ID */ kid: string; /** * Key Type */ kty: 'oct'; } } } export interface ConfigurationDeleteResponse { /** * UUID. */ id?: string; } export interface ConfigurationEditResponse { /** * UUID. */ id?: string; description?: string; title?: string; token_sources?: Array<string>; } export interface ConfigurationCreateParams { /** * Path param: Identifier. */ zone_id: string; /** * Body param: Request payload for create and PUT credentials operations. Provided * keys define the complete stored key set. Key identities (`{alg,kid}`) must be * unique. */ credentials: ConfigurationCreateParams.Credentials; /** * Body param */ description: string; /** * Body param */ title: string; /** * Body param */ token_sources: Array<string>; /** * Body param */ token_type: 'JWT'; } export namespace ConfigurationCreateParams { /** * Request payload for create and PUT credentials operations. Provided keys define * the complete stored key set. Key identities (`{alg,kid}`) must be unique. */ export interface Credentials { keys: Array< | Credentials.APIShieldCredentialsJWTKeyRSA | Credentials.APIShieldCredentialsJWTKeyEcEs256 | Credentials.APIShieldCredentialsJWTKeyEcEs384 | Credentials.APIShieldCredentialsJWTKeyOctRequest >; } export namespace Credentials { /** * JSON representation of an RSA key. */ export interface APIShieldCredentialsJWTKeyRSA { /** * Algorithm */ alg: 'RS256' | 'RS384' | 'RS512' | 'PS256' | 'PS384' | 'PS512'; /** * RSA exponent */ e: string; /** * Key ID */ kid: string; /** * Key Type */ kty: 'RSA'; /** * RSA modulus */ n: string; } /** * JSON representation of an ES256 key */ export interface APIShieldCredentialsJWTKeyEcEs256 { /** * Algorithm */ alg: 'ES256'; /** * Curve */ crv: 'P-256'; /** * Key ID */ kid: string; /** * Key Type */ kty: 'EC'; /** * X EC coordinate */ x: string; /** * Y EC coordinate */ y: string; } /** * JSON representation of an ES384 key */ export interface APIShieldCredentialsJWTKeyEcEs384 { /** * Algorithm */ alg: 'ES384'; /** * Curve */ crv: 'P-384'; /** * Key ID */ kid: string; /** * Key Type */ kty: 'EC'; /** * X EC coordinate */ x: string; /** * Y EC coordinate */ y: string; } /** * JSON representation of a symmetric key for create/PUT requests. */ export interface APIShieldCredentialsJWTKeyOctRequest { /** * Algorithm */ alg: 'HS256' | 'HS384' | 'HS512'; /** * Symmetric key material. Required for create and PUT update requests. */ k: string; /** * Key ID */ kid: string; /** * Key Type */ kty: 'oct'; } } } export interface ConfigurationListParams extends V4PagePaginationArrayParams { /** * Path param: Identifier. */ zone_id: string; } export interface ConfigurationDeleteParams { /** * Identifier. */ zone_id: string; } export interface ConfigurationEditParams { /** * Path param: Identifier. */ zone_id: string; /** * Body param */ description?: string; /** * Body param */ title?: string; /** * Body param */ token_sources?: Array<string>; } export interface ConfigurationGetParams { /** * Identifier. */ zone_id: string; } Configuration.Credentials = CredentialsAPICredentials; Configuration.BaseCredentials = BaseCredentials; export declare namespace Configuration { export { type TokenConfig as TokenConfig, type ConfigurationDeleteResponse as ConfigurationDeleteResponse, type ConfigurationEditResponse as ConfigurationEditResponse, type TokenConfigsV4PagePaginationArray as TokenConfigsV4PagePaginationArray, type ConfigurationCreateParams as ConfigurationCreateParams, type ConfigurationListParams as ConfigurationListParams, type ConfigurationDeleteParams as ConfigurationDeleteParams, type ConfigurationEditParams as ConfigurationEditParams, type ConfigurationGetParams as ConfigurationGetParams, }; export { CredentialsAPICredentials as Credentials, BaseCredentials as BaseCredentials, type CredentialUpdateResponse as CredentialUpdateResponse, type CredentialEditResponse as CredentialEditResponse, type CredentialUpdateParams as CredentialUpdateParams, type CredentialEditParams as CredentialEditParams, }; }