UNPKG

cloudflare

Version:

The official TypeScript library for the Cloudflare API

147 lines • 5.97 kB
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { APIResource } from "../../core/resource.mjs"; import { CloudflareError } from "../../core/error.mjs"; import { V4PagePaginationArray } from "../../core/pagination.mjs"; import { path } from "../../internal/utils/path.mjs"; export var BaseCustomCsrs = /* @__PURE__ */ (() => { class BaseCustomCsrs extends APIResource { /** * Generate a new custom Certificate Signing Request (CSR) for an account or zone. * Cloudflare generates and securely stores the private key associated with the * CSR. * * @example * ```ts * const customCsr = await client.customCsrs.create({ * common_name: 'example.com', * country: 'US', * locality: 'San Francisco', * organization: 'Cloudflare, Inc.', * sans: ['example.com', 'www.example.com'], * state: 'California', * 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}/custom_csrs`, { body, ...options, })._thenUnwrap((obj) => obj.result); } /** * List all custom Certificate Signing Requests (CSRs) for an account or zone. * * @example * ```ts * // Automatically fetches more pages as needed. * for await (const customCsrListResponse of client.customCsrs.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}/custom_csrs`, (V4PagePaginationArray), { query, ...options }); } /** * Delete a custom Certificate Signing Request (CSR) and its associated private * key. * * @example * ```ts * const customCsr = await client.customCsrs.delete( * '7b163417-1d2b-4c84-a38a-2fb7a0cd7752', * { account_id: 'account_id' }, * ); * ``` */ delete(customCsrID, 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}/custom_csrs/${customCsrID}`, options)._thenUnwrap((obj) => obj.result); } /** * Retrieve details for a specific custom Certificate Signing Request (CSR). * * @example * ```ts * const customCsr = await client.customCsrs.get( * '7b163417-1d2b-4c84-a38a-2fb7a0cd7752', * { account_id: 'account_id' }, * ); * ``` */ get(customCsrID, 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}/custom_csrs/${customCsrID}`, options)._thenUnwrap((obj) => obj.result); } } BaseCustomCsrs._key = Object.freeze(['customCsrs']); return BaseCustomCsrs; })(); export class CustomCsrs extends BaseCustomCsrs { } //# sourceMappingURL=custom-csrs.mjs.map