cloudflare/cloudflare-typescript

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
f282d9b3db9dcace369cf37489757aeaecd792a2

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/index.ts

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