@jesseditson/dnsimple
Version:
A Node.JS client for the DNSimple API.
236 lines (235 loc) • 11.3 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.Templates = void 0;
const paginate_1 = require("./paginate");
class Templates {
constructor(_client) {
this._client = _client;
/**
* Lists the templates in the account.
*
* This API is paginated. Call `listTemplates.iterateAll(account, params)` to get an asynchronous iterator over individual items across all pages. You can also use `await listTemplates.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}/templates
*
* @see https://developer.dnsimple.com/v2/templates/#listTemplates
*
* @param account The account id
* @param params Query parameters
* @param params.sort Sort results. Default sorting is by id ascending.
*/
this.listTemplates = (() => {
const method = (account, params = {}) => this._client.request("GET", `/${account}/templates`, 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 template.
*
* POST /{account}/templates
*
* @see https://developer.dnsimple.com/v2/templates/#createTemplate
*
* @param account The account id
* @param params Query parameters
*/
this.createTemplate = (() => {
const method = (account, data, params = {}) => this._client.request("POST", `/${account}/templates`, data, params);
return method;
})();
/**
* Retrieves the details of an existing template.
*
* GET /{account}/templates/{template}
*
* @see https://developer.dnsimple.com/v2/templates/#getTemplate
*
* @param account The account id
* @param template The template id or short name
* @param params Query parameters
*/
this.getTemplate = (() => {
const method = (account, template, params = {}) => this._client.request("GET", `/${account}/templates/${template}`, null, params);
return method;
})();
/**
* Updates the template details.
*
* PATCH /{account}/templates/{template}
*
* @see https://developer.dnsimple.com/v2/templates/#updateTemplate
*
* @param account The account id
* @param template The template id or short name
* @param params Query parameters
*/
this.updateTemplate = (() => {
const method = (account, template, data, params = {}) => this._client.request("PATCH", `/${account}/templates/${template}`, data, params);
return method;
})();
/**
* Permanently deletes a template.
*
* DELETE /{account}/templates/{template}
*
* @see https://developer.dnsimple.com/v2/templates/#deleteTemplate
*
* @param account The account id
* @param template The template id or short name
* @param params Query parameters
*/
this.deleteTemplate = (() => {
const method = (account, template, params = {}) => this._client.request("DELETE", `/${account}/templates/${template}`, null, params);
return method;
})();
/**
* Lists the records for a template.
*
* This API is paginated. Call `listTemplateRecords.iterateAll(account, template, params)` to get an asynchronous iterator over individual items across all pages. You can also use `await listTemplateRecords.collectAll(account, template, 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}/templates/{template}/records
*
* @see https://developer.dnsimple.com/v2/templates/#listTemplateRecords
*
* @param account The account id
* @param template The template id or short name
* @param params Query parameters
* @param params.sort Sort results. Default sorting is by id ascending.
*/
this.listTemplateRecords = (() => {
const method = (account, template, params = {}) => this._client.request("GET", `/${account}/templates/${template}/records`, null, params);
method.iterateAll = (account, template, params = {}) => (0, paginate_1.paginate)((page) => method(account, template, Object.assign(Object.assign({}, params), { page })));
method.collectAll = (account, template, 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, template, 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;
})();
/**
* Creates a new template record.
*
* POST /{account}/templates/{template}/records
*
* @see https://developer.dnsimple.com/v2/templates/#createTemplateRecord
*
* @param account The account id
* @param template The template id or short name
* @param params Query parameters
*/
this.createTemplateRecord = (() => {
const method = (account, template, data, params = {}) => this._client.request("POST", `/${account}/templates/${template}/records`, data, params);
return method;
})();
/**
* Retrieves the details of an existing template record.
*
* GET /{account}/templates/{template}/records/{templaterecord}
*
* @see https://developer.dnsimple.com/v2/templates/#getTemplateRecord
*
* @param account The account id
* @param template The template id or short name
* @param templaterecord The template record id
* @param params Query parameters
*/
this.getTemplateRecord = (() => {
const method = (account, template, templaterecord, params = {}) => this._client.request("GET", `/${account}/templates/${template}/records/${templaterecord}`, null, params);
return method;
})();
/**
* Permanently deletes a template record.
*
* DELETE /{account}/templates/{template}/records/{templaterecord}
*
* @see https://developer.dnsimple.com/v2/templates/#deleteTemplateRecord
*
* @param account The account id
* @param template The template id or short name
* @param templaterecord The template record id
* @param params Query parameters
*/
this.deleteTemplateRecord = (() => {
const method = (account, template, templaterecord, params = {}) => this._client.request("DELETE", `/${account}/templates/${template}/records/${templaterecord}`, null, params);
return method;
})();
/**
* Applies a template to a domain.
*
* POST /{account}/domains/{domain}/templates/{template}
*
* @see https://developer.dnsimple.com/v2/templates/#applyTemplateToDomain
*
* @param account The account id
* @param domain The domain name or id
* @param template The template id or short name
* @param params Query parameters
*/
this.applyTemplate = (() => {
const method = (account, domain, template, params = {}) => this._client.request("POST", `/${account}/domains/${domain}/templates/${template}`, null, params);
return method;
})();
}
}
exports.Templates = Templates;
;