UNPKG

cloudflare

Version:

The official TypeScript library for the Cloudflare API

323 lines 15 kB
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. var _a; import * as Core from "./core.mjs"; import * as Errors from "./error.mjs"; import * as Uploads from "./uploads.mjs"; import * as qs from 'qs'; import * as Pagination from 'cloudflare/pagination'; import * as API from 'cloudflare/resources/index'; /** API Client for interfacing with the Cloudflare API. */ export class Cloudflare extends Core.APIClient { /** * API Client for interfacing with the Cloudflare API. * * @param {string | null | undefined} [opts.apiToken=process.env['CLOUDFLARE_API_TOKEN'] ?? null] * @param {string | null | undefined} [opts.apiKey=process.env['CLOUDFLARE_API_KEY'] ?? null] * @param {string | null | undefined} [opts.apiEmail=process.env['CLOUDFLARE_EMAIL'] ?? null] * @param {string | null | undefined} [opts.userServiceKey=process.env['CLOUDFLARE_API_USER_SERVICE_KEY'] ?? null] * @param {string} [opts.baseURL=process.env['CLOUDFLARE_BASE_URL'] ?? https://api.cloudflare.com/client/v4] - Override the default base URL for the API. * @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out. * @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections. * @param {Core.Fetch} [opts.fetch] - Specify a custom `fetch` function implementation. * @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request. * @param {Core.Headers} opts.defaultHeaders - Default headers to include with every request to the API. * @param {Core.DefaultQuery} opts.defaultQuery - Default query parameters to include with every request to the API. */ constructor({ baseURL = Core.readEnv('CLOUDFLARE_BASE_URL'), apiToken = Core.readEnv('CLOUDFLARE_API_TOKEN') ?? null, apiKey = Core.readEnv('CLOUDFLARE_API_KEY') ?? null, apiEmail = Core.readEnv('CLOUDFLARE_EMAIL') ?? null, userServiceKey = Core.readEnv('CLOUDFLARE_API_USER_SERVICE_KEY') ?? null, ...opts } = {}) { const options = { apiToken, apiKey, apiEmail, userServiceKey, ...opts, baseURL: baseURL || `https://api.cloudflare.com/client/v4`, }; super({ baseURL: options.baseURL, timeout: options.timeout ?? 60000 /* 1 minute */, httpAgent: options.httpAgent, maxRetries: options.maxRetries, fetch: options.fetch, }); this.accounts = new API.Accounts(this); this.originCACertificates = new API.OriginCACertificates(this); this.ips = new API.IPs(this); this.memberships = new API.Memberships(this); this.user = new API.User(this); this.zones = new API.Zones(this); this.loadBalancers = new API.LoadBalancers(this); this.cache = new API.Cache(this); this.ssl = new API.SSL(this); this.subscriptions = new API.Subscriptions(this); this.acm = new API.ACM(this); this.argo = new API.Argo(this); this.plans = new API.Plans(this); this.ratePlans = new API.RatePlans(this); this.certificateAuthorities = new API.CertificateAuthorities(this); this.clientCertificates = new API.ClientCertificates(this); this.customCertificates = new API.CustomCertificates(this); this.customHostnames = new API.CustomHostnames(this); this.customNameservers = new API.CustomNameservers(this); this.dns = new API.DNS(this); this.dnssec = new API.DNSSECResource(this); this.emailRouting = new API.EmailRouting(this); this.filters = new API.Filters(this); this.firewall = new API.Firewall(this); this.healthchecks = new API.Healthchecks(this); this.keylessCertificates = new API.KeylessCertificates(this); this.logpush = new API.Logpush(this); this.logs = new API.Logs(this); this.originTLSClientAuth = new API.OriginTLSClientAuth(this); this.pagerules = new API.Pagerules(this); this.rateLimits = new API.RateLimits(this); this.secondaryDNS = new API.SecondaryDNS(this); this.waitingRooms = new API.WaitingRooms(this); this.web3 = new API.Web3(this); this.workers = new API.Workers(this); this.kv = new API.KV(this); this.durableObjects = new API.DurableObjects(this); this.queues = new API.Queues(this); this.managedHeaders = new API.ManagedHeaders(this); this.pageShield = new API.PageShield(this); this.rulesets = new API.Rulesets(this); this.urlNormalization = new API.URLNormalization(this); this.spectrum = new API.Spectrum(this); this.addressing = new API.Addressing(this); this.auditLogs = new API.AuditLogs(this); this.billing = new API.Billing(this); this.brandProtection = new API.BrandProtection(this); this.diagnostics = new API.Diagnostics(this); this.images = new API.Images(this); this.intel = new API.Intel(this); this.magicTransit = new API.MagicTransit(this); this.magicNetworkMonitoring = new API.MagicNetworkMonitoring(this); this.mtlsCertificates = new API.MTLSCertificates(this); this.pages = new API.Pages(this); this.pcaps = new API.PCAPs(this); this.registrar = new API.Registrar(this); this.requestTracers = new API.RequestTracers(this); this.rules = new API.Rules(this); this.storage = new API.Storage(this); this.stream = new API.Stream(this); this.alerting = new API.Alerting(this); this.d1 = new API.D1Resource(this); this.r2 = new API.R2(this); this.warpConnector = new API.WARPConnector(this); this.workersForPlatforms = new API.WorkersForPlatforms(this); this.zeroTrust = new API.ZeroTrust(this); this.challenges = new API.Challenges(this); this.hyperdrive = new API.HyperdriveResource(this); this.rum = new API.RUM(this); this.vectorize = new API.Vectorize(this); this.urlScanner = new API.URLScanner(this); this.radar = new API.Radar(this); this.botManagement = new API.BotManagement(this); this.originPostQuantumEncryption = new API.OriginPostQuantumEncryption(this); this.speed = new API.Speed(this); this.dcvDelegation = new API.DCVDelegation(this); this.hostnames = new API.Hostnames(this); this.snippets = new API.Snippets(this); this.calls = new API.Calls(this); this.cloudforceOne = new API.CloudforceOne(this); this.eventNotifications = new API.EventNotifications(this); this._options = options; this.apiToken = apiToken; this.apiKey = apiKey; this.apiEmail = apiEmail; this.userServiceKey = userServiceKey; } defaultQuery() { return this._options.defaultQuery; } defaultHeaders(opts) { return { ...super.defaultHeaders(opts), 'X-Auth-Key': this.apiKey, 'X-Auth-Email': this.apiEmail, ...this._options.defaultHeaders, }; } validateHeaders(headers, customHeaders) { if (this.apiEmail && headers['x-auth-email']) { return; } if (customHeaders['x-auth-email'] === null) { return; } if (this.apiKey && headers['x-auth-key']) { return; } if (customHeaders['x-auth-key'] === null) { return; } if (this.apiToken && headers['authorization']) { return; } if (customHeaders['authorization'] === null) { return; } if (this.userServiceKey && headers['x-auth-user-service-key']) { return; } if (customHeaders['x-auth-user-service-key'] === null) { return; } throw new Error('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'); } authHeaders(opts) { const apiEmailAuth = this.apiEmailAuth(opts); const apiKeyAuth = this.apiKeyAuth(opts); const apiTokenAuth = this.apiTokenAuth(opts); const userServiceKeyAuth = this.userServiceKeyAuth(opts); if (apiEmailAuth != null && !Core.isEmptyObj(apiEmailAuth) && apiKeyAuth != null && !Core.isEmptyObj(apiKeyAuth)) { return { ...apiEmailAuth, ...apiKeyAuth }; } if (apiTokenAuth != null && !Core.isEmptyObj(apiTokenAuth)) { return apiTokenAuth; } if (userServiceKeyAuth != null && !Core.isEmptyObj(userServiceKeyAuth)) { return userServiceKeyAuth; } return {}; } apiEmailAuth(opts) { if (this.apiEmail == null) { return {}; } return { 'X-Auth-Email': this.apiEmail }; } apiKeyAuth(opts) { if (this.apiKey == null) { return {}; } return { 'X-Auth-Key': this.apiKey }; } apiTokenAuth(opts) { if (this.apiToken == null) { return {}; } return { Authorization: `Bearer ${this.apiToken}` }; } userServiceKeyAuth(opts) { if (this.userServiceKey == null) { return {}; } return { 'X-Auth-User-Service-Key': this.userServiceKey }; } stringifyQuery(query) { return qs.stringify(query, { arrayFormat: 'repeat' }); } } _a = Cloudflare; Cloudflare.Cloudflare = _a; Cloudflare.CloudflareError = Errors.CloudflareError; Cloudflare.APIError = Errors.APIError; Cloudflare.APIConnectionError = Errors.APIConnectionError; Cloudflare.APIConnectionTimeoutError = Errors.APIConnectionTimeoutError; Cloudflare.APIUserAbortError = Errors.APIUserAbortError; Cloudflare.NotFoundError = Errors.NotFoundError; Cloudflare.ConflictError = Errors.ConflictError; Cloudflare.RateLimitError = Errors.RateLimitError; Cloudflare.BadRequestError = Errors.BadRequestError; Cloudflare.AuthenticationError = Errors.AuthenticationError; Cloudflare.InternalServerError = Errors.InternalServerError; Cloudflare.PermissionDeniedError = Errors.PermissionDeniedError; Cloudflare.UnprocessableEntityError = Errors.UnprocessableEntityError; Cloudflare.toFile = Uploads.toFile; Cloudflare.fileFromPath = Uploads.fileFromPath; export const { CloudflareError, APIError, APIConnectionError, APIConnectionTimeoutError, APIUserAbortError, NotFoundError, ConflictError, RateLimitError, BadRequestError, AuthenticationError, InternalServerError, PermissionDeniedError, UnprocessableEntityError, } = Errors; export var toFile = Uploads.toFile; export var fileFromPath = Uploads.fileFromPath; (function (Cloudflare) { Cloudflare.V4PagePagination = Pagination.V4PagePagination; Cloudflare.V4PagePaginationArray = Pagination.V4PagePaginationArray; Cloudflare.CursorPagination = Pagination.CursorPagination; Cloudflare.CursorLimitPagination = Pagination.CursorLimitPagination; Cloudflare.SinglePage = Pagination.SinglePage; Cloudflare.Accounts = API.Accounts; Cloudflare.OriginCACertificates = API.OriginCACertificates; Cloudflare.IPs = API.IPs; Cloudflare.Memberships = API.Memberships; Cloudflare.User = API.User; Cloudflare.Zones = API.Zones; Cloudflare.LoadBalancers = API.LoadBalancers; Cloudflare.Cache = API.Cache; Cloudflare.SSL = API.SSL; Cloudflare.Subscriptions = API.Subscriptions; Cloudflare.ACM = API.ACM; Cloudflare.Argo = API.Argo; Cloudflare.Plans = API.Plans; Cloudflare.RatePlans = API.RatePlans; Cloudflare.CertificateAuthorities = API.CertificateAuthorities; Cloudflare.ClientCertificates = API.ClientCertificates; Cloudflare.CustomCertificates = API.CustomCertificates; Cloudflare.CustomHostnames = API.CustomHostnames; Cloudflare.CustomNameservers = API.CustomNameservers; Cloudflare.DNS = API.DNS; Cloudflare.DNSSECResource = API.DNSSECResource; Cloudflare.EmailRouting = API.EmailRouting; Cloudflare.Filters = API.Filters; Cloudflare.Firewall = API.Firewall; Cloudflare.Healthchecks = API.Healthchecks; Cloudflare.KeylessCertificates = API.KeylessCertificates; Cloudflare.Logpush = API.Logpush; Cloudflare.Logs = API.Logs; Cloudflare.OriginTLSClientAuth = API.OriginTLSClientAuth; Cloudflare.Pagerules = API.Pagerules; Cloudflare.RateLimits = API.RateLimits; Cloudflare.SecondaryDNS = API.SecondaryDNS; Cloudflare.WaitingRooms = API.WaitingRooms; Cloudflare.Web3 = API.Web3; Cloudflare.Workers = API.Workers; Cloudflare.KV = API.KV; Cloudflare.DurableObjects = API.DurableObjects; Cloudflare.Queues = API.Queues; Cloudflare.ManagedHeaders = API.ManagedHeaders; Cloudflare.PageShield = API.PageShield; Cloudflare.Rulesets = API.Rulesets; Cloudflare.URLNormalization = API.URLNormalization; Cloudflare.Spectrum = API.Spectrum; Cloudflare.Addressing = API.Addressing; Cloudflare.AuditLogs = API.AuditLogs; Cloudflare.Billing = API.Billing; Cloudflare.BrandProtection = API.BrandProtection; Cloudflare.Diagnostics = API.Diagnostics; Cloudflare.Images = API.Images; Cloudflare.Intel = API.Intel; Cloudflare.MagicTransit = API.MagicTransit; Cloudflare.MagicNetworkMonitoring = API.MagicNetworkMonitoring; Cloudflare.MTLSCertificates = API.MTLSCertificates; Cloudflare.Pages = API.Pages; Cloudflare.PCAPs = API.PCAPs; Cloudflare.Registrar = API.Registrar; Cloudflare.RequestTracers = API.RequestTracers; Cloudflare.Rules = API.Rules; Cloudflare.Storage = API.Storage; Cloudflare.Stream = API.Stream; Cloudflare.Alerting = API.Alerting; Cloudflare.D1Resource = API.D1Resource; Cloudflare.R2 = API.R2; Cloudflare.WARPConnector = API.WARPConnector; Cloudflare.WorkersForPlatforms = API.WorkersForPlatforms; Cloudflare.ZeroTrust = API.ZeroTrust; Cloudflare.Challenges = API.Challenges; Cloudflare.HyperdriveResource = API.HyperdriveResource; Cloudflare.RUM = API.RUM; Cloudflare.Vectorize = API.Vectorize; Cloudflare.URLScanner = API.URLScanner; Cloudflare.Radar = API.Radar; Cloudflare.BotManagement = API.BotManagement; Cloudflare.OriginPostQuantumEncryption = API.OriginPostQuantumEncryption; Cloudflare.Speed = API.Speed; Cloudflare.DCVDelegation = API.DCVDelegation; Cloudflare.Hostnames = API.Hostnames; Cloudflare.Snippets = API.Snippets; Cloudflare.Calls = API.Calls; Cloudflare.CloudforceOne = API.CloudforceOne; Cloudflare.EventNotifications = API.EventNotifications; })(Cloudflare || (Cloudflare = {})); export default Cloudflare; //# sourceMappingURL=index.mjs.map