@mopinion/survey
Version:
Collect customer feedback with the Mopinion survey library
85 lines (84 loc) • 3.56 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _request3 = _interopRequireDefault(require("./request"));
var _utils = require("../utils");
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 get(url) {
var _request = (0, _request3["default"])(url, {
method: 'get',
crossOrigin: true
}),
promise = _request.promise;
return promise.then(function (response) {
return (response.text()
);
}).then(function (response) {
return typeof response === 'string' ? JSON.parse(response) : _typeof(response) === 'object' ? response : {};
})["catch"](function (error) {
return (0, _utils.log)(error);
});
}
function post(url, data) {
var _request2 = (0, _request3["default"])(url, {
method: 'post',
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
},
body: (0, _utils.serialize)(data)
}),
promise = _request2.promise,
abort = _request2.abort;
return promise.then(function (response) {
return response.json();
}).then(function (response) {
return response;
});
}
function api(_ref) {
var formKey = _ref.formKey,
domain = _ref.domain,
_ref$cacheDomain = _ref.cacheDomain,
cacheDomain = _ref$cacheDomain === void 0 ? 'cacheorcheck.mopinion.com' : _ref$cacheDomain,
customDomain = _ref.customDomain,
_ref$feedbackDomain = _ref.feedbackDomain,
feedbackDomain = _ref$feedbackDomain === void 0 ? 'survey.mopinion.com' : _ref$feedbackDomain,
webView = _ref.webView,
noCache = _ref.noCache,
refresh = _ref.refresh;
var api = {
cache: "https://".concat(cacheDomain, "/survey/public"),
domain: "https://".concat(customDomain !== null && customDomain !== void 0 ? customDomain : domain, "/survey/public"),
send: "https://".concat(feedbackDomain, "/api/1/data")
};
function whichApi(useApi, useDomainApi) {
if (useApi === 'send') return api.send;
if (noCache || useDomainApi || ['beta.mopinion.com', 'accept.mopinion.com'].indexOf(domain) > -1) {
return api.domain;
}
return api[useApi];
}
return {
getConfig: function getConfig(withBase, useDomainApi) {
return get("".concat(whichApi('cache', useDomainApi), "/json-config?key=").concat(formKey, "&domain=").concat(domain).concat(webView ? '&webView=true' : '').concat(withBase ? '&withBase=true' : '').concat(refresh ? '&' + Date.now() : ''));
},
getEmoji: function getEmoji(blockId) {
return get(whichApi('cache') + "/emoji?blockId=".concat(blockId, "&domain=").concat(domain));
},
getIcons: function getIcons(icons) {
icons = (0, _utils.isArray)(icons) ? icons : [icons];
return get(whichApi('cache') + "/icons?icons=".concat(icons.join(','), "&domain=").concat(domain));
},
validateReCaptcha: function validateReCaptcha(data) {
return post(whichApi('domain') + '/validate-recaptcha', data);
},
validateBusinessEmail: function validateBusinessEmail(data) {
return post(whichApi('domain') + '/validate-business-email', data);
}
};
}
var _default = exports["default"] = api;
//# sourceMappingURL=index.js.map