UNPKG

@elasticemail/elasticemail-client

Version:

Official ElasticEmail SDK. This API is based on the REST API architecture, allowing the user to easily manage their data with this resource-based approach.

290 lines (274 loc) 14.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; var _ApiClient = _interopRequireDefault(require("../ApiClient")); var _BodyPart = _interopRequireDefault(require("./BodyPart")); var _MessageAttachment = _interopRequireDefault(require("./MessageAttachment")); var _Utm = _interopRequireDefault(require("./Utm")); function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; } function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; } function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } } function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); } function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } } function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /** * Elastic Email REST API * This API is based on the REST API architecture, allowing the user to easily manage their data with this resource-based approach. Every API call is established on which specific request type (GET, POST, PUT, DELETE) will be used. The API has a limit of 20 concurrent connections and a hard timeout of 600 seconds per request. To start using this API, you will need your Access Token (available <a target=\"_blank\" href=\"https://app.elasticemail.com/marketing/settings/new/manage-api\">here</a>). Remember to keep it safe. Required access levels are listed in the given request’s description. Downloadable library clients can be found in our Github repository <a target=\"_blank\" href=\"https://github.com/ElasticEmail?tab=repositories&q=%22rest+api%22+in%3Areadme\">here</a> * * The version of the OpenAPI document: 4.0.0 * Contact: support@elasticemail.com * * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). * https://openapi-generator.tech * Do not edit the class manually. * */ /** * The EmailContent model module. * @module model/EmailContent * @version 4.0.26 */ var EmailContent = /*#__PURE__*/function () { /** * Constructs a new <code>EmailContent</code>. * Proper e-mail content * @alias module:model/EmailContent * @param from {String} Your e-mail with an optional name (e.g.: John Doe <email@domain.com>) */ function EmailContent(from) { _classCallCheck(this, EmailContent); EmailContent.initialize(this, from); } /** * Initializes the fields of this object. * This method is used by the constructors of any subclasses, in order to implement multiple inheritance (mix-ins). * Only for internal use. */ return _createClass(EmailContent, null, [{ key: "initialize", value: function initialize(obj, from) { obj['From'] = from; } /** * Constructs a <code>EmailContent</code> from a plain JavaScript object, optionally creating a new instance. * Copies all relevant properties from <code>data</code> to <code>obj</code> if supplied or a new instance if not. * @param {Object} data The plain JavaScript object bearing properties of interest. * @param {module:model/EmailContent} obj Optional instance to populate. * @return {module:model/EmailContent} The populated <code>EmailContent</code> instance. */ }, { key: "constructFromObject", value: function constructFromObject(data, obj) { if (data) { obj = obj || new EmailContent(); if (data.hasOwnProperty('Body')) { obj['Body'] = _ApiClient["default"].convertToType(data['Body'], [_BodyPart["default"]]); } if (data.hasOwnProperty('Merge')) { obj['Merge'] = _ApiClient["default"].convertToType(data['Merge'], { 'String': 'String' }); } if (data.hasOwnProperty('Attachments')) { obj['Attachments'] = _ApiClient["default"].convertToType(data['Attachments'], [_MessageAttachment["default"]]); } if (data.hasOwnProperty('Headers')) { obj['Headers'] = _ApiClient["default"].convertToType(data['Headers'], { 'String': 'String' }); } if (data.hasOwnProperty('Postback')) { obj['Postback'] = _ApiClient["default"].convertToType(data['Postback'], 'String'); } if (data.hasOwnProperty('EnvelopeFrom')) { obj['EnvelopeFrom'] = _ApiClient["default"].convertToType(data['EnvelopeFrom'], 'String'); } if (data.hasOwnProperty('From')) { obj['From'] = _ApiClient["default"].convertToType(data['From'], 'String'); } if (data.hasOwnProperty('ReplyTo')) { obj['ReplyTo'] = _ApiClient["default"].convertToType(data['ReplyTo'], 'String'); } if (data.hasOwnProperty('Subject')) { obj['Subject'] = _ApiClient["default"].convertToType(data['Subject'], 'String'); } if (data.hasOwnProperty('TemplateName')) { obj['TemplateName'] = _ApiClient["default"].convertToType(data['TemplateName'], 'String'); } if (data.hasOwnProperty('AttachFiles')) { obj['AttachFiles'] = _ApiClient["default"].convertToType(data['AttachFiles'], ['String']); } if (data.hasOwnProperty('Utm')) { obj['Utm'] = _Utm["default"].constructFromObject(data['Utm']); } } return obj; } /** * Validates the JSON data with respect to <code>EmailContent</code>. * @param {Object} data The plain JavaScript object bearing properties of interest. * @return {boolean} to indicate whether the JSON data is valid with respect to <code>EmailContent</code>. */ }, { key: "validateJSON", value: function validateJSON(data) { // check to make sure all required properties are present in the JSON string var _iterator = _createForOfIteratorHelper(EmailContent.RequiredProperties), _step; try { for (_iterator.s(); !(_step = _iterator.n()).done;) { var property = _step.value; if (!data.hasOwnProperty(property)) { throw new Error("The required field `" + property + "` is not found in the JSON data: " + JSON.stringify(data)); } } } catch (err) { _iterator.e(err); } finally { _iterator.f(); } if (data['Body']) { // data not null // ensure the json data is an array if (!Array.isArray(data['Body'])) { throw new Error("Expected the field `Body` to be an array in the JSON data but got " + data['Body']); } // validate the optional field `Body` (array) var _iterator2 = _createForOfIteratorHelper(data['Body']), _step2; try { for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { var item = _step2.value; _BodyPart["default"].validateJSON(item); } } catch (err) { _iterator2.e(err); } finally { _iterator2.f(); } ; } if (data['Attachments']) { // data not null // ensure the json data is an array if (!Array.isArray(data['Attachments'])) { throw new Error("Expected the field `Attachments` to be an array in the JSON data but got " + data['Attachments']); } // validate the optional field `Attachments` (array) var _iterator3 = _createForOfIteratorHelper(data['Attachments']), _step3; try { for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) { var _item = _step3.value; _MessageAttachment["default"].validateJSON(_item); } } catch (err) { _iterator3.e(err); } finally { _iterator3.f(); } ; } // ensure the json data is a string if (data['Postback'] && !(typeof data['Postback'] === 'string' || data['Postback'] instanceof String)) { throw new Error("Expected the field `Postback` to be a primitive type in the JSON string but got " + data['Postback']); } // ensure the json data is a string if (data['EnvelopeFrom'] && !(typeof data['EnvelopeFrom'] === 'string' || data['EnvelopeFrom'] instanceof String)) { throw new Error("Expected the field `EnvelopeFrom` to be a primitive type in the JSON string but got " + data['EnvelopeFrom']); } // ensure the json data is a string if (data['From'] && !(typeof data['From'] === 'string' || data['From'] instanceof String)) { throw new Error("Expected the field `From` to be a primitive type in the JSON string but got " + data['From']); } // ensure the json data is a string if (data['ReplyTo'] && !(typeof data['ReplyTo'] === 'string' || data['ReplyTo'] instanceof String)) { throw new Error("Expected the field `ReplyTo` to be a primitive type in the JSON string but got " + data['ReplyTo']); } // ensure the json data is a string if (data['Subject'] && !(typeof data['Subject'] === 'string' || data['Subject'] instanceof String)) { throw new Error("Expected the field `Subject` to be a primitive type in the JSON string but got " + data['Subject']); } // ensure the json data is a string if (data['TemplateName'] && !(typeof data['TemplateName'] === 'string' || data['TemplateName'] instanceof String)) { throw new Error("Expected the field `TemplateName` to be a primitive type in the JSON string but got " + data['TemplateName']); } // ensure the json data is an array if (!Array.isArray(data['AttachFiles'])) { throw new Error("Expected the field `AttachFiles` to be an array in the JSON data but got " + data['AttachFiles']); } // validate the optional field `Utm` if (data['Utm']) { // data not null _Utm["default"].validateJSON(data['Utm']); } return true; } }]); }(); EmailContent.RequiredProperties = ["From"]; /** * List of e-mail body parts, with user-provided MIME types (text/html, text/plain etc) * @member {Array.<module:model/BodyPart>} Body */ EmailContent.prototype['Body'] = undefined; /** * A key-value collection of custom merge fields, shared between recipients. Should be used in e-mail body like so: {firstname}, {lastname} etc. * @member {Object.<String, String>} Merge */ EmailContent.prototype['Merge'] = undefined; /** * Attachments provided by sending binary data * @member {Array.<module:model/MessageAttachment>} Attachments */ EmailContent.prototype['Attachments'] = undefined; /** * A key-value collection of custom e-mail headers. * @member {Object.<String, String>} Headers */ EmailContent.prototype['Headers'] = undefined; /** * Postback header. * @member {String} Postback */ EmailContent.prototype['Postback'] = undefined; /** * E-mail with an optional name to be used as the envelope from address (e.g.: John Doe <email@domain.com>) * @member {String} EnvelopeFrom */ EmailContent.prototype['EnvelopeFrom'] = undefined; /** * Your e-mail with an optional name (e.g.: John Doe <email@domain.com>) * @member {String} From */ EmailContent.prototype['From'] = undefined; /** * To what address should the recipients reply to (e.g. John Doe <email@domain.com>) * @member {String} ReplyTo */ EmailContent.prototype['ReplyTo'] = undefined; /** * Default subject of email. * @member {String} Subject */ EmailContent.prototype['Subject'] = undefined; /** * Name of template. * @member {String} TemplateName */ EmailContent.prototype['TemplateName'] = undefined; /** * Names of previously uploaded files that should be sent as downloadable attachments * @member {Array.<String>} AttachFiles */ EmailContent.prototype['AttachFiles'] = undefined; /** * @member {module:model/Utm} Utm */ EmailContent.prototype['Utm'] = undefined; var _default = exports["default"] = EmailContent;