cloudflare
Version:
The official TypeScript library for the Cloudflare API
202 lines • 8.17 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Certificates = exports.BaseCertificates = void 0;
const tslib_1 = require("../../../../internal/tslib.js");
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
const resource_1 = require("../../../../core/resource.js");
const SettingsAPI = tslib_1.__importStar(require("./settings.js"));
const settings_1 = require("./settings.js");
const error_1 = require("../../../../core/error.js");
const pagination_1 = require("../../../../core/pagination.js");
const path_1 = require("../../../../internal/utils/path.js");
var BaseCertificates = /* @__PURE__ */ (() => {
class BaseCertificates extends resource_1.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 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}/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 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.put((0, path_1.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 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}/access/certificates`, (pagination_1.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 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}/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 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}/access/certificates/${certificateID}`, options)._thenUnwrap((obj) => obj.result);
}
}
BaseCertificates._key = Object.freeze([
'zeroTrust',
'access',
'certificates',
]);
return BaseCertificates;
})();
exports.BaseCertificates = BaseCertificates;
var Certificates = /* @__PURE__ */ (() => {
class Certificates extends BaseCertificates {
constructor() {
super(...arguments);
this.settings = new SettingsAPI.Settings(this._client);
}
}
Certificates.Settings = settings_1.Settings;
Certificates.BaseSettings = settings_1.BaseSettings;
return Certificates;
})();
exports.Certificates = Certificates;
//# sourceMappingURL=certificates.js.map