UNPKG

@jesseditson/dnsimple

Version:

A Node.JS client for the DNSimple API.

158 lines (157 loc) 7.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.SecondaryDns = void 0; const paginate_1 = require("./paginate"); class SecondaryDns { constructor(_client) { this._client = _client; /** * List the primary servers in the account. * * This API is paginated. Call `listPrimaryServers.iterateAll(account, params)` to get an asynchronous iterator over individual items across all pages. You can also use `await listPrimaryServers.collectAll(account, 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}/secondary_dns/primaries * * @see https://developer.dnsimple.com/v2/secondary-dns/#listPrimaryServers * * @param account The account id * @param params Query parameters * @param params.sort Sort results. Default sorting is ascending by id. */ this.listPrimaryServers = (() => { const method = (account, params = {}) => this._client.request("GET", `/${account}/secondary_dns/primaries`, null, params); method.iterateAll = (account, params = {}) => (0, paginate_1.paginate)((page) => method(account, Object.assign(Object.assign({}, params), { page }))); method.collectAll = (account, 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, 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; })(); /** * Creates a primary server into the account. * * POST /{account}/secondary_dns/primaries * * @see https://developer.dnsimple.com/v2/secondary-dns/#createPrimaryServer * * @param account The account id * @param params Query parameters */ this.createPrimaryServer = (() => { const method = (account, data, params = {}) => this._client.request("POST", `/${account}/secondary_dns/primaries`, data, params); return method; })(); /** * Retrieves the details of an existing primary server. * * GET /{account}/secondary_dns/primaries/{primaryserver} * * @see https://developer.dnsimple.com/v2/secondary-dns/#getPrimaryServer * * @param account The account id * @param primaryserver The primary server id * @param params Query parameters */ this.getPrimaryServer = (() => { const method = (account, primaryserver, params = {}) => this._client.request("GET", `/${account}/secondary_dns/primaries/${primaryserver}`, null, params); return method; })(); /** * Permanently deletes a primary server. * * DELETE /{account}/secondary_dns/primaries/{primaryserver} * * @see https://developer.dnsimple.com/v2/secondary-dns/#removePrimaryServer * * @param account The account id * @param primaryserver The primary server id * @param params Query parameters */ this.removePrimaryServer = (() => { const method = (account, primaryserver, params = {}) => this._client.request("DELETE", `/${account}/secondary_dns/primaries/${primaryserver}`, null, params); return method; })(); /** * Link the primary server to a secondary zone. * * PUT /{account}/secondary_dns/primaries/{primaryserver}/link * * @see https://developer.dnsimple.com/v2/secondary-dns/#linkPrimaryServer * * @param account The account id * @param primaryserver The primary server id * @param params Query parameters */ this.linkPrimaryServer = (() => { const method = (account, primaryserver, params = {}) => this._client.request("PUT", `/${account}/secondary_dns/primaries/${primaryserver}/link`, null, params); return method; })(); /** * Unlink the primary server from a secondary zone. * * PUT /{account}/secondary_dns/primaries/{primaryserver}/unlink * * @see https://developer.dnsimple.com/v2/secondary-dns/#unlinkPrimaryServer * * @param account The account id * @param primaryserver The primary server id * @param params Query parameters */ this.unlinkPrimaryServer = (() => { const method = (account, primaryserver, params = {}) => this._client.request("PUT", `/${account}/secondary_dns/primaries/${primaryserver}/unlink`, null, params); return method; })(); /** * Creates a secondary zone into the account. * * POST /{account}/secondary_dns/zones * * @see https://developer.dnsimple.com/v2/secondary-dns/#createSecondaryZone * * @param account The account id * @param params Query parameters */ this.createSecondaryZone = (() => { const method = (account, data, params = {}) => this._client.request("POST", `/${account}/secondary_dns/zones`, data, params); return method; })(); } } exports.SecondaryDns = SecondaryDns;