@readpress/wp-blog 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -4
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/index.mjs +2 -2
- package/dist/react.d.mts +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/types-D8A_jJkk.d.mts +248 -0
- package/dist/types-D8A_jJkk.d.ts +248 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
A minimal, read-only headless WordPress blog adapter for modern web apps. Useful when you already have a web app and want to ship a fast, reliable blog from a WordPress installation.
|
|
4
4
|
|
|
5
|
-
- Fetch
|
|
6
|
-
- Supports
|
|
7
|
-
- Framework-agnostic core with Next.js App Router
|
|
8
|
-
- Read-only
|
|
5
|
+
- Fetch posts, authors, categories, and tags; includes post search
|
|
6
|
+
- Supports draft/private reads for preview flows with auth
|
|
7
|
+
- Framework-agnostic core with Next.js App Router examples
|
|
8
|
+
- Read-only API (no write/update operations)
|
|
9
9
|
|
|
10
10
|
## Requirements
|
|
11
11
|
|
|
@@ -26,10 +26,36 @@ Required:
|
|
|
26
26
|
WP_URL=https://example.com
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
+
Optional (if your posts endpoint is not the default `/wp-json/wp/v2/posts`):
|
|
30
|
+
|
|
31
|
+
```env
|
|
32
|
+
WP_REST_ENDPOINT=/wp-json/wp/v2/posts
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Recommended setup for production apps
|
|
36
|
+
|
|
37
|
+
- Configure `rewriteLinks` so internal links in WordPress content stay inside your app routes (for example `/blog/...`) instead of sending users to raw WordPress URLs.
|
|
38
|
+
- Configure `classNameMap` to replace class names in post HTML fetched from WordPress into your app (e.g., replace Gutenberg block class names with Tailwind classes in Next.js).
|
|
39
|
+
|
|
29
40
|
## Quick start
|
|
30
41
|
See docs/quickstart.mdx
|
|
31
42
|
|
|
43
|
+
## AI-ready docs
|
|
44
|
+
|
|
45
|
+
This repo has clear docs with examples to support rapid setup with AI coding agents (e.g., Codex, Cursor).
|
|
46
|
+
|
|
47
|
+
Recommended:
|
|
48
|
+
- Connect your agent to GitHub MCP so it can read docs directly from this repository.
|
|
49
|
+
- Or point your agent to the `docs/` folder in this repo on GitHub.
|
|
50
|
+
|
|
32
51
|
## Examples
|
|
33
52
|
- `examples/nextjs-blog`
|
|
34
53
|
- `examples/gutenberg-blocks-tailwind`
|
|
35
54
|
- `examples/nextjs-post-components`
|
|
55
|
+
|
|
56
|
+
## Advanced guides
|
|
57
|
+
|
|
58
|
+
- Drafts and preview: `docs/guides/drafts-and-preview.mdx`
|
|
59
|
+
- SEO in Next.js: `docs/recipes/seo-nextjs.mdx`
|
|
60
|
+
- Link rewriting: `docs/content/link-rewriting.mdx`
|
|
61
|
+
- Class mapping (custom class names): `docs/content/class-mapping.mdx`
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { P as PlaceholderParseOptions, W as WpContentPart, a as WpClientOptions, b as WpBlogClient, c as WpAuthor, G as GetAuthorsParams, d as GetTermsParams, B as BlogTerm, e as BlogPostField, f as GetPostParams, S as SelectFields, g as BlogPost, h as BlogPostSummaryField, i as GetPostsParams, j as PostListResult, k as BlogPostSummary, Q as QueryGraphqlParams, l as QueryGraphqlResult, m as QueryRawParams, n as SearchPostsParams } from './types-
|
|
2
|
-
export { o as BlogAuthor, p as BlogTermOrder, q as BlogTextMode, C as ClassNameMap, r as ClassNameMapMode, s as ClassNameMapRule, t as ClassNameMapValue, H as HtmlContentPart, L as LinkRewriteContext, u as LinkRewriteRule, v as PaginationMeta, w as PlaceholderContentPart, x as PlaceholderProps, y as QueryRawRestInput, z as WpAuthConfig, A as WpAuthResolvedConfig, D as WpAuthType, E as WpEmbedded, F as WpFeaturedMedia, I as WpPost, J as WpRenderedField, K as WpTerm } from './types-
|
|
1
|
+
import { P as PlaceholderParseOptions, W as WpContentPart, a as WpClientOptions, b as WpBlogClient, c as WpAuthor, G as GetAuthorsParams, d as GetTermsParams, B as BlogTerm, e as BlogPostField, f as GetPostParams, S as SelectFields, g as BlogPost, h as BlogPostSummaryField, i as GetPostsParams, j as PostListResult, k as BlogPostSummary, Q as QueryGraphqlParams, l as QueryGraphqlResult, m as QueryRawParams, n as SearchPostsParams } from './types-D8A_jJkk.mjs';
|
|
2
|
+
export { o as BlogAuthor, p as BlogTermOrder, q as BlogTextMode, C as ClassNameMap, r as ClassNameMapMode, s as ClassNameMapRule, t as ClassNameMapValue, H as HtmlContentPart, L as LinkRewriteContext, u as LinkRewriteRule, v as PaginationMeta, w as PlaceholderContentPart, x as PlaceholderProps, y as QueryRawRestInput, z as WpAuthConfig, A as WpAuthResolvedConfig, D as WpAuthType, E as WpEmbedded, F as WpFeaturedMedia, I as WpPost, J as WpRenderedField, K as WpTerm } from './types-D8A_jJkk.mjs';
|
|
3
3
|
|
|
4
4
|
type WpClientErrorCode = "INVALID_CONFIG" | "INVALID_INPUT" | "REQUEST_FAILED" | "INVALID_RESPONSE";
|
|
5
5
|
interface WpApiErrorDetails {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { P as PlaceholderParseOptions, W as WpContentPart, a as WpClientOptions, b as WpBlogClient, c as WpAuthor, G as GetAuthorsParams, d as GetTermsParams, B as BlogTerm, e as BlogPostField, f as GetPostParams, S as SelectFields, g as BlogPost, h as BlogPostSummaryField, i as GetPostsParams, j as PostListResult, k as BlogPostSummary, Q as QueryGraphqlParams, l as QueryGraphqlResult, m as QueryRawParams, n as SearchPostsParams } from './types-
|
|
2
|
-
export { o as BlogAuthor, p as BlogTermOrder, q as BlogTextMode, C as ClassNameMap, r as ClassNameMapMode, s as ClassNameMapRule, t as ClassNameMapValue, H as HtmlContentPart, L as LinkRewriteContext, u as LinkRewriteRule, v as PaginationMeta, w as PlaceholderContentPart, x as PlaceholderProps, y as QueryRawRestInput, z as WpAuthConfig, A as WpAuthResolvedConfig, D as WpAuthType, E as WpEmbedded, F as WpFeaturedMedia, I as WpPost, J as WpRenderedField, K as WpTerm } from './types-
|
|
1
|
+
import { P as PlaceholderParseOptions, W as WpContentPart, a as WpClientOptions, b as WpBlogClient, c as WpAuthor, G as GetAuthorsParams, d as GetTermsParams, B as BlogTerm, e as BlogPostField, f as GetPostParams, S as SelectFields, g as BlogPost, h as BlogPostSummaryField, i as GetPostsParams, j as PostListResult, k as BlogPostSummary, Q as QueryGraphqlParams, l as QueryGraphqlResult, m as QueryRawParams, n as SearchPostsParams } from './types-D8A_jJkk.js';
|
|
2
|
+
export { o as BlogAuthor, p as BlogTermOrder, q as BlogTextMode, C as ClassNameMap, r as ClassNameMapMode, s as ClassNameMapRule, t as ClassNameMapValue, H as HtmlContentPart, L as LinkRewriteContext, u as LinkRewriteRule, v as PaginationMeta, w as PlaceholderContentPart, x as PlaceholderProps, y as QueryRawRestInput, z as WpAuthConfig, A as WpAuthResolvedConfig, D as WpAuthType, E as WpEmbedded, F as WpFeaturedMedia, I as WpPost, J as WpRenderedField, K as WpTerm } from './types-D8A_jJkk.js';
|
|
3
3
|
|
|
4
4
|
type WpClientErrorCode = "INVALID_CONFIG" | "INVALID_INPUT" | "REQUEST_FAILED" | "INVALID_RESPONSE";
|
|
5
5
|
interface WpApiErrorDetails {
|
package/dist/index.js
CHANGED
|
@@ -336,8 +336,8 @@ function resolveClientOptions(options = {}) {
|
|
|
336
336
|
}
|
|
337
337
|
const perPage = (_c = options.perPage) != null ? _c : DEFAULT_PER_PAGE;
|
|
338
338
|
const endpoint = normalizePathOrUrl(
|
|
339
|
-
(_e = (_d = options.endpoint) != null ? _d : readEnv("
|
|
340
|
-
"
|
|
339
|
+
(_e = (_d = options.endpoint) != null ? _d : readEnv("WP_REST_ENDPOINT")) != null ? _e : DEFAULT_ENDPOINT,
|
|
340
|
+
"WP_REST_ENDPOINT"
|
|
341
341
|
);
|
|
342
342
|
return {
|
|
343
343
|
wpUrl: normalizeWpUrl(wpUrl),
|
package/dist/index.mjs
CHANGED
|
@@ -207,8 +207,8 @@ function resolveClientOptions(options = {}) {
|
|
|
207
207
|
}
|
|
208
208
|
const perPage = (_c = options.perPage) != null ? _c : DEFAULT_PER_PAGE;
|
|
209
209
|
const endpoint = normalizePathOrUrl(
|
|
210
|
-
(_e = (_d = options.endpoint) != null ? _d : readEnv("
|
|
211
|
-
"
|
|
210
|
+
(_e = (_d = options.endpoint) != null ? _d : readEnv("WP_REST_ENDPOINT")) != null ? _e : DEFAULT_ENDPOINT,
|
|
211
|
+
"WP_REST_ENDPOINT"
|
|
212
212
|
);
|
|
213
213
|
return {
|
|
214
214
|
wpUrl: normalizeWpUrl(wpUrl),
|
package/dist/react.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { ComponentType } from 'react';
|
|
3
|
-
import { W as WpContentPart } from './types-
|
|
3
|
+
import { W as WpContentPart } from './types-D8A_jJkk.mjs';
|
|
4
4
|
|
|
5
5
|
type WpPlaceholderComponents = Record<string, ComponentType<Record<string, unknown>>>;
|
|
6
6
|
interface WpContentProps {
|
package/dist/react.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { ComponentType } from 'react';
|
|
3
|
-
import { W as WpContentPart } from './types-
|
|
3
|
+
import { W as WpContentPart } from './types-D8A_jJkk.js';
|
|
4
4
|
|
|
5
5
|
type WpPlaceholderComponents = Record<string, ComponentType<Record<string, unknown>>>;
|
|
6
6
|
interface WpContentProps {
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
interface WpRenderedField {
|
|
2
|
+
rendered: string;
|
|
3
|
+
}
|
|
4
|
+
interface WpFeaturedMedia {
|
|
5
|
+
source_url?: string;
|
|
6
|
+
}
|
|
7
|
+
interface WpTerm {
|
|
8
|
+
id: number;
|
|
9
|
+
slug?: string;
|
|
10
|
+
name?: string;
|
|
11
|
+
taxonomy?: string;
|
|
12
|
+
count?: number;
|
|
13
|
+
}
|
|
14
|
+
interface WpAuthor {
|
|
15
|
+
id: number;
|
|
16
|
+
name?: string;
|
|
17
|
+
slug?: string;
|
|
18
|
+
url?: string;
|
|
19
|
+
description?: string;
|
|
20
|
+
link?: string;
|
|
21
|
+
avatar_urls?: Record<string, string>;
|
|
22
|
+
[key: string]: unknown;
|
|
23
|
+
}
|
|
24
|
+
interface WpEmbedded {
|
|
25
|
+
"wp:featuredmedia"?: WpFeaturedMedia[];
|
|
26
|
+
"wp:term"?: WpTerm[][];
|
|
27
|
+
author?: WpAuthor[];
|
|
28
|
+
}
|
|
29
|
+
interface WpPost {
|
|
30
|
+
id: number;
|
|
31
|
+
slug: string;
|
|
32
|
+
link: string;
|
|
33
|
+
date: string;
|
|
34
|
+
modified: string;
|
|
35
|
+
title: WpRenderedField;
|
|
36
|
+
excerpt: WpRenderedField;
|
|
37
|
+
content: WpRenderedField;
|
|
38
|
+
_embedded?: WpEmbedded;
|
|
39
|
+
}
|
|
40
|
+
interface LinkRewriteContext {
|
|
41
|
+
href: string;
|
|
42
|
+
pathname: string;
|
|
43
|
+
search: string;
|
|
44
|
+
hash: string;
|
|
45
|
+
}
|
|
46
|
+
interface LinkRewriteRule {
|
|
47
|
+
source: string;
|
|
48
|
+
destination?: string;
|
|
49
|
+
action?: "ignore";
|
|
50
|
+
transform?: (context: LinkRewriteContext) => string;
|
|
51
|
+
}
|
|
52
|
+
type ClassNameMapMode = "append" | "replace" | "replace-all";
|
|
53
|
+
interface ClassNameMapRule {
|
|
54
|
+
className: string;
|
|
55
|
+
mode?: ClassNameMapMode;
|
|
56
|
+
}
|
|
57
|
+
type ClassNameMapValue = string | ClassNameMapRule;
|
|
58
|
+
type ClassNameMap = Record<string, ClassNameMapValue>;
|
|
59
|
+
type PlaceholderProps = Record<string, unknown>;
|
|
60
|
+
interface HtmlContentPart {
|
|
61
|
+
type: "html";
|
|
62
|
+
html: string;
|
|
63
|
+
}
|
|
64
|
+
interface PlaceholderContentPart {
|
|
65
|
+
type: "placeholder";
|
|
66
|
+
name: string;
|
|
67
|
+
props: PlaceholderProps;
|
|
68
|
+
}
|
|
69
|
+
type WpContentPart = HtmlContentPart | PlaceholderContentPart;
|
|
70
|
+
interface PlaceholderParseOptions {
|
|
71
|
+
namespace?: string;
|
|
72
|
+
maxPropsLength?: number;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Normalized post shape returned by this package.
|
|
76
|
+
*/
|
|
77
|
+
interface BlogPostSummary {
|
|
78
|
+
id: number;
|
|
79
|
+
slug: string;
|
|
80
|
+
url: string;
|
|
81
|
+
date: string;
|
|
82
|
+
modified: string;
|
|
83
|
+
publishedDate: string;
|
|
84
|
+
updatedDate: string;
|
|
85
|
+
title: string;
|
|
86
|
+
excerpt: string;
|
|
87
|
+
featuredImageUrl: string | null;
|
|
88
|
+
author: BlogAuthor | null;
|
|
89
|
+
categories: BlogTerm[];
|
|
90
|
+
tags: BlogTerm[];
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Full post shape returned by single-post methods.
|
|
94
|
+
*/
|
|
95
|
+
interface BlogPost extends BlogPostSummary {
|
|
96
|
+
contentHtml: string;
|
|
97
|
+
}
|
|
98
|
+
interface BlogTerm {
|
|
99
|
+
id: number;
|
|
100
|
+
slug: string;
|
|
101
|
+
name: string;
|
|
102
|
+
count: number;
|
|
103
|
+
}
|
|
104
|
+
type BlogAuthor = WpAuthor;
|
|
105
|
+
type BlogTermOrder = "default" | "alphabetical" | "count";
|
|
106
|
+
interface GetTermsParams {
|
|
107
|
+
order?: BlogTermOrder;
|
|
108
|
+
}
|
|
109
|
+
interface GetAuthorsParams {
|
|
110
|
+
page?: number;
|
|
111
|
+
perPage?: number;
|
|
112
|
+
}
|
|
113
|
+
type BlogTextMode = "plain" | "html";
|
|
114
|
+
type BlogPostSummaryField = keyof BlogPostSummary;
|
|
115
|
+
type BlogPostField = keyof BlogPost;
|
|
116
|
+
type SelectFields<T, TSelect extends readonly (keyof T)[] | undefined> = TSelect extends readonly (keyof T)[] ? Pick<T, TSelect[number]> : T;
|
|
117
|
+
/**
|
|
118
|
+
* Pagination metadata returned from list endpoints.
|
|
119
|
+
*/
|
|
120
|
+
interface PaginationMeta {
|
|
121
|
+
page: number;
|
|
122
|
+
perPage: number;
|
|
123
|
+
totalItems: number;
|
|
124
|
+
totalPages: number;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Response returned by getPosts.
|
|
128
|
+
*/
|
|
129
|
+
interface PostListResult<TItem = BlogPostSummary> {
|
|
130
|
+
items: TItem[];
|
|
131
|
+
pagination: PaginationMeta;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Optional pagination parameters for getPosts.
|
|
135
|
+
*/
|
|
136
|
+
interface GetPostsParams<TSelect extends readonly BlogPostSummaryField[] | undefined = undefined> {
|
|
137
|
+
page?: number;
|
|
138
|
+
perPage?: number;
|
|
139
|
+
status?: "draft" | "private" | "publish" | "any";
|
|
140
|
+
categorySlug?: string;
|
|
141
|
+
tagSlug?: string;
|
|
142
|
+
textMode?: BlogTextMode;
|
|
143
|
+
select?: TSelect;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Parameters for searching published posts.
|
|
147
|
+
*/
|
|
148
|
+
interface SearchPostsParams<TSelect extends readonly BlogPostSummaryField[] | undefined = undefined> extends GetPostsParams<TSelect> {
|
|
149
|
+
query: string;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Options for creating an explicit WordPress client.
|
|
153
|
+
*/
|
|
154
|
+
interface WpClientOptions {
|
|
155
|
+
wpUrl?: string;
|
|
156
|
+
endpoint?: string;
|
|
157
|
+
perPage?: number;
|
|
158
|
+
auth?: WpAuthConfig;
|
|
159
|
+
rewriteLinks?: LinkRewriteRule[];
|
|
160
|
+
classNameMap?: ClassNameMap;
|
|
161
|
+
fetchImpl?: typeof fetch;
|
|
162
|
+
requestInit?: RequestInit;
|
|
163
|
+
}
|
|
164
|
+
type WpAuthType = "none" | "basic" | "bearer" | "headers";
|
|
165
|
+
interface WpAuthConfig {
|
|
166
|
+
type?: WpAuthType;
|
|
167
|
+
user?: string;
|
|
168
|
+
appPassword?: string;
|
|
169
|
+
token?: string;
|
|
170
|
+
headers?: Record<string, string>;
|
|
171
|
+
}
|
|
172
|
+
interface WpAuthResolvedConfig {
|
|
173
|
+
type: WpAuthType;
|
|
174
|
+
user?: string;
|
|
175
|
+
appPassword?: string;
|
|
176
|
+
token?: string;
|
|
177
|
+
headers?: Record<string, string>;
|
|
178
|
+
}
|
|
179
|
+
interface GetPostParams<TSelect extends readonly BlogPostField[] | undefined = undefined> {
|
|
180
|
+
status?: "draft" | "private" | "publish" | "any";
|
|
181
|
+
textMode?: BlogTextMode;
|
|
182
|
+
select?: TSelect;
|
|
183
|
+
}
|
|
184
|
+
interface QueryRawRestInput {
|
|
185
|
+
path: string;
|
|
186
|
+
params?: Record<string, string | number | boolean | null | undefined>;
|
|
187
|
+
method?: string;
|
|
188
|
+
body?: unknown;
|
|
189
|
+
headers?: Record<string, string>;
|
|
190
|
+
}
|
|
191
|
+
interface QueryRawParams {
|
|
192
|
+
rest?: QueryRawRestInput;
|
|
193
|
+
authRequired?: boolean;
|
|
194
|
+
}
|
|
195
|
+
interface QueryGraphqlParams {
|
|
196
|
+
query: string;
|
|
197
|
+
variables?: Record<string, unknown>;
|
|
198
|
+
}
|
|
199
|
+
interface QueryGraphqlResult<TData = unknown> {
|
|
200
|
+
data?: TData;
|
|
201
|
+
errors?: Array<Record<string, unknown>>;
|
|
202
|
+
}
|
|
203
|
+
interface WpBlogClient {
|
|
204
|
+
/**
|
|
205
|
+
* Fetches a page of published WordPress posts.
|
|
206
|
+
*/
|
|
207
|
+
getPosts<TSelect extends readonly BlogPostSummaryField[] | undefined = undefined>(params?: GetPostsParams<TSelect>): Promise<PostListResult<SelectFields<BlogPostSummary, TSelect>>>;
|
|
208
|
+
/**
|
|
209
|
+
* Searches posts using the WordPress REST search parameter.
|
|
210
|
+
*/
|
|
211
|
+
searchPosts<TSelect extends readonly BlogPostSummaryField[] | undefined = undefined>(params: SearchPostsParams<TSelect>): Promise<PostListResult<SelectFields<BlogPostSummary, TSelect>>>;
|
|
212
|
+
/**
|
|
213
|
+
* Fetches a single post by slug, or null when not found.
|
|
214
|
+
*/
|
|
215
|
+
getPostBySlug<TSelect extends readonly BlogPostField[] | undefined = undefined>(slug: string, params?: GetPostParams<TSelect>): Promise<SelectFields<BlogPost, TSelect> | null>;
|
|
216
|
+
/**
|
|
217
|
+
* Fetches a single published post by WordPress post ID, or null when not found.
|
|
218
|
+
*/
|
|
219
|
+
getPostById<TSelect extends readonly BlogPostField[] | undefined = undefined>(id: number, params?: GetPostParams<TSelect>): Promise<SelectFields<BlogPost, TSelect> | null>;
|
|
220
|
+
/**
|
|
221
|
+
* Executes a raw request against REST for custom fields/shapes.
|
|
222
|
+
* Use this as an escape hatch for custom fields/shapes.
|
|
223
|
+
*/
|
|
224
|
+
queryRaw<TData = unknown>(params: QueryRawParams): Promise<TData>;
|
|
225
|
+
/**
|
|
226
|
+
* Executes a raw GraphQL request.
|
|
227
|
+
* Uses WP_URL + endpoint and existing WP_AUTH_* auth config.
|
|
228
|
+
*/
|
|
229
|
+
queryGraphql<TData = unknown>(params: QueryGraphqlParams): Promise<QueryGraphqlResult<TData>>;
|
|
230
|
+
/**
|
|
231
|
+
* Fetches blog categories for archive navigation/sidebars.
|
|
232
|
+
*/
|
|
233
|
+
getCategories(params?: GetTermsParams): Promise<BlogTerm[]>;
|
|
234
|
+
/**
|
|
235
|
+
* Fetches blog tags for archive navigation/sidebars.
|
|
236
|
+
*/
|
|
237
|
+
getTags(params?: GetTermsParams): Promise<BlogTerm[]>;
|
|
238
|
+
/**
|
|
239
|
+
* Fetches a page of WordPress authors.
|
|
240
|
+
*/
|
|
241
|
+
getAuthors(params?: GetAuthorsParams): Promise<BlogAuthor[]>;
|
|
242
|
+
/**
|
|
243
|
+
* Fetches a single WordPress author by ID.
|
|
244
|
+
*/
|
|
245
|
+
getAuthorById(id: number): Promise<BlogAuthor | null>;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
export type { WpAuthResolvedConfig as A, BlogTerm as B, ClassNameMap as C, WpAuthType as D, WpEmbedded as E, WpFeaturedMedia as F, GetAuthorsParams as G, HtmlContentPart as H, WpPost as I, WpRenderedField as J, WpTerm as K, LinkRewriteContext as L, PlaceholderParseOptions as P, QueryGraphqlParams as Q, SelectFields as S, WpContentPart as W, WpClientOptions as a, WpBlogClient as b, WpAuthor as c, GetTermsParams as d, BlogPostField as e, GetPostParams as f, BlogPost as g, BlogPostSummaryField as h, GetPostsParams as i, PostListResult as j, BlogPostSummary as k, QueryGraphqlResult as l, QueryRawParams as m, SearchPostsParams as n, BlogAuthor as o, BlogTermOrder as p, BlogTextMode as q, ClassNameMapMode as r, ClassNameMapRule as s, ClassNameMapValue as t, LinkRewriteRule as u, PaginationMeta as v, PlaceholderContentPart as w, PlaceholderProps as x, QueryRawRestInput as y, WpAuthConfig as z };
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
interface WpRenderedField {
|
|
2
|
+
rendered: string;
|
|
3
|
+
}
|
|
4
|
+
interface WpFeaturedMedia {
|
|
5
|
+
source_url?: string;
|
|
6
|
+
}
|
|
7
|
+
interface WpTerm {
|
|
8
|
+
id: number;
|
|
9
|
+
slug?: string;
|
|
10
|
+
name?: string;
|
|
11
|
+
taxonomy?: string;
|
|
12
|
+
count?: number;
|
|
13
|
+
}
|
|
14
|
+
interface WpAuthor {
|
|
15
|
+
id: number;
|
|
16
|
+
name?: string;
|
|
17
|
+
slug?: string;
|
|
18
|
+
url?: string;
|
|
19
|
+
description?: string;
|
|
20
|
+
link?: string;
|
|
21
|
+
avatar_urls?: Record<string, string>;
|
|
22
|
+
[key: string]: unknown;
|
|
23
|
+
}
|
|
24
|
+
interface WpEmbedded {
|
|
25
|
+
"wp:featuredmedia"?: WpFeaturedMedia[];
|
|
26
|
+
"wp:term"?: WpTerm[][];
|
|
27
|
+
author?: WpAuthor[];
|
|
28
|
+
}
|
|
29
|
+
interface WpPost {
|
|
30
|
+
id: number;
|
|
31
|
+
slug: string;
|
|
32
|
+
link: string;
|
|
33
|
+
date: string;
|
|
34
|
+
modified: string;
|
|
35
|
+
title: WpRenderedField;
|
|
36
|
+
excerpt: WpRenderedField;
|
|
37
|
+
content: WpRenderedField;
|
|
38
|
+
_embedded?: WpEmbedded;
|
|
39
|
+
}
|
|
40
|
+
interface LinkRewriteContext {
|
|
41
|
+
href: string;
|
|
42
|
+
pathname: string;
|
|
43
|
+
search: string;
|
|
44
|
+
hash: string;
|
|
45
|
+
}
|
|
46
|
+
interface LinkRewriteRule {
|
|
47
|
+
source: string;
|
|
48
|
+
destination?: string;
|
|
49
|
+
action?: "ignore";
|
|
50
|
+
transform?: (context: LinkRewriteContext) => string;
|
|
51
|
+
}
|
|
52
|
+
type ClassNameMapMode = "append" | "replace" | "replace-all";
|
|
53
|
+
interface ClassNameMapRule {
|
|
54
|
+
className: string;
|
|
55
|
+
mode?: ClassNameMapMode;
|
|
56
|
+
}
|
|
57
|
+
type ClassNameMapValue = string | ClassNameMapRule;
|
|
58
|
+
type ClassNameMap = Record<string, ClassNameMapValue>;
|
|
59
|
+
type PlaceholderProps = Record<string, unknown>;
|
|
60
|
+
interface HtmlContentPart {
|
|
61
|
+
type: "html";
|
|
62
|
+
html: string;
|
|
63
|
+
}
|
|
64
|
+
interface PlaceholderContentPart {
|
|
65
|
+
type: "placeholder";
|
|
66
|
+
name: string;
|
|
67
|
+
props: PlaceholderProps;
|
|
68
|
+
}
|
|
69
|
+
type WpContentPart = HtmlContentPart | PlaceholderContentPart;
|
|
70
|
+
interface PlaceholderParseOptions {
|
|
71
|
+
namespace?: string;
|
|
72
|
+
maxPropsLength?: number;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Normalized post shape returned by this package.
|
|
76
|
+
*/
|
|
77
|
+
interface BlogPostSummary {
|
|
78
|
+
id: number;
|
|
79
|
+
slug: string;
|
|
80
|
+
url: string;
|
|
81
|
+
date: string;
|
|
82
|
+
modified: string;
|
|
83
|
+
publishedDate: string;
|
|
84
|
+
updatedDate: string;
|
|
85
|
+
title: string;
|
|
86
|
+
excerpt: string;
|
|
87
|
+
featuredImageUrl: string | null;
|
|
88
|
+
author: BlogAuthor | null;
|
|
89
|
+
categories: BlogTerm[];
|
|
90
|
+
tags: BlogTerm[];
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Full post shape returned by single-post methods.
|
|
94
|
+
*/
|
|
95
|
+
interface BlogPost extends BlogPostSummary {
|
|
96
|
+
contentHtml: string;
|
|
97
|
+
}
|
|
98
|
+
interface BlogTerm {
|
|
99
|
+
id: number;
|
|
100
|
+
slug: string;
|
|
101
|
+
name: string;
|
|
102
|
+
count: number;
|
|
103
|
+
}
|
|
104
|
+
type BlogAuthor = WpAuthor;
|
|
105
|
+
type BlogTermOrder = "default" | "alphabetical" | "count";
|
|
106
|
+
interface GetTermsParams {
|
|
107
|
+
order?: BlogTermOrder;
|
|
108
|
+
}
|
|
109
|
+
interface GetAuthorsParams {
|
|
110
|
+
page?: number;
|
|
111
|
+
perPage?: number;
|
|
112
|
+
}
|
|
113
|
+
type BlogTextMode = "plain" | "html";
|
|
114
|
+
type BlogPostSummaryField = keyof BlogPostSummary;
|
|
115
|
+
type BlogPostField = keyof BlogPost;
|
|
116
|
+
type SelectFields<T, TSelect extends readonly (keyof T)[] | undefined> = TSelect extends readonly (keyof T)[] ? Pick<T, TSelect[number]> : T;
|
|
117
|
+
/**
|
|
118
|
+
* Pagination metadata returned from list endpoints.
|
|
119
|
+
*/
|
|
120
|
+
interface PaginationMeta {
|
|
121
|
+
page: number;
|
|
122
|
+
perPage: number;
|
|
123
|
+
totalItems: number;
|
|
124
|
+
totalPages: number;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Response returned by getPosts.
|
|
128
|
+
*/
|
|
129
|
+
interface PostListResult<TItem = BlogPostSummary> {
|
|
130
|
+
items: TItem[];
|
|
131
|
+
pagination: PaginationMeta;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Optional pagination parameters for getPosts.
|
|
135
|
+
*/
|
|
136
|
+
interface GetPostsParams<TSelect extends readonly BlogPostSummaryField[] | undefined = undefined> {
|
|
137
|
+
page?: number;
|
|
138
|
+
perPage?: number;
|
|
139
|
+
status?: "draft" | "private" | "publish" | "any";
|
|
140
|
+
categorySlug?: string;
|
|
141
|
+
tagSlug?: string;
|
|
142
|
+
textMode?: BlogTextMode;
|
|
143
|
+
select?: TSelect;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Parameters for searching published posts.
|
|
147
|
+
*/
|
|
148
|
+
interface SearchPostsParams<TSelect extends readonly BlogPostSummaryField[] | undefined = undefined> extends GetPostsParams<TSelect> {
|
|
149
|
+
query: string;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Options for creating an explicit WordPress client.
|
|
153
|
+
*/
|
|
154
|
+
interface WpClientOptions {
|
|
155
|
+
wpUrl?: string;
|
|
156
|
+
endpoint?: string;
|
|
157
|
+
perPage?: number;
|
|
158
|
+
auth?: WpAuthConfig;
|
|
159
|
+
rewriteLinks?: LinkRewriteRule[];
|
|
160
|
+
classNameMap?: ClassNameMap;
|
|
161
|
+
fetchImpl?: typeof fetch;
|
|
162
|
+
requestInit?: RequestInit;
|
|
163
|
+
}
|
|
164
|
+
type WpAuthType = "none" | "basic" | "bearer" | "headers";
|
|
165
|
+
interface WpAuthConfig {
|
|
166
|
+
type?: WpAuthType;
|
|
167
|
+
user?: string;
|
|
168
|
+
appPassword?: string;
|
|
169
|
+
token?: string;
|
|
170
|
+
headers?: Record<string, string>;
|
|
171
|
+
}
|
|
172
|
+
interface WpAuthResolvedConfig {
|
|
173
|
+
type: WpAuthType;
|
|
174
|
+
user?: string;
|
|
175
|
+
appPassword?: string;
|
|
176
|
+
token?: string;
|
|
177
|
+
headers?: Record<string, string>;
|
|
178
|
+
}
|
|
179
|
+
interface GetPostParams<TSelect extends readonly BlogPostField[] | undefined = undefined> {
|
|
180
|
+
status?: "draft" | "private" | "publish" | "any";
|
|
181
|
+
textMode?: BlogTextMode;
|
|
182
|
+
select?: TSelect;
|
|
183
|
+
}
|
|
184
|
+
interface QueryRawRestInput {
|
|
185
|
+
path: string;
|
|
186
|
+
params?: Record<string, string | number | boolean | null | undefined>;
|
|
187
|
+
method?: string;
|
|
188
|
+
body?: unknown;
|
|
189
|
+
headers?: Record<string, string>;
|
|
190
|
+
}
|
|
191
|
+
interface QueryRawParams {
|
|
192
|
+
rest?: QueryRawRestInput;
|
|
193
|
+
authRequired?: boolean;
|
|
194
|
+
}
|
|
195
|
+
interface QueryGraphqlParams {
|
|
196
|
+
query: string;
|
|
197
|
+
variables?: Record<string, unknown>;
|
|
198
|
+
}
|
|
199
|
+
interface QueryGraphqlResult<TData = unknown> {
|
|
200
|
+
data?: TData;
|
|
201
|
+
errors?: Array<Record<string, unknown>>;
|
|
202
|
+
}
|
|
203
|
+
interface WpBlogClient {
|
|
204
|
+
/**
|
|
205
|
+
* Fetches a page of published WordPress posts.
|
|
206
|
+
*/
|
|
207
|
+
getPosts<TSelect extends readonly BlogPostSummaryField[] | undefined = undefined>(params?: GetPostsParams<TSelect>): Promise<PostListResult<SelectFields<BlogPostSummary, TSelect>>>;
|
|
208
|
+
/**
|
|
209
|
+
* Searches posts using the WordPress REST search parameter.
|
|
210
|
+
*/
|
|
211
|
+
searchPosts<TSelect extends readonly BlogPostSummaryField[] | undefined = undefined>(params: SearchPostsParams<TSelect>): Promise<PostListResult<SelectFields<BlogPostSummary, TSelect>>>;
|
|
212
|
+
/**
|
|
213
|
+
* Fetches a single post by slug, or null when not found.
|
|
214
|
+
*/
|
|
215
|
+
getPostBySlug<TSelect extends readonly BlogPostField[] | undefined = undefined>(slug: string, params?: GetPostParams<TSelect>): Promise<SelectFields<BlogPost, TSelect> | null>;
|
|
216
|
+
/**
|
|
217
|
+
* Fetches a single published post by WordPress post ID, or null when not found.
|
|
218
|
+
*/
|
|
219
|
+
getPostById<TSelect extends readonly BlogPostField[] | undefined = undefined>(id: number, params?: GetPostParams<TSelect>): Promise<SelectFields<BlogPost, TSelect> | null>;
|
|
220
|
+
/**
|
|
221
|
+
* Executes a raw request against REST for custom fields/shapes.
|
|
222
|
+
* Use this as an escape hatch for custom fields/shapes.
|
|
223
|
+
*/
|
|
224
|
+
queryRaw<TData = unknown>(params: QueryRawParams): Promise<TData>;
|
|
225
|
+
/**
|
|
226
|
+
* Executes a raw GraphQL request.
|
|
227
|
+
* Uses WP_URL + endpoint and existing WP_AUTH_* auth config.
|
|
228
|
+
*/
|
|
229
|
+
queryGraphql<TData = unknown>(params: QueryGraphqlParams): Promise<QueryGraphqlResult<TData>>;
|
|
230
|
+
/**
|
|
231
|
+
* Fetches blog categories for archive navigation/sidebars.
|
|
232
|
+
*/
|
|
233
|
+
getCategories(params?: GetTermsParams): Promise<BlogTerm[]>;
|
|
234
|
+
/**
|
|
235
|
+
* Fetches blog tags for archive navigation/sidebars.
|
|
236
|
+
*/
|
|
237
|
+
getTags(params?: GetTermsParams): Promise<BlogTerm[]>;
|
|
238
|
+
/**
|
|
239
|
+
* Fetches a page of WordPress authors.
|
|
240
|
+
*/
|
|
241
|
+
getAuthors(params?: GetAuthorsParams): Promise<BlogAuthor[]>;
|
|
242
|
+
/**
|
|
243
|
+
* Fetches a single WordPress author by ID.
|
|
244
|
+
*/
|
|
245
|
+
getAuthorById(id: number): Promise<BlogAuthor | null>;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
export type { WpAuthResolvedConfig as A, BlogTerm as B, ClassNameMap as C, WpAuthType as D, WpEmbedded as E, WpFeaturedMedia as F, GetAuthorsParams as G, HtmlContentPart as H, WpPost as I, WpRenderedField as J, WpTerm as K, LinkRewriteContext as L, PlaceholderParseOptions as P, QueryGraphqlParams as Q, SelectFields as S, WpContentPart as W, WpClientOptions as a, WpBlogClient as b, WpAuthor as c, GetTermsParams as d, BlogPostField as e, GetPostParams as f, BlogPost as g, BlogPostSummaryField as h, GetPostsParams as i, PostListResult as j, BlogPostSummary as k, QueryGraphqlResult as l, QueryRawParams as m, SearchPostsParams as n, BlogAuthor as o, BlogTermOrder as p, BlogTextMode as q, ClassNameMapMode as r, ClassNameMapRule as s, ClassNameMapValue as t, LinkRewriteRule as u, PaginationMeta as v, PlaceholderContentPart as w, PlaceholderProps as x, QueryRawRestInput as y, WpAuthConfig as z };
|