UNPKG

cloudflare

Version:

The official TypeScript library for the Cloudflare API

196 lines • 7.73 kB
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { APIResource } from "../../../../core/resource.mjs"; import * as SettingsAPI from "./settings.mjs"; import { BaseSettings, Settings, } from "./settings.mjs"; import { CloudflareError } from "../../../../core/error.mjs"; import { V4PagePaginationArray, } from "../../../../core/pagination.mjs"; import { path } from "../../../../internal/utils/path.mjs"; export var BaseCertificates = /* @__PURE__ */ (() => { class BaseCertificates extends APIResource { /** * Adds a new mTLS root certificate to Access. * * @example * ```ts * const certificate = * await client.zeroTrust.access.certificates.create({ * certificate: * '-----BEGIN CERTIFICATE-----\nMIIGAjCCA+qgAwIBAgIJAI7kymlF7CWT...N4RI7KKB7nikiuUf8vhULKy5IX10\nDrUtmu/B\n-----END CERTIFICATE-----', * name: 'Allow devs', * 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}/access/certificates`, { body, ...options, })._thenUnwrap((obj) => obj.result); } /** * Updates a configured mTLS certificate. * * @example * ```ts * const certificate = * await client.zeroTrust.access.certificates.update( * 'f174e90a-fafe-4643-bbbc-4a0ed4fc8415', * { * associated_hostnames: ['admin.example.com'], * account_id: 'account_id', * }, * ); * ``` */ update(certificateID, 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}/access/certificates/${certificateID}`, { body, ...options, })._thenUnwrap((obj) => obj.result); } /** * Lists all mTLS root certificates. * * @example * ```ts * // Automatically fetches more pages as needed. * for await (const certificate of client.zeroTrust.access.certificates.list( * { account_id: 'account_id' }, * )) { * // ... * } * ``` */ list(params = {}, options) { const { account_id, zone_id, ...query } = 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}/access/certificates`, (V4PagePaginationArray), { query, ...options }); } /** * Deletes an mTLS certificate. * * @example * ```ts * const certificate = * await client.zeroTrust.access.certificates.delete( * 'f174e90a-fafe-4643-bbbc-4a0ed4fc8415', * { account_id: 'account_id' }, * ); * ``` */ delete(certificateID, 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}/access/certificates/${certificateID}`, options)._thenUnwrap((obj) => obj.result); } /** * Fetches a single mTLS certificate. * * @example * ```ts * const certificate = * await client.zeroTrust.access.certificates.get( * 'f174e90a-fafe-4643-bbbc-4a0ed4fc8415', * { account_id: 'account_id' }, * ); * ``` */ get(certificateID, 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}/access/certificates/${certificateID}`, options)._thenUnwrap((obj) => obj.result); } } BaseCertificates._key = Object.freeze([ 'zeroTrust', 'access', 'certificates', ]); return BaseCertificates; })(); export var Certificates = /* @__PURE__ */ (() => { class Certificates extends BaseCertificates { constructor() { super(...arguments); this.settings = new SettingsAPI.Settings(this._client); } } Certificates.Settings = Settings; Certificates.BaseSettings = BaseSettings; return Certificates; })(); //# sourceMappingURL=certificates.mjs.map