Skip to content
Snippets Groups Projects
Commit 09ad113c authored by Rich Lott / Artful Robot's avatar Rich Lott / Artful Robot
Browse files

Production build

parent 33426c10
Branches
Tags
No related merge requests found
(()=>{function n(o){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},n(o)}window.CiviCRMInlay=window.CiviCRMInlay||{app:null,inlays:{},debug:function(){}},window.CiviCRMInlay.app||function(){localStorage&&localStorage.getItem("inlayDebug")&&(window.CiviCRMInlay.debug=console.debug);var o=window.CiviCRMInlay.debug;o("Defining CiviCRMInlay.app");var e=window.CiviCRMInlay;e.app={bundleInfo:function(n,o){var e=Math.floor(((new Date).getTime()-n)/1e3),t="s",r=e<300?console.info:console.log;e>120?(e=Math.floor(e/60),t="mins"):e>1440?(e=Math.floor(e/24/60),t="days"):e>60&&(e=Math.floor(e/60),t="hrs"),r("Inlay bundle ".concat(o," created ").concat(e," ").concat(t," ago"))},bootWhenReady:function(){"complete"===document.readyState?(o("Document is already ready, booting any new inlays."),e.app.boot()):(o("Waiting for DOMContentLoaded to boot any new inlays."),document.addEventListener("DOMContentLoaded",e.app.boot))},boot:function(){o("Inlay app booting");var t=[];[].forEach.call(document.querySelectorAll("script[data-inlay-id]"),(function(r){t.push(r);var i=r.dataset.inlayId;r.inlayBooted?o("Inlay ".concat(i,": already booted")):i in e.inlays?(o("Inlay ".concat(i,": booting")),r.inlayBooted=!0,e.inlays[i]&&e.inlays[i].init in window?window[e.inlays[i].init]({initData:e.inlays[i],publicID:i,script:r,request:function(o){return e.app.request(i,o).catch((function(o){return console.error("Inlay caught unexpected "+n(o),o),alert("Sorry, an error occurred."),{error:o,responseOk:!1,responseStatus:500}}))}}):console.error("Failed to boot inlay ".concat(i,": missing data or init function"))):console.warn("Inlay ".concat(i,": Failed to instantiate from script:"))})),o("All inlays booted",t)},request:function(o,t){if(!o)return console.warn("Inlay broken: missing publicID in call to request()"),Promise.resolve({error:"Configuration problem on website. Code Inlay1"});if(!e.inlays[o])return console.warn("Inlay broken: invalid publicID in call to request()"),Promise.resolve({error:"Configuration problem on website. Code Inlay2"});if("object"!==n(t.body))return console.warn("Inlay broken: request must be called with object for body"),Promise.resolve({error:"Configuration problem on website. Code Inlay3"});(t=JSON.parse(JSON.stringify(t))).headers&&t.headers["Content-Type"]||(t.headers=t.headers||{},t.headers["Content-Type"]="application/json"),t.body.publicID=o,t.body=JSON.stringify(t.body);var r=e.inlays[o].inlayEndpoint;return"xdebug"in t&&(r+=(r.indexOf("?")>-1?"&":"?")+"XDEBUG_SESSION_START="+encodeURIComponent(t.xdebug),delete t.xdebug),"get"===t.method&&(r+=(r.indexOf("?")>-1?"&":"?")+"inlayJSON="+encodeURIComponent(t.body),delete t.body),Object.assign(t,{mode:"cors",cache:"no-cache",credentials:"omit",redirect:"error",referrerPolicy:"origin-when-cross-origin"}),fetch(r,t).then((function(n){var o=n.headers.get("content-type");if(!o||!o.includes("application/json"))throw new TypeError("Server Error: JSON response required.");return n.json().then((function(o){return o.responseStatus=n.status,o.responseOk=n.ok,o}))}))}}}()})();
\ No newline at end of file
/******/ (() => { // webpackBootstrap
var __webpack_exports__ = {};
/*!**********************!*\
!*** ./src/inlay.js ***!
\**********************/
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
window.CiviCRMInlay = window.CiviCRMInlay || {
app: null,
inlays: {},
debug: function debug() {}
};
// Define the app once.
if (!window.CiviCRMInlay.app) {
(function () {
if (localStorage && localStorage.getItem('inlayDebug')) {
window.CiviCRMInlay.debug = console.debug;
}
var debug = window.CiviCRMInlay.debug;
debug("Defining CiviCRMInlay.app");
var inlay = window.CiviCRMInlay;
inlay.app = {
// Reports to console the bundle ID and its age.
bundleInfo: function bundleInfo(bundleCreateTime, bundleId) {
var age = Math.floor((new Date().getTime() - bundleCreateTime) / 1000),
unit = 's',
facility = age < 300 ? console.info : console.log;
if (age > 120) {
age = Math.floor(age / 60);
unit = 'mins';
} else if (age > 24 * 60) {
age = Math.floor(age / 24 / 60);
unit = 'days';
} else if (age > 60) {
age = Math.floor(age / 60);
unit = 'hrs';
}
facility("Inlay bundle ".concat(bundleId, " created ").concat(age, " ").concat(unit, " ago"));
},
bootWhenReady: function bootWhenReady() {
// Typically we have to wait for DOMContentLoaded, but this might have already happened.
if (document.readyState === "complete") {
debug("Document is already ready, booting any new inlays.");
inlay.app.boot();
} else {
debug("Waiting for DOMContentLoaded to boot any new inlays.");
document.addEventListener('DOMContentLoaded', inlay.app.boot);
}
},
boot: function boot() {
debug("Inlay app booting");
// Boot inlays that have not been booted yet.
var found = [];
[].forEach.call(document.querySelectorAll('script[data-inlay-id]'), function (script) {
found.push(script);
var publicID = script.dataset.inlayId;
if (script.inlayBooted) {
debug("Inlay ".concat(publicID, ": already booted"));
return;
}
// Script needs booting.
if (!(publicID in inlay.inlays)) {
console.warn("Inlay ".concat(publicID, ": Failed to instantiate from script:"));
return;
}
debug("Inlay ".concat(publicID, ": booting"));
// Remember we've booted it.
script.inlayBooted = true;
/**
* Boot the inlay now.
*
* The inlay object has the following properties:
* - initData object of data served along with the bundle script.
* - publicID string for the inlay instance on the server. Nb. you may have
* multiple instances of that instance(!) on a web page.
* - script DOM node of the script tag that has caused us to be loaded,
* e.g. useful for positioning our UI after it, or extracting
* locally specified data- attributes.
* - request(fetchParams)
* method providing fetch() wrapper for all Inlay-related
* requests. The URL is fixed, so you only provide the params
* object.
*/
if (inlay.inlays[publicID] && inlay.inlays[publicID].init in window) {
window[inlay.inlays[publicID].init]({
initData: inlay.inlays[publicID],
publicID: publicID,
script: script,
// Here we provide a simplified .request method for our inlays to use.
// It will add in the publicID of the Inlay, the URL to the inlay endpoint etc.
// Using .then(r) gives direct access to the JSON returned, as
// well as r.responseStatus which is the http status, e.g. 200,
// and r.responseOk which is a shortcut to 200 <=
// r.responseStatus <299
request: function request(fetchParams) {
return inlay.app.request(publicID, fetchParams)["catch"](function (e) {
// Note: Errors here will be things like:
// - network errors
// - server error that meant the response output was not parsable JSON.
// It is assumed that inlays do not want to handle these errors, so
// we just inform the user with a generic error message.
console.error('Inlay caught unexpected ' + _typeof(e), e);
alert("Sorry, an error occurred.");
return {
error: e,
responseOk: false,
responseStatus: 500 // probably.
};
});
}
});
} else {
console.error("Failed to boot inlay ".concat(publicID, ": missing data or init function"));
}
});
debug('All inlays booted', found);
},
request: function request(publicID, fetchParams) {
if (!publicID) {
console.warn("Inlay broken: missing publicID in call to request()");
return Promise.resolve({
error: "Configuration problem on website. Code Inlay1"
});
}
if (!inlay.inlays[publicID]) {
console.warn("Inlay broken: invalid publicID in call to request()");
return Promise.resolve({
error: "Configuration problem on website. Code Inlay2"
});
}
if (_typeof(fetchParams.body) !== 'object') {
console.warn("Inlay broken: request must be called with object for body");
return Promise.resolve({
error: "Configuration problem on website. Code Inlay3"
});
}
// Take a deep copy of the fetchParams since we need to be able to make changes
// but do not want to change an extenal object.
fetchParams = JSON.parse(JSON.stringify(fetchParams));
if (!fetchParams.headers || !fetchParams.headers['Content-Type']) {
// Provide default content type json header, and ensure body is stringified.
fetchParams.headers = fetchParams.headers || {};
fetchParams.headers['Content-Type'] = 'application/json';
}
// Add the publicID to the payload.
fetchParams.body.publicID = publicID;
// JSONify payload.
fetchParams.body = JSON.stringify(fetchParams.body);
// Prepare the URL.
var url = inlay.inlays[publicID].inlayEndpoint;
// Support xdebug for debugging/dev. Make a request with an 'xdebug'
// property on the fetch params, the value of this should be the string
// expected by your IDE.
if ('xdebug' in fetchParams) {
url += (url.indexOf('?') > -1 ? '&' : '?') + 'XDEBUG_SESSION_START=' + encodeURIComponent(fetchParams.xdebug);
delete fetchParams.xdebug;
}
// If method is GET, then we send the json in the query string under inlayJSON
if (fetchParams.method === 'get') {
url += (url.indexOf('?') > -1 ? '&' : '?') + 'inlayJSON=' + encodeURIComponent(fetchParams.body);
delete fetchParams.body;
}
// Require certain params.
Object.assign(fetchParams, {
mode: 'cors',
// no-cors, cors, same-origin
cache: 'no-cache',
// default, no-cache, reload, force-cache, only-if-cached
credentials: 'omit',
// include, same-origin, omit
redirect: 'error',
// manual, follow, error
referrerPolicy: 'origin-when-cross-origin' // no-referrer, *no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-url
});
return fetch(url, fetchParams).then(function (r) {
var contentType = r.headers.get('content-type');
if (!contentType || !contentType.includes('application/json')) {
throw new TypeError("Server Error: JSON response required.");
}
// r.json() returns a Promise that resolves /to/ the parsed object.
return r.json().then(function (d) {
// Copy the status code to the object we pass on.
d.responseStatus = r.status;
d.responseOk = r.ok;
// Pass on the JSON object.
return d;
});
});
}
};
})();
}
/******/ })()
;
\ No newline at end of file
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment