cloudflare/cloudflare-typescript

Public

mirrored fromhttps://github.com/cloudflare/cloudflare-typescriptAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v6.3.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/index.ts

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