cloudflare/cloudflare-typescript

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
next

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/index.ts

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