UNPKG

@jesseditson/dnsimple

Version:

A Node.JS client for the DNSimple API.

183 lines (182 loc) 9.68 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __asyncValues = (this && this.__asyncValues) || function (o) { if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); var m = o[Symbol.asyncIterator], i; return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i); function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; } function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); } }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Certificates = void 0; const paginate_1 = require("./paginate"); class Certificates { constructor(_client) { this._client = _client; /** * Lists the certificates for a domain. * * This API is paginated. Call `listCertificates.iterateAll(account, domain, params)` to get an asynchronous iterator over individual items across all pages. You can also use `await listCertificates.collectAll(account, domain, params)` to quickly retrieve all items across all pages into an array. We suggest using `iterateAll` when possible, as `collectAll` will make all requests at once, which may increase latency and trigger rate limits. * * GET /{account}/domains/{domain}/certificates * * @see https://developer.dnsimple.com/v2/certificates/#listCertificates * * @param account The account id * @param domain The domain name or id * @param params Query parameters * @param params.sort Sort results. Default sorting is by id. */ this.listCertificates = (() => { const method = (account, domain, params = {}) => this._client.request("GET", `/${account}/domains/${domain}/certificates`, null, params); method.iterateAll = (account, domain, params = {}) => (0, paginate_1.paginate)((page) => method(account, domain, Object.assign(Object.assign({}, params), { page }))); method.collectAll = (account, domain, params = {}) => __awaiter(this, void 0, void 0, function* () { var _a, e_1, _b, _c; const items = []; try { for (var _d = true, _e = __asyncValues(method.iterateAll(account, domain, params)), _f; _f = yield _e.next(), _a = _f.done, !_a;) { _c = _f.value; _d = false; try { const item = _c; items.push(item); } finally { _d = true; } } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (!_d && !_a && (_b = _e.return)) yield _b.call(_e); } finally { if (e_1) throw e_1.error; } } return items; }); return method; })(); /** * Retrieves the details of an existing certificate. * * GET /{account}/domains/{domain}/certificates/{certificate} * * @see https://developer.dnsimple.com/v2/certificates/#getCertificate * * @param account The account id * @param domain The domain name or id * @param certificate The certificate id * @param params Query parameters */ this.getCertificate = (() => { const method = (account, domain, certificate, params = {}) => this._client.request("GET", `/${account}/domains/${domain}/certificates/${certificate}`, null, params); return method; })(); /** * Gets the PEM-encoded certificate, along with the root certificate and intermediate chain. * * GET /{account}/domains/{domain}/certificates/{certificate}/download * * @see https://developer.dnsimple.com/v2/certificates/#downloadCertificate * * @param account The account id * @param domain The domain name or id * @param certificate The certificate id * @param params Query parameters */ this.downloadCertificate = (() => { const method = (account, domain, certificate, params = {}) => this._client.request("GET", `/${account}/domains/${domain}/certificates/${certificate}/download`, null, params); return method; })(); /** * Gets the PEM-encoded certificate private key. * * GET /{account}/domains/{domain}/certificates/{certificate}/private_key * * @see https://developer.dnsimple.com/v2/certificates/#getCertificatePrivateKey * * @param account The account id * @param domain The domain name or id * @param certificate The certificate id * @param params Query parameters */ this.getCertificatePrivateKey = (() => { const method = (account, domain, certificate, params = {}) => this._client.request("GET", `/${account}/domains/${domain}/certificates/${certificate}/private_key`, null, params); return method; })(); /** * Orders a [Let's Encrypt](https://dnsimple.com/letsencrypt) certificate with DNSimple. * * POST /{account}/domains/{domain}/certificates/letsencrypt * * @see https://developer.dnsimple.com/v2/certificates/#purchaseLetsencryptCertificate * * @param account The account id * @param domain The domain name or id * @param params Query parameters */ this.purchaseLetsencryptCertificate = (() => { const method = (account, domain, data, params = {}) => this._client.request("POST", `/${account}/domains/${domain}/certificates/letsencrypt`, data, params); return method; })(); /** * Issues a [Let's Encrypt](https://dnsimple.com/letsencrypt) certificate ordered with DNSimple. * * POST /{account}/domains/{domain}/certificates/letsencrypt/{purchaseId}/issue * * @see https://developer.dnsimple.com/v2/certificates/#issueLetsencryptCertificate * * @param account The account id * @param domain The domain name or id * @param purchaseId The certificate purchase order id received by `purchaseLetsencryptCertificate`. * @param params Query parameters */ this.issueLetsencryptCertificate = (() => { const method = (account, domain, purchaseId, params = {}) => this._client.request("POST", `/${account}/domains/${domain}/certificates/letsencrypt/${purchaseId}/issue`, null, params); return method; })(); /** * Renews a [Let's Encrypt](https://dnsimple.com/letsencrypt) certificate ordered with DNSimple. * * POST /{account}/domains/{domain}/certificates/letsencrypt/{certificate}/renewals * * @see https://developer.dnsimple.com/v2/certificates/#purchaseRenewalLetsencryptCertificate * * @param account The account id * @param domain The domain name or id * @param certificate The certificate id * @param params Query parameters */ this.purchaseLetsencryptCertificateRenewal = (() => { const method = (account, domain, certificate, data, params = {}) => this._client.request("POST", `/${account}/domains/${domain}/certificates/letsencrypt/${certificate}/renewals`, data, params); return method; })(); /** * Issues a [Let's Encrypt](https://dnsimple.com/letsencrypt) certificate renewal ordered with DNSimple. * * POST /{account}/domains/{domain}/certificates/letsencrypt/{certificate}/renewals/{renewalId}/issue * * @see https://developer.dnsimple.com/v2/certificates/#issueRenewalLetsencryptCertificate * * @param account The account id * @param domain The domain name or id * @param certificate The certificate id * @param renewalId The certificate renewal order id received by `purchaseRenewalLetsencryptCertificate`. * @param params Query parameters */ this.issueLetsencryptCertificateRenewal = (() => { const method = (account, domain, certificate, renewalId, params = {}) => this._client.request("POST", `/${account}/domains/${domain}/certificates/letsencrypt/${certificate}/renewals/${renewalId}/issue`, null, params); return method; })(); } } exports.Certificates = Certificates;