@frontegg/injector
Advanced tools
Comparing version 0.0.14 to 0.0.15
@@ -27,5 +27,5 @@ import { InjectorOptions } from './types'; | ||
protected loadEntrypoints(): Promise<void[]>; | ||
injectJavascript(url: string | HTMLScriptElement, entrypoint?: boolean): Promise<void>; | ||
injectJavascript(url: string | HTMLScriptElement): Promise<void>; | ||
injectCss(url: string | HTMLLinkElement): Promise<void>; | ||
} | ||
export default Injector; |
@@ -142,9 +142,8 @@ "use strict"; | ||
return __generator(this, function (_a) { | ||
return [2 /*return*/, Promise.all(__spreadArrays(this.js.map(function (file) { return _this.injectJavascript(_this.cdn + "/" + _this.version + "/js/" + file, true); }), this.css.map(function (file) { return _this.injectCss(_this.cdn + "/" + _this.version + "/css/" + file); })))]; | ||
return [2 /*return*/, Promise.all(__spreadArrays(this.js.map(function (file) { return _this.injectJavascript(_this.cdn + "/" + _this.version + "/js/" + file); }), this.css.map(function (file) { return _this.injectCss(_this.cdn + "/" + _this.version + "/css/" + file); })))]; | ||
}); | ||
}); | ||
}; | ||
Injector.prototype.injectJavascript = function (url, entrypoint) { | ||
Injector.prototype.injectJavascript = function (url) { | ||
var _this = this; | ||
if (entrypoint === void 0) { entrypoint = false; } | ||
return new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () { | ||
@@ -151,0 +150,0 @@ var logger, res, contentScript, bundleScript; |
@@ -27,5 +27,5 @@ import { InjectorOptions } from './types'; | ||
protected loadEntrypoints(): Promise<void[]>; | ||
injectJavascript(url: string | HTMLScriptElement, entrypoint?: boolean): Promise<void>; | ||
injectJavascript(url: string | HTMLScriptElement): Promise<void>; | ||
injectCss(url: string | HTMLLinkElement): Promise<void>; | ||
} | ||
export default Injector; |
@@ -77,3 +77,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return Promise.all([ | ||
...this.js.map((file) => this.injectJavascript(`${this.cdn}/${this.version}/js/${file}`, true)), | ||
...this.js.map((file) => this.injectJavascript(`${this.cdn}/${this.version}/js/${file}`)), | ||
...this.css.map((file) => this.injectCss(`${this.cdn}/${this.version}/css/${file}`)), | ||
@@ -83,3 +83,3 @@ ]); | ||
} | ||
injectJavascript(url, entrypoint = false) { | ||
injectJavascript(url) { | ||
return new Promise((resolve) => __awaiter(this, void 0, void 0, function* () { | ||
@@ -89,2 +89,10 @@ const logger = this.logger; | ||
logger.info('Loading JS file from ', url); | ||
// const bundleScript = document.createElement('script'); | ||
// bundleScript.setAttribute('charset', 'utf-8'); | ||
// bundleScript.src = url; | ||
// this.shadowEl.appendChild(bundleScript); | ||
// bundleScript.onload = e => { | ||
// logger.info('JS loaded successfully', url); | ||
// resolve(); | ||
// }; | ||
const res = yield fetch(url, { method: 'GET', cache: 'default' }); | ||
@@ -91,0 +99,0 @@ let contentScript = yield res.text(); |
@@ -27,5 +27,5 @@ import { InjectorOptions } from './types'; | ||
protected loadEntrypoints(): Promise<void[]>; | ||
injectJavascript(url: string | HTMLScriptElement, entrypoint?: boolean): Promise<void>; | ||
injectJavascript(url: string | HTMLScriptElement): Promise<void>; | ||
injectCss(url: string | HTMLLinkElement): Promise<void>; | ||
} | ||
export default Injector; |
@@ -137,9 +137,8 @@ var __assign = (this && this.__assign) || function () { | ||
return __generator(this, function (_a) { | ||
return [2 /*return*/, Promise.all(__spreadArrays(this.js.map(function (file) { return _this.injectJavascript(_this.cdn + "/" + _this.version + "/js/" + file, true); }), this.css.map(function (file) { return _this.injectCss(_this.cdn + "/" + _this.version + "/css/" + file); })))]; | ||
return [2 /*return*/, Promise.all(__spreadArrays(this.js.map(function (file) { return _this.injectJavascript(_this.cdn + "/" + _this.version + "/js/" + file); }), this.css.map(function (file) { return _this.injectCss(_this.cdn + "/" + _this.version + "/css/" + file); })))]; | ||
}); | ||
}); | ||
}; | ||
Injector.prototype.injectJavascript = function (url, entrypoint) { | ||
Injector.prototype.injectJavascript = function (url) { | ||
var _this = this; | ||
if (entrypoint === void 0) { entrypoint = false; } | ||
return new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () { | ||
@@ -146,0 +145,0 @@ var logger, res, contentScript, bundleScript; |
@@ -237,7 +237,7 @@ (function (global, factory) { | ||
return __generator$1(this, function (_a) { | ||
return [2 /*return*/, Promise.all(__spreadArrays(this.js.map(function (file) { return _this.injectJavascript(_this.cdn + "/" + _this.version + "/js/" + file, true); }), this.css.map(function (file) { return _this.injectCss(_this.cdn + "/" + _this.version + "/css/" + file); })))]; | ||
return [2 /*return*/, Promise.all(__spreadArrays(this.js.map(function (file) { return _this.injectJavascript(_this.cdn + "/" + _this.version + "/js/" + file); }), this.css.map(function (file) { return _this.injectCss(_this.cdn + "/" + _this.version + "/css/" + file); })))]; | ||
}); | ||
}); | ||
}; | ||
Injector.prototype.injectJavascript = function (url, entrypoint) { | ||
Injector.prototype.injectJavascript = function (url) { | ||
var _this = this; | ||
@@ -244,0 +244,0 @@ return new Promise(function (resolve) { return __awaiter$1(_this, void 0, void 0, function () { |
@@ -1,1 +0,1 @@ | ||
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(n="undefined"!=typeof globalThis?globalThis:n||self).AdminBoxInjector=t()}(this,function(){"use strict";var e=function(n,t){var o=this;void 0===n&&(n=!1),this.disabled=n,this.logger=t,this.log=function(n,t,e){return o.disabled?function(){}:"function"==typeof o.logger?o.logger:void 0===console.log.bind?Function.prototype.bind.call(console[n],console,t||"",e||"-"):console[n].bind(console,t||"",e||"-")},this.info=null===(t=this.log)||void 0===t?void 0:t.call(this,"log","%c[AdminBox]","background:#e8e8e8;"),this.warn=null===(t=this.log)||void 0===t?void 0:t.call(this,"warn","[AdminBox]"),this.error=null===(t=this.log)||void 0===t?void 0:t.call(this,"error","[AdminBox]")},c=window&&window.__awaiter||function(n,s,c,a){return new(c=c||Promise)(function(e,t){function o(n){try{r(a.next(n))}catch(n){t(n)}}function i(n){try{r(a.throw(n))}catch(n){t(n)}}function r(n){var t;n.done?e(n.value):((t=n.value)instanceof c?t:new c(function(n){n(t)})).then(o,i)}r((a=a.apply(n,s||[])).next())})},a=window&&window.__generator||function(e,o){var i,r,s,c={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]},n={next:t(0),throw:t(1),return:t(2)};return"function"==typeof Symbol&&(n[Symbol.iterator]=function(){return this}),n;function t(t){return function(n){return function(t){if(i)throw new TypeError("Generator is already executing.");for(;c;)try{if(i=1,r&&(s=2&t[0]?r.return:t[0]?r.throw||((s=r.return)&&s.call(r),0):r.next)&&!(s=s.call(r,t[1])).done)return s;switch(r=0,(t=s?[2&t[0],s.value]:t)[0]){case 0:case 1:s=t;break;case 4:return c.label++,{value:t[1],done:!1};case 5:c.label++,r=t[1],t=[0];continue;case 7:t=c.ops.pop(),c.trys.pop();continue;default:if(!(s=0<(s=c.trys).length&&s[s.length-1])&&(6===t[0]||2===t[0])){c=0;continue}if(3===t[0]&&(!s||t[1]>s[0]&&t[1]<s[3])){c.label=t[1];break}if(6===t[0]&&c.label<s[1]){c.label=s[1],s=t;break}if(s&&c.label<s[2]){c.label=s[2],c.ops.push(t);break}s[2]&&c.ops.pop(),c.trys.pop();continue}t=o.call(e,c)}catch(n){t=[6,n],r=0}finally{i=s=0}if(5&t[0])throw t[1];return{value:t[0]?t[1]:void 0,done:!0}}([t,n])}}};function o(n,t){var e=t.querySelector("#"+n);return e||((e=document.createElement("div")).setAttribute("id",n),t.appendChild(e)),e}var l=window&&window.__assign||function(){return(l=Object.assign||function(n){for(var t,e=1,o=arguments.length;e<o;e++)for(var i in t=arguments[e])Object.prototype.hasOwnProperty.call(t,i)&&(n[i]=t[i]);return n}).apply(this,arguments)},u=window&&window.__awaiter||function(n,s,c,a){return new(c=c||Promise)(function(e,t){function o(n){try{r(a.next(n))}catch(n){t(n)}}function i(n){try{r(a.throw(n))}catch(n){t(n)}}function r(n){var t;n.done?e(n.value):((t=n.value)instanceof c?t:new c(function(n){n(t)})).then(o,i)}r((a=a.apply(n,s||[])).next())})},f=window&&window.__generator||function(e,o){var i,r,s,c={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]},n={next:t(0),throw:t(1),return:t(2)};return"function"==typeof Symbol&&(n[Symbol.iterator]=function(){return this}),n;function t(t){return function(n){return function(t){if(i)throw new TypeError("Generator is already executing.");for(;c;)try{if(i=1,r&&(s=2&t[0]?r.return:t[0]?r.throw||((s=r.return)&&s.call(r),0):r.next)&&!(s=s.call(r,t[1])).done)return s;switch(r=0,(t=s?[2&t[0],s.value]:t)[0]){case 0:case 1:s=t;break;case 4:return c.label++,{value:t[1],done:!1};case 5:c.label++,r=t[1],t=[0];continue;case 7:t=c.ops.pop(),c.trys.pop();continue;default:if(!(s=0<(s=c.trys).length&&s[s.length-1])&&(6===t[0]||2===t[0])){c=0;continue}if(3===t[0]&&(!s||t[1]>s[0]&&t[1]<s[3])){c.label=t[1];break}if(6===t[0]&&c.label<s[1]){c.label=s[1],s=t;break}if(s&&c.label<s[2]){c.label=s[2],c.ops.push(t);break}s[2]&&c.ops.pop(),c.trys.pop();continue}t=o.call(e,c)}catch(n){t=[6,n],r=0}finally{i=s=0}if(5&t[0])throw t[1];return{value:t[0]?t[1]:void 0,done:!0}}([t,n])}}},i=window&&window.__spreadArrays||function(){for(var n=0,t=0,e=arguments.length;t<e;t++)n+=arguments[t].length;for(var o=Array(n),i=0,t=0;t<e;t++)for(var r=arguments[t],s=0,c=r.length;s<c;s++,i++)o[i]=r[s];return o};function d(n){var t=this;this.js=[],this.css=[],this.name="default",this.cdn="https://fronteggdeveustorage.blob.core.windows.net/admin-box",this.version="latest",this.mount=function(){t.logger.error("App not loaded yet")},this.unmount=function(){t.logger.error("App not loaded yet")},this.logger=new e,this.logger.info("Create shadow dom element"),this.hostEl=o("frontegg-host-"+n,document.body),this.shadowEl=this.hostEl.attachShadow({mode:"open"}),this.rootEl=o("frontegg-content",this.shadowEl),this.name=n,this.open=this.open.bind(this),this.close=this.close.bind(this),this.destroy=this.destroy.bind(this),this.injectJavascript=this.injectJavascript.bind(this),this.injectCss=this.injectCss.bind(this)}return d.init=function(i,r){var s;return void 0===r&&(r="default"),u(this,void 0,void 0,function(){var t,e,o;return f(this,function(n){switch(n.label){case 0:return Object.assign(window,{FronteggInjector:d}),t=new d(r),(e=t.logger).info("Initializing Injector instance"),t.cdn=null!==(s=i.cdn)&&void 0!==s?s:t.cdn,t.cdn=t.cdn.endsWith("/")?t.cdn.substring(0,t.cdn.length-1):t.cdn,e.info("Retrieving version metadata"),[4,function(e,o,i){return c(this,void 0,void 0,function(){var t;return a(this,function(n){switch(n.label){case 0:return e.info("Retrieving version from cdn: "+o+" version: "+i),"latest"!==(t=i)&&"stable"!==t&&(t=i+"/config"),[4,fetch(o+"/"+t+".json",{cache:"no-cache",mode:"no-cors"})];case 1:return[2,n.sent().json()]}})})}(e,t.cdn,i.version)];case 1:return o=n.sent(),t.version=o.version,t.js=o.js,t.css=o.css,e.info("Injector instance initialized successfully",l({name:r,cdn:t.version},o)),d._apps[r]=t,e.info("Loading entrypoint files"),[4,t.loadEntrypoints()];case 2:return n.sent(),e.info("Entrypoint files loaded successfully"),[2]}})})},d.getInstance=function(n){var t=d._apps[n=void 0===n?"default":n];if(!t)throw Error("injector instance not found for name: "+n+".\nInject.init(options"+("default"===n?"":", '"+n+"'")+") must be called");return t},d.prototype.open=function(){this.mount(this.rootEl)},d.prototype.close=function(){this.unmount(this.rootEl)},d.prototype.destroy=function(){delete d._apps[this.name],this.hostEl.remove(),this.logger.info(this.name+" destroyed")},d.prototype.loadEntrypoints=function(){return u(this,void 0,void 0,function(){var t=this;return f(this,function(n){return[2,Promise.all(i(this.js.map(function(n){return t.injectJavascript(t.cdn+"/"+t.version+"/js/"+n,!0)}),this.css.map(function(n){return t.injectCss(t.cdn+"/"+t.version+"/css/"+n)})))]})})},d.prototype.injectJavascript=function(r,n){var t=this;return new Promise(function(i){return u(t,void 0,void 0,function(){var t,e,o;return f(this,function(n){switch(n.label){case 0:return(t=this.logger,"string"!=typeof r)?[3,3]:(t.info("Loading JS file from ",r),[4,fetch(r,{method:"GET",cache:"default"})]);case 1:return[4,n.sent().text()];case 2:return e=n.sent(),(o=document.createElement("script")).setAttribute("charset","utf-8"),o.setAttribute("type","text/javascript"),e.indexOf("FRONTEGG_INJECTOR_CDN_HOST")&&(e=e.replace("/FRONTEGG_INJECTOR_CDN_HOST",this.cdn),e="(()=> { const fronteggInjector = FronteggInjector.getInstance('"+this.name+"');\n "+e+"\n })();"),o.innerHTML=e,this.shadowEl.appendChild(o),t.info("JS loaded successfully",r),[3,4];case 3:t.info("Loading lazy JS file from ",r.src),this.shadowEl.appendChild(r),n.label=4;case 4:return i(),[2]}})})})},d.prototype.injectCss=function(o){var i=this;return new Promise(function(t){var n,e=i.logger;"string"==typeof o?(e.info("Loading CSS file from ",o),(n=document.createElement("link")).href=o,n.rel="stylesheet",n.type="text/css",i.shadowEl.prepend(n),n.onload=function(n){e.info("CSS loaded successfully",o),t()}):(e.info("Loading lazy CSS file from ",o.href),i.shadowEl.insertBefore(o,i.rootEl),t())})},d._apps={},d}); | ||
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(n="undefined"!=typeof globalThis?globalThis:n||self).AdminBoxInjector=t()}(this,function(){"use strict";var e=function(n,t){var o=this;void 0===n&&(n=!1),this.disabled=n,this.logger=t,this.log=function(n,t,e){return o.disabled?function(){}:"function"==typeof o.logger?o.logger:void 0===console.log.bind?Function.prototype.bind.call(console[n],console,t||"",e||"-"):console[n].bind(console,t||"",e||"-")},this.info=null===(t=this.log)||void 0===t?void 0:t.call(this,"log","%c[AdminBox]","background:#e8e8e8;"),this.warn=null===(t=this.log)||void 0===t?void 0:t.call(this,"warn","[AdminBox]"),this.error=null===(t=this.log)||void 0===t?void 0:t.call(this,"error","[AdminBox]")},c=window&&window.__awaiter||function(n,s,c,a){return new(c=c||Promise)(function(e,t){function o(n){try{r(a.next(n))}catch(n){t(n)}}function i(n){try{r(a.throw(n))}catch(n){t(n)}}function r(n){var t;n.done?e(n.value):((t=n.value)instanceof c?t:new c(function(n){n(t)})).then(o,i)}r((a=a.apply(n,s||[])).next())})},a=window&&window.__generator||function(e,o){var i,r,s,c={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]},n={next:t(0),throw:t(1),return:t(2)};return"function"==typeof Symbol&&(n[Symbol.iterator]=function(){return this}),n;function t(t){return function(n){return function(t){if(i)throw new TypeError("Generator is already executing.");for(;c;)try{if(i=1,r&&(s=2&t[0]?r.return:t[0]?r.throw||((s=r.return)&&s.call(r),0):r.next)&&!(s=s.call(r,t[1])).done)return s;switch(r=0,(t=s?[2&t[0],s.value]:t)[0]){case 0:case 1:s=t;break;case 4:return c.label++,{value:t[1],done:!1};case 5:c.label++,r=t[1],t=[0];continue;case 7:t=c.ops.pop(),c.trys.pop();continue;default:if(!(s=0<(s=c.trys).length&&s[s.length-1])&&(6===t[0]||2===t[0])){c=0;continue}if(3===t[0]&&(!s||t[1]>s[0]&&t[1]<s[3])){c.label=t[1];break}if(6===t[0]&&c.label<s[1]){c.label=s[1],s=t;break}if(s&&c.label<s[2]){c.label=s[2],c.ops.push(t);break}s[2]&&c.ops.pop(),c.trys.pop();continue}t=o.call(e,c)}catch(n){t=[6,n],r=0}finally{i=s=0}if(5&t[0])throw t[1];return{value:t[0]?t[1]:void 0,done:!0}}([t,n])}}};function o(n,t){var e=t.querySelector("#"+n);return e||((e=document.createElement("div")).setAttribute("id",n),t.appendChild(e)),e}var l=window&&window.__assign||function(){return(l=Object.assign||function(n){for(var t,e=1,o=arguments.length;e<o;e++)for(var i in t=arguments[e])Object.prototype.hasOwnProperty.call(t,i)&&(n[i]=t[i]);return n}).apply(this,arguments)},t=window&&window.__awaiter||function(n,s,c,a){return new(c=c||Promise)(function(e,t){function o(n){try{r(a.next(n))}catch(n){t(n)}}function i(n){try{r(a.throw(n))}catch(n){t(n)}}function r(n){var t;n.done?e(n.value):((t=n.value)instanceof c?t:new c(function(n){n(t)})).then(o,i)}r((a=a.apply(n,s||[])).next())})},u=window&&window.__generator||function(e,o){var i,r,s,c={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]},n={next:t(0),throw:t(1),return:t(2)};return"function"==typeof Symbol&&(n[Symbol.iterator]=function(){return this}),n;function t(t){return function(n){return function(t){if(i)throw new TypeError("Generator is already executing.");for(;c;)try{if(i=1,r&&(s=2&t[0]?r.return:t[0]?r.throw||((s=r.return)&&s.call(r),0):r.next)&&!(s=s.call(r,t[1])).done)return s;switch(r=0,(t=s?[2&t[0],s.value]:t)[0]){case 0:case 1:s=t;break;case 4:return c.label++,{value:t[1],done:!1};case 5:c.label++,r=t[1],t=[0];continue;case 7:t=c.ops.pop(),c.trys.pop();continue;default:if(!(s=0<(s=c.trys).length&&s[s.length-1])&&(6===t[0]||2===t[0])){c=0;continue}if(3===t[0]&&(!s||t[1]>s[0]&&t[1]<s[3])){c.label=t[1];break}if(6===t[0]&&c.label<s[1]){c.label=s[1],s=t;break}if(s&&c.label<s[2]){c.label=s[2],c.ops.push(t);break}s[2]&&c.ops.pop(),c.trys.pop();continue}t=o.call(e,c)}catch(n){t=[6,n],r=0}finally{i=s=0}if(5&t[0])throw t[1];return{value:t[0]?t[1]:void 0,done:!0}}([t,n])}}},i=window&&window.__spreadArrays||function(){for(var n=0,t=0,e=arguments.length;t<e;t++)n+=arguments[t].length;for(var o=Array(n),i=0,t=0;t<e;t++)for(var r=arguments[t],s=0,c=r.length;s<c;s++,i++)o[i]=r[s];return o};function f(n){var t=this;this.js=[],this.css=[],this.name="default",this.cdn="https://fronteggdeveustorage.blob.core.windows.net/admin-box",this.version="latest",this.mount=function(){t.logger.error("App not loaded yet")},this.unmount=function(){t.logger.error("App not loaded yet")},this.logger=new e,this.logger.info("Create shadow dom element"),this.hostEl=o("frontegg-host-"+n,document.body),this.shadowEl=this.hostEl.attachShadow({mode:"open"}),this.rootEl=o("frontegg-content",this.shadowEl),this.name=n,this.open=this.open.bind(this),this.close=this.close.bind(this),this.destroy=this.destroy.bind(this),this.injectJavascript=this.injectJavascript.bind(this),this.injectCss=this.injectCss.bind(this)}return f.init=function(i,r){var s;return void 0===r&&(r="default"),t(this,void 0,void 0,function(){var t,e,o;return u(this,function(n){switch(n.label){case 0:return Object.assign(window,{FronteggInjector:f}),t=new f(r),(e=t.logger).info("Initializing Injector instance"),t.cdn=null!==(s=i.cdn)&&void 0!==s?s:t.cdn,t.cdn=t.cdn.endsWith("/")?t.cdn.substring(0,t.cdn.length-1):t.cdn,e.info("Retrieving version metadata"),[4,function(e,o,i){return c(this,void 0,void 0,function(){var t;return a(this,function(n){switch(n.label){case 0:return e.info("Retrieving version from cdn: "+o+" version: "+i),"latest"!==(t=i)&&"stable"!==t&&(t=i+"/config"),[4,fetch(o+"/"+t+".json",{cache:"no-cache",mode:"no-cors"})];case 1:return[2,n.sent().json()]}})})}(e,t.cdn,i.version)];case 1:return o=n.sent(),t.version=o.version,t.js=o.js,t.css=o.css,e.info("Injector instance initialized successfully",l({name:r,cdn:t.version},o)),f._apps[r]=t,e.info("Loading entrypoint files"),[4,t.loadEntrypoints()];case 2:return n.sent(),e.info("Entrypoint files loaded successfully"),[2]}})})},f.getInstance=function(n){var t=f._apps[n=void 0===n?"default":n];if(!t)throw Error("injector instance not found for name: "+n+".\nInject.init(options"+("default"===n?"":", '"+n+"'")+") must be called");return t},f.prototype.open=function(){this.mount(this.rootEl)},f.prototype.close=function(){this.unmount(this.rootEl)},f.prototype.destroy=function(){delete f._apps[this.name],this.hostEl.remove(),this.logger.info(this.name+" destroyed")},f.prototype.loadEntrypoints=function(){return t(this,void 0,void 0,function(){var t=this;return u(this,function(n){return[2,Promise.all(i(this.js.map(function(n){return t.injectJavascript(t.cdn+"/"+t.version+"/js/"+n)}),this.css.map(function(n){return t.injectCss(t.cdn+"/"+t.version+"/css/"+n)})))]})})},f.prototype.injectJavascript=function(r){var n=this;return new Promise(function(i){return t(n,void 0,void 0,function(){var t,e,o;return u(this,function(n){switch(n.label){case 0:return(t=this.logger,"string"!=typeof r)?[3,3]:(t.info("Loading JS file from ",r),[4,fetch(r,{method:"GET",cache:"default"})]);case 1:return[4,n.sent().text()];case 2:return e=n.sent(),(o=document.createElement("script")).setAttribute("charset","utf-8"),o.setAttribute("type","text/javascript"),e.indexOf("FRONTEGG_INJECTOR_CDN_HOST")&&(e=e.replace("/FRONTEGG_INJECTOR_CDN_HOST",this.cdn),e="(()=> { const fronteggInjector = FronteggInjector.getInstance('"+this.name+"');\n "+e+"\n })();"),o.innerHTML=e,this.shadowEl.appendChild(o),t.info("JS loaded successfully",r),[3,4];case 3:t.info("Loading lazy JS file from ",r.src),this.shadowEl.appendChild(r),n.label=4;case 4:return i(),[2]}})})})},f.prototype.injectCss=function(o){var i=this;return new Promise(function(t){var n,e=i.logger;"string"==typeof o?(e.info("Loading CSS file from ",o),(n=document.createElement("link")).href=o,n.rel="stylesheet",n.type="text/css",i.shadowEl.prepend(n),n.onload=function(n){e.info("CSS loaded successfully",o),t()}):(e.info("Loading lazy CSS file from ",o.href),i.shadowEl.insertBefore(o,i.rootEl),t())})},f._apps={},f}); |
{ | ||
"name": "@frontegg/injector", | ||
"version": "0.0.14", | ||
"version": "0.0.15", | ||
"main": "dist/cjs/index.js", | ||
@@ -19,3 +19,3 @@ "types": "dist/esm/index.d.ts", | ||
}, | ||
"gitHead": "ab6d631c1801f4b286c6f417bd6372362d311460" | ||
"gitHead": "78f1cfa1bd68d3b8a666ccb7220380b9574e6bdd" | ||
} |
@@ -101,30 +101,30 @@ import Logger from './logger'; | ||
logger.info('Loading JS file from ', url); | ||
// const bundleScript = document.createElement('script'); | ||
// bundleScript.setAttribute('charset', 'utf-8'); | ||
// bundleScript.src = url; | ||
// this.shadowEl.appendChild(bundleScript); | ||
// bundleScript.onload = e => { | ||
// logger.info('JS loaded successfully', url); | ||
// resolve(); | ||
// }; | ||
const res = await fetch(url, { method: 'GET', cache: 'default' }); | ||
let contentScript = await res.text(); | ||
const bundleScript = document.createElement('script'); | ||
bundleScript.setAttribute('charset', 'utf-8'); | ||
bundleScript.src = url; | ||
this.shadowEl.appendChild(bundleScript); | ||
bundleScript.onload = e => { | ||
logger.info('JS loaded successfully', url); | ||
resolve(); | ||
}; | ||
bundleScript.setAttribute('type', 'text/javascript'); | ||
// const res = await fetch(url, { method: 'GET', cache: 'default' }); | ||
// let contentScript = await res.text(); | ||
// const bundleScript = document.createElement('script'); | ||
// bundleScript.setAttribute('charset', 'utf-8'); | ||
// bundleScript.setAttribute('type', 'text/javascript'); | ||
// | ||
// if (contentScript.indexOf('FRONTEGG_INJECTOR_CDN_HOST')) { | ||
// contentScript = contentScript.replace('/FRONTEGG_INJECTOR_CDN_HOST', this.cdn); | ||
// | ||
// contentScript = `(()=> { const fronteggInjector = FronteggInjector.getInstance('${this.name}'); | ||
// ${contentScript} | ||
// })();`; | ||
// | ||
// } | ||
// bundleScript.innerHTML = contentScript; | ||
if (contentScript.indexOf('FRONTEGG_INJECTOR_CDN_HOST')) { | ||
contentScript = contentScript.replace('/FRONTEGG_INJECTOR_CDN_HOST', this.cdn); | ||
// this.shadowEl.appendChild(bundleScript); | ||
// logger.info('JS loaded successfully', url); | ||
contentScript = `(()=> { const fronteggInjector = FronteggInjector.getInstance('${this.name}'); | ||
${contentScript} | ||
})();`; | ||
} | ||
bundleScript.innerHTML = contentScript; | ||
this.shadowEl.appendChild(bundleScript); | ||
logger.info('JS loaded successfully', url); | ||
} else { | ||
@@ -131,0 +131,0 @@ logger.info('Loading lazy JS file from ', url.src); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1463
151678