@jesseditson/dnsimple
Version:
A Node.JS client for the DNSimple API.
158 lines (157 loc) • 7.88 kB
JavaScript
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.Services = void 0;
const paginate_1 = require("./paginate");
class Services {
constructor(_client) {
this._client = _client;
/**
* List all available one-click services.
*
* This API is paginated. Call `listServices.iterateAll(params)` to get an asynchronous iterator over individual items across all pages. You can also use `await listServices.collectAll(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 /services
*
* @see https://developer.dnsimple.com/v2/services/#listServices
*
* @param params Query parameters
* @param params.sort Sort results. Default sorting is by id ascending.
*/
this.listServices = (() => {
const method = (params = {}) => this._client.request("GET", `/services`, null, params);
method.iterateAll = (params = {}) => (0, paginate_1.paginate)((page) => method(Object.assign(Object.assign({}, params), { page })));
method.collectAll = (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(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 a one-click service.
*
* GET /services/{service}
*
* @see https://developer.dnsimple.com/v2/services/#getService
*
* @param service The service sid or id
* @param params Query parameters
*/
this.getService = (() => {
const method = (service, params = {}) => this._client.request("GET", `/services/${service}`, null, params);
return method;
})();
/**
* List services applied to a domain.
*
* This API is paginated. Call `applyService.iterateAll(account, domain, params)` to get an asynchronous iterator over individual items across all pages. You can also use `await applyService.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}/services
*
* @see https://developer.dnsimple.com/v2/services/#listDomainAppliedServices
*
* @param account The account id
* @param domain The domain name or id
* @param params Query parameters
*/
this.applyService = (() => {
const method = (account, domain, params = {}) => this._client.request("GET", `/${account}/domains/${domain}/services`, 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_2, _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_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
}
finally { if (e_2) throw e_2.error; }
}
return items;
});
return method;
})();
/**
* Applies a service to a domain.
*
* POST /{account}/domains/{domain}/services/{service}
*
* @see https://developer.dnsimple.com/v2/services/#applyServiceToDomain
*
* @param account The account id
* @param domain The domain name or id
* @param service The service sid or id
* @param params Query parameters
*/
this.appliedServices = (() => {
const method = (account, domain, service, data, params = {}) => this._client.request("POST", `/${account}/domains/${domain}/services/${service}`, data, params);
return method;
})();
/**
* Unapplies a service from a domain.
*
* DELETE /{account}/domains/{domain}/services/{service}
*
* @see https://developer.dnsimple.com/v2/services/#unapplyServiceFromDomain
*
* @param account The account id
* @param domain The domain name or id
* @param service The service sid or id
* @param params Query parameters
*/
this.unapplyService = (() => {
const method = (account, domain, service, params = {}) => this._client.request("DELETE", `/${account}/domains/${domain}/services/${service}`, null, params);
return method;
})();
}
}
exports.Services = Services;
;