Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Async error handling and fetch without try-catch.
import { it } from 'avait'
import { readFile } from 'fs/promises'
const { error, value } = await it(readFile('./my-file.txt', 'utf-8'))
if (error) return alert('Error')
console.log(`File contents: ${value}`)
It's possible to resolve multiple promises in a row.
const { error, title } = await it(fetch('https://dummyjson.com/products/1')).add((next) =>
next.json(),
)
// title => 'iPhone 9' or similar.
When an error is thrown but the error
property isn't accessed errors will be sent to any registered error handlers.
import { it, registerErrorHandler } from 'avait'
import { readFile } from 'fs/promises'
registerErrorHandler((error) => alert(error))
const { value } = await it(readFile('./my-file.txt', 'utf-8'))
console.log(`File contents: ${value}`)
It's possible to pass an array of promises. In this case the result value
as well as the error
will also be returned as an array. Using the second argument parallelism can be enabled which leads to the promises being run in parallel.
import { it } from 'avait'
const { value } = await it([firstPromise, secondPromise])
console.log(value[0])
// With parallelism enabled
const { value } = await it([firstPromise, secondPromise], { parallel: true })
console.log(value[1])
fetch
This is a super small wrapper around fetch
that's supposed to make error handling and accessing the data simple.
import { load } from 'avait'
const { error, status, data, text } = await load('http://localhost:3000/api') // GET method
// error: boolean | string, indicating if the request errored.
// status: The HTTP status code.
// data: parsed JSON data if response is JSON.
// text: string, text content if response contains text.
// ...props: For a JSON response top-level object properties will be spread on the return object.
await load('http://localhost:3000/api', { name: 'John Doe' }) // POST method
await load('http://localhost:3000/api', { id: 1, name: 'John Doe' }) // PUT method
await load('http://localhost:3000/api', 1) // DELETE method
[!IMPORTANT] This feature has been removed with Version 2 of this plugin. I haven't found it useful and it currently doensn't work with Bun. Check out make-synchronized if you're looking to provide a synchronized interface to an asynchronous method.
Error handling inspired by await-to-js.
FAQs
Async error handling and fetch without try-catch.
The npm package avait receives a total of 19 weekly downloads. As such, avait popularity was classified as not popular.
We found that avait demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 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’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.