UNPKG

alfresco-js-api

Version:

JavaScript client library for the Alfresco REST API

1,273 lines (1,126 loc) 2.93 MB
(function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(); else if(typeof define === 'function' && define.amd) define([], factory); else if(typeof exports === 'object') exports["AlfrescoApi"] = factory(); else root["AlfrescoApi"] = factory(); })(window, function() { return /******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; /******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ /******/ // Check if module is in cache /******/ if(installedModules[moduleId]) { /******/ return installedModules[moduleId].exports; /******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { /******/ i: moduleId, /******/ l: false, /******/ exports: {} /******/ }; /******/ /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ /******/ // Flag the module as loaded /******/ module.l = true; /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /******/ /******/ // expose the modules object (__webpack_modules__) /******/ __webpack_require__.m = modules; /******/ /******/ // expose the module cache /******/ __webpack_require__.c = installedModules; /******/ /******/ // define getter function for harmony exports /******/ __webpack_require__.d = function(exports, name, getter) { /******/ if(!__webpack_require__.o(exports, name)) { /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); /******/ } /******/ }; /******/ /******/ // define __esModule on exports /******/ __webpack_require__.r = function(exports) { /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); /******/ } /******/ Object.defineProperty(exports, '__esModule', { value: true }); /******/ }; /******/ /******/ // create a fake namespace object /******/ // mode & 1: value is a module id, require it /******/ // mode & 2: merge all properties of value into the ns /******/ // mode & 4: return value when already ns object /******/ // mode & 8|1: behave like require /******/ __webpack_require__.t = function(value, mode) { /******/ if(mode & 1) value = __webpack_require__(value); /******/ if(mode & 8) return value; /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; /******/ var ns = Object.create(null); /******/ __webpack_require__.r(ns); /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); /******/ return ns; /******/ }; /******/ /******/ // getDefaultExport function for compatibility with non-harmony modules /******/ __webpack_require__.n = function(module) { /******/ var getter = module && module.__esModule ? /******/ function getDefault() { return module['default']; } : /******/ function getModuleExports() { return module; }; /******/ __webpack_require__.d(getter, 'a', getter); /******/ return getter; /******/ }; /******/ /******/ // Object.prototype.hasOwnProperty.call /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; /******/ /******/ // __webpack_public_path__ /******/ __webpack_require__.p = ""; /******/ /******/ /******/ // Load entry module and return exports /******/ return __webpack_require__(__webpack_require__.s = 548); /******/ }) /************************************************************************/ /******/ ([ /* 0 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; /* WEBPACK VAR INJECTION */(function(process) { function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : _defaults(subClass, superClass); } var Emitter = __webpack_require__(15); var ApiClient = __webpack_require__(1); var superagent = __webpack_require__(392); var Storage = __webpack_require__(308); var AlfrescoApiClient = function (_ApiClient) { _inherits(AlfrescoApiClient, _ApiClient); /** * @param {String} host * */ function AlfrescoApiClient(host) { _classCallCheck(this, AlfrescoApiClient); var _this2 = _possibleConstructorReturn(this, _ApiClient.call(this)); _this2.storage = new Storage(); _this2.host = host; Emitter.call(_this2); return _this2; } /** * Invokes the REST service using the supplied settings and parameters. * * @param {String} path The base URL to invoke. * @param {String} httpMethod The HTTP method to use. * @param {Object.<String, String>} pathParams A map of path parameters and their values. * @param {Object.<String, Object>} queryParams A map of query parameters and their values. * @param {Object.<String, Object>} headerParams A map of header parameters and their values. * @param {Object.<String, Object>} formParams A map of form parameters and their values. * @param {Object} bodyParam The value to pass as the request body. * @param {String[]} authNames An array of authentication type names. * @param {String[]} contentTypes An array of request MIME types. * @param {String[]} accepts An array of acceptable response MIME types. * @param {(String|Array|ObjectFunction)} returnType The required type to return; can be a string for simple types or the * @param {(String)} contextRoot alternative contextRoot * @param {(String)} responseType is an enumerated value that returns the type of the response. * It also lets the author change the response type to one "arraybuffer", "blob", "document", * "json", or "text". * If an empty string is set as the value of responseType, it is assumed as type "text". * constructor for a complex type. * @returns {Promise} A Promise object. */ AlfrescoApiClient.prototype.callApi = function callApi(path, httpMethod, pathParams, queryParams, headerParams, formParams, bodyParam, authNames, contentTypes, accepts, returnType, contextRoot, responseType) { var url; if (contextRoot) { var basePath = this.host + '/' + contextRoot; url = this.buildUrlCustomBasePath(basePath, path, pathParams); } else { url = this.buildUrl(path, pathParams); } return this.callHostApi(path, httpMethod, pathParams, queryParams, headerParams, formParams, bodyParam, authNames, contentTypes, accepts, returnType, contextRoot, responseType, url); }; /** * Invokes the REST service using the supplied settings and parameters but not the basepath. * * @param {String} path The base URL to invoke. * @param {String} httpMethod The HTTP method to use. * @param {Object.<String, String>} pathParams A map of path parameters and their values. * @param {Object.<String, Object>} queryParams A map of query parameters and their values. * @param {Object.<String, Object>} headerParams A map of header parameters and their values. * @param {Object.<String, Object>} formParams A map of form parameters and their values. * @param {Object} bodyParam The value to pass as the request body. * @param {String[]} authNames An array of authentication type names. * @param {String[]} contentTypes An array of request MIME types. * @param {String[]} accepts An array of acceptable response MIME types. * @param {(String|Array|ObjectFunction)} returnType The required type to return; can be a string for simple types or the * @param {(String)} contextRoot alternative contextRoot * @param {(String)} responseType is an enumerated value that returns the type of the response. * It also lets the author change the response type to one "arraybuffer", "blob", "document", * "json", or "text". * If an empty string is set as the value of responseType, it is assumed as type "text". * constructor for a complex type. * @returns {Promise} A Promise object. */ AlfrescoApiClient.prototype.callCustomApi = function callCustomApi(path, httpMethod, pathParams, queryParams, headerParams, formParams, bodyParam, authNames, contentTypes, accepts, returnType, contextRoot, responseType) { var url = this.buildUrlCustomBasePath(path, '', pathParams); return this.callHostApi(path, httpMethod, pathParams, queryParams, headerParams, formParams, bodyParam, authNames, contentTypes, accepts, returnType, contextRoot, responseType, url); }; /** * Invokes the REST service using the supplied settings and parameters. * * @param {String} path The base URL to invoke. * @param {String} httpMethod The HTTP method to use. * @param {Object.<String, String>} pathParams A map of path parameters and their values. * @param {Object.<String, Object>} queryParams A map of query parameters and their values. * @param {Object.<String, Object>} headerParams A map of header parameters and their values. * @param {Object.<String, Object>} formParams A map of form parameters and their values. * @param {Object} bodyParam The value to pass as the request body. * @param {String[]} authNames An array of authentication type names. * @param {String[]} contentTypes An array of request MIME types. * @param {String[]} accepts An array of acceptable response MIME types. * @param {(String|Array|ObjectFunction)} returnType The required type to return; can be a string for simple types or the * @param {(String)} contextRoot alternative contextRoot * @param {(String)} responseType is an enumerated value that returns the type of the response. * It also lets the author change the response type to one "arraybuffer", "blob", "document", * "json", or "text". * If an empty string is set as the value of responseType, it is assumed as type "text". * constructor for a complex type. * @returns {Promise} A Promise object. */ AlfrescoApiClient.prototype.callHostApi = function callHostApi(path, httpMethod, pathParams, queryParams, headerParams, formParams, bodyParam, authNames, contentTypes, accepts, returnType, contextRoot, responseType, url) { var _this3 = this; var eventEmitter = {}; Emitter(eventEmitter); // jshint ignore:line var request = this.buildRequest(httpMethod, url, queryParams, headerParams, formParams, bodyParam, contentTypes, accepts, responseType, eventEmitter, returnType); if (returnType === 'Binary') { request = request.buffer(true).parse(superagent.parse['application/octet-stream']); } this.promise = new Promise(function (resolve, reject) { request.end(function (error, response) { if (error) { _this3.emit('error', error); eventEmitter.emit('error', error); if (error.status === 401) { _this3.emit('unauthorized'); eventEmitter.emit('unauthorized'); } if (response && response.text) { error = error || {}; reject(Object.assign(error, { message: response.text })); } else { reject({ error: error }); } } else { if (_this3.isBpmRequest()) { if (response.header && response.header.hasOwnProperty('set-cookie')) { _this3.authentications.cookie = response.header['set-cookie']; } } var data = {}; if (response.type === 'text/html') { data = _this3.deserialize(response, 'String'); } else { data = _this3.deserialize(response, returnType); } eventEmitter.emit('success', data); resolve(data); } }).on('abort', function () { eventEmitter.emit('abort'); }); }); this.promise.on = function () { eventEmitter.on.apply(eventEmitter, arguments); return this; }; this.promise.once = function () { eventEmitter.once.apply(eventEmitter, arguments); return this; }; this.promise.emit = function () { eventEmitter.emit.apply(eventEmitter, arguments); return this; }; this.promise.off = function () { eventEmitter.off.apply(eventEmitter, arguments); return this; }; this.promise.abort = function () { request.abort(); return this; }; return this.promise; }; AlfrescoApiClient.prototype.isBpmRequest = function isBpmRequest() { return this.className === 'BpmAuth' || this.className === 'BpmClient'; }; AlfrescoApiClient.prototype.isCsrfEnabled = function isCsrfEnabled() { if (this.config) { return !this.config.disableCsrf; } else { return true; } }; AlfrescoApiClient.prototype.setCsrfToken = function setCsrfToken(request) { var token = this.token(); request.set('X-CSRF-TOKEN', token); if (this.isNodeEnv()) { request.set('Cookie', 'CSRF-TOKEN=' + token + ';path=/'); } try { document.cookie = 'CSRF-TOKEN=' + token + ';path=/'; } catch (err) {} }; AlfrescoApiClient.prototype.isNodeEnv = function isNodeEnv() { return typeof process !== 'undefined' && process.release && process.release.name === 'node'; }; AlfrescoApiClient.prototype.token = function token(a) { return a ? (a ^ Math.random() * 16 >> a / 4).toString(16) : ([1e16] + 1e16).replace(/[01]/g, this.token); }; AlfrescoApiClient.prototype.progress = function progress(event, eventEmitter) { if (event.lengthComputable && this.promise) { var percent = Math.round(event.loaded / event.total * 100); eventEmitter.emit('progress', { total: event.total, loaded: event.loaded, percent: percent }); } }; /** * Builds full URL by appending the given path to the base URL and replacing path parameter place-holders * with parameter values. * * @param {String} basePath the base path * @param {String} path The path to append to the base URL. * @param {Object} pathParams The parameter values to append. * @returns {String} The encoded path with parameter values substituted. */ AlfrescoApiClient.prototype.buildUrlCustomBasePath = function buildUrlCustomBasePath(basePath, path, pathParams) { if (!path.match(/^\//)) { path = '/' + path; } var url = basePath + path; var _this = this; url = url.replace(/\{([\w-]+)\}/g, function (fullMatch, key) { var value; if (pathParams.hasOwnProperty(key)) { value = _this.paramToString(pathParams[key]); } else { value = fullMatch; } return encodeURIComponent(value); }); return url; }; AlfrescoApiClient.prototype.buildRequest = function buildRequest(httpMethod, url, queryParams, headerParams, formParams, bodyParam, contentTypes, accepts, responseType, eventEmitter, returnType) { var _this4 = this; var request = superagent(httpMethod, url); // apply authentications this.applyAuthToRequest(request, ['basicAuth']); // set query parameters request.query(this.normalizeParams(queryParams)); // set header parameters request.set(this.defaultHeaders).set(this.normalizeParams(headerParams)); if (this.isBpmRequest() && this.isCsrfEnabled()) { this.setCsrfToken(request); } // add cookie for activiti if (this.isBpmRequest()) { request._withCredentials = true; if (this.authentications.cookie) { if (this.isNodeEnv()) { request.set('Cookie', this.authentications.cookie); } } } // set request timeout request.timeout(this.timeout); var contentType = this.jsonPreferredMime(contentTypes); if (contentType && contentType !== 'multipart/form-data') { request.type(contentType); } else if (!request.header['Content-Type'] && contentType !== 'multipart/form-data') { request.type('application/json'); } if (contentType === 'application/x-www-form-urlencoded') { request.send(this.normalizeParams(formParams)).on('progress', function (event) { _this4.progress(event, eventEmitter); }); } else if (contentType === 'multipart/form-data') { var _formParams = this.normalizeParams(formParams); for (var key in _formParams) { if (_formParams.hasOwnProperty(key)) { if (this.isFileParam(_formParams[key])) { // file field request.attach(key, _formParams[key]).on('progress', function (event) { // jshint ignore:line _this4.progress(event, eventEmitter); }); } else { request.field(key, _formParams[key]).on('progress', function (event) { // jshint ignore:line _this4.progress(event, eventEmitter); }); } } } } else if (bodyParam) { request.send(bodyParam).on('progress', function (event) { _this4.progress(event, eventEmitter); }); } var accept = this.jsonPreferredMime(accepts); if (accept) { request.accept(accept); } if (returnType === 'Blob' || responseType === 'blob' || responseType === 'Blob') { request.responseType('blob'); } else if (returnType === 'String') { request.responseType('string'); } return request; }; return AlfrescoApiClient; }(ApiClient); Emitter(AlfrescoApiClient.prototype); // jshint ignore:line module.exports = AlfrescoApiClient; /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(503))) /***/ }), /* 1 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; /* WEBPACK VAR INJECTION */(function(Buffer) {var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__; var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; (function (root, factory) { if (true) { // AMD. Register as an anonymous module. !(__WEBPACK_AMD_DEFINE_ARRAY__ = [__webpack_require__(392)], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory), __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); } else {} })(undefined, function (superagent) { 'use strict'; /** * @module ApiClient * @version 0.1.0 */ /** * Manages low level client-server communications, parameter marshalling, etc. There should not be any need for an * application to use this class directly - the *Api and model classes provide the public API for the service. The * contents of this file should be regarded as internal but are documented for completeness. * @alias module:ApiClient * @class */ var exports = function exports() { /** * The base URL against which to resolve every API call's (relative) path. * @type {String} * @default https://localhost/alfresco/api/-default-/public/alfresco/versions/1 */ this.basePath = 'https://localhost/alfresco/api/-default-/public/alfresco/versions/1'.replace(/\/+$/, ''); /** * The authentication methods to be included for all API calls. * @type {string[]} */ this.authentications = { 'basicAuth': { type: 'basic' } }; /** * The default HTTP headers to be included for all API calls. * @type {string[]} * @default {} */ this.defaultHeaders = {}; /** * The default HTTP timeout for all API calls. * @type {Number} * @default 60000 */ this.timeout = undefined; }; /** * Returns a string representation for an actual parameter. * @param param The actual parameter. * @returns {String} The string representation of <code>param</code>. */ exports.prototype.paramToString = function (param) { if (param == undefined || param == null) { return ''; } if (param instanceof Date) { return param.toJSON(); } return param.toString(); }; /** * Builds full URL by appending the given path to the base URL and replacing path parameter place-holders with parameter values. * NOTE: query parameters are not handled here. * @param {String} path The path to append to the base URL. * @param {Object} pathParams The parameter values to append. * @returns {String} The encoded path with parameter values substituted. */ exports.prototype.buildUrl = function (path, pathParams) { if (!path.match(/^\//)) { path = '/' + path; } var url = this.basePath + path; var _this = this; url = url.replace(/\{([\w-]+)\}/g, function (fullMatch, key) { var value; if (pathParams.hasOwnProperty(key)) { value = _this.paramToString(pathParams[key]); } else { value = fullMatch; } return encodeURIComponent(value); }); return url; }; /** * Checks whether the given content type represents JSON.<br> * JSON content type examples:<br> * <ul> * <li>application/json</li> * <li>application/json; charset=UTF8</li> * <li>APPLICATION/JSON</li> * </ul> * @param {String} contentType The MIME content type to check. * @returns {Boolean} <code>true</code> if <code>contentType</code> represents JSON, otherwise <code>false</code>. */ exports.prototype.isJsonMime = function (contentType) { return Boolean(contentType != null && contentType.match(/^application\/json(;.*)?$/i)); }; /** * Chooses a content type from the given array, with JSON preferred; i.e. return JSON if included, otherwise return the first. * @param {string[]} contentTypes * @returns {String} The chosen content type, preferring JSON. */ exports.prototype.jsonPreferredMime = function (contentTypes) { for (var i = 0; i < contentTypes.length; i++) { if (this.isJsonMime(contentTypes[i])) { return contentTypes[i]; } } return contentTypes[0]; }; /** * Checks whether the given parameter value represents file-like content. * @param param The parameter to check. * @returns {Boolean} <code>true</code> if <code>param</code> represents a file. */ exports.prototype.isFileParam = function (param) { // fs.ReadStream in Node.js (but not in runtime like browserify) if (_typeof(__webpack_require__(124).ReadStream) === 'object') { if (typeof window === 'undefined' && "function" === 'function' && __webpack_require__(124) && param instanceof __webpack_require__(124).ReadStream) { return true; } } // Buffer in Node.js if (typeof Buffer === 'function' && param instanceof Buffer) { return true; } // Blob in browser if (typeof Blob === 'function' && param instanceof Blob) { return true; } // File in browser (it seems File object is also instance of Blob, but keep this for safe) if (typeof File === 'function' && param instanceof File) { return true; } // Safari fix if ((typeof File === 'undefined' ? 'undefined' : _typeof(File)) === 'object' && param instanceof File) { return true; } return false; }; /** * Normalizes parameter values: * <ul> * <li>remove nils</li> * <li>keep files and arrays</li> * <li>format to string with `paramToString` for other cases</li> * </ul> * @param {Object.<String, Object>} params The parameters as object properties. * @returns {Object.<String, Object>} normalized parameters. */ exports.prototype.normalizeParams = function (params) { var newParams = {}; for (var key in params) { if (params.hasOwnProperty(key) && params[key] != undefined && params[key] != null) { var value = params[key]; if (this.isFileParam(value) || Array.isArray(value)) { newParams[key] = value; } else { newParams[key] = this.paramToString(value); } } } return newParams; }; /** * Enumeration of collection format separator strategies. * @enum {String} * @readonly */ exports.CollectionFormatEnum = { /** * Comma-separated values. Value: <code>csv</code> * @const */ CSV: ',', /** * Space-separated values. Value: <code>ssv</code> * @const */ SSV: ' ', /** * Tab-separated values. Value: <code>tsv</code> * @const */ TSV: '\t', /** * Pipe(|)-separated values. Value: <code>pipes</code> * @const */ PIPES: '|', /** * Native array. Value: <code>multi</code> * @const */ MULTI: 'multi' }; /** * Builds a string representation of an array-type actual parameter, according to the given collection format. * @param {Array} param An array parameter. * @param {module:ApiClient.CollectionFormatEnum} collectionFormat The array element separator strategy. * @returns {String|Array} A string representation of the supplied collection, using the specified delimiter. Returns * <code>param</code> as is if <code>collectionFormat</code> is <code>multi</code>. */ exports.prototype.buildCollectionParam = function buildCollectionParam(param, collectionFormat) { if (param == null) { return null; } switch (collectionFormat) { case 'csv': return param.map(this.paramToString).join(','); case 'ssv': return param.map(this.paramToString).join(' '); case 'tsv': return param.map(this.paramToString).join('\t'); case 'pipes': return param.map(this.paramToString).join('|'); case 'multi': // return the array directly as SuperAgent will handle it as expected return param.map(this.paramToString); default: throw new Error('Unknown collection format: ' + collectionFormat); } }; /** * Applies authentication headers to the request. * @param {Object} request The request object created by a <code>superagent()</code> call. * @param {string[]} authNames An array of authentication method names. */ exports.prototype.applyAuthToRequest = function (request, authNames) { var _this = this; authNames.forEach(function (authName) { var auth = _this.authentications[authName]; switch (auth.type) { case 'basic': if (auth.username || auth.password) { request.auth(auth.username ? encodeURI(auth.username) : '', auth.password ? encodeURI(auth.password) : ''); } break; case 'apiKey': if (auth.apiKey) { var data = {}; if (auth.apiKeyPrefix) { data[auth.name] = auth.apiKeyPrefix + ' ' + auth.apiKey; } else { data[auth.name] = auth.apiKey; } if (auth['in'] === 'header') { request.set(data); } else { request.query(data); } } break; case 'activiti': if (auth.ticket) { request.set({ 'Authorization': auth.ticket }); } break; case 'oauth2': if (auth.accessToken) { request.set({ 'Authorization': 'Bearer ' + auth.accessToken }); } break; default: throw new Error('Unknown authentication type: ' + auth.type); } }); }; /** * Deserializes an HTTP response body into a value of the specified type. * @param {Object} response A SuperAgent response object. * @param {(String|string[]|Object.<String, Object>|Function)} returnType The type to return. Pass a string for simple types * or the constructor function for a complex type. Pass an array containing the type name to return an array of that type. To * return an object, pass an object with one property whose name is the key type and whose value is the corresponding value type: * all properties on <code>data<code> will be converted to this type. * @returns A value of the specified type. */ exports.prototype.deserialize = function deserialize(response, returnType) { if (response == null || returnType == null) { return null; } // Rely on SuperAgent for parsing response body. // See http://visionmedia.github.io/superagent/#parsing-response-bodies var data = response.body; if (data == null) { // SuperAgent does not always produce a body; use the unparsed response as a fallback data = response.text; } return exports.convertToType(data, returnType); }; /** * Invokes the REST service using the supplied settings and parameters. * @param {String} path The base URL to invoke. * @param {String} httpMethod The HTTP method to use. * @param {Object.<String, String>} pathParams A map of path parameters and their values. * @param {Object.<String, Object>} queryParams A map of query parameters and their values. * @param {Object.<String, Object>} headerParams A map of header parameters and their values. * @param {Object.<String, Object>} formParams A map of form parameters and their values. * @param {Object} bodyParam The value to pass as the request body. * @param {string[]} authNames An array of authentication type names. * @param {string[]} contentTypes An array of request MIME types. * @param {string[]} accepts An array of acceptable response MIME types. * @param {(String|Array|ObjectFunction)} returnType The required type to return; can be a string for simple types or the * constructor for a complex type. * @returns {Promise} A Promise object. */ exports.prototype.callApi = function callApi(path, httpMethod, pathParams, queryParams, headerParams, formParams, bodyParam, authNames, contentTypes, accepts, returnType) { var _this = this; var url = this.buildUrl(path, pathParams); var request = superagent(httpMethod, url); // apply authentications this.applyAuthToRequest(request, authNames); // set query parameters request.query(this.normalizeParams(queryParams)); // set header parameters request.set(this.defaultHeaders).set(this.normalizeParams(headerParams)); // set request timeout request.timeout(this.timeout); var contentType = this.jsonPreferredMime(contentTypes); if (contentType) { request.type(contentType); } else if (!request.header['Content-Type']) { request.type('application/json'); } if (contentType === 'application/x-www-form-urlencoded') { request.send(this.normalizeParams(formParams)); } else if (contentType == 'multipart/form-data') { var _formParams = this.normalizeParams(formParams); for (var key in _formParams) { if (_formParams.hasOwnProperty(key)) { if (this.isFileParam(_formParams[key])) { // file field request.attach(key, _formParams[key]); } else { request.field(key, _formParams[key]); } } } } else if (bodyParam) { request.send(bodyParam); } var accept = this.jsonPreferredMime(accepts); if (accept) { request.accept(accept); } return new Promise(function (resolve, reject) { request.end(function (error, response) { if (error) { if (response && response.text) { reject({ error: error, message: response.text }); } else { reject({ error: error }); } } else { var data = _this.deserialize(response, returnType); resolve(data); } }); }); }; /** * Parses an ISO-8601 string representation of a date value. * @param {String} str The date value as a string. * @returns {Date} The parsed date object. */ exports.parseDate = function (str) { var dateLength = 10; var separatorPos = str.substring(dateLength).search(/[\+\-]/) + dateLength; var dateStr = separatorPos > dateLength ? str.substring(0, separatorPos) : str; var tzStr = separatorPos > dateLength ? str.substring(separatorPos) : ''; var parsedDate = exports.parseDateTime(dateStr); var tzOffsetMins = exports.parseDateTimeZone(tzStr); parsedDate.setTime(parsedDate.getTime() + tzOffsetMins * 60000); return parsedDate; }; /** * Parses the date component of a ISO-8601 string representation of a date value. * @param {String} str The date value as a string. * @returns {Date} The parsed date object. */ exports.parseDateTime = function (str) { // TODO: review when Safari 10 is released // return new Date(str.replace(/T/i, ' ')); // Compatible with Safari 9.1.2 var parts = str.split('+'); var dateParts = str.split(/[^0-9]/).map(function (s) { return parseInt(s, 10); }); return new Date(Date.UTC(dateParts[0], dateParts[1] - 1 || 0, dateParts[2] || 1, dateParts[3] || 0, dateParts[4] || 0, dateParts[5] || 0, dateParts[6] || 0)); }; /** * Parses the timezone component of a ISO-8601 string representation of a date value. * @param {String} str The timezone offset as a string, e.g. '+0000', '+2000' or '-0500'. * @returns {number} The number of minutes offset from UTC. */ exports.parseDateTimeZone = function (str) { var match = /([\+\-])(\d{2}):?(\d{2})?/.exec(str); if (match !== null) { return parseInt(match[1] + '1') * -1 * (parseInt(match[2]) * 60) + parseInt(match[3] || 0); } else { return 0; } }; /** * Converts a value to the specified type. * @param {(String|Object)} data The data to convert, as a string or object. * @param {(String|string[]|Object.<String, Object>|Function)} type The type to return. Pass a string for simple types * or the constructor function for a complex type. Pass an array containing the type name to return an array of that type. To * return an object, pass an object with one property whose name is the key type and whose value is the corresponding value type: * all properties on <code>data<code> will be converted to this type. * @returns An instance of the specified type. */ exports.convertToType = function (data, type) { switch (type) { case 'Binary': return data; case 'Boolean': return Boolean(data); case 'Integer': return parseInt(data, 10); case 'Number': return parseFloat(data); case 'String': return data !== null && data !== undefined ? String(data) : data; case 'Date': return data ? this.parseDate(String(data)) : null; default: if (type === Object) { // generic object, return directly return data; } else if (typeof type === 'function') { // for model type like: User return type.constructFromObject(data); } else if (Array.isArray(type)) { // for array type like: ['String'] var itemType = type[0]; if (data) { return data.map(function (item) { return exports.convertToType(item, itemType); }); } else { return null; } } else if ((typeof type === 'undefined' ? 'undefined' : _typeof(type)) === 'object') { // for plain object type like: {'String': 'Integer'} var keyType, valueType; for (var k in type) { if (type.hasOwnProperty(k)) { keyType = k; valueType = type[k]; break; } } var result = {}; for (var k in data) { if (data.hasOwnProperty(k)) { var key = exports.convertToType(k, keyType); var value = exports.convertToType(data[k], valueType); result[key] = value; } } return result; } else { // for unknown type, return the data directly return data; } } }; /** * The default API client implementation. * @type {module:ApiClient} */ exports.instance = new exports(); return exports; }); /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(49).Buffer)) /***/ }), /* 2 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__; var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; (function (root, factory) { if (true) { // AMD. Register as an anonymous module. !(__WEBPACK_AMD_DEFINE_ARRAY__ = [__webpack_require__(0), __webpack_require__(162)], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory), __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); } else {} })(undefined, function (ApiClient, AbstractRepresentation) { 'use strict'; /** * The ResultListDataRepresentation model module. * @module model/ResultListDataRepresentation * @version 1.4.0 */ /** * Constructs a new <code>ResultListDataRepresentation</code>. * @alias module:model/ResultListDataRepresentation * @class */ var exports = function exports() { var _this = this; }; /** * Constructs a <code>ResultListDataRepresentation</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/ResultListDataRepresentation} obj Optional instance to populate. * @return {module:model/ResultListDataRepresentation} The populated <code>ResultListDataRepresentation</code> instance. */ exports.constructFromObject = function (data, obj) { if (data) { obj = data || new exports(); if (data.hasOwnProperty('data')) { obj['data'] = ApiClient.convertToType(data['data'], 'object'); } if (data.hasOwnProperty('size')) { obj['size'] = ApiClient.convertToType(data['size'], 'Integer'); } if (data.hasOwnProperty('start')) { obj['start'] = ApiClient.convertToType(data['start'], 'Integer'); } if (data.hasOwnProperty('total')) { obj['total'] = ApiClient.convertToType(data['total'], 'Integer'); } } return obj; }; /** * @member {Array.<module:model/AbstractRepresentation>} data */ exports.prototype['data'] = undefined; /** * @member {Integer} size */ exports.prototype['size'] = undefined; /** * @member {Integer} start */ exports.prototype['start'] = undefined; /** * @member {Integer} total */ exports.prototype['total'] = undefined; return exports; }); /***/ }), /* 3 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__; var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; (function (root, factory) { if (true) { // AMD. Register as an anonymous module. !(__WEBPACK_AMD_DEFINE_ARRAY__ = [__webpack_require__(1)], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory), __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); } else {} })(undefined, function (ApiClient) { 'use strict'; /** * The Pagination model module. * @module model/Pagination * @version 0.1.0 */ /** * Constructs a new <code>Pagination</code>. * @alias module:model/Pagination * @class * @param count * @param hasMoreItems * @param skipCount * @param maxItems */ var exports = function exports(count, hasMoreItems, skipCount, maxItems) { this['count'] = count; this['hasMoreItems'] = hasMoreItems; this['skipCount'] = skipCount; this['maxItems'] = maxItems; }; /** * Constructs a <code>Pagination</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/Pagination} obj Optional instance to populate. * @return {module:model/Pagination} The populated <code>Pagination</code> instance. */ exports.constructFromObject = function (data, obj) { if (data) { obj = data || new exports(); if (data.hasOwnProperty('count')) { obj['count'] = ApiClient.convertToType(data['count'], 'Integer'); } if (data.hasOwnProperty('hasMoreItems')) { obj['hasMoreItems'] = ApiClient.convertToType(data['hasMoreItems'], 'Boolean'); } if (data.hasOwnProperty('totalItems')) { obj['totalItems'] = ApiClient.convertToType(data['totalItems'], 'Integer'); } if (data.hasOwnProperty('skipCount')) { obj['skipCount'] = ApiClient.convertToType(data['skipCount'], 'Integer'); } if (data.hasOwnProperty('maxItems')) { obj['maxItems'] = ApiClient.convertToType(data['maxItems'], 'Integer'); } } return obj; }; /** * The number of objects in the entries array.\n * @member {Integer} count */ exports.prototype['count'] = undefined; /** * A boolean value which is **true** if there are more entities in the collection\nbeyond those in this response. A true value means a request with a larger value\nfor the **skipCount** or the **maxItems** parameter will return more entities.\n * @member {Boolean} hasMoreItems */ exports.prototype['hasMoreItems'] = undefined; /** * An integer describing the total number of entities in the collection.\nThe API might not be able to determine this value,\nin which case this property will not be present.\n * @member {Integer} totalItems */ exports.prototype['totalItems'] = undefined; /** * An integer describing how many entities exist in the collection before\nthose included in this list.\n * @member {Integer} skipCount */ exports.prototype['skipCount'] = undefined; /** * The value of the **maxItems** parameter used to generate this list,\nor if there was no **maxItems** parameter the default value, 10\n * @member {Integer} maxItems */ exports.prototype['maxItems'] = undefined; return exports; }); /***/ }), /* 4 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__; var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; (function (root, factory) { if (true) { // AMD. Register as an anonymous module. !(__WEBPACK_AMD_DEFINE_ARRAY__ = [__webpack_require__(0)], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory), __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); } else {} })(undefined, function (ApiClient) { 'use strict'; /** * The UserInfo model module. * @module UserInfo * @version 0.1.0 */ /** * Constructs a new <code>UserInfo</code>. * @alias UserInfo * @class * @param displayName {string} * @param id {string} */ var exports = function exports(displayName, id) { var _this = this; _this['displayName'] = displayName; _this['id'] = id; }; /** * Constructs a <code>UserInfo</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 {UserInfo} obj Optional instance to populate. * @return {UserInfo} The populated <code>UserInfo</code> instance. */ exports.constructFromObject = function (data, obj) { if (data) { obj = obj || new exports(); if (data.hasOwnProperty('displayName')) { obj['displayName'] = ApiClient.convertToType(data['displayName'], 'String'); } if (data.hasOwnProperty('id')) { obj['id'] = ApiClient.convertToType(data['id'], 'String'); } } return obj; }; /** * @member {string} displayName */ exports.prototype['displayName'] = undefined; /** * @member {string} id */ exports.prototype['id'] = undefined; return exports; }); /***/ }), /* 5 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__; var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; (function (root, factory) { if (true) { // AMD. Register as an anonymous module. !(__WEBPACK_AMD_DEFINE_ARRAY__ = [__webpack_require__(1), __webpack_require__(388)], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory), __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); } else {} })(undefined, function (ApiClient, ErrorError) { 'use strict'; /** * The Error model module. * @module model/Error * @vers