UNPKG

@jesseditson/dnsimple

Version:

A Node.JS client for the DNSimple API.

129 lines (128 loc) 6.06 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.Contacts = void 0; const paginate_1 = require("./paginate"); class Contacts { constructor(_client) { this._client = _client; /** * List contacts in the account. * * This API is paginated. Call `listContacts.iterateAll(account, params)` to get an asynchronous iterator over individual items across all pages. You can also use `await listContacts.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}/contacts * * @see https://developer.dnsimple.com/v2/contacts/#listContacts * * @param account The account id * @param params Query parameters * @param params.sort Sort results. Default sorting is by id ascending. */ this.listContacts = (() => { const method = (account, params = {}) => this._client.request("GET", `/${account}/contacts`, 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 contact. * * POST /{account}/contacts * * @see https://developer.dnsimple.com/v2/contacts/#createContact * * @param account The account id * @param params Query parameters */ this.createContact = (() => { const method = (account, data, params = {}) => this._client.request("POST", `/${account}/contacts`, data, params); return method; })(); /** * Retrieves the details of an existing contact. * * GET /{account}/contacts/{contact} * * @see https://developer.dnsimple.com/v2/contacts/#getContact * * @param account The account id * @param contact The contact id * @param params Query parameters */ this.getContact = (() => { const method = (account, contact, params = {}) => this._client.request("GET", `/${account}/contacts/${contact}`, null, params); return method; })(); /** * Updates the contact details. * * PATCH /{account}/contacts/{contact} * * @see https://developer.dnsimple.com/v2/contacts/#updateContact * * @param account The account id * @param contact The contact id * @param params Query parameters */ this.updateContact = (() => { const method = (account, contact, data, params = {}) => this._client.request("PATCH", `/${account}/contacts/${contact}`, data, params); return method; })(); /** * Permanently deletes a contact from the account. * * DELETE /{account}/contacts/{contact} * * @see https://developer.dnsimple.com/v2/contacts/#deleteContact * * @param account The account id * @param contact The contact id * @param params Query parameters */ this.deleteContact = (() => { const method = (account, contact, params = {}) => this._client.request("DELETE", `/${account}/contacts/${contact}`, null, params); return method; })(); } } exports.Contacts = Contacts;