
Security News
The Hidden Blast Radius of the Axios Compromise
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.
A fluent js/ts implementation of the result monad, utilizing Happy/Sad path terminology.
The twitten library lets you handle errors in JavaScript and TypeScript in a type safe and expressive way. The way this is done is nothing new, especially if you're familiar with how success and error cases are handled in the functional world. What's unique as far as I know is that this little library utlize 'Happy & Sad path' temrinology drawn from the world of testing.
function createUser(uname: string, pw: string): User {
if (!(uname && pw))
throw new Error("Validation failed!");
return { username: uname, password: pw };
}
try {
const user = createUser("John Doe", "hello123");
console.log(user.username, user.password);
} catch (error) {
throw error;
}
This approach makes our code harder to reason about than it has to be. Since js and ts does not allow us to embedd the throw jump statement in our function and method signatures, we have to rip up the hood and read the implementation details for clues to what errors we could handle.
There's more to it than that! Like other jump statements the throw statement makes the control flow of our applications harder to reason about. The control flow following an expected path from module a -> b -> c... is disturbed. We could have the control go from module a -> d... or a -> b -> c -> g -> p -> x..-. There are many possibilites, and its hard to reason about!
Adding to the stack of hard to reasons, js and ts doesn't have the powerful catch clause that we know from languages like C#.
import { Path, Happy, Sad } from "twitten"function createUser(uname: string, pw: string): Path<User> {
if (!(uname && pw))
return Sad.path(new Error("Something went wrong!"));
return Happy.path({ username: uname, password: pw });
}
//Must do explicit type checking before we know the correct type of outcome
const user = createUser("John Doe", "hello123");
if (Path.isHappy(user.outcome))
console.log(user.outcome.username, user.outcome.password);
else //outcome.message refers to 'Error.message'
console.log(user.outcome.message);
const user = createUser("John Doe", "hello123");
user.onHappyPath(usr => console.log(usr.username, usr.password))
.onSadPath(error => console.log(error.message));
const user = createUser("John Doe", "hello123");
user.onHappyPath(usr => {
console.log(usr.username, usr.password);
return usr;
}).onHappyPath(usr => usr.username.replace(" ", "_"))
.onHappyPath(uname => console.log(uname));
By embedding errors within the type system, we force awarness of potential failures upon consumers of our code. By doing so we make a clear distinction between unexpected and exceptional errors (exceptions) on one side, and expected errors (sad paths) on the other.
If an exception bubbles up to the end-user it will not have anything to with the expected like a input validation error, so we know that something went seriously wrong.
FAQs
A fluent js/ts implementation of the result monad, utilizing Happy/Sad path terminology.
We found that twitten demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.

Research
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.

Research
Malicious versions of the Telnyx Python SDK on PyPI delivered credential-stealing malware via a multi-stage supply chain attack.