@readpress/wp-blog 1.0.0

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.
@@ -0,0 +1,238 @@
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
+ * Options for creating an explicit WordPress client.
147
+ */
148
+ interface WpClientOptions {
149
+ wpUrl?: string;
150
+ endpoint?: string;
151
+ perPage?: number;
152
+ auth?: WpAuthConfig;
153
+ rewriteLinks?: LinkRewriteRule[];
154
+ classNameMap?: ClassNameMap;
155
+ fetchImpl?: typeof fetch;
156
+ requestInit?: RequestInit;
157
+ }
158
+ type WpAuthType = "none" | "basic" | "bearer" | "headers";
159
+ interface WpAuthConfig {
160
+ type?: WpAuthType;
161
+ user?: string;
162
+ appPassword?: string;
163
+ token?: string;
164
+ headers?: Record<string, string>;
165
+ }
166
+ interface WpAuthResolvedConfig {
167
+ type: WpAuthType;
168
+ user?: string;
169
+ appPassword?: string;
170
+ token?: string;
171
+ headers?: Record<string, string>;
172
+ }
173
+ interface GetPostParams<TSelect extends readonly BlogPostField[] | undefined = undefined> {
174
+ status?: "draft" | "private" | "publish" | "any";
175
+ textMode?: BlogTextMode;
176
+ select?: TSelect;
177
+ }
178
+ interface QueryRawRestInput {
179
+ path: string;
180
+ params?: Record<string, string | number | boolean | null | undefined>;
181
+ method?: string;
182
+ body?: unknown;
183
+ headers?: Record<string, string>;
184
+ }
185
+ interface QueryRawParams {
186
+ rest?: QueryRawRestInput;
187
+ authRequired?: boolean;
188
+ }
189
+ interface QueryGraphqlParams {
190
+ query: string;
191
+ variables?: Record<string, unknown>;
192
+ }
193
+ interface QueryGraphqlResult<TData = unknown> {
194
+ data?: TData;
195
+ errors?: Array<Record<string, unknown>>;
196
+ }
197
+ interface WpBlogClient {
198
+ /**
199
+ * Fetches a page of published WordPress posts.
200
+ */
201
+ getPosts<TSelect extends readonly BlogPostSummaryField[] | undefined = undefined>(params?: GetPostsParams<TSelect>): Promise<PostListResult<SelectFields<BlogPostSummary, TSelect>>>;
202
+ /**
203
+ * Fetches a single post by slug, or null when not found.
204
+ */
205
+ getPostBySlug<TSelect extends readonly BlogPostField[] | undefined = undefined>(slug: string, params?: GetPostParams<TSelect>): Promise<SelectFields<BlogPost, TSelect> | null>;
206
+ /**
207
+ * Fetches a single published post by WordPress post ID, or null when not found.
208
+ */
209
+ getPostById<TSelect extends readonly BlogPostField[] | undefined = undefined>(id: number, params?: GetPostParams<TSelect>): Promise<SelectFields<BlogPost, TSelect> | null>;
210
+ /**
211
+ * Executes a raw request against REST for custom fields/shapes.
212
+ * Use this as an escape hatch for custom fields/shapes.
213
+ */
214
+ queryRaw<TData = unknown>(params: QueryRawParams): Promise<TData>;
215
+ /**
216
+ * Executes a raw GraphQL request.
217
+ * Uses WP_URL + WP_ENDPOINT and existing WP_AUTH_* auth config.
218
+ */
219
+ queryGraphql<TData = unknown>(params: QueryGraphqlParams): Promise<QueryGraphqlResult<TData>>;
220
+ /**
221
+ * Fetches blog categories for archive navigation/sidebars.
222
+ */
223
+ getCategories(params?: GetTermsParams): Promise<BlogTerm[]>;
224
+ /**
225
+ * Fetches blog tags for archive navigation/sidebars.
226
+ */
227
+ getTags(params?: GetTermsParams): Promise<BlogTerm[]>;
228
+ /**
229
+ * Fetches a page of WordPress authors.
230
+ */
231
+ getAuthors(params?: GetAuthorsParams): Promise<BlogAuthor[]>;
232
+ /**
233
+ * Fetches a single WordPress author by ID.
234
+ */
235
+ getAuthorById(id: number): Promise<BlogAuthor | null>;
236
+ }
237
+
238
+ export type { WpAuthType as A, BlogTerm as B, ClassNameMap as C, WpEmbedded as D, WpFeaturedMedia as E, WpPost as F, GetAuthorsParams as G, HtmlContentPart as H, WpRenderedField as I, WpTerm as J, 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, BlogAuthor as n, BlogTermOrder as o, BlogTextMode as p, ClassNameMapMode as q, ClassNameMapRule as r, ClassNameMapValue as s, LinkRewriteRule as t, PaginationMeta as u, PlaceholderContentPart as v, PlaceholderProps as w, QueryRawRestInput as x, WpAuthConfig as y, WpAuthResolvedConfig as z };
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@readpress/wp-blog",
3
+ "version": "1.0.0",
4
+ "description": "Lightweight headless WordPress blog adapter for modern web apps",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.mjs",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "require": "./dist/index.js",
12
+ "import": "./dist/index.mjs"
13
+ },
14
+ "./react": {
15
+ "types": "./dist/react.d.ts",
16
+ "require": "./dist/react.js",
17
+ "import": "./dist/react.mjs"
18
+ }
19
+ },
20
+ "files": [
21
+ "dist"
22
+ ],
23
+ "scripts": {
24
+ "build": "tsup",
25
+ "prepack": "npm run build",
26
+ "test": "npm run build && node --test test/*.test.mjs",
27
+ "docs:api": "typedoc",
28
+ "docs:api:clean": "rm -rf docs/reference && typedoc"
29
+ },
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "https://github.com/readpress/wp-blog.git"
33
+ },
34
+ "homepage": "https://github.com/readpress/wp-blog#readme",
35
+ "bugs": {
36
+ "url": "https://github.com/readpress/wp-blog/issues"
37
+ },
38
+ "keywords": [
39
+ "wordpress",
40
+ "headless",
41
+ "adapter",
42
+ "rest-api"
43
+ ],
44
+ "author": "",
45
+ "license": "MIT",
46
+ "publishConfig": {
47
+ "access": "public"
48
+ },
49
+ "peerDependencies": {
50
+ "react": "^18.0.0 || ^19.0.0"
51
+ },
52
+ "devDependencies": {
53
+ "tslib": "^2.8.1",
54
+ "tsup": "^8.5.1",
55
+ "typedoc": "^0.28.17",
56
+ "typedoc-plugin-markdown": "^4.10.0",
57
+ "typescript": "^5.9.3"
58
+ }
59
+ }