feat(apiclient): Add native Admin & Content API clients, JWT generator, and tag visibility features; remove external @tryghost deps and update docs
This commit is contained in:
@@ -22,13 +22,13 @@ export class Ghost {
|
||||
this.adminApi = new plugins.GhostAdminAPI({
|
||||
url: this.options.baseUrl,
|
||||
key: this.options.adminApiKey,
|
||||
version: 'v3',
|
||||
version: 'v6.0',
|
||||
});
|
||||
|
||||
this.contentApi = new plugins.GhostContentAPI({
|
||||
url: this.options.baseUrl,
|
||||
key: this.options.contentApiKey,
|
||||
version: 'v3',
|
||||
version: 'v6.0',
|
||||
});
|
||||
}
|
||||
|
||||
@@ -95,22 +95,50 @@ export class Ghost {
|
||||
return new Post(this, postData);
|
||||
}
|
||||
|
||||
public async getTags(optionsArg?: { filter?: string; limit?: number }): Promise<ITag[]> {
|
||||
public async getTags(optionsArg?: {
|
||||
filter?: string;
|
||||
limit?: number;
|
||||
visibility?: 'public' | 'internal' | 'all';
|
||||
include?: string;
|
||||
}): Promise<ITag[]> {
|
||||
try {
|
||||
const limit = optionsArg?.limit || 1000;
|
||||
const tagsData = await this.contentApi.tags.browse({ limit });
|
||||
|
||||
const visibility = optionsArg?.visibility || 'all';
|
||||
|
||||
// Use Admin API to get ALL tags including those with zero posts
|
||||
const browseOptions: any = { limit };
|
||||
|
||||
// Add visibility filter if not 'all'
|
||||
if (visibility !== 'all') {
|
||||
browseOptions.filter = `visibility:${visibility}`;
|
||||
}
|
||||
|
||||
if (optionsArg?.include) {
|
||||
browseOptions.include = optionsArg.include;
|
||||
}
|
||||
|
||||
const tagsData = await this.adminApi.tags.browse(browseOptions);
|
||||
|
||||
// Apply minimatch filter if provided
|
||||
if (optionsArg?.filter) {
|
||||
const matcher = new plugins.smartmatch.SmartMatch(optionsArg.filter);
|
||||
return tagsData.filter((tag: ITag) => matcher.match(tag.slug));
|
||||
}
|
||||
|
||||
|
||||
return tagsData;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
public async getPublicTags(optionsArg?: { filter?: string; limit?: number }): Promise<ITag[]> {
|
||||
return this.getTags({ ...optionsArg, visibility: 'public' });
|
||||
}
|
||||
|
||||
public async getInternalTags(optionsArg?: { filter?: string; limit?: number }): Promise<ITag[]> {
|
||||
return this.getTags({ ...optionsArg, visibility: 'internal' });
|
||||
}
|
||||
|
||||
public async getTagById(id: string): Promise<Tag> {
|
||||
try {
|
||||
const tagData = await this.contentApi.tags.read({ id });
|
||||
|
Reference in New Issue
Block a user