cloudflare/cloudflare-typescript
Publicmirrored fromhttps://github.com/cloudflare/cloudflare-typescriptAvailable
src/index.ts
870lines · modecode
| 1 | // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
| 2 | |
| 3 | import { type Agent } from './_shims/index'; |
| 4 | import * as qs from './internal/qs'; |
| 5 | import * as Core from './core'; |
| 6 | import * as Errors from './error'; |
| 7 | import * as Pagination from './pagination'; |
| 8 | import { |
| 9 | type CursorLimitPaginationParams, |
| 10 | CursorLimitPaginationResponse, |
| 11 | type CursorPaginationAfterParams, |
| 12 | CursorPaginationAfterResponse, |
| 13 | type CursorPaginationParams, |
| 14 | CursorPaginationResponse, |
| 15 | SinglePageResponse, |
| 16 | type V4PagePaginationArrayParams, |
| 17 | V4PagePaginationArrayResponse, |
| 18 | type V4PagePaginationParams, |
| 19 | V4PagePaginationResponse, |
| 20 | } from './pagination'; |
| 21 | import * as Uploads from './uploads'; |
| 22 | import * as API from './resources/index'; |
| 23 | import { AbuseReports } from './resources/abuse-reports'; |
| 24 | import { AuditLogs } from './resources/audit-logs'; |
| 25 | import { BotManagement } from './resources/bot-management'; |
| 26 | import { ClientCertificates } from './resources/client-certificates'; |
| 27 | import { CustomNameservers } from './resources/custom-nameservers'; |
| 28 | import { CustomPages } from './resources/custom-pages'; |
| 29 | import { DCVDelegation } from './resources/dcv-delegation'; |
| 30 | import { Filters } from './resources/filters'; |
| 31 | import { IPs } from './resources/ips'; |
| 32 | import { KeylessCertificates } from './resources/keyless-certificates'; |
| 33 | import { ManagedTransforms } from './resources/managed-transforms'; |
| 34 | import { Memberships } from './resources/memberships'; |
| 35 | import { OriginCACertificates } from './resources/origin-ca-certificates'; |
| 36 | import { OriginPostQuantumEncryption } from './resources/origin-post-quantum-encryption'; |
| 37 | import { PageRules } from './resources/page-rules'; |
| 38 | import { Pipelines } from './resources/pipelines'; |
| 39 | import { RateLimits } from './resources/rate-limits'; |
| 40 | import { SecurityTXT } from './resources/security-txt'; |
| 41 | import { URLNormalization } from './resources/url-normalization'; |
| 42 | import { Accounts } from './resources/accounts/accounts'; |
| 43 | import { ACM } from './resources/acm/acm'; |
| 44 | import { Addressing } from './resources/addressing/addressing'; |
| 45 | import { AIGateway } from './resources/ai-gateway/ai-gateway'; |
| 46 | import { AI } from './resources/ai/ai'; |
| 47 | import { Alerting } from './resources/alerting/alerting'; |
| 48 | import { APIGateway } from './resources/api-gateway/api-gateway'; |
| 49 | import { Argo } from './resources/argo/argo'; |
| 50 | import { Billing } from './resources/billing/billing'; |
| 51 | import { BotnetFeed } from './resources/botnet-feed/botnet-feed'; |
| 52 | import { BrandProtection } from './resources/brand-protection/brand-protection'; |
| 53 | import { BrowserRendering } from './resources/browser-rendering/browser-rendering'; |
| 54 | import { Cache } from './resources/cache/cache'; |
| 55 | import { Calls } from './resources/calls/calls'; |
| 56 | import { CertificateAuthorities } from './resources/certificate-authorities/certificate-authorities'; |
| 57 | import { CloudConnector } from './resources/cloud-connector/cloud-connector'; |
| 58 | import { CloudforceOne } from './resources/cloudforce-one/cloudforce-one'; |
| 59 | import { ContentScanning } from './resources/content-scanning/content-scanning'; |
| 60 | import { CustomCertificates } from './resources/custom-certificates/custom-certificates'; |
| 61 | import { CustomHostnames } from './resources/custom-hostnames/custom-hostnames'; |
| 62 | import { D1Resource } from './resources/d1/d1'; |
| 63 | import { Diagnostics } from './resources/diagnostics/diagnostics'; |
| 64 | import { DNSFirewall } from './resources/dns-firewall/dns-firewall'; |
| 65 | import { DNS } from './resources/dns/dns'; |
| 66 | import { DurableObjects } from './resources/durable-objects/durable-objects'; |
| 67 | import { EmailRouting } from './resources/email-routing/email-routing'; |
| 68 | import { EmailSecurity } from './resources/email-security/email-security'; |
| 69 | import { Firewall } from './resources/firewall/firewall'; |
| 70 | import { Healthchecks } from './resources/healthchecks/healthchecks'; |
| 71 | import { Hostnames } from './resources/hostnames/hostnames'; |
| 72 | import { HyperdriveResource } from './resources/hyperdrive/hyperdrive'; |
| 73 | import { IAM } from './resources/iam/iam'; |
| 74 | import { Images } from './resources/images/images'; |
| 75 | import { Intel } from './resources/intel/intel'; |
| 76 | import { KV } from './resources/kv/kv'; |
| 77 | import { LeakedCredentialChecks } from './resources/leaked-credential-checks/leaked-credential-checks'; |
| 78 | import { LoadBalancers } from './resources/load-balancers/load-balancers'; |
| 79 | import { Logpush } from './resources/logpush/logpush'; |
| 80 | import { Logs } from './resources/logs/logs'; |
| 81 | import { MagicCloudNetworking } from './resources/magic-cloud-networking/magic-cloud-networking'; |
| 82 | import { MagicNetworkMonitoring } from './resources/magic-network-monitoring/magic-network-monitoring'; |
| 83 | import { MagicTransit } from './resources/magic-transit/magic-transit'; |
| 84 | import { MTLSCertificates } from './resources/mtls-certificates/mtls-certificates'; |
| 85 | import { NetworkInterconnects } from './resources/network-interconnects/network-interconnects'; |
| 86 | import { OriginTLSClientAuth } from './resources/origin-tls-client-auth/origin-tls-client-auth'; |
| 87 | import { PageShield } from './resources/page-shield/page-shield'; |
| 88 | import { Pages } from './resources/pages/pages'; |
| 89 | import { Queues } from './resources/queues/queues'; |
| 90 | import { R2 } from './resources/r2/r2'; |
| 91 | import { Radar } from './resources/radar/radar'; |
| 92 | import { Registrar } from './resources/registrar/registrar'; |
| 93 | import { RequestTracers } from './resources/request-tracers/request-tracers'; |
| 94 | import { ResourceSharing } from './resources/resource-sharing/resource-sharing'; |
| 95 | import { Rules } from './resources/rules/rules'; |
| 96 | import { Rulesets } from './resources/rulesets/rulesets'; |
| 97 | import { RUM } from './resources/rum/rum'; |
| 98 | import { SchemaValidation } from './resources/schema-validation/schema-validation'; |
| 99 | import { SecretsStore } from './resources/secrets-store/secrets-store'; |
| 100 | import { SecurityCenter } from './resources/security-center/security-center'; |
| 101 | import { Snippets } from './resources/snippets/snippets'; |
| 102 | import { Spectrum } from './resources/spectrum/spectrum'; |
| 103 | import { Speed } from './resources/speed/speed'; |
| 104 | import { SSL } from './resources/ssl/ssl'; |
| 105 | import { Stream } from './resources/stream/stream'; |
| 106 | import { Turnstile } from './resources/turnstile/turnstile'; |
| 107 | import { URLScanner } from './resources/url-scanner/url-scanner'; |
| 108 | import { User } from './resources/user/user'; |
| 109 | import { Vectorize } from './resources/vectorize/vectorize'; |
| 110 | import { WaitingRooms } from './resources/waiting-rooms/waiting-rooms'; |
| 111 | import { Web3 } from './resources/web3/web3'; |
| 112 | import { WorkersForPlatforms } from './resources/workers-for-platforms/workers-for-platforms'; |
| 113 | import { Workers } from './resources/workers/workers'; |
| 114 | import { Workflows } from './resources/workflows/workflows'; |
| 115 | import { Zaraz } from './resources/zaraz/zaraz'; |
| 116 | import { ZeroTrust } from './resources/zero-trust/zero-trust'; |
| 117 | import { Zones } from './resources/zones/zones'; |
| 118 | |
| 119 | export interface ClientOptions { |
| 120 | /** |
| 121 | * The preferred authorization scheme for interacting with the Cloudflare API. [Create a token](https://developers.cloudflare.com/fundamentals/api/get-started/create-token/). |
| 122 | */ |
| 123 | apiToken?: string | null | undefined; |
| 124 | |
| 125 | /** |
| 126 | * The previous authorization scheme for interacting with the Cloudflare API. When possible, use API tokens instead of Global API keys. |
| 127 | */ |
| 128 | apiKey?: string | null | undefined; |
| 129 | |
| 130 | /** |
| 131 | * The previous authorization scheme for interacting with the Cloudflare API, used in conjunction with a Global API key. |
| 132 | */ |
| 133 | apiEmail?: string | null | undefined; |
| 134 | |
| 135 | /** |
| 136 | * Used when interacting with the Origin CA certificates API. [View/change your key](https://developers.cloudflare.com/fundamentals/api/get-started/ca-keys/#viewchange-your-origin-ca-keys). |
| 137 | */ |
| 138 | userServiceKey?: string | null | undefined; |
| 139 | |
| 140 | /** |
| 141 | * Override the default base URL for the API, e.g., "https://api.example.com/v2/" |
| 142 | * |
| 143 | * Defaults to process.env['CLOUDFLARE_BASE_URL']. |
| 144 | */ |
| 145 | baseURL?: string | null | undefined; |
| 146 | |
| 147 | /** |
| 148 | * Define the API version to target for the requests, e.g., "2025-01-01" |
| 149 | */ |
| 150 | apiVersion?: string | null; |
| 151 | |
| 152 | /** |
| 153 | * The maximum amount of time (in milliseconds) that the client should wait for a response |
| 154 | * from the server before timing out a single request. |
| 155 | * |
| 156 | * Note that request timeouts are retried by default, so in a worst-case scenario you may wait |
| 157 | * much longer than this timeout before the promise succeeds or fails. |
| 158 | * |
| 159 | * @unit milliseconds |
| 160 | */ |
| 161 | timeout?: number | undefined; |
| 162 | |
| 163 | /** |
| 164 | * An HTTP agent used to manage HTTP(S) connections. |
| 165 | * |
| 166 | * If not provided, an agent will be constructed by default in the Node.js environment, |
| 167 | * otherwise no agent is used. |
| 168 | */ |
| 169 | httpAgent?: Agent | undefined; |
| 170 | |
| 171 | /** |
| 172 | * Specify a custom `fetch` function implementation. |
| 173 | * |
| 174 | * If not provided, we use `node-fetch` on Node.js and otherwise expect that `fetch` is |
| 175 | * defined globally. |
| 176 | */ |
| 177 | fetch?: Core.Fetch | undefined; |
| 178 | |
| 179 | /** |
| 180 | * The maximum number of times that the client will retry a request in case of a |
| 181 | * temporary failure, like a network error or a 5XX error from the server. |
| 182 | * |
| 183 | * @default 2 |
| 184 | */ |
| 185 | maxRetries?: number | undefined; |
| 186 | |
| 187 | /** |
| 188 | * Default headers to include with every request to the API. |
| 189 | * |
| 190 | * These can be removed in individual requests by explicitly setting the |
| 191 | * header to `undefined` or `null` in request options. |
| 192 | */ |
| 193 | defaultHeaders?: Core.Headers | undefined; |
| 194 | |
| 195 | /** |
| 196 | * Default query parameters to include with every request to the API. |
| 197 | * |
| 198 | * These can be removed in individual requests by explicitly setting the |
| 199 | * param to `undefined` in request options. |
| 200 | */ |
| 201 | defaultQuery?: Core.DefaultQuery | undefined; |
| 202 | } |
| 203 | |
| 204 | /** |
| 205 | * API Client for interfacing with the Cloudflare API. |
| 206 | */ |
| 207 | export class Cloudflare extends Core.APIClient { |
| 208 | apiToken: string | null; |
| 209 | apiKey: string | null; |
| 210 | apiEmail: string | null; |
| 211 | userServiceKey: string | null; |
| 212 | |
| 213 | private _options: ClientOptions; |
| 214 | |
| 215 | /** |
| 216 | * API Client for interfacing with the Cloudflare API. |
| 217 | * |
| 218 | * @param {string | null | undefined} [opts.apiToken=process.env['CLOUDFLARE_API_TOKEN'] ?? null] |
| 219 | * @param {string | null | undefined} [opts.apiKey=process.env['CLOUDFLARE_API_KEY'] ?? null] |
| 220 | * @param {string | null | undefined} [opts.apiEmail=process.env['CLOUDFLARE_EMAIL'] ?? null] |
| 221 | * @param {string | null | undefined} [opts.userServiceKey=process.env['CLOUDFLARE_API_USER_SERVICE_KEY'] ?? null] |
| 222 | * @param {string} [opts.baseURL=process.env['CLOUDFLARE_BASE_URL'] ?? https://api.cloudflare.com/client/v4] - Override the default base URL for the API. |
| 223 | * @param {string | null} [opts.apiVersion] - Define the version to target for the API. |
| 224 | * @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out. |
| 225 | * @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections. |
| 226 | * @param {Core.Fetch} [opts.fetch] - Specify a custom `fetch` function implementation. |
| 227 | * @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request. |
| 228 | * @param {Core.Headers} opts.defaultHeaders - Default headers to include with every request to the API. |
| 229 | * @param {Core.DefaultQuery} opts.defaultQuery - Default query parameters to include with every request to the API. |
| 230 | */ |
| 231 | constructor({ |
| 232 | baseURL = Core.readEnv('CLOUDFLARE_BASE_URL'), |
| 233 | apiVersion = null, |
| 234 | apiToken = Core.readEnv('CLOUDFLARE_API_TOKEN') ?? null, |
| 235 | apiKey = Core.readEnv('CLOUDFLARE_API_KEY') ?? null, |
| 236 | apiEmail = Core.readEnv('CLOUDFLARE_EMAIL') ?? null, |
| 237 | userServiceKey = Core.readEnv('CLOUDFLARE_API_USER_SERVICE_KEY') ?? null, |
| 238 | ...opts |
| 239 | }: ClientOptions = {}) { |
| 240 | const options: ClientOptions = { |
| 241 | apiToken, |
| 242 | apiKey, |
| 243 | apiEmail, |
| 244 | userServiceKey, |
| 245 | ...opts, |
| 246 | baseURL: baseURL || `https://api.cloudflare.com/client/v4`, |
| 247 | apiVersion: apiVersion || new Date().toISOString().slice(0, 10), |
| 248 | }; |
| 249 | |
| 250 | super({ |
| 251 | baseURL: options.baseURL!, |
| 252 | apiVersion: options.apiVersion!, |
| 253 | baseURLOverridden: baseURL ? baseURL !== 'https://api.cloudflare.com/client/v4' : false, |
| 254 | timeout: options.timeout ?? 60000 /* 1 minute */, |
| 255 | httpAgent: options.httpAgent, |
| 256 | maxRetries: options.maxRetries, |
| 257 | fetch: options.fetch, |
| 258 | }); |
| 259 | |
| 260 | this._options = options; |
| 261 | |
| 262 | this.apiToken = apiToken; |
| 263 | this.apiKey = apiKey; |
| 264 | this.apiEmail = apiEmail; |
| 265 | this.userServiceKey = userServiceKey; |
| 266 | } |
| 267 | |
| 268 | accounts: API.Accounts = new API.Accounts(this); |
| 269 | originCACertificates: API.OriginCACertificates = new API.OriginCACertificates(this); |
| 270 | ips: API.IPs = new API.IPs(this); |
| 271 | memberships: API.Memberships = new API.Memberships(this); |
| 272 | user: API.User = new API.User(this); |
| 273 | zones: API.Zones = new API.Zones(this); |
| 274 | loadBalancers: API.LoadBalancers = new API.LoadBalancers(this); |
| 275 | cache: API.Cache = new API.Cache(this); |
| 276 | ssl: API.SSL = new API.SSL(this); |
| 277 | acm: API.ACM = new API.ACM(this); |
| 278 | argo: API.Argo = new API.Argo(this); |
| 279 | certificateAuthorities: API.CertificateAuthorities = new API.CertificateAuthorities(this); |
| 280 | clientCertificates: API.ClientCertificates = new API.ClientCertificates(this); |
| 281 | customCertificates: API.CustomCertificates = new API.CustomCertificates(this); |
| 282 | customHostnames: API.CustomHostnames = new API.CustomHostnames(this); |
| 283 | customNameservers: API.CustomNameservers = new API.CustomNameservers(this); |
| 284 | dnsFirewall: API.DNSFirewall = new API.DNSFirewall(this); |
| 285 | dns: API.DNS = new API.DNS(this); |
| 286 | emailSecurity: API.EmailSecurity = new API.EmailSecurity(this); |
| 287 | emailRouting: API.EmailRouting = new API.EmailRouting(this); |
| 288 | filters: API.Filters = new API.Filters(this); |
| 289 | firewall: API.Firewall = new API.Firewall(this); |
| 290 | healthchecks: API.Healthchecks = new API.Healthchecks(this); |
| 291 | keylessCertificates: API.KeylessCertificates = new API.KeylessCertificates(this); |
| 292 | logpush: API.Logpush = new API.Logpush(this); |
| 293 | logs: API.Logs = new API.Logs(this); |
| 294 | originTLSClientAuth: API.OriginTLSClientAuth = new API.OriginTLSClientAuth(this); |
| 295 | pageRules: API.PageRules = new API.PageRules(this); |
| 296 | rateLimits: API.RateLimits = new API.RateLimits(this); |
| 297 | waitingRooms: API.WaitingRooms = new API.WaitingRooms(this); |
| 298 | web3: API.Web3 = new API.Web3(this); |
| 299 | workers: API.Workers = new API.Workers(this); |
| 300 | kv: API.KV = new API.KV(this); |
| 301 | durableObjects: API.DurableObjects = new API.DurableObjects(this); |
| 302 | queues: API.Queues = new API.Queues(this); |
| 303 | apiGateway: API.APIGateway = new API.APIGateway(this); |
| 304 | managedTransforms: API.ManagedTransforms = new API.ManagedTransforms(this); |
| 305 | pageShield: API.PageShield = new API.PageShield(this); |
| 306 | rulesets: API.Rulesets = new API.Rulesets(this); |
| 307 | urlNormalization: API.URLNormalization = new API.URLNormalization(this); |
| 308 | spectrum: API.Spectrum = new API.Spectrum(this); |
| 309 | addressing: API.Addressing = new API.Addressing(this); |
| 310 | auditLogs: API.AuditLogs = new API.AuditLogs(this); |
| 311 | billing: API.Billing = new API.Billing(this); |
| 312 | brandProtection: API.BrandProtection = new API.BrandProtection(this); |
| 313 | diagnostics: API.Diagnostics = new API.Diagnostics(this); |
| 314 | images: API.Images = new API.Images(this); |
| 315 | intel: API.Intel = new API.Intel(this); |
| 316 | magicTransit: API.MagicTransit = new API.MagicTransit(this); |
| 317 | magicNetworkMonitoring: API.MagicNetworkMonitoring = new API.MagicNetworkMonitoring(this); |
| 318 | magicCloudNetworking: API.MagicCloudNetworking = new API.MagicCloudNetworking(this); |
| 319 | networkInterconnects: API.NetworkInterconnects = new API.NetworkInterconnects(this); |
| 320 | mtlsCertificates: API.MTLSCertificates = new API.MTLSCertificates(this); |
| 321 | pages: API.Pages = new API.Pages(this); |
| 322 | registrar: API.Registrar = new API.Registrar(this); |
| 323 | requestTracers: API.RequestTracers = new API.RequestTracers(this); |
| 324 | rules: API.Rules = new API.Rules(this); |
| 325 | stream: API.Stream = new API.Stream(this); |
| 326 | alerting: API.Alerting = new API.Alerting(this); |
| 327 | d1: API.D1Resource = new API.D1Resource(this); |
| 328 | r2: API.R2 = new API.R2(this); |
| 329 | workersForPlatforms: API.WorkersForPlatforms = new API.WorkersForPlatforms(this); |
| 330 | zeroTrust: API.ZeroTrust = new API.ZeroTrust(this); |
| 331 | turnstile: API.Turnstile = new API.Turnstile(this); |
| 332 | hyperdrive: API.HyperdriveResource = new API.HyperdriveResource(this); |
| 333 | rum: API.RUM = new API.RUM(this); |
| 334 | vectorize: API.Vectorize = new API.Vectorize(this); |
| 335 | urlScanner: API.URLScanner = new API.URLScanner(this); |
| 336 | radar: API.Radar = new API.Radar(this); |
| 337 | botManagement: API.BotManagement = new API.BotManagement(this); |
| 338 | originPostQuantumEncryption: API.OriginPostQuantumEncryption = new API.OriginPostQuantumEncryption(this); |
| 339 | zaraz: API.Zaraz = new API.Zaraz(this); |
| 340 | speed: API.Speed = new API.Speed(this); |
| 341 | dcvDelegation: API.DCVDelegation = new API.DCVDelegation(this); |
| 342 | hostnames: API.Hostnames = new API.Hostnames(this); |
| 343 | snippets: API.Snippets = new API.Snippets(this); |
| 344 | calls: API.Calls = new API.Calls(this); |
| 345 | cloudforceOne: API.CloudforceOne = new API.CloudforceOne(this); |
| 346 | aiGateway: API.AIGateway = new API.AIGateway(this); |
| 347 | iam: API.IAM = new API.IAM(this); |
| 348 | cloudConnector: API.CloudConnector = new API.CloudConnector(this); |
| 349 | botnetFeed: API.BotnetFeed = new API.BotnetFeed(this); |
| 350 | securityTXT: API.SecurityTXT = new API.SecurityTXT(this); |
| 351 | workflows: API.Workflows = new API.Workflows(this); |
| 352 | resourceSharing: API.ResourceSharing = new API.ResourceSharing(this); |
| 353 | leakedCredentialChecks: API.LeakedCredentialChecks = new API.LeakedCredentialChecks(this); |
| 354 | contentScanning: API.ContentScanning = new API.ContentScanning(this); |
| 355 | abuseReports: API.AbuseReports = new API.AbuseReports(this); |
| 356 | ai: API.AI = new API.AI(this); |
| 357 | securityCenter: API.SecurityCenter = new API.SecurityCenter(this); |
| 358 | browserRendering: API.BrowserRendering = new API.BrowserRendering(this); |
| 359 | customPages: API.CustomPages = new API.CustomPages(this); |
| 360 | secretsStore: API.SecretsStore = new API.SecretsStore(this); |
| 361 | pipelines: API.Pipelines = new API.Pipelines(this); |
| 362 | schemaValidation: API.SchemaValidation = new API.SchemaValidation(this); |
| 363 | |
| 364 | /** |
| 365 | * Check whether the base URL is set to its default. |
| 366 | */ |
| 367 | #baseURLOverridden(): boolean { |
| 368 | return this.baseURL !== 'https://api.cloudflare.com/client/v4'; |
| 369 | } |
| 370 | |
| 371 | protected override defaultQuery(): Core.DefaultQuery | undefined { |
| 372 | return this._options.defaultQuery; |
| 373 | } |
| 374 | |
| 375 | protected override defaultHeaders(opts: Core.FinalRequestOptions): Core.Headers { |
| 376 | return { |
| 377 | ...super.defaultHeaders(opts), |
| 378 | 'X-Auth-Key': this.apiKey, |
| 379 | 'X-Auth-Email': this.apiEmail, |
| 380 | ...this._options.defaultHeaders, |
| 381 | }; |
| 382 | } |
| 383 | |
| 384 | protected override validateHeaders( |
| 385 | headers: Core.Headers, |
| 386 | customHeaders: Core.Headers, |
| 387 | usingCustomFetch: boolean, |
| 388 | ) { |
| 389 | if (this.apiEmail && headers['x-auth-email']) { |
| 390 | return; |
| 391 | } |
| 392 | if (customHeaders['x-auth-email'] === null) { |
| 393 | return; |
| 394 | } |
| 395 | |
| 396 | if (this.apiKey && headers['x-auth-key']) { |
| 397 | return; |
| 398 | } |
| 399 | if (customHeaders['x-auth-key'] === null) { |
| 400 | return; |
| 401 | } |
| 402 | |
| 403 | if (this.apiToken && headers['authorization']) { |
| 404 | return; |
| 405 | } |
| 406 | if (customHeaders['authorization'] === null) { |
| 407 | return; |
| 408 | } |
| 409 | |
| 410 | if (this.userServiceKey && headers['x-auth-user-service-key']) { |
| 411 | return; |
| 412 | } |
| 413 | if (customHeaders['x-auth-user-service-key'] === null) { |
| 414 | return; |
| 415 | } |
| 416 | |
| 417 | // we can't check for the presence of the headers with a custom fetch implementation, so we shouldn't throw an error |
| 418 | if (usingCustomFetch) { |
| 419 | return; |
| 420 | } |
| 421 | |
| 422 | throw new Error( |
| 423 | 'Could not resolve authentication method. Expected one of apiEmail, apiKey, apiToken or userServiceKey to be set. Or for one of the "X-Auth-Email", "X-Auth-Key", "Authorization" or "X-Auth-User-Service-Key" headers to be explicitly omitted', |
| 424 | ); |
| 425 | } |
| 426 | |
| 427 | protected override authHeaders(opts: Core.FinalRequestOptions): Core.Headers { |
| 428 | const apiEmailAuth = this.apiEmailAuth(opts); |
| 429 | const apiKeyAuth = this.apiKeyAuth(opts); |
| 430 | const apiTokenAuth = this.apiTokenAuth(opts); |
| 431 | const userServiceKeyAuth = this.userServiceKeyAuth(opts); |
| 432 | |
| 433 | if ( |
| 434 | apiEmailAuth != null && |
| 435 | !Core.isEmptyObj(apiEmailAuth) && |
| 436 | apiKeyAuth != null && |
| 437 | !Core.isEmptyObj(apiKeyAuth) |
| 438 | ) { |
| 439 | return { ...apiEmailAuth, ...apiKeyAuth }; |
| 440 | } |
| 441 | |
| 442 | if (apiTokenAuth != null && !Core.isEmptyObj(apiTokenAuth)) { |
| 443 | return apiTokenAuth; |
| 444 | } |
| 445 | |
| 446 | if (userServiceKeyAuth != null && !Core.isEmptyObj(userServiceKeyAuth)) { |
| 447 | return userServiceKeyAuth; |
| 448 | } |
| 449 | return {}; |
| 450 | } |
| 451 | |
| 452 | protected apiEmailAuth(opts: Core.FinalRequestOptions): Core.Headers { |
| 453 | if (this.apiEmail == null) { |
| 454 | return {}; |
| 455 | } |
| 456 | return { 'X-Auth-Email': this.apiEmail }; |
| 457 | } |
| 458 | |
| 459 | protected apiKeyAuth(opts: Core.FinalRequestOptions): Core.Headers { |
| 460 | if (this.apiKey == null) { |
| 461 | return {}; |
| 462 | } |
| 463 | return { 'X-Auth-Key': this.apiKey }; |
| 464 | } |
| 465 | |
| 466 | protected apiTokenAuth(opts: Core.FinalRequestOptions): Core.Headers { |
| 467 | if (this.apiToken == null) { |
| 468 | return {}; |
| 469 | } |
| 470 | return { Authorization: `Bearer ${this.apiToken}` }; |
| 471 | } |
| 472 | |
| 473 | protected userServiceKeyAuth(opts: Core.FinalRequestOptions): Core.Headers { |
| 474 | if (this.userServiceKey == null) { |
| 475 | return {}; |
| 476 | } |
| 477 | return { 'X-Auth-User-Service-Key': this.userServiceKey }; |
| 478 | } |
| 479 | |
| 480 | protected override stringifyQuery(query: Record<string, unknown>): string { |
| 481 | return qs.stringify(query, { allowDots: true, arrayFormat: 'repeat' }); |
| 482 | } |
| 483 | |
| 484 | static Cloudflare = this; |
| 485 | static DEFAULT_TIMEOUT = 60000; // 1 minute |
| 486 | |
| 487 | static CloudflareError = Errors.CloudflareError; |
| 488 | static APIError = Errors.APIError; |
| 489 | static APIConnectionError = Errors.APIConnectionError; |
| 490 | static APIConnectionTimeoutError = Errors.APIConnectionTimeoutError; |
| 491 | static APIUserAbortError = Errors.APIUserAbortError; |
| 492 | static NotFoundError = Errors.NotFoundError; |
| 493 | static ConflictError = Errors.ConflictError; |
| 494 | static RateLimitError = Errors.RateLimitError; |
| 495 | static BadRequestError = Errors.BadRequestError; |
| 496 | static AuthenticationError = Errors.AuthenticationError; |
| 497 | static InternalServerError = Errors.InternalServerError; |
| 498 | static PermissionDeniedError = Errors.PermissionDeniedError; |
| 499 | static UnprocessableEntityError = Errors.UnprocessableEntityError; |
| 500 | |
| 501 | static toFile = Uploads.toFile; |
| 502 | static fileFromPath = Uploads.fileFromPath; |
| 503 | } |
| 504 | |
| 505 | Cloudflare.Accounts = Accounts; |
| 506 | Cloudflare.OriginCACertificates = OriginCACertificates; |
| 507 | Cloudflare.IPs = IPs; |
| 508 | Cloudflare.Memberships = Memberships; |
| 509 | Cloudflare.User = User; |
| 510 | Cloudflare.Zones = Zones; |
| 511 | Cloudflare.LoadBalancers = LoadBalancers; |
| 512 | Cloudflare.Cache = Cache; |
| 513 | Cloudflare.SSL = SSL; |
| 514 | Cloudflare.ACM = ACM; |
| 515 | Cloudflare.Argo = Argo; |
| 516 | Cloudflare.CertificateAuthorities = CertificateAuthorities; |
| 517 | Cloudflare.ClientCertificates = ClientCertificates; |
| 518 | Cloudflare.CustomCertificates = CustomCertificates; |
| 519 | Cloudflare.CustomHostnames = CustomHostnames; |
| 520 | Cloudflare.CustomNameservers = CustomNameservers; |
| 521 | Cloudflare.DNSFirewall = DNSFirewall; |
| 522 | Cloudflare.DNS = DNS; |
| 523 | Cloudflare.EmailSecurity = EmailSecurity; |
| 524 | Cloudflare.EmailRouting = EmailRouting; |
| 525 | Cloudflare.Filters = Filters; |
| 526 | Cloudflare.Firewall = Firewall; |
| 527 | Cloudflare.Healthchecks = Healthchecks; |
| 528 | Cloudflare.KeylessCertificates = KeylessCertificates; |
| 529 | Cloudflare.Logpush = Logpush; |
| 530 | Cloudflare.Logs = Logs; |
| 531 | Cloudflare.OriginTLSClientAuth = OriginTLSClientAuth; |
| 532 | Cloudflare.PageRules = PageRules; |
| 533 | Cloudflare.RateLimits = RateLimits; |
| 534 | Cloudflare.WaitingRooms = WaitingRooms; |
| 535 | Cloudflare.Web3 = Web3; |
| 536 | Cloudflare.Workers = Workers; |
| 537 | Cloudflare.KV = KV; |
| 538 | Cloudflare.DurableObjects = DurableObjects; |
| 539 | Cloudflare.Queues = Queues; |
| 540 | Cloudflare.APIGateway = APIGateway; |
| 541 | Cloudflare.ManagedTransforms = ManagedTransforms; |
| 542 | Cloudflare.PageShield = PageShield; |
| 543 | Cloudflare.Rulesets = Rulesets; |
| 544 | Cloudflare.URLNormalization = URLNormalization; |
| 545 | Cloudflare.Spectrum = Spectrum; |
| 546 | Cloudflare.Addressing = Addressing; |
| 547 | Cloudflare.AuditLogs = AuditLogs; |
| 548 | Cloudflare.Billing = Billing; |
| 549 | Cloudflare.BrandProtection = BrandProtection; |
| 550 | Cloudflare.Diagnostics = Diagnostics; |
| 551 | Cloudflare.Images = Images; |
| 552 | Cloudflare.Intel = Intel; |
| 553 | Cloudflare.MagicTransit = MagicTransit; |
| 554 | Cloudflare.MagicNetworkMonitoring = MagicNetworkMonitoring; |
| 555 | Cloudflare.MagicCloudNetworking = MagicCloudNetworking; |
| 556 | Cloudflare.NetworkInterconnects = NetworkInterconnects; |
| 557 | Cloudflare.MTLSCertificates = MTLSCertificates; |
| 558 | Cloudflare.Pages = Pages; |
| 559 | Cloudflare.Registrar = Registrar; |
| 560 | Cloudflare.RequestTracers = RequestTracers; |
| 561 | Cloudflare.Rules = Rules; |
| 562 | Cloudflare.Stream = Stream; |
| 563 | Cloudflare.Alerting = Alerting; |
| 564 | Cloudflare.D1Resource = D1Resource; |
| 565 | Cloudflare.R2 = R2; |
| 566 | Cloudflare.WorkersForPlatforms = WorkersForPlatforms; |
| 567 | Cloudflare.ZeroTrust = ZeroTrust; |
| 568 | Cloudflare.Turnstile = Turnstile; |
| 569 | Cloudflare.HyperdriveResource = HyperdriveResource; |
| 570 | Cloudflare.RUM = RUM; |
| 571 | Cloudflare.Vectorize = Vectorize; |
| 572 | Cloudflare.URLScanner = URLScanner; |
| 573 | Cloudflare.Radar = Radar; |
| 574 | Cloudflare.BotManagement = BotManagement; |
| 575 | Cloudflare.OriginPostQuantumEncryption = OriginPostQuantumEncryption; |
| 576 | Cloudflare.Zaraz = Zaraz; |
| 577 | Cloudflare.Speed = Speed; |
| 578 | Cloudflare.DCVDelegation = DCVDelegation; |
| 579 | Cloudflare.Hostnames = Hostnames; |
| 580 | Cloudflare.Snippets = Snippets; |
| 581 | Cloudflare.Calls = Calls; |
| 582 | Cloudflare.CloudforceOne = CloudforceOne; |
| 583 | Cloudflare.AIGateway = AIGateway; |
| 584 | Cloudflare.IAM = IAM; |
| 585 | Cloudflare.CloudConnector = CloudConnector; |
| 586 | Cloudflare.BotnetFeed = BotnetFeed; |
| 587 | Cloudflare.SecurityTXT = SecurityTXT; |
| 588 | Cloudflare.Workflows = Workflows; |
| 589 | Cloudflare.ResourceSharing = ResourceSharing; |
| 590 | Cloudflare.LeakedCredentialChecks = LeakedCredentialChecks; |
| 591 | Cloudflare.ContentScanning = ContentScanning; |
| 592 | Cloudflare.AbuseReports = AbuseReports; |
| 593 | Cloudflare.AI = AI; |
| 594 | Cloudflare.SecurityCenter = SecurityCenter; |
| 595 | Cloudflare.BrowserRendering = BrowserRendering; |
| 596 | Cloudflare.CustomPages = CustomPages; |
| 597 | Cloudflare.SecretsStore = SecretsStore; |
| 598 | Cloudflare.Pipelines = Pipelines; |
| 599 | Cloudflare.SchemaValidation = SchemaValidation; |
| 600 | |
| 601 | export declare namespace Cloudflare { |
| 602 | export type RequestOptions = Core.RequestOptions; |
| 603 | |
| 604 | export import V4PagePagination = Pagination.V4PagePagination; |
| 605 | export { |
| 606 | type V4PagePaginationParams as V4PagePaginationParams, |
| 607 | type V4PagePaginationResponse as V4PagePaginationResponse, |
| 608 | }; |
| 609 | |
| 610 | export import V4PagePaginationArray = Pagination.V4PagePaginationArray; |
| 611 | export { |
| 612 | type V4PagePaginationArrayParams as V4PagePaginationArrayParams, |
| 613 | type V4PagePaginationArrayResponse as V4PagePaginationArrayResponse, |
| 614 | }; |
| 615 | |
| 616 | export import CursorPagination = Pagination.CursorPagination; |
| 617 | export { |
| 618 | type CursorPaginationParams as CursorPaginationParams, |
| 619 | type CursorPaginationResponse as CursorPaginationResponse, |
| 620 | }; |
| 621 | |
| 622 | export import CursorPaginationAfter = Pagination.CursorPaginationAfter; |
| 623 | export { |
| 624 | type CursorPaginationAfterParams as CursorPaginationAfterParams, |
| 625 | type CursorPaginationAfterResponse as CursorPaginationAfterResponse, |
| 626 | }; |
| 627 | |
| 628 | export import CursorLimitPagination = Pagination.CursorLimitPagination; |
| 629 | export { |
| 630 | type CursorLimitPaginationParams as CursorLimitPaginationParams, |
| 631 | type CursorLimitPaginationResponse as CursorLimitPaginationResponse, |
| 632 | }; |
| 633 | |
| 634 | export import SinglePage = Pagination.SinglePage; |
| 635 | export { type SinglePageResponse as SinglePageResponse }; |
| 636 | |
| 637 | export { Accounts as Accounts }; |
| 638 | |
| 639 | export { OriginCACertificates as OriginCACertificates }; |
| 640 | |
| 641 | export { IPs as IPs }; |
| 642 | |
| 643 | export { Memberships as Memberships }; |
| 644 | |
| 645 | export { User as User }; |
| 646 | |
| 647 | export { Zones as Zones }; |
| 648 | |
| 649 | export { LoadBalancers as LoadBalancers }; |
| 650 | |
| 651 | export { Cache as Cache }; |
| 652 | |
| 653 | export { SSL as SSL }; |
| 654 | |
| 655 | export { ACM as ACM }; |
| 656 | |
| 657 | export { Argo as Argo }; |
| 658 | |
| 659 | export { CertificateAuthorities as CertificateAuthorities }; |
| 660 | |
| 661 | export { ClientCertificates as ClientCertificates }; |
| 662 | |
| 663 | export { CustomCertificates as CustomCertificates }; |
| 664 | |
| 665 | export { CustomHostnames as CustomHostnames }; |
| 666 | |
| 667 | export { CustomNameservers as CustomNameservers }; |
| 668 | |
| 669 | export { DNSFirewall as DNSFirewall }; |
| 670 | |
| 671 | export { DNS as DNS }; |
| 672 | |
| 673 | export { EmailSecurity as EmailSecurity }; |
| 674 | |
| 675 | export { EmailRouting as EmailRouting }; |
| 676 | |
| 677 | export { Filters as Filters }; |
| 678 | |
| 679 | export { Firewall as Firewall }; |
| 680 | |
| 681 | export { Healthchecks as Healthchecks }; |
| 682 | |
| 683 | export { KeylessCertificates as KeylessCertificates }; |
| 684 | |
| 685 | export { Logpush as Logpush }; |
| 686 | |
| 687 | export { Logs as Logs }; |
| 688 | |
| 689 | export { OriginTLSClientAuth as OriginTLSClientAuth }; |
| 690 | |
| 691 | export { PageRules as PageRules }; |
| 692 | |
| 693 | export { RateLimits as RateLimits }; |
| 694 | |
| 695 | export { WaitingRooms as WaitingRooms }; |
| 696 | |
| 697 | export { Web3 as Web3 }; |
| 698 | |
| 699 | export { Workers as Workers }; |
| 700 | |
| 701 | export { KV as KV }; |
| 702 | |
| 703 | export { DurableObjects as DurableObjects }; |
| 704 | |
| 705 | export { Queues as Queues }; |
| 706 | |
| 707 | export { APIGateway as APIGateway }; |
| 708 | |
| 709 | export { ManagedTransforms as ManagedTransforms }; |
| 710 | |
| 711 | export { PageShield as PageShield }; |
| 712 | |
| 713 | export { Rulesets as Rulesets }; |
| 714 | |
| 715 | export { URLNormalization as URLNormalization }; |
| 716 | |
| 717 | export { Spectrum as Spectrum }; |
| 718 | |
| 719 | export { Addressing as Addressing }; |
| 720 | |
| 721 | export { AuditLogs as AuditLogs }; |
| 722 | |
| 723 | export { Billing as Billing }; |
| 724 | |
| 725 | export { BrandProtection as BrandProtection }; |
| 726 | |
| 727 | export { Diagnostics as Diagnostics }; |
| 728 | |
| 729 | export { Images as Images }; |
| 730 | |
| 731 | export { Intel as Intel }; |
| 732 | |
| 733 | export { MagicTransit as MagicTransit }; |
| 734 | |
| 735 | export { MagicNetworkMonitoring as MagicNetworkMonitoring }; |
| 736 | |
| 737 | export { MagicCloudNetworking as MagicCloudNetworking }; |
| 738 | |
| 739 | export { NetworkInterconnects as NetworkInterconnects }; |
| 740 | |
| 741 | export { MTLSCertificates as MTLSCertificates }; |
| 742 | |
| 743 | export { Pages as Pages }; |
| 744 | |
| 745 | export { Registrar as Registrar }; |
| 746 | |
| 747 | export { RequestTracers as RequestTracers }; |
| 748 | |
| 749 | export { Rules as Rules }; |
| 750 | |
| 751 | export { Stream as Stream }; |
| 752 | |
| 753 | export { Alerting as Alerting }; |
| 754 | |
| 755 | export { D1Resource as D1Resource }; |
| 756 | |
| 757 | export { R2 as R2 }; |
| 758 | |
| 759 | export { WorkersForPlatforms as WorkersForPlatforms }; |
| 760 | |
| 761 | export { ZeroTrust as ZeroTrust }; |
| 762 | |
| 763 | export { Turnstile as Turnstile }; |
| 764 | |
| 765 | export { HyperdriveResource as HyperdriveResource }; |
| 766 | |
| 767 | export { RUM as RUM }; |
| 768 | |
| 769 | export { Vectorize as Vectorize }; |
| 770 | |
| 771 | export { URLScanner as URLScanner }; |
| 772 | |
| 773 | export { Radar as Radar }; |
| 774 | |
| 775 | export { BotManagement as BotManagement }; |
| 776 | |
| 777 | export { OriginPostQuantumEncryption as OriginPostQuantumEncryption }; |
| 778 | |
| 779 | export { Zaraz as Zaraz }; |
| 780 | |
| 781 | export { Speed as Speed }; |
| 782 | |
| 783 | export { DCVDelegation as DCVDelegation }; |
| 784 | |
| 785 | export { Hostnames as Hostnames }; |
| 786 | |
| 787 | export { Snippets as Snippets }; |
| 788 | |
| 789 | export { Calls as Calls }; |
| 790 | |
| 791 | export { CloudforceOne as CloudforceOne }; |
| 792 | |
| 793 | export { AIGateway as AIGateway }; |
| 794 | |
| 795 | export { IAM as IAM }; |
| 796 | |
| 797 | export { CloudConnector as CloudConnector }; |
| 798 | |
| 799 | export { BotnetFeed as BotnetFeed }; |
| 800 | |
| 801 | export { SecurityTXT as SecurityTXT }; |
| 802 | |
| 803 | export { Workflows as Workflows }; |
| 804 | |
| 805 | export { ResourceSharing as ResourceSharing }; |
| 806 | |
| 807 | export { LeakedCredentialChecks as LeakedCredentialChecks }; |
| 808 | |
| 809 | export { ContentScanning as ContentScanning }; |
| 810 | |
| 811 | export { AbuseReports as AbuseReports }; |
| 812 | |
| 813 | export { AI as AI }; |
| 814 | |
| 815 | export { SecurityCenter as SecurityCenter }; |
| 816 | |
| 817 | export { BrowserRendering as BrowserRendering }; |
| 818 | |
| 819 | export { CustomPages as CustomPages }; |
| 820 | |
| 821 | export { SecretsStore as SecretsStore }; |
| 822 | |
| 823 | export { Pipelines as Pipelines }; |
| 824 | |
| 825 | export { SchemaValidation as SchemaValidation }; |
| 826 | |
| 827 | export type ASN = API.ASN; |
| 828 | export type AuditLog = API.AuditLog; |
| 829 | export type CertificateCA = API.CertificateCA; |
| 830 | export type CertificateRequestType = API.CertificateRequestType; |
| 831 | export type CloudflareTunnel = API.CloudflareTunnel; |
| 832 | export type ErrorData = API.ErrorData; |
| 833 | export type Identifier = API.Identifier; |
| 834 | export type LoadBalancerPreview = API.LoadBalancerPreview; |
| 835 | export type Member = API.Member; |
| 836 | export type PaginationInfo = API.PaginationInfo; |
| 837 | export type Permission = API.Permission; |
| 838 | export type PermissionGrant = API.PermissionGrant; |
| 839 | export type RatePlan = API.RatePlan; |
| 840 | export type ResponseInfo = API.ResponseInfo; |
| 841 | export type Result = API.Result; |
| 842 | export type Role = API.Role; |
| 843 | export type SortDirection = API.SortDirection; |
| 844 | export type Subscription = API.Subscription; |
| 845 | export type SubscriptionComponent = API.SubscriptionComponent; |
| 846 | export type SubscriptionZone = API.SubscriptionZone; |
| 847 | export type Token = API.Token; |
| 848 | export type TokenConditionCIDRList = API.TokenConditionCIDRList; |
| 849 | export type TokenPolicy = API.TokenPolicy; |
| 850 | export type TokenValue = API.TokenValue; |
| 851 | } |
| 852 | |
| 853 | export { toFile, fileFromPath } from './uploads'; |
| 854 | export { |
| 855 | CloudflareError, |
| 856 | APIError, |
| 857 | APIConnectionError, |
| 858 | APIConnectionTimeoutError, |
| 859 | APIUserAbortError, |
| 860 | NotFoundError, |
| 861 | ConflictError, |
| 862 | RateLimitError, |
| 863 | BadRequestError, |
| 864 | AuthenticationError, |
| 865 | InternalServerError, |
| 866 | PermissionDeniedError, |
| 867 | UnprocessableEntityError, |
| 868 | } from './error'; |
| 869 | |
| 870 | export default Cloudflare; |
| 871 | |