cloudflare/cloudflare-typescript

Public

mirrored from https://github.com/cloudflare/cloudflare-typescriptAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v6.5.0

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/index.ts

997lines · modecode

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