Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
@octokit/webhooks-types
Advanced tools
Generated TypeScript definitions based on community contributed JSON Schemas
@octokit/webhooks-types is an npm package that provides TypeScript definitions for GitHub webhook events. It helps developers to type-check their code when handling GitHub webhooks, ensuring that they are using the correct event payloads and properties.
Type Definitions for Webhook Events
This feature provides type definitions for various GitHub webhook events, such as 'push', 'pull_request', etc. The code sample demonstrates how to handle a 'push' event with type safety.
const { WebhookEvent } = require('@octokit/webhooks-types');
/**
* Example of handling a 'push' event
* @param {WebhookEvent<'push'>} event - The push event payload
*/
function handlePushEvent(event) {
console.log(`Received a push event for ${event.payload.repository.full_name}`);
console.log(`Pushed by: ${event.payload.pusher.name}`);
}
// Example payload
const pushEventPayload = {
payload: {
repository: { full_name: 'octocat/Hello-World' },
pusher: { name: 'octocat' }
}
};
handlePushEvent(pushEventPayload);
TypeScript Support
This feature ensures that developers can use TypeScript to handle GitHub webhook events with type safety. The code sample demonstrates handling a 'pull_request' event with TypeScript.
import { WebhookEvent } from '@octokit/webhooks-types';
/**
* Example of handling a 'pull_request' event
* @param {WebhookEvent<'pull_request'>} event - The pull request event payload
*/
function handlePullRequestEvent(event: WebhookEvent<'pull_request'>) {
console.log(`Received a pull request event for ${event.payload.repository.full_name}`);
console.log(`Action: ${event.payload.action}`);
}
// Example payload
const pullRequestEventPayload = {
payload: {
repository: { full_name: 'octocat/Hello-World' },
action: 'opened'
}
};
handlePullRequestEvent(pullRequestEventPayload);
Probot is a framework for building GitHub Apps to automate and improve workflows. It provides tools for handling webhook events, managing app authentication, and more. While Probot offers a higher-level abstraction for building GitHub Apps, @octokit/webhooks-types focuses on providing type definitions for webhook events.
node-github-webhook is a lightweight package for handling GitHub webhook events in Node.js. It provides basic functionality for setting up a webhook listener and processing events. Compared to @octokit/webhooks-types, it is more focused on the event handling aspect and does not provide TypeScript type definitions.
machine-readable, always up-to-date GitHub Webhooks specifications
Download the latest specification at octokit.github.io/webhooks/payload-examples/api.github.com/index.json
This package ships with types for the webhook events generated from the respective json schemas, which you can use like so:
import { WebhookEvent, IssuesOpenedEvent } from "@octokit/webhooks-types";
const handleWebhookEvent = (event: WebhookEvent) => {
if ("action" in event && event.action === "completed") {
console.log(`${event.sender.login} completed something!`);
}
};
const handleIssuesOpenedEvent = (event: IssuesOpenedEvent) => {
console.log(
`${event.sender.login} opened "${event.issue.title}" on ${event.repository.full_name}`,
);
};
⚠️ Caution ⚠️: Webhooks Types are expected to be used with the strictNullChecks
option enabled in your tsconfig
. If you don't have this option enabled, there's the possibility that you get never
as the inferred type in some use cases. See #395 for details.
FAQs
Generated TypeScript definitions based on community contributed JSON Schemas
The npm package @octokit/webhooks-types receives a total of 872,986 weekly downloads. As such, @octokit/webhooks-types popularity was classified as popular.
We found that @octokit/webhooks-types 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.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.