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

rebuild js

parent 0c9e53c4
Branches master
No related tags found
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
(()=>{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,window.CiviCRMInlay.xdebug=!0);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",i=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"),i("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(i){t.push(i);var r=i.dataset.inlayId;i.inlayBooted?o("Inlay ".concat(r,": already booted")):r in e.inlays?(o("Inlay ".concat(r,": booting")),i.inlayBooted=!0,e.inlays[r]&&e.inlays[r].init in window?window[e.inlays[r].init]({initData:e.inlays[r],publicID:r,script:i,request:function(o){return e.app.request(r,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(r,": missing data or init function"))):console.warn("Inlay ".concat(r,": 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 i=e.inlays[o].inlayEndpoint;return("xdebug"in t||window.CiviCRMInlay.xdebug)&&(i+=(i.indexOf("?")>-1?"&":"?")+"XDEBUG_TRIGGER=1",delete t.xdebug),"get"===t.method&&(i+=(i.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(i,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
window.CiviCRMInlay = window.CiviCRMInlay || { app: null, inlays: {}, debug: () => {} };
window.CiviCRMInlay = window.CiviCRMInlay || {
app: null,
inlays: {},
debug: () => {}
};
// Define the app once.
if (!window.CiviCRMInlay.app) {
(() => {
if ((localStorage && localStorage.getItem('inlayDebug'))) {
if (localStorage && localStorage.getItem("inlayDebug")) {
window.CiviCRMInlay.debug = console.debug;
window.CiviCRMInlay.xdebug = true;
}
let debug = window.CiviCRMInlay.debug;
debug("Defining CiviCRMInlay.app");
......@@ -12,30 +17,37 @@ if (!window.CiviCRMInlay.app) {
inlay.app = {
// Reports to console the bundle ID and its age.
bundleInfo(bundleCreateTime, bundleId) {
let 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'; }
let 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 ${bundleId} created ${age} ${unit} ago`);
},
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.")
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);
} else {
debug("Waiting for DOMContentLoaded to boot any new inlays.");
document.addEventListener("DOMContentLoaded", inlay.app.boot);
}
},
boot() {
debug("Inlay app booting");
// Boot inlays that have not been booted yet.
let found = [];
[].forEach.call(document.querySelectorAll('script[data-inlay-id]'),
[].forEach.call(
document.querySelectorAll("script[data-inlay-id]"),
script => {
found.push(script);
const publicID = script.dataset.inlayId;
......@@ -45,7 +57,9 @@ if (!window.CiviCRMInlay.app) {
}
// Script needs booting.
if (!(publicID in inlay.inlays)) {
console.warn(`Inlay ${publicID}: Failed to instantiate from script:`);
console.warn(
`Inlay ${publicID}: Failed to instantiate from script:`
);
return;
}
debug(`Inlay ${publicID}: booting`);
......@@ -66,7 +80,10 @@ if (!window.CiviCRMInlay.app) {
* requests. The URL is fixed, so you only provide the params
* object.
*/
if (inlay.inlays[publicID] && (inlay.inlays[publicID].init in window)) {
if (
inlay.inlays[publicID] &&
inlay.inlays[publicID].init in window
) {
window[inlay.inlays[publicID].init]({
initData: inlay.inlays[publicID],
publicID,
......@@ -77,53 +94,62 @@ if (!window.CiviCRMInlay.app) {
// 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: (fetchParams) =>
inlay.app.request(publicID, fetchParams)
.catch(e => {
request: fetchParams =>
inlay.app.request(publicID, fetchParams).catch(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);
console.error("Inlay caught unexpected " + typeof e, e);
alert("Sorry, an error occurred.");
return {
error: e,
responseOk: false,
responseStatus: 500, // probably.
responseStatus: 500 // probably.
};
})
});
} else {
console.error(
`Failed to boot inlay ${publicID}: missing data or init function`
);
}
else {
console.error(`Failed to boot inlay ${publicID}: missing data or init function`);
}
});
debug('All inlays booted', found);
}
);
debug("All inlays booted", found);
},
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"});
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"});
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"});
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']) {
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';
fetchParams.headers["Content-Type"] = "application/json";
}
// Add the publicID to the payload.
......@@ -137,31 +163,32 @@ if (!window.CiviCRMInlay.app) {
// 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);
if ("xdebug" in fetchParams || window.CiviCRMInlay.xdebug) {
url += (url.indexOf("?") > -1 ? "&" : "?") + "XDEBUG_TRIGGER=1";
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);
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
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(r => {
const contentType = r.headers.get('content-type');
if (!contentType || !contentType.includes('application/json')) {
const contentType = r.headers.get("content-type");
if (!contentType || !contentType.includes("application/json")) {
throw new TypeError("Server Error: JSON response required.");
}
......
......@@ -1793,9 +1793,9 @@ caniuse-api@^3.0.0:
lodash.uniq "^4.5.0"
caniuse-lite@^1.0.0, caniuse-lite@^1.0.30001426, caniuse-lite@^1.0.30001449:
version "1.0.30001457"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001457.tgz#6af34bb5d720074e2099432aa522c21555a18301"
integrity sha512-SDIV6bgE1aVbK6XyxdURbUE89zY7+k1BBBaOwYwkNCglXlel/E7mELiHC64HQ+W0xSKlqWhV9Wh7iHxUjMs4fA==
version "1.0.30001585"
resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001585.tgz"
integrity sha512-yr2BWR1yLXQ8fMpdS/4ZZXpseBgE7o4g41x3a6AJOqZuOi+iE/WdJYAuZ6Y95i4Ohd2Y+9MzIWRR+uGABH4s3Q==
chalk@^2.0.0:
version "2.4.2"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment