Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
@apiclient.xyz/ghost
Advanced tools
An unofficial Ghost CMS API package enabling content and admin functionality for managing posts.
An unofficial Ghost API package
To install the @apiclient.xyz/ghost package, you can use npm or yarn. Make sure you're using a package manager that supports ESM and TypeScript.
NPM:
npm install @apiclient.xyz/ghost
Yarn:
yarn add @apiclient.xyz/ghost
Below is a detailed guide on how to use the @apiclient.xyz/ghost
package in your TypeScript projects. We will cover everything from initialization to advanced usage scenarios.
First, you need to import the necessary classes and initialize the Ghost instance with the required API keys.
import { Ghost } from '@apiclient.xyz/ghost';
// Initialize the Ghost instance
const ghostInstance = new Ghost({
baseUrl: 'https://your-ghost-url.com',
contentApiKey: 'your-content-api-key',
adminApiKey: 'your-admin-api-key'
});
You can fetch posts with the following method. This will give you an array of Post
instances.
// Fetch all posts
const posts = await ghostInstance.getPosts();
// Print titles of all posts
posts.forEach(post => {
console.log(post.getTitle());
});
To fetch a single post by its ID:
const postId = 'your-post-id';
const post = await ghostInstance.getPostById(postId);
console.log(post.getTitle());
console.log(post.getHtml());
The Post
class has several methods that can be useful for different scenarios.
These methods allow you to retrieve various parts of the post data.
const postId = post.getId();
const postTitle = post.getTitle();
const postHtml = post.getHtml();
const postExcerpt = post.getExcerpt();
const postFeatureImage = post.getFeatureImage();
console.log(`ID: ${postId}`);
console.log(`Title: ${postTitle}`);
console.log(`HTML: ${postHtml}`);
console.log(`Excerpt: ${postExcerpt}`);
console.log(`Feature Image: ${postFeatureImage}`);
To update a post, you can use the update
method. Make sure you have the necessary permissions and fields.
const updatedPostData = {
...post.toJson(),
title: 'Updated Title',
html: '<p>Updated HTML content</p>'
};
await post.update(updatedPostData);
console.log('Post updated successfully');
To delete a post:
await post.delete();
console.log('Post deleted successfully');
You can create a new post using the createPost
method of the Ghost
class.
const newPostData = {
id: 'new-post-id',
title: 'New Post Title',
html: '<p>This is the content of the new post.</p>',
excerpt: 'New post excerpt',
feature_image: 'https://your-image-url.com/image.jpg'
};
const newPost = await ghostInstance.createPost(newPostData);
console.log('New post created successfully');
console.log(`ID: ${newPost.getId()}`);
console.log(`Title: ${newPost.getTitle()}`);
Both the Ghost
and Post
classes throw errors that you can catch and handle.
try {
const posts = await ghostInstance.getPosts();
console.log('Posts fetched successfully');
} catch (error) {
console.error('Error fetching posts:', error);
}
Similarly, for updating or deleting a post:
try {
await post.update({ title: 'Updated Title' });
console.log('Post updated successfully');
} catch (error) {
console.error('Error updating post:', error);
}
try {
await post.delete();
console.log('Post deleted successfully');
} catch (error) {
console.error('Error deleting post:', error);
}
The getPosts
method can accept various filters and options.
const filteredPosts = await ghostInstance.getPosts({ limit: 10, include: 'tags,authors' });
filteredPosts.forEach(post => {
console.log(post.getTitle());
});
To give you a comprehensive understanding, let's look at a couple of example projects.
In this scenario, we will create a simple script to fetch all posts and display their titles.
import { Ghost } from '@apiclient.xyz/ghost';
(async () => {
const ghostInstance = new Ghost({
baseUrl: 'https://your-ghost-url.com',
contentApiKey: 'your-content-api-key',
adminApiKey: 'your-admin-api-key'
});
try {
const posts = await ghostInstance.getPosts();
posts.forEach(post => console.log(post.getTitle()));
} catch (error) {
console.error('Error fetching posts:', error);
}
})();
In this example, let's create a tool that can fetch, create, update, and delete posts.
import { Ghost, Post, IPostOptions } from '@apiclient.xyz/ghost';
const ghostInstance = new Ghost({
baseUrl: 'https://your-ghost-url.com',
contentApiKey: 'your-content-api-key',
adminApiKey: 'your-admin-api-key'
});
(async () => {
// Fetch posts
const posts = await ghostInstance.getPosts();
console.log('Fetched posts:');
posts.forEach(post => console.log(post.getTitle()));
// Create a new post
const newPostData: IPostOptions = {
id: 'new-post-id',
title: 'New Post Title',
html: '<p>This is the content of the new post.</p>',
};
const newPost = await ghostInstance.createPost(newPostData);
console.log('New post created:', newPost.getTitle());
// Update the new post
const updatedPost = await newPost.update({ title: 'Updated Post Title' });
console.log('Post updated:', updatedPost.getTitle());
// Delete the new post
await updatedPost.delete();
console.log('Post deleted');
})();
This package includes unit tests written using the @push.rocks/tapbundle
and @push.rocks/qenv
libraries. Here is how you can run them.
npm install
npm test
The @apiclient.xyz/ghost
package provides a comprehensive and type-safe way to interact with the Ghost CMS API using TypeScript. The features provided by the Ghost
and Post
classes allow for a wide range of interactions, from basic CRUD operations to advanced filtering and error handling.
For more information, please refer to the documentation. undefined
FAQs
An unofficial Ghost CMS API package enabling content and admin functionality for managing posts.
The npm package @apiclient.xyz/ghost receives a total of 5 weekly downloads. As such, @apiclient.xyz/ghost popularity was classified as not popular.
We found that @apiclient.xyz/ghost 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
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.