Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
static get authorizedListener() {
if (!window[LISTENER_KEY]) {
// TODO: get rid of post robot, too heavy for our needs
window[LISTENER_KEY] = new EventEmitter()
postRobot.on('BEARER_AUTHORIZED', ({ data }) => {
window[LISTENER_KEY].emit(authorizeEvent(data.scenarioId || data.integrationId), data)
})
postRobot.on('BEARER_REJECTED', ({ data }) => {
window[LISTENER_KEY].emit(rejectEvent(data.scenarioId || data.integrationId), data)
})
}
return window[LISTENER_KEY]
}
function startPostMessageListener() {
postRobot.CONFIG.LOG_LEVEL = "error";
postRobot.on("bcup-close-dialog", () => {
hideInputDialog();
hideSaveDialog();
});
postRobot.on("bcup-get-url", () => window.location.href);
postRobot.on("bcup-open-url", event => {
const { url } = event.data;
chrome.runtime.sendMessage({ type: "open-tab", url });
});
}
if (storage.isSet(id)) {
return storage.get(id);
} else {
return undefined;
}
}
function check_access(event) {
if (whitelist) {
if (!whitelist.some(o => { return event.origin.endsWith(o) })) {
throw `Access denied from ${event.origin}`
}
}
}
postRobot.on('update', {window: window.parent}, function(event) {
check_access(event);
let entity = event.data.entity;
let storage = _ctx(event.data.context);
let now = _timestamp();
if (entity.entityID && !entity.entity_id) {
entity.entity_id = entity.entityID;
}
let id = entity.entity_id.hexEncode();
let item = get_entity(storage, id);
if (!is_valid(item, now)) {
item = { "last_refresh": now, "last_use": now, "entity": entity };
} else {
item.last_refresh = now;
item.last_use = now;
item.entity = entity;
}
function startPostMessageListener() {
postRobot.CONFIG.LOG_LEVEL = "error";
postRobot.on("bcup-close-dialog", () => {
hideInputDialog();
hideSaveDialog();
});
postRobot.on("bcup-get-url", () => window.location.href);
postRobot.on("bcup-open-url", event => {
const { url } = event.data;
chrome.runtime.sendMessage({ type: "open-tab", url });
});
}
function startPostMessageListener() {
postRobot.CONFIG.LOG_LEVEL = "error";
postRobot.on("bcup-close-dialog", () => {
hideInputDialog();
hideSaveDialog();
});
postRobot.on("bcup-get-url", () => window.location.href);
postRobot.on("bcup-open-url", event => {
const { url } = event.data;
chrome.runtime.sendMessage({ type: "open-tab", url });
});
}
initSession() {
if (this.window !== undefined && !document.querySelector(`#${IFRAME_NAME}`)) {
postRobot.on(Events.SESSION_INITIALIZED, event => {
this.sessionInitialized(event)
})
postRobot.on(Events.AUTHORIZED, this.authorized)
postRobot.on(Events.REVOKED, this.revoked)
this.iframe = document.createElement('iframe')
this.iframe.src = `${this.bearerConfig.authorizationHost}v1/user/initialize`
this.iframe.id = IFRAME_NAME
this.iframe.width = '0'
this.iframe.height = '0'
this.iframe.frameBorder = '0'
this.iframe.style.display = 'none'
document.body.appendChild(this.iframe)
}
}
initSession() {
if (this.window !== undefined && !document.querySelector(`#${IFRAME_NAME}`)) {
postRobot.on(Events.SESSION_INITIALIZED, event => {
this.sessionInitialized(event)
})
postRobot.on(Events.AUTHORIZED, this.authorized)
postRobot.on(Events.REVOKED, this.revoked)
this.iframe = document.createElement('iframe')
this.iframe.src = `${this.bearerConfig.authorizationHost}v1/user/initialize`
this.iframe.id = IFRAME_NAME
this.iframe.width = '0'
this.iframe.height = '0'
this.iframe.frameBorder = '0'
this.iframe.style.display = 'none'
document.body.appendChild(this.iframe)
}
}
initSession() {
if (this.window !== undefined && !document.querySelector(`#${IFRAME_NAME}`)) {
postRobot.on(Events.SESSION_INITIALIZED, event => {
this.sessionInitialized(event)
})
postRobot.on(Events.AUTHORIZED, this.authorized)
postRobot.on(Events.REVOKED, this.revoked)
this.iframe = document.createElement('iframe')
this.iframe.src = `${this.bearerConfig.authorizationHost}v1/user/initialize`
this.iframe.id = IFRAME_NAME
this.iframe.width = '0'
this.iframe.height = '0'
this.iframe.frameBorder = '0'
this.iframe.style.display = 'none'
document.body.appendChild(this.iframe)
}
}
let storage = _ctx(event.data.context);
let entity_id = event.data.entity_id;
if (!entity_id) {
throw new Error("Unable to find entity_id in request")
}
let id = entity_id.hexEncode();
let item = get_entity(storage, id);
if (item) {
let now = _timestamp();
item.last_use = now;
storage.set(id, clean_item(item));
}
return item;
});
postRobot.on('remove', {window: window.parent}, function(event) {
check_access(event);
let storage = _ctx(event.data.context);
let entity_id = event.data.entity_id;
if (entity_id === undefined) {
} else {
storage.remove(entity_id.hexEncode());
}
});