cloudflare
Version:
The official TypeScript library for the Cloudflare API
152 lines • 6.28 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CustomCsrs = exports.BaseCustomCsrs = void 0;
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
const resource_1 = require("../../core/resource.js");
const error_1 = require("../../core/error.js");
const pagination_1 = require("../../core/pagination.js");
const path_1 = require("../../internal/utils/path.js");
var BaseCustomCsrs = /* @__PURE__ */ (() => {
class BaseCustomCsrs extends resource_1.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 error_1.CloudflareError('You must provide either account_id or zone_id.');
}
if (account_id && zone_id) {
throw new error_1.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((0, path_1.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 error_1.CloudflareError('You must provide either account_id or zone_id.');
}
if (account_id && zone_id) {
throw new error_1.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((0, path_1.path) `/${accountOrZone}/${accountOrZoneId}/custom_csrs`, (pagination_1.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 error_1.CloudflareError('You must provide either account_id or zone_id.');
}
if (account_id && zone_id) {
throw new error_1.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((0, path_1.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 error_1.CloudflareError('You must provide either account_id or zone_id.');
}
if (account_id && zone_id) {
throw new error_1.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((0, path_1.path) `/${accountOrZone}/${accountOrZoneId}/custom_csrs/${customCsrID}`, options)._thenUnwrap((obj) => obj.result);
}
}
BaseCustomCsrs._key = Object.freeze(['customCsrs']);
return BaseCustomCsrs;
})();
exports.BaseCustomCsrs = BaseCustomCsrs;
class CustomCsrs extends BaseCustomCsrs {
}
exports.CustomCsrs = CustomCsrs;
//# sourceMappingURL=custom-csrs.js.map