UNPKG

@mozaic-io/mozaic-sdk-node

Version:

The Mozaic Node SDK enables you to pay your creators easily via the Mozaic API.

83 lines (82 loc) 4.5 kB
"use strict"; /** * This is the main entry point for working with Payment Cycles. * @group ResourcesGroup * @category ResourcesCat * @document ../../../documents/resources/PaymentCycles.md */ 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.Contacts = void 0; const api_1 = require("../../api"); const BaseResource_1 = require("../BaseResource"); const Contact_1 = require("./Contact"); const ContactList_1 = require("./ContactList"); class Contacts extends BaseResource_1.BaseResource { /** * @internal * You should not call this constructor directly. Instead, use the Mozaic main * entry point to get access to the SDK classes. * @param configuration */ constructor(mozaic, configuration) { super(); this._mozaic = mozaic; this._contactsApi = new api_1.ContactsApi(configuration); } /** * Get the underlying API for direct calls to the Mozaic API. */ get ContactsApi() { return this._contactsApi; } /** * Get a contact by external ID. If you have more than one contact with the same external ID, * this will return the first contact that matches the external ID. Use getContacts to return all * contacts with the same external ID. * @param externalId The external ID of the contact to retrieve. This ID represents the user in an external system. * @returns A contact that matches the external ID. */ getContactByExternalId(externalId) { return __awaiter(this, void 0, void 0, function* () { const result = yield this.getContacts(1, 1, undefined, externalId); if (result.data.length == 0) { throw new Error(`No contact found with external ID ${externalId}`); } return result.data[0]; }); } /** * Searches for a contact using various search parameters. You must supply either a term or an external ID. * @param limit The number of items to return per page. Must be between 1 and 100 inclusive. * @param page The page number to return. Must be greater than 0. * @param term The search term to use. This will search the known name (the name you gave the contact), first name, last name, external ID, and email address of the contact. This parameter is limited to 50 chars max. * @param externalId The external ID of the contact to retrieve. This ID represents the user in an external system. * @param sinceUTC The date and time to use as a filter. This will return all contacts that were created or updated after this date and time. * @param contactStatus An array of contact statuses. Contacts with a status in this array will be returned. * @returns A list of contacts that match the search criteria. */ getContacts(limit, page, term, externalId, sinceUTC, contactStatus) { return __awaiter(this, void 0, void 0, function* () { var _a; if (term != null && term.length > 50) throw new Error("The search term is limited to 50 characters."); if (externalId == null && term == null) throw new Error("You must provide at least one search term or an external ID."); const result = yield this.execute(() => this._contactsApi.contactsSearch(term, externalId, sinceUTC, undefined, undefined, undefined, undefined, contactStatus, undefined, undefined, undefined, undefined, limit, page, undefined, undefined)); var contacts = (_a = result.data) === null || _a === void 0 ? void 0 : _a.map(p => new Contact_1.Contact(this._mozaic, this._contactsApi, p)); if (contacts == null) contacts = []; return new ContactList_1.ContactList(result, contacts); }); } } exports.Contacts = Contacts;