From c2ae3386add857a3a780d9387adae808bdf0f08c Mon Sep 17 00:00:00 2001 From: Simon Lukasik Date: Tue, 5 Jul 2022 16:32:29 +0100 Subject: [PATCH] wip: event_stream example --- examples/browser/event_stream.html | 38 ++++++++++ examples/browser/event_stream.ts | 116 +++++++++++++++++++++++++++++ 2 files changed, 154 insertions(+) create mode 100644 examples/browser/event_stream.html create mode 100644 examples/browser/event_stream.ts diff --git a/examples/browser/event_stream.html b/examples/browser/event_stream.html new file mode 100644 index 00000000..b2d62272 --- /dev/null +++ b/examples/browser/event_stream.html @@ -0,0 +1,38 @@ + + + CrowdStrike Falcon Sensor Download :: Falconjs Example + + + + + +
+
+
+

CrowdStrike API: Please Log in

+ + +
+ + +
+ +
+
+
+ + + + + + diff --git a/examples/browser/event_stream.ts b/examples/browser/event_stream.ts new file mode 100644 index 00000000..25442733 --- /dev/null +++ b/examples/browser/event_stream.ts @@ -0,0 +1,116 @@ +import { FalconClient, FalconErrorExplain, DomainSensorInstallerV1 } from "./../../src"; + +let client: FalconClient | null = null; + +module.exports = { + onLogin: async function () { + client = new FalconClient({ + cloud: "us-1", + clientId: "", + clientSecret: "", + }); + + const appName = "falconjs-my-app-id-1"; + const resp = await client.availableEventStreams(appName) + .then((streams) => { + streams.forEach((stream) => { + const x = stream.process((item) => { + console.log("callback"); + console.log(item); + } + ); + console.log(x); + }) + }) + .catch((err) => { + console.log("Could not list available streams: ", err); + }); + console.log(resp); + }, + downloadSensor: async function (id: string, name: string) { + if (client === null) { + return; + } + await client.sensorDownload + .downloadSensorInstallerById(id) + .catch(async function (err) { + alert("Could not download sensor: " + (await FalconErrorExplain(err))); + }) + .then((blob) => { + saveAs(blob, name); + }); + }, +}; + +function showSensors(sensors: Array) { + const heading = "" + "Description" + "Version" + "OS" + "Download"; + + const data = sensors + .map((sensor) => { + return ( + "
" + + sensor.description + + "
" + + sensor.version + + "" + + sensor.os + + " " + + sensor.osVersion + + "" + + "" + ); + }) + .join(" "); + + show("" + heading + data + "
"); +} + +function show(html: string) { + const main = document.getElementById("loginPopup"); + if (main != null) { + main.innerHTML = html; + } +} + +function closeForm() { + const login = document.getElementById("popupForm"); + if (login != null) { + login.style.display = "none"; + } +} + +function getFormField(fieldName: string): string { + const fields = document.getElementsByName(fieldName); + if (fields != null && fields.length == 1 && fields[0] instanceof HTMLInputElement) { + return fields[0].value; + } + throw "Internal Error: cannot find input element"; +} + +function saveAs(blob: Blob | void, fileName: string) { + if (blob == null) { + return; + } + const url = window.URL.createObjectURL(blob); + const anchorElem = document.createElement("a"); + anchorElem.style.display = "none"; + anchorElem.href = url; + anchorElem.download = fileName; + + document.body.appendChild(anchorElem); + anchorElem.click(); + + document.body.removeChild(anchorElem); + + setTimeout(function () { + window.URL.revokeObjectURL(url); + }, 1000); +}