cloudflare
Version:
The official TypeScript library for the Cloudflare API
257 lines • 10.6 kB
JavaScript
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import { APIResource } from "../../core/resource.mjs";
import * as PreviewsAPI from "./previews.mjs";
import { BasePreviews, Previews } from "./previews.mjs";
import * as RegionsAPI from "./regions.mjs";
import { BaseRegions, Regions, } from "./regions.mjs";
import * as SearchesAPI from "./searches.mjs";
import { BaseSearches, Searches, } from "./searches.mjs";
import * as MonitorGroupsAPI from "./monitor-groups/monitor-groups.mjs";
import { BaseMonitorGroups, MonitorGroups, } from "./monitor-groups/monitor-groups.mjs";
import * as MonitorsAPI from "./monitors/monitors.mjs";
import { BaseMonitors, Monitors, } from "./monitors/monitors.mjs";
import * as PoolsAPI from "./pools/pools.mjs";
import { BasePools, Pools, } from "./pools/pools.mjs";
import { CloudflareError } from "../../core/error.mjs";
import { SinglePage } from "../../core/pagination.mjs";
import { path } from "../../internal/utils/path.mjs";
export var BaseLoadBalancers = /* @__PURE__ */ (() => {
class BaseLoadBalancers extends APIResource {
/**
* Create a new account or zone-scoped load balancer.
*
* @example
* ```ts
* const loadBalancer = await client.loadBalancers.create({
* default_pools: [
* '17b5962d775c646f3f9725cbc7a53df4',
* '9290f38c5d07c2e2f4df57b1f61d4196',
* '00920f38ce07c2e2f4df50b1f61d4194',
* ],
* fallback_pool: 'fallback_pool',
* name: 'www.example.com',
* account_id: 'account_id',
* });
* ```
*/
create(params, options) {
const { account_id, zone_id, ...body } = params;
if (!account_id && !zone_id) {
throw new CloudflareError('You must provide either account_id or zone_id.');
}
if (account_id && zone_id) {
throw new CloudflareError('You cannot provide both account_id and zone_id.');
}
const { accountOrZone, accountOrZoneId } = account_id ?
{
accountOrZone: 'accounts',
accountOrZoneId: account_id,
}
: {
accountOrZone: 'zones',
accountOrZoneId: zone_id,
};
return this._client.post(path `/${accountOrZone}/${accountOrZoneId}/load_balancers`, {
body,
...options,
})._thenUnwrap((obj) => obj.result);
}
/**
* Update a configured account or zone-scoped load balancer.
*
* @example
* ```ts
* const loadBalancer = await client.loadBalancers.update(
* '699d98642c564d2e855e9661899b7252',
* {
* default_pools: [
* '17b5962d775c646f3f9725cbc7a53df4',
* '9290f38c5d07c2e2f4df57b1f61d4196',
* '00920f38ce07c2e2f4df50b1f61d4194',
* ],
* fallback_pool: 'fallback_pool',
* name: 'www.example.com',
* account_id: 'account_id',
* },
* );
* ```
*/
update(loadBalancerID, params, options) {
const { account_id, zone_id, ...body } = params;
if (!account_id && !zone_id) {
throw new CloudflareError('You must provide either account_id or zone_id.');
}
if (account_id && zone_id) {
throw new CloudflareError('You cannot provide both account_id and zone_id.');
}
const { accountOrZone, accountOrZoneId } = account_id ?
{
accountOrZone: 'accounts',
accountOrZoneId: account_id,
}
: {
accountOrZone: 'zones',
accountOrZoneId: zone_id,
};
return this._client.put(path `/${accountOrZone}/${accountOrZoneId}/load_balancers/${loadBalancerID}`, {
body,
...options,
})._thenUnwrap((obj) => obj.result);
}
/**
* List configured account or zone-scoped load balancers.
*
* @example
* ```ts
* // Automatically fetches more pages as needed.
* for await (const loadBalancer of client.loadBalancers.list({
* account_id: 'account_id',
* })) {
* // ...
* }
* ```
*/
list(params = {}, options) {
const { account_id, zone_id } = params ?? {};
if (!account_id && !zone_id) {
throw new CloudflareError('You must provide either account_id or zone_id.');
}
if (account_id && zone_id) {
throw new CloudflareError('You cannot provide both account_id and zone_id.');
}
const { accountOrZone, accountOrZoneId } = account_id ?
{
accountOrZone: 'accounts',
accountOrZoneId: account_id,
}
: {
accountOrZone: 'zones',
accountOrZoneId: zone_id,
};
return this._client.getAPIList(path `/${accountOrZone}/${accountOrZoneId}/load_balancers`, (SinglePage), options);
}
/**
* Delete a configured account or zone-scoped load balancer.
*
* @example
* ```ts
* const loadBalancer = await client.loadBalancers.delete(
* '699d98642c564d2e855e9661899b7252',
* { account_id: 'account_id' },
* );
* ```
*/
delete(loadBalancerID, params = {}, options) {
const { account_id, zone_id } = params ?? {};
if (!account_id && !zone_id) {
throw new CloudflareError('You must provide either account_id or zone_id.');
}
if (account_id && zone_id) {
throw new CloudflareError('You cannot provide both account_id and zone_id.');
}
const { accountOrZone, accountOrZoneId } = account_id ?
{
accountOrZone: 'accounts',
accountOrZoneId: account_id,
}
: {
accountOrZone: 'zones',
accountOrZoneId: zone_id,
};
return this._client.delete(path `/${accountOrZone}/${accountOrZoneId}/load_balancers/${loadBalancerID}`, options)._thenUnwrap((obj) => obj.result);
}
/**
* Apply changes to an existing account or zone-scoped load balancer, overwriting
* the supplied properties.
*
* @example
* ```ts
* const loadBalancer = await client.loadBalancers.edit(
* '699d98642c564d2e855e9661899b7252',
* { account_id: 'account_id' },
* );
* ```
*/
edit(loadBalancerID, params, options) {
const { account_id, zone_id, ...body } = params;
if (!account_id && !zone_id) {
throw new CloudflareError('You must provide either account_id or zone_id.');
}
if (account_id && zone_id) {
throw new CloudflareError('You cannot provide both account_id and zone_id.');
}
const { accountOrZone, accountOrZoneId } = account_id ?
{
accountOrZone: 'accounts',
accountOrZoneId: account_id,
}
: {
accountOrZone: 'zones',
accountOrZoneId: zone_id,
};
return this._client.patch(path `/${accountOrZone}/${accountOrZoneId}/load_balancers/${loadBalancerID}`, {
body,
...options,
})._thenUnwrap((obj) => obj.result);
}
/**
* Fetch a single configured account or zone-scoped load balancer.
*
* @example
* ```ts
* const loadBalancer = await client.loadBalancers.get(
* '699d98642c564d2e855e9661899b7252',
* { account_id: 'account_id' },
* );
* ```
*/
get(loadBalancerID, params = {}, options) {
const { account_id, zone_id } = params ?? {};
if (!account_id && !zone_id) {
throw new CloudflareError('You must provide either account_id or zone_id.');
}
if (account_id && zone_id) {
throw new CloudflareError('You cannot provide both account_id and zone_id.');
}
const { accountOrZone, accountOrZoneId } = account_id ?
{
accountOrZone: 'accounts',
accountOrZoneId: account_id,
}
: {
accountOrZone: 'zones',
accountOrZoneId: zone_id,
};
return this._client.get(path `/${accountOrZone}/${accountOrZoneId}/load_balancers/${loadBalancerID}`, options)._thenUnwrap((obj) => obj.result);
}
}
BaseLoadBalancers._key = Object.freeze(['loadBalancers']);
return BaseLoadBalancers;
})();
export var LoadBalancers = /* @__PURE__ */ (() => {
class LoadBalancers extends BaseLoadBalancers {
constructor() {
super(...arguments);
this.monitors = new MonitorsAPI.Monitors(this._client);
this.monitorGroups = new MonitorGroupsAPI.MonitorGroups(this._client);
this.pools = new PoolsAPI.Pools(this._client);
this.previews = new PreviewsAPI.Previews(this._client);
this.regions = new RegionsAPI.Regions(this._client);
this.searches = new SearchesAPI.Searches(this._client);
}
}
LoadBalancers.Monitors = Monitors;
LoadBalancers.BaseMonitors = BaseMonitors;
LoadBalancers.MonitorGroups = MonitorGroups;
LoadBalancers.BaseMonitorGroups = BaseMonitorGroups;
LoadBalancers.Pools = Pools;
LoadBalancers.BasePools = BasePools;
LoadBalancers.Previews = Previews;
LoadBalancers.BasePreviews = BasePreviews;
LoadBalancers.Regions = Regions;
LoadBalancers.BaseRegions = BaseRegions;
LoadBalancers.Searches = Searches;
LoadBalancers.BaseSearches = BaseSearches;
return LoadBalancers;
})();
//# sourceMappingURL=load-balancers.mjs.map