New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@frontegg/injector

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@frontegg/injector - npm Package Compare versions

Comparing version 0.0.23 to 0.0.24

7

cjs/index.d.ts

@@ -9,2 +9,3 @@ import { InjectorOptions } from './types';

declare class Injector {
private key;
private static _apps;

@@ -25,5 +26,5 @@ private readonly options;

unmount: (element: HTMLElement) => void;
protected constructor(name: string, options: InjectorOptions);
static init(options: InjectorOptions, name?: string): Promise<void>;
static getInstance(name?: string): Injector;
protected constructor(name: string, key: string, options: InjectorOptions);
static init(options: InjectorOptions, name?: string, key?: string): Promise<void>;
static getInstance(name?: string, key?: string): Injector;
open(): void;

@@ -30,0 +31,0 @@ close(): void;

@@ -76,4 +76,5 @@ "use strict";

var Injector = /** @class */ (function () {
function Injector(name, options) {
function Injector(name, key, options) {
var _this = this;
this.key = key;
this.js = [];

@@ -104,5 +105,6 @@ this.css = [];

}
Injector.init = function (options, name) {
Injector.init = function (options, name, key) {
var _a;
if (name === void 0) { name = 'default'; }
if (key === void 0) { key = 'default'; }
return __awaiter(this, void 0, void 0, function () {

@@ -113,4 +115,4 @@ var instance, logger, metadata;

case 0:
Object.assign(window, { FronteggInjector: Injector });
instance = new Injector(name, options);
Object.assign(window, { FronteggConnector: Injector });
instance = new Injector(name, key, options);
logger = instance.logger;

@@ -140,6 +142,8 @@ Injector._apps[name] = instance;

};
Injector.getInstance = function (name) {
Injector.getInstance = function (name, key) {
if (name === void 0) { name = 'default'; }
if (key === void 0) { key = 'default'; }
var instance = Injector._apps[name];
if (!instance) {
if (!instance || instance.key !== key) {
delete Injector._apps[name];
throw Error("injector instance not found for name: " + name + ".\nInject.init(options" + (name === 'default' ? '' : ", '" + name + "'") + ") must be called");

@@ -199,3 +203,3 @@ }

contentScript = contentScript.replace('/FRONTEGG_INJECTOR_CDN_HOST', this.cdn);
contentScript = "(()=> { const fronteggInjector = FronteggInjector.getInstance('" + this.name + "');\n " + contentScript + "\n })();";
contentScript = "(()=> { const fronteggInjector = FronteggConnector.getInstance('" + this.name + "', '" + this.key + "');\n " + contentScript + "\n })();";
}

@@ -202,0 +206,0 @@ bundleScript.innerHTML = contentScript;

@@ -9,2 +9,3 @@ import { InjectorOptions } from './types';

declare class Injector {
private key;
private static _apps;

@@ -25,5 +26,5 @@ private readonly options;

unmount: (element: HTMLElement) => void;
protected constructor(name: string, options: InjectorOptions);
static init(options: InjectorOptions, name?: string): Promise<void>;
static getInstance(name?: string): Injector;
protected constructor(name: string, key: string, options: InjectorOptions);
static init(options: InjectorOptions, name?: string, key?: string): Promise<void>;
static getInstance(name?: string, key?: string): Injector;
open(): void;

@@ -30,0 +31,0 @@ close(): void;

@@ -16,3 +16,4 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

class Injector {
constructor(name, options) {
constructor(name, key, options) {
this.key = key;
this.js = [];

@@ -43,7 +44,7 @@ this.css = [];

}
static init(options, name = 'default') {
static init(options, name = 'default', key = 'default') {
var _a;
return __awaiter(this, void 0, void 0, function* () {
Object.assign(window, { FronteggInjector: Injector });
const instance = new Injector(name, options);
Object.assign(window, { FronteggConnector: Injector });
const instance = new Injector(name, key, options);
const { logger } = instance;

@@ -66,5 +67,6 @@ Injector._apps[name] = instance;

}
static getInstance(name = 'default') {
static getInstance(name = 'default', key = 'default') {
const instance = Injector._apps[name];
if (!instance) {
if (!instance || instance.key !== key) {
delete Injector._apps[name];
throw Error(`injector instance not found for name: ${name}.\nInject.init(options${name === 'default' ? '' : `, '${name}'`}) must be called`);

@@ -115,3 +117,3 @@ }

contentScript = contentScript.replace('/FRONTEGG_INJECTOR_CDN_HOST', this.cdn);
contentScript = `(()=> { const fronteggInjector = FronteggInjector.getInstance('${this.name}');
contentScript = `(()=> { const fronteggInjector = FronteggConnector.getInstance('${this.name}', '${this.key}');
${contentScript}

@@ -118,0 +120,0 @@ })();`;

@@ -9,2 +9,3 @@ import { InjectorOptions } from './types';

declare class Injector {
private key;
private static _apps;

@@ -25,5 +26,5 @@ private readonly options;

unmount: (element: HTMLElement) => void;
protected constructor(name: string, options: InjectorOptions);
static init(options: InjectorOptions, name?: string): Promise<void>;
static getInstance(name?: string): Injector;
protected constructor(name: string, key: string, options: InjectorOptions);
static init(options: InjectorOptions, name?: string, key?: string): Promise<void>;
static getInstance(name?: string, key?: string): Injector;
open(): void;

@@ -30,0 +31,0 @@ close(): void;

@@ -61,4 +61,5 @@ var __assign = (this && this.__assign) || function () {

var Injector = /** @class */ (function () {
function Injector(name, options) {
function Injector(name, key, options) {
var _this = this;
this.key = key;
this.js = [];

@@ -89,5 +90,6 @@ this.css = [];

}
Injector.init = function (options, name) {
Injector.init = function (options, name, key) {
var _a;
if (name === void 0) { name = 'default'; }
if (key === void 0) { key = 'default'; }
return __awaiter(this, void 0, void 0, function () {

@@ -98,4 +100,4 @@ var instance, logger, metadata;

case 0:
Object.assign(window, { FronteggInjector: Injector });
instance = new Injector(name, options);
Object.assign(window, { FronteggConnector: Injector });
instance = new Injector(name, key, options);
logger = instance.logger;

@@ -125,6 +127,8 @@ Injector._apps[name] = instance;

};
Injector.getInstance = function (name) {
Injector.getInstance = function (name, key) {
if (name === void 0) { name = 'default'; }
if (key === void 0) { key = 'default'; }
var instance = Injector._apps[name];
if (!instance) {
if (!instance || instance.key !== key) {
delete Injector._apps[name];
throw Error("injector instance not found for name: " + name + ".\nInject.init(options" + (name === 'default' ? '' : ", '" + name + "'") + ") must be called");

@@ -184,3 +188,3 @@ }

contentScript = contentScript.replace('/FRONTEGG_INJECTOR_CDN_HOST', this.cdn);
contentScript = "(()=> { const fronteggInjector = FronteggInjector.getInstance('" + this.name + "');\n " + contentScript + "\n })();";
contentScript = "(()=> { const fronteggInjector = FronteggConnector.getInstance('" + this.name + "', '" + this.key + "');\n " + contentScript + "\n })();";
}

@@ -187,0 +191,0 @@ bundleScript.innerHTML = contentScript;

{
"name": "@frontegg/injector",
"version": "0.0.23",
"version": "0.0.24",
"main": "cjs/index.js",

@@ -5,0 +5,0 @@ "types": "esm/index.d.ts",

@@ -160,4 +160,5 @@ (function (global, factory) {

var Injector = /** @class */ (function () {
function Injector(name, options) {
function Injector(name, key, options) {
var _this = this;
this.key = key;
this.js = [];

@@ -188,5 +189,6 @@ this.css = [];

}
Injector.init = function (options, name) {
Injector.init = function (options, name, key) {
var _a;
if (name === void 0) { name = 'default'; }
if (key === void 0) { key = 'default'; }
return __awaiter$1(this, void 0, void 0, function () {

@@ -197,4 +199,4 @@ var instance, logger, metadata;

case 0:
Object.assign(window, { FronteggInjector: Injector });
instance = new Injector(name, options);
Object.assign(window, { FronteggConnector: Injector });
instance = new Injector(name, key, options);
logger = instance.logger;

@@ -224,6 +226,8 @@ Injector._apps[name] = instance;

};
Injector.getInstance = function (name) {
Injector.getInstance = function (name, key) {
if (name === void 0) { name = 'default'; }
if (key === void 0) { key = 'default'; }
var instance = Injector._apps[name];
if (!instance) {
if (!instance || instance.key !== key) {
delete Injector._apps[name];
throw Error("injector instance not found for name: " + name + ".\nInject.init(options" + (name === 'default' ? '' : ", '" + name + "'") + ") must be called");

@@ -283,3 +287,3 @@ }

contentScript = contentScript.replace('/FRONTEGG_INJECTOR_CDN_HOST', this.cdn);
contentScript = "(()=> { const fronteggInjector = FronteggInjector.getInstance('" + this.name + "');\n " + contentScript + "\n })();";
contentScript = "(()=> { const fronteggInjector = FronteggConnector.getInstance('" + this.name + "', '" + this.key + "');\n " + contentScript + "\n })();";
}

@@ -286,0 +290,0 @@ bundleScript.innerHTML = contentScript;

@@ -1,1 +0,1 @@

!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(t="undefined"!=typeof globalThis?globalThis:t||self).AdminBoxInjector=n()}(this,function(){"use strict";var o=function(t,n){var o=this;void 0===t&&(t=!1),this.disabled=t,this.logger=n,this.log=function(t,n,e){return o.disabled?function(){}:"function"==typeof o.logger?o.logger:void 0===console.log.bind?Function.prototype.bind.call(console[t],console,n||"",e||"-"):console[t].bind(console,n||"",e||"-")},this.info=null===(n=this.log)||void 0===n?void 0:n.call(this,"log","%c[AdminBox]","background:#e8e8e8;"),this.warn=null===(n=this.log)||void 0===n?void 0:n.call(this,"warn","[AdminBox]"),this.error=null===(n=this.log)||void 0===n?void 0:n.call(this,"error","[AdminBox]")},a=window&&window.__awaiter||function(t,s,a,c){return new(a=a||Promise)(function(e,n){function o(t){try{r(c.next(t))}catch(t){n(t)}}function i(t){try{r(c.throw(t))}catch(t){n(t)}}function r(t){var n;t.done?e(t.value):((n=t.value)instanceof a?n:new a(function(t){t(n)})).then(o,i)}r((c=c.apply(t,s||[])).next())})},c=window&&window.__generator||function(e,o){var i,r,s,a={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]},t={next:n(0),throw:n(1),return:n(2)};return"function"==typeof Symbol&&(t[Symbol.iterator]=function(){return this}),t;function n(n){return function(t){return function(n){if(i)throw new TypeError("Generator is already executing.");for(;a;)try{if(i=1,r&&(s=2&n[0]?r.return:n[0]?r.throw||((s=r.return)&&s.call(r),0):r.next)&&!(s=s.call(r,n[1])).done)return s;switch(r=0,(n=s?[2&n[0],s.value]:n)[0]){case 0:case 1:s=n;break;case 4:return a.label++,{value:n[1],done:!1};case 5:a.label++,r=n[1],n=[0];continue;case 7:n=a.ops.pop(),a.trys.pop();continue;default:if(!(s=0<(s=a.trys).length&&s[s.length-1])&&(6===n[0]||2===n[0])){a=0;continue}if(3===n[0]&&(!s||n[1]>s[0]&&n[1]<s[3])){a.label=n[1];break}if(6===n[0]&&a.label<s[1]){a.label=s[1],s=n;break}if(s&&a.label<s[2]){a.label=s[2],a.ops.push(n);break}s[2]&&a.ops.pop(),a.trys.pop();continue}n=o.call(e,a)}catch(t){n=[6,t],r=0}finally{i=s=0}if(5&n[0])throw n[1];return{value:n[0]?n[1]:void 0,done:!0}}([n,t])}}};function i(t,n){var e=n.querySelector("#"+t);return e||((e=document.createElement("div")).setAttribute("id",t),n.appendChild(e)),e}var l=window&&window.__assign||function(){return(l=Object.assign||function(t){for(var n,e=1,o=arguments.length;e<o;e++)for(var i in n=arguments[e])Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i]);return t}).apply(this,arguments)},t=window&&window.__awaiter||function(t,s,a,c){return new(a=a||Promise)(function(e,n){function o(t){try{r(c.next(t))}catch(t){n(t)}}function i(t){try{r(c.throw(t))}catch(t){n(t)}}function r(t){var n;t.done?e(t.value):((n=t.value)instanceof a?n:new a(function(t){t(n)})).then(o,i)}r((c=c.apply(t,s||[])).next())})},u=window&&window.__generator||function(e,o){var i,r,s,a={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]},t={next:n(0),throw:n(1),return:n(2)};return"function"==typeof Symbol&&(t[Symbol.iterator]=function(){return this}),t;function n(n){return function(t){return function(n){if(i)throw new TypeError("Generator is already executing.");for(;a;)try{if(i=1,r&&(s=2&n[0]?r.return:n[0]?r.throw||((s=r.return)&&s.call(r),0):r.next)&&!(s=s.call(r,n[1])).done)return s;switch(r=0,(n=s?[2&n[0],s.value]:n)[0]){case 0:case 1:s=n;break;case 4:return a.label++,{value:n[1],done:!1};case 5:a.label++,r=n[1],n=[0];continue;case 7:n=a.ops.pop(),a.trys.pop();continue;default:if(!(s=0<(s=a.trys).length&&s[s.length-1])&&(6===n[0]||2===n[0])){a=0;continue}if(3===n[0]&&(!s||n[1]>s[0]&&n[1]<s[3])){a.label=n[1];break}if(6===n[0]&&a.label<s[1]){a.label=s[1],s=n;break}if(s&&a.label<s[2]){a.label=s[2],a.ops.push(n);break}s[2]&&a.ops.pop(),a.trys.pop();continue}n=o.call(e,a)}catch(t){n=[6,t],r=0}finally{i=s=0}if(5&n[0])throw n[1];return{value:n[0]?n[1]:void 0,done:!0}}([n,t])}}},e=window&&window.__spreadArrays||function(){for(var t=0,n=0,e=arguments.length;n<e;n++)t+=arguments[n].length;for(var o=Array(t),i=0,n=0;n<e;n++)for(var r=arguments[n],s=0,a=r.length;s<a;s++,i++)o[i]=r[s];return o};function d(t,n){var e=this;this.js=[],this.css=[],this.isOpen=!1,this.loaded=!1,this.name="default",this.cdn="https://fronteggdeveustorage.blob.core.windows.net/admin-box",this.version="latest",this.mount=function(){e.logger.error("App not loaded yet")},this.unmount=function(){e.logger.error("App not loaded yet")},this.logger=new o(!0),this.logger.info("Create shadow dom element"),this.hostEl=i("frontegg-host-"+t,document.body),this.shadowEl=this.hostEl.attachShadow({mode:"open",delegatesFocus:!0}),this.rootEl=i("frontegg-content",this.shadowEl),this.name=t,this.options=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"),t(this,void 0,void 0,function(){var n,e,o;return u(this,function(t){switch(t.label){case 0:return Object.assign(window,{FronteggInjector:d}),n=new d(r,i),e=n.logger,d._apps[r]=n,e.info("Initializing Injector instance"),n.cdn=null!==(s=i.cdn)&&void 0!==s?s:n.cdn,n.cdn=n.cdn.endsWith("/")?n.cdn.substring(0,n.cdn.length-1):n.cdn,e.info("Retrieving version metadata"),[4,function(e,o,i){return a(this,void 0,void 0,function(){var n;return c(this,function(t){switch(t.label){case 0:return e.info("Retrieving version from cdn: "+o+" version: "+i),"latest"!==(n=i)&&"stable"!==n&&"next"!==n&&(n=i+"/config"),[4,fetch(o+"/"+n+".json",{cache:"no-cache"})];case 1:return[2,t.sent().json()]}})})}(e,n.cdn,i.version)];case 1:return o=t.sent(),n.version=o.version,n.js=o.js,n.css=o.css,e.info("Injector instance initialized successfully",l({name:r,cdn:n.version},o)),n.loaded=!0,e.info("Loading entrypoint files"),[4,n.loadEntrypoints()];case 2:return t.sent(),e.info("Entrypoint files loaded successfully"),[2]}})})},d.getInstance=function(t){var n=d._apps[t=void 0===t?"default":t];if(!n)throw Error("injector instance not found for name: "+t+".\nInject.init(options"+("default"===t?"":", '"+t+"'")+") must be called");return n},d.prototype.open=function(){if(!this.loaded)throw Error("Injected app ["+this.name+"] not loaded yet!");this.mount(this.rootEl,this.options),this.isOpen=!0},d.prototype.close=function(){if(!this.loaded)throw Error("Injected app ["+this.name+"] not loaded yet!");this.unmount(this.rootEl),this.isOpen=!1},d.prototype.destroy=function(){delete d._apps[this.name],this.hostEl.remove(),this.logger.info(this.name+" destroyed")},d.prototype.loadEntrypoints=function(){return t(this,void 0,void 0,function(){var n=this;return u(this,function(t){return[2,Promise.all(e(this.js.map(function(t){return n.injectJavascript(n.cdn+"/"+n.version+"/js/"+t)}),this.css.map(function(t){return n.injectCss(n.cdn+"/"+n.version+"/css/"+t)})))]})})},d.prototype.injectJavascript=function(i){return t(this,void 0,void 0,function(){var n,e,o;return u(this,function(t){switch(t.label){case 0:return n=this.logger,"string"!=typeof i&&(i=i.src),n.info("Loading JS file from ",i),[4,fetch(i,{method:"GET",cache:"default"})];case 1:return[4,t.sent().text()];case 2:return e=t.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),n.info("JS loaded successfully",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(){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(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(t="undefined"!=typeof globalThis?globalThis:t||self).AdminBoxInjector=n()}(this,function(){"use strict";var i=function(t,n){var o=this;void 0===t&&(t=!1),this.disabled=t,this.logger=n,this.log=function(t,n,e){return o.disabled?function(){}:"function"==typeof o.logger?o.logger:void 0===console.log.bind?Function.prototype.bind.call(console[t],console,n||"",e||"-"):console[t].bind(console,n||"",e||"-")},this.info=null===(n=this.log)||void 0===n?void 0:n.call(this,"log","%c[AdminBox]","background:#e8e8e8;"),this.warn=null===(n=this.log)||void 0===n?void 0:n.call(this,"warn","[AdminBox]"),this.error=null===(n=this.log)||void 0===n?void 0:n.call(this,"error","[AdminBox]")},c=window&&window.__awaiter||function(t,s,a,c){return new(a=a||Promise)(function(e,n){function o(t){try{r(c.next(t))}catch(t){n(t)}}function i(t){try{r(c.throw(t))}catch(t){n(t)}}function r(t){var n;t.done?e(t.value):((n=t.value)instanceof a?n:new a(function(t){t(n)})).then(o,i)}r((c=c.apply(t,s||[])).next())})},l=window&&window.__generator||function(e,o){var i,r,s,a={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]},t={next:n(0),throw:n(1),return:n(2)};return"function"==typeof Symbol&&(t[Symbol.iterator]=function(){return this}),t;function n(n){return function(t){return function(n){if(i)throw new TypeError("Generator is already executing.");for(;a;)try{if(i=1,r&&(s=2&n[0]?r.return:n[0]?r.throw||((s=r.return)&&s.call(r),0):r.next)&&!(s=s.call(r,n[1])).done)return s;switch(r=0,(n=s?[2&n[0],s.value]:n)[0]){case 0:case 1:s=n;break;case 4:return a.label++,{value:n[1],done:!1};case 5:a.label++,r=n[1],n=[0];continue;case 7:n=a.ops.pop(),a.trys.pop();continue;default:if(!(s=0<(s=a.trys).length&&s[s.length-1])&&(6===n[0]||2===n[0])){a=0;continue}if(3===n[0]&&(!s||n[1]>s[0]&&n[1]<s[3])){a.label=n[1];break}if(6===n[0]&&a.label<s[1]){a.label=s[1],s=n;break}if(s&&a.label<s[2]){a.label=s[2],a.ops.push(n);break}s[2]&&a.ops.pop(),a.trys.pop();continue}n=o.call(e,a)}catch(t){n=[6,t],r=0}finally{i=s=0}if(5&n[0])throw n[1];return{value:n[0]?n[1]:void 0,done:!0}}([n,t])}}};function r(t,n){var e=n.querySelector("#"+t);return e||((e=document.createElement("div")).setAttribute("id",t),n.appendChild(e)),e}var u=window&&window.__assign||function(){return(u=Object.assign||function(t){for(var n,e=1,o=arguments.length;e<o;e++)for(var i in n=arguments[e])Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i]);return t}).apply(this,arguments)},t=window&&window.__awaiter||function(t,s,a,c){return new(a=a||Promise)(function(e,n){function o(t){try{r(c.next(t))}catch(t){n(t)}}function i(t){try{r(c.throw(t))}catch(t){n(t)}}function r(t){var n;t.done?e(t.value):((n=t.value)instanceof a?n:new a(function(t){t(n)})).then(o,i)}r((c=c.apply(t,s||[])).next())})},d=window&&window.__generator||function(e,o){var i,r,s,a={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]},t={next:n(0),throw:n(1),return:n(2)};return"function"==typeof Symbol&&(t[Symbol.iterator]=function(){return this}),t;function n(n){return function(t){return function(n){if(i)throw new TypeError("Generator is already executing.");for(;a;)try{if(i=1,r&&(s=2&n[0]?r.return:n[0]?r.throw||((s=r.return)&&s.call(r),0):r.next)&&!(s=s.call(r,n[1])).done)return s;switch(r=0,(n=s?[2&n[0],s.value]:n)[0]){case 0:case 1:s=n;break;case 4:return a.label++,{value:n[1],done:!1};case 5:a.label++,r=n[1],n=[0];continue;case 7:n=a.ops.pop(),a.trys.pop();continue;default:if(!(s=0<(s=a.trys).length&&s[s.length-1])&&(6===n[0]||2===n[0])){a=0;continue}if(3===n[0]&&(!s||n[1]>s[0]&&n[1]<s[3])){a.label=n[1];break}if(6===n[0]&&a.label<s[1]){a.label=s[1],s=n;break}if(s&&a.label<s[2]){a.label=s[2],a.ops.push(n);break}s[2]&&a.ops.pop(),a.trys.pop();continue}n=o.call(e,a)}catch(t){n=[6,t],r=0}finally{i=s=0}if(5&n[0])throw n[1];return{value:n[0]?n[1]:void 0,done:!0}}([n,t])}}},e=window&&window.__spreadArrays||function(){for(var t=0,n=0,e=arguments.length;n<e;n++)t+=arguments[n].length;for(var o=Array(t),i=0,n=0;n<e;n++)for(var r=arguments[n],s=0,a=r.length;s<a;s++,i++)o[i]=r[s];return o};function f(t,n,e){var o=this;this.key=n,this.js=[],this.css=[],this.isOpen=!1,this.loaded=!1,this.name="default",this.cdn="https://fronteggdeveustorage.blob.core.windows.net/admin-box",this.version="latest",this.mount=function(){o.logger.error("App not loaded yet")},this.unmount=function(){o.logger.error("App not loaded yet")},this.logger=new i(!0),this.logger.info("Create shadow dom element"),this.hostEl=r("frontegg-host-"+t,document.body),this.shadowEl=this.hostEl.attachShadow({mode:"open",delegatesFocus:!0}),this.rootEl=r("frontegg-content",this.shadowEl),this.name=t,this.options=e,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,s){var a;return void 0===r&&(r="default"),void 0===s&&(s="default"),t(this,void 0,void 0,function(){var n,e,o;return d(this,function(t){switch(t.label){case 0:return Object.assign(window,{FronteggConnector:f}),n=new f(r,s,i),e=n.logger,f._apps[r]=n,e.info("Initializing Injector instance"),n.cdn=null!==(a=i.cdn)&&void 0!==a?a:n.cdn,n.cdn=n.cdn.endsWith("/")?n.cdn.substring(0,n.cdn.length-1):n.cdn,e.info("Retrieving version metadata"),[4,function(e,o,i){return c(this,void 0,void 0,function(){var n;return l(this,function(t){switch(t.label){case 0:return e.info("Retrieving version from cdn: "+o+" version: "+i),"latest"!==(n=i)&&"stable"!==n&&"next"!==n&&(n=i+"/config"),[4,fetch(o+"/"+n+".json",{cache:"no-cache"})];case 1:return[2,t.sent().json()]}})})}(e,n.cdn,i.version)];case 1:return o=t.sent(),n.version=o.version,n.js=o.js,n.css=o.css,e.info("Injector instance initialized successfully",u({name:r,cdn:n.version},o)),n.loaded=!0,e.info("Loading entrypoint files"),[4,n.loadEntrypoints()];case 2:return t.sent(),e.info("Entrypoint files loaded successfully"),[2]}})})},f.getInstance=function(t,n){void 0===n&&(n="default");var e=f._apps[t=void 0===t?"default":t];if(!e||e.key!==n)throw delete f._apps[t],Error("injector instance not found for name: "+t+".\nInject.init(options"+("default"===t?"":", '"+t+"'")+") must be called");return e},f.prototype.open=function(){if(!this.loaded)throw Error("Injected app ["+this.name+"] not loaded yet!");this.mount(this.rootEl,this.options),this.isOpen=!0},f.prototype.close=function(){if(!this.loaded)throw Error("Injected app ["+this.name+"] not loaded yet!");this.unmount(this.rootEl),this.isOpen=!1},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 n=this;return d(this,function(t){return[2,Promise.all(e(this.js.map(function(t){return n.injectJavascript(n.cdn+"/"+n.version+"/js/"+t)}),this.css.map(function(t){return n.injectCss(n.cdn+"/"+n.version+"/css/"+t)})))]})})},f.prototype.injectJavascript=function(i){return t(this,void 0,void 0,function(){var n,e,o;return d(this,function(t){switch(t.label){case 0:return n=this.logger,"string"!=typeof i&&(i=i.src),n.info("Loading JS file from ",i),[4,fetch(i,{method:"GET",cache:"default"})];case 1:return[4,t.sent().text()];case 2:return e=t.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 = FronteggConnector.getInstance('"+this.name+"', '"+this.key+"');\n "+e+"\n })();"),o.innerHTML=e,this.shadowEl.appendChild(o),n.info("JS loaded successfully",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(){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});

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc