Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
@equinor/fusion
Advanced tools
Everything a Fusion app needs to communicate with the core.
$ yarn add @equinor/fusion
$ npm install @equinor/fusion --save
import React from "react";
import { Spinner } from "@equinor/fusion-components";
import { useCurrentUser } from "@equinor/fusion";
const MyComponent = () => {
const currentUser = useCurrentUser();
// Current user might not be retrieved from the cache when the component loads,
// So check for nulL!
if(currentUser == null) {
return <Spinner />;
}
return (
<h1>Hi {currentUser.name}!</h1>
);
};
export default MyComponent;
import React from "react";
import { Spinner } from "@equinor/fusion-components";
import { useCurrentContext, ContextTypes, useHandover, useHandoverMcpkgs } from "@equinor/fusion";
const MyHandoverCommpkgDetails = ({ id }) => {
const currentProject = useCurrentContext(ContextTypes.PDP);
const [isFetching, handoverMcpkgs] = useHandoverMcpkgs(currentProject, id);
if(isFetching) {
return <Spinner />;
}
return (
<ul>
{handoverMcpkgs.map(mcpkg => (
<li>
{mcpkg.mcPkgNo}
</li>
))}
</ul>
);
};
const MyHandoverComponent = () => {
const currentProject = useCurrentContext(ContextTypes.PDP);
const [isFetching, handoverData] = useHandover(currentProject);
if(isFetching) {
return <Spinner />;
}
return (
<ul>
{handoverData.map(handoverItem => (
<li>
<h2>{handoverItem.commpkgNo}</h2>
<MyHandoverCommpkgDetails id={handoverItem.id} />
</li>
))}
</ul>
);
};
export default MyComponent;
Core settings are read-only for apps
import React from "react";
import { useCoreSettings, ComponentDisplayTypes } from "@equinor/fusion";
const MyComponent = () => {
const coreSettings = useCoreSettings();
if(coreSettings.componentDisplayType === ComponentDisplayTypes.Compact) {
return (<span>Looks like you prefere compact mode!</span>);
} else {
return (<h2>Some more spacing for you!</h2>)
}
};
export default MyComponent;
App settings are automatically scoped to the current app
import React from "react";
import { Button } from "@equinor/fusion-components";
import { useAppSettings } from "@equinor/fusion";
const MyComponent = () => {
const [appSettings, setAppSettings] = useAppSettings();
return (
<Button
primary contained
onClick={() => setAppSettings("toggle", !appSettings.toggle)}
>
Click to toggle {appSettings.toggle ? "On" : "Off"}
</Button>
);
};
export default MyComponent;
import React, { useRef } from "react";
import { render } from "react-dom";
import { Router } from "react-router";
import { createBrowserHistory } from "history";
import {
AuthContainer,
createFusionContext,
FusionContext,
ServiceResolver,
} from "@equinor/fusion";
const serviceResolver: ServiceResolver = {
getDataProxyUrl: () => "http://api.url.com",
getOrgUrl: () => "http://api.url.com",
};
const start = async () => {
const authContainer = new AuthContainer();
// Handle redirect from login
await authContainer.handleWindowCallbackAsync();
// Register the main fusion AAD app (get the client id from config)
const coreAppClientId = "{client-id}";
const coreAppRegistered = await authContainer.registerAppAsync(
coreAppClientId,
[serviceResolver.getDataProxyUrl(), serviceResolver.getOrgUrl()]
);
if(!coreAppRegistered) {
authContainer.login(coreAppClientId);
} else {
const Root = () => {
const root = useRef();
const overlay = useRef();
const fusionContext = createFusionContext(
authContainer,
serviceResolver,
{ root, overlay, }
);
return (
<Router history={fusionContext.history}>
<FusionContext.Provider value={fusionContext}>
<div id="fusion-root" ref={rootRef}>
{/* The app component goes here */}
</div>
<div id="overlay-container" ref={overlayRef}>
{/* Leave this empty. Used for dialogs, popovers, tooltips etc. */}
</div>
</FusionContext.Provider>
</Router>
);
};
render(<Root />, document.getElementById("app"));
}
};
start();
This hook will make an HTTP callback abortable, i.e allows for cancellation of a pending HTTP request. The HTTP callback in the example below is defined as executeRequest
, which will make an HTTP request towards some API client. The callback will be made abortable when the callback is passed onto the useAbortableRequest
hook, with the custom abort signal handler onAbort
. E.g if the abortable callback onInput
initiates a request, but the MyComponents
component is unmounted, the initiated HTTP request will be cancelled.
export const MyComponents = () => {
const {someClient} = useApiClients();
const [state, setState] = useState();
const [error, setError] = useState();
const [loading, setLoading] = useState();
const executeRequest = useCallback(async(e: Event) => {
try{
setLoading(true);
const response = someClient.getFoo(e.target.value);
setState(response);
} catch (e) {
setError(e.message);
} finally (){
setLoading(false);
}
}, [someClient]);
const onAbort = useCallback(() => console.debug('request was aborted'));
const onInput = useAbortableRequest(executeRequest, onAbort);
return (
<div>
<input type="text" onInput={onInput} />
<span>${state}</span>
</div>
}
FAQs
Everything a Fusion app needs to communicate with the core
The npm package @equinor/fusion receives a total of 716 weekly downloads. As such, @equinor/fusion popularity was classified as not popular.
We found that @equinor/fusion demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.