UNPKG

cloudflare

Version:

The official TypeScript library for the Cloudflare API

136 lines 5.51 kB
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { APIResource } from 'cloudflare/resource'; import { isRequestOptions } from 'cloudflare/core'; import { CloudflareError } from 'cloudflare/error'; import * as CertificatesAPI from 'cloudflare/resources/zero-trust/access/certificates/certificates'; import * as SettingsAPI from 'cloudflare/resources/zero-trust/access/certificates/settings'; import { SinglePage } from 'cloudflare/pagination'; export class Certificates extends APIResource { constructor() { super(...arguments); this.settings = new SettingsAPI.Settings(this._client); } /** * Adds a new mTLS root certificate to Access. */ 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(`/${accountOrZone}/${accountOrZoneId}/access/certificates`, { body, ...options, })._thenUnwrap((obj) => obj.result); } /** * Updates a configured mTLS certificate. */ update(uuid, 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(`/${accountOrZone}/${accountOrZoneId}/access/certificates/${uuid}`, { body, ...options, })._thenUnwrap((obj) => obj.result); } list(params = {}, options) { if (isRequestOptions(params)) { return this.list({}, params); } 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(`/${accountOrZone}/${accountOrZoneId}/access/certificates`, ZeroTrustCertificatesSinglePage, options); } delete(uuid, params = {}, options) { if (isRequestOptions(params)) { return this.delete(uuid, {}, params); } 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(`/${accountOrZone}/${accountOrZoneId}/access/certificates/${uuid}`, options)._thenUnwrap((obj) => obj.result); } get(uuid, params = {}, options) { if (isRequestOptions(params)) { return this.get(uuid, {}, params); } 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(`/${accountOrZone}/${accountOrZoneId}/access/certificates/${uuid}`, options)._thenUnwrap((obj) => obj.result); } } export class ZeroTrustCertificatesSinglePage extends SinglePage { } (function (Certificates) { Certificates.ZeroTrustCertificatesSinglePage = CertificatesAPI.ZeroTrustCertificatesSinglePage; Certificates.Settings = SettingsAPI.Settings; })(Certificates || (Certificates = {})); //# sourceMappingURL=certificates.mjs.map