@mozaic-io/mozaic-sdk-node
Version:
The Mozaic Node SDK enables you to pay your creators easily via the Mozaic API.
56 lines (55 loc) • 3.39 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());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Contact = void 0;
const BaseResource_1 = require("../BaseResource");
const Payment_1 = require("../Payments/Payment");
const PaymentList_1 = require("../Payments/PaymentList");
class Contact extends BaseResource_1.BaseResource {
/**
* @internal
* Internal use only. Please use the Mozaic object to utilize this object.
* @param contactInfo
*/
constructor(mozaic, contactsApi, contactInfo) {
var _a;
super();
this._mozaic = mozaic;
this._contactsApi = contactsApi;
this.rawObject = contactInfo;
this.id = this.throwIfNullOrUndefined("contactInfo.id", contactInfo.id);
this.name = this.throwIfNullOrUndefined("contactInfo.known_name", contactInfo.known_name);
this.status = this.throwIfNullOrUndefined("contactInfo.status", contactInfo.contact_status);
// Find the contact's primary email address.
let emails = this.throwIfNullOrUndefined("contactInfo.email", contactInfo.email_addresses);
let primaryEmail = (_a = emails.find((email) => email.is_primary === true)) === null || _a === void 0 ? void 0 : _a.address;
this.email = this.throwIfNullOrUndefined("contactInfo.email (no primary email)", primaryEmail);
this.externalId = contactInfo.external_id;
}
/**
* Returns a list of payments that have been sent to this contact. From these payments, you can see the payment cycle that the payment was sent from.
* Note that only payments that have been sent to this contact will be returned. Payments that have been sent from a payment cycle that is
* still in Draft status will not be returned because they have not been created yet.
* @param limit An integer number between 1 and 100.
* @param page An integer number of the page starting at 1.
*/
getPayments(limit, page) {
return __awaiter(this, void 0, void 0, function* () {
var _a;
const result = yield this.execute(() => this._contactsApi.getPayments(this.id, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, limit, page, undefined, undefined));
let data = (_a = result.data) === null || _a === void 0 ? void 0 : _a.map((value) => new Payment_1.Payment(this._mozaic, value));
if (data === undefined)
data = [];
return new PaymentList_1.PaymentList(result, data);
});
}
}
exports.Contact = Contact;