UNPKG

@aurigma/design-atoms

Version:

Design Atoms is a part of Customer's Canvas SDK which allows for manipulating individual design elements through your code.

92 lines 3.52 kB
var __values = (this && this.__values) || function(o) { var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; if (m) return m.call(o); if (o && typeof o.length === "number") return { next: function () { if (o && i >= o.length) o = void 0; return { value: o && o[i++], done: !o }; } }; throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); }; import { AjaxResponseException } from "../Exception/AjaxResponseException"; export var request = function (parameters) { return new Promise(function (resolve, reject) { var e_1, _a; var xhr = new XMLHttpRequest(); xhr.open(parameters.type, parameters.url, true); xhr.setRequestHeader("Accept", "*/*"); if (parameters.headers != null) try { for (var _b = __values(parameters.headers), _c = _b.next(); !_c.done; _c = _b.next()) { var header = _c.value; xhr.setRequestHeader(header.name, header.value); } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (_c && !_c.done && (_a = _b.return)) _a.call(_b); } finally { if (e_1) throw e_1.error; } } if (parameters.responseType != null) xhr.responseType = parameters.responseType; xhr.send(parameters.data); xhr.onreadystatechange = function () { if (xhr.readyState !== 4) return; var status = xhr.status; var response = { value: xhr.responseType !== "arraybuffer" ? xhr.responseText : "", status: status, contentType: xhr.getResponseHeader("content-type"), xhr: xhr }; if (status >= 200 && status < 300) resolve(response); else reject(new AjaxResponseException(response)); }; }); }; export var getJson = function (url) { return request({ url: url, type: RequestType.get, headers: [ContentType.json] }); }; export var postJson = function (url, data) { return request({ url: url, type: RequestType.post, headers: [ContentType.json], data: data }); }; export var StatusCode; (function (StatusCode) { StatusCode[StatusCode["Ok"] = 200] = "Ok"; StatusCode[StatusCode["NoContent"] = 204] = "NoContent"; StatusCode[StatusCode["NotFound"] = 404] = "NotFound"; StatusCode[StatusCode["InternalServerError"] = 500] = "InternalServerError"; })(StatusCode || (StatusCode = {})); var Exception = /** @class */ (function () { function Exception(response) { this.response = response; } return Exception; }()); export { Exception }; export var RequestType; (function (RequestType) { RequestType.post = "POST"; RequestType.get = "GET"; // ReSharper disable once InconsistentNaming RequestType.Delete = "DELETE"; })(RequestType || (RequestType = {})); export var ContentType; (function (ContentType) { function isJsonContentType(contentType) { return contentType.trim().toLowerCase().indexOf('application/json') === 0; } ContentType.isJsonContentType = isJsonContentType; ContentType.json = { name: 'Content-Type', value: 'application/json;charset=UTF-8' }; ContentType.text = { name: 'Content-Type', value: 'text/plain' }; })(ContentType || (ContentType = {})); //# sourceMappingURL=Ajax.js.map