files.com
Version:
Files.com SDK for JavaScript
228 lines (227 loc) • 12.4 kB
JavaScript
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
exports.__esModule = true;
exports.default = void 0;
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _Api = _interopRequireDefault(require("../Api"));
var errors = _interopRequireWildcard(require("../Errors"));
var _utils = require("../utils");
var _As2OutgoingMessage;
/* eslint-disable no-unused-vars */
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
/* eslint-enable no-unused-vars */
/**
* Class As2OutgoingMessage
*/
var As2OutgoingMessage = /*#__PURE__*/(0, _createClass2.default)(function As2OutgoingMessage() {
var _this = this;
var attributes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
(0, _classCallCheck2.default)(this, As2OutgoingMessage);
(0, _defineProperty2.default)(this, "attributes", {});
(0, _defineProperty2.default)(this, "options", {});
(0, _defineProperty2.default)(this, "isLoaded", function () {
return !!_this.attributes.id;
});
// int64 # Id of the AS2 Partner.
(0, _defineProperty2.default)(this, "getId", function () {
return _this.attributes.id;
});
// int64 # Id of the AS2 Partner associated with this message.
(0, _defineProperty2.default)(this, "getAs2PartnerId", function () {
return _this.attributes.as2_partner_id;
});
// int64 # Id of the AS2 Station associated with this message.
(0, _defineProperty2.default)(this, "getAs2StationId", function () {
return _this.attributes.as2_station_id;
});
// string # UUID assigned to this message.
(0, _defineProperty2.default)(this, "getUuid", function () {
return _this.attributes.uuid;
});
// object # HTTP Headers sent with this message.
(0, _defineProperty2.default)(this, "getHttpHeaders", function () {
return _this.attributes.http_headers;
});
// string # Result of processing.
(0, _defineProperty2.default)(this, "getProcessingResult", function () {
return _this.attributes.processing_result;
});
// string # Result of processing description.
(0, _defineProperty2.default)(this, "getProcessingResultDescription", function () {
return _this.attributes.processing_result_description;
});
// string # AS2 Message Integrity Check SHA1
(0, _defineProperty2.default)(this, "getMic", function () {
return _this.attributes.mic;
});
// string # AS2 Message Integrity Check SHA256
(0, _defineProperty2.default)(this, "getMicSha256", function () {
return _this.attributes.mic_sha_256;
});
// string # AS2 TO
(0, _defineProperty2.default)(this, "getAs2To", function () {
return _this.attributes.as2_to;
});
// string # AS2 FROM
(0, _defineProperty2.default)(this, "getAs2From", function () {
return _this.attributes.as2_from;
});
// string # Date Header
(0, _defineProperty2.default)(this, "getDate", function () {
return _this.attributes.date;
});
// string # AS2 Message Id
(0, _defineProperty2.default)(this, "getMessageId", function () {
return _this.attributes.message_id;
});
// string # Encrypted Payload Body Size
(0, _defineProperty2.default)(this, "getBodySize", function () {
return _this.attributes.body_size;
});
// string # Filename of the file being sent.
(0, _defineProperty2.default)(this, "getAttachmentFilename", function () {
return _this.attributes.attachment_filename;
});
// date-time # Message creation date/time
(0, _defineProperty2.default)(this, "getCreatedAt", function () {
return _this.attributes.created_at;
});
// string # HTTP Response Code received for this message
(0, _defineProperty2.default)(this, "getHttpResponseCode", function () {
return _this.attributes.http_response_code;
});
// object # HTTP Headers received for this message.
(0, _defineProperty2.default)(this, "getHttpResponseHeaders", function () {
return _this.attributes.http_response_headers;
});
// double # HTTP transmission duration in seceonds
(0, _defineProperty2.default)(this, "getHttpTransmissionDuration", function () {
return _this.attributes.http_transmission_duration;
});
// boolean # Did the partner give a response body?
(0, _defineProperty2.default)(this, "getMdnReceived", function () {
return _this.attributes.mdn_received;
});
// boolean # Is the response in MDN format?
(0, _defineProperty2.default)(this, "getMdnValid", function () {
return _this.attributes.mdn_valid;
});
// boolean # MDN signature verified?
(0, _defineProperty2.default)(this, "getMdnSignatureVerified", function () {
return _this.attributes.mdn_signature_verified;
});
// boolean # MDN message id matched?
(0, _defineProperty2.default)(this, "getMdnMessageIdMatched", function () {
return _this.attributes.mdn_message_id_matched;
});
// boolean # MDN MIC matched?
(0, _defineProperty2.default)(this, "getMdnMicMatched", function () {
return _this.attributes.mdn_mic_matched;
});
// boolean # MDN disposition indicate a successful processing?
(0, _defineProperty2.default)(this, "getMdnProcessingSuccess", function () {
return _this.attributes.mdn_processing_success;
});
// string # URL to download the original file contents
(0, _defineProperty2.default)(this, "getRawUri", function () {
return _this.attributes.raw_uri;
});
// string # URL to download the file contents encoded as smime
(0, _defineProperty2.default)(this, "getSmimeUri", function () {
return _this.attributes.smime_uri;
});
// string # URL to download the file contents as smime with signature
(0, _defineProperty2.default)(this, "getSmimeSignedUri", function () {
return _this.attributes.smime_signed_uri;
});
// string # URL to download the encrypted signed smime that is to sent as AS2 body
(0, _defineProperty2.default)(this, "getEncryptedUri", function () {
return _this.attributes.encrypted_uri;
});
// string # URL to download the http response body
(0, _defineProperty2.default)(this, "getMdnResponseUri", function () {
return _this.attributes.mdn_response_uri;
});
Object.entries(attributes).forEach(function (_ref) {
var _ref2 = (0, _slicedToArray2.default)(_ref, 2),
key = _ref2[0],
value = _ref2[1];
var normalizedKey = key.replace('?', '');
_this.attributes[normalizedKey] = value;
Object.defineProperty(_this, normalizedKey, {
value: value,
writable: false
});
});
this.options = _objectSpread({}, options);
});
_As2OutgoingMessage = As2OutgoingMessage;
// Parameters:
// cursor - string - Used for pagination. When a list request has more records available, cursors are provided in the response headers `X-Files-Cursor-Next` and `X-Files-Cursor-Prev`. Send one of those cursor value here to resume an existing list from the next available record. Note: many of our SDKs have iterator methods that will automatically handle cursor-based pagination.
// per_page - int64 - Number of records to show per page. (Max: 10,000, 1,000 or less is recommended).
// sort_by - object - If set, sort records by the specified field in either `asc` or `desc` direction. Valid fields are `created_at` and `as2_partner_id`.
// filter - object - If set, return records where the specified field is equal to the supplied value. Valid fields are `created_at`.
// filter_gt - object - If set, return records where the specified field is greater than the supplied value. Valid fields are `created_at`.
// filter_gteq - object - If set, return records where the specified field is greater than or equal the supplied value. Valid fields are `created_at`.
// filter_lt - object - If set, return records where the specified field is less than the supplied value. Valid fields are `created_at`.
// filter_lteq - object - If set, return records where the specified field is less than or equal the supplied value. Valid fields are `created_at`.
// as2_partner_id - int64 - As2 Partner ID. If provided, will return message specific to that partner.
(0, _defineProperty2.default)(As2OutgoingMessage, "list", /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee() {
var _response$data;
var params,
options,
response,
_args = arguments;
return _regenerator.default.wrap(function (_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
params = _args.length > 0 && _args[0] !== undefined ? _args[0] : {};
options = _args.length > 1 && _args[1] !== undefined ? _args[1] : {};
if (!(params.cursor && !(0, _utils.isString)(params.cursor))) {
_context.next = 1;
break;
}
throw new errors.InvalidParameterError("Bad parameter: cursor must be of type String, received ".concat((0, _utils.getType)(params.cursor)));
case 1:
if (!(params.per_page && !(0, _utils.isInt)(params.per_page))) {
_context.next = 2;
break;
}
throw new errors.InvalidParameterError("Bad parameter: per_page must be of type Int, received ".concat((0, _utils.getType)(params.per_page)));
case 2:
if (!(params.as2_partner_id && !(0, _utils.isInt)(params.as2_partner_id))) {
_context.next = 3;
break;
}
throw new errors.InvalidParameterError("Bad parameter: as2_partner_id must be of type Int, received ".concat((0, _utils.getType)(params.as2_partner_id)));
case 3:
_context.next = 4;
return _Api.default.sendRequest('/as2_outgoing_messages', 'GET', params, options);
case 4:
response = _context.sent;
return _context.abrupt("return", (response === null || response === void 0 || (_response$data = response.data) === null || _response$data === void 0 ? void 0 : _response$data.map(function (obj) {
return new _As2OutgoingMessage(obj, options);
})) || []);
case 5:
case "end":
return _context.stop();
}
}, _callee);
})));
(0, _defineProperty2.default)(As2OutgoingMessage, "all", function () {
var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
return _As2OutgoingMessage.list(params, options);
});
var _default = exports.default = As2OutgoingMessage;
module.exports = As2OutgoingMessage;
module.exports.default = As2OutgoingMessage;