@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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Virgiliu Diaconu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # @readpress/wp-blog
2
+
3
+ A minimal, read-only WordPress blog adapter for modern web apps.
4
+
5
+ - Fetch and search posts, plus authors, categories, and tags
6
+ - Supports drafts/private posts with auth
7
+ - Framework-agnostic core with Next.js App Router docs and examples
8
+ - Read-only by design
9
+
10
+ ## Requirements
11
+
12
+ - Node.js 18+
13
+ - WordPress REST API enabled (default in WordPress)
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ npm install @readpress/wp-blog
19
+ ```
20
+
21
+ ## Configuration
22
+
23
+ Required:
24
+
25
+ ```env
26
+ WP_URL=https://example.com
27
+ ```
28
+
29
+ ## Quick start
30
+ See docs/quickstart.mdx
31
+
32
+ ## Examples
33
+ - `examples/nextjs-blog`
34
+ - `examples/gutenberg-blocks-tailwind`
35
+ - `examples/nextjs-post-components`
@@ -0,0 +1,105 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+
21
+ // src/domain/placeholders.ts
22
+ var DEFAULT_NAMESPACE = "wpapp";
23
+ var DEFAULT_MAX_PROPS_LENGTH = 1e4;
24
+ var PLACEHOLDER_NAME_REGEX = /^[A-Za-z][A-Za-z0-9_-]*$/;
25
+ function escapeRegex(value) {
26
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
27
+ }
28
+ function normalizeNamespace(value) {
29
+ const trimmed = value == null ? void 0 : value.trim();
30
+ if (!trimmed) {
31
+ return DEFAULT_NAMESPACE;
32
+ }
33
+ return trimmed;
34
+ }
35
+ function normalizeMaxPropsLength(value) {
36
+ if (!value || !Number.isInteger(value) || value <= 0) {
37
+ return DEFAULT_MAX_PROPS_LENGTH;
38
+ }
39
+ return value;
40
+ }
41
+ function parseProps(rawProps, maxPropsLength) {
42
+ const trimmed = rawProps == null ? void 0 : rawProps.trim();
43
+ if (!trimmed) {
44
+ return {};
45
+ }
46
+ if (trimmed.length > maxPropsLength) {
47
+ return null;
48
+ }
49
+ try {
50
+ const parsed = JSON.parse(trimmed);
51
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
52
+ return null;
53
+ }
54
+ return parsed;
55
+ } catch (e) {
56
+ return null;
57
+ }
58
+ }
59
+ function parseContentPlaceholders(contentHtml, options = {}) {
60
+ if (!contentHtml) {
61
+ return [{ type: "html", html: "" }];
62
+ }
63
+ const namespace = normalizeNamespace(options.namespace);
64
+ const maxPropsLength = normalizeMaxPropsLength(options.maxPropsLength);
65
+ const markerRegex = new RegExp(
66
+ `<!--\\s*${escapeRegex(namespace)}:([A-Za-z][A-Za-z0-9_-]*)(?:\\s+([\\s\\S]*?))?\\s*-->`,
67
+ "g"
68
+ );
69
+ const parts = [];
70
+ let cursor = 0;
71
+ let match;
72
+ while ((match = markerRegex.exec(contentHtml)) !== null) {
73
+ const [fullMatch, rawName, rawProps] = match;
74
+ const matchIndex = match.index;
75
+ if (matchIndex > cursor) {
76
+ parts.push({ type: "html", html: contentHtml.slice(cursor, matchIndex) });
77
+ }
78
+ const name = rawName == null ? void 0 : rawName.trim();
79
+ const props = parseProps(rawProps, maxPropsLength);
80
+ if (!name || !PLACEHOLDER_NAME_REGEX.test(name) || !props) {
81
+ parts.push({ type: "html", html: fullMatch });
82
+ cursor = markerRegex.lastIndex;
83
+ continue;
84
+ }
85
+ parts.push({
86
+ type: "placeholder",
87
+ name,
88
+ props
89
+ });
90
+ cursor = markerRegex.lastIndex;
91
+ }
92
+ if (cursor < contentHtml.length) {
93
+ parts.push({ type: "html", html: contentHtml.slice(cursor) });
94
+ }
95
+ if (parts.length === 0) {
96
+ return [{ type: "html", html: contentHtml }];
97
+ }
98
+ return parts;
99
+ }
100
+
101
+ export {
102
+ __spreadValues,
103
+ __spreadProps,
104
+ parseContentPlaceholders
105
+ };
@@ -0,0 +1,78 @@
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-BDmCnhFG.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-BDmCnhFG.mjs';
3
+
4
+ type WpClientErrorCode = "INVALID_CONFIG" | "INVALID_INPUT" | "REQUEST_FAILED" | "INVALID_RESPONSE";
5
+ interface WpApiErrorDetails {
6
+ wpCode?: string;
7
+ wpMessage?: string;
8
+ wpData?: unknown;
9
+ }
10
+ /**
11
+ * Error thrown by the WordPress adapter for config, input, request, or response failures.
12
+ */
13
+ declare class WpClientError extends Error {
14
+ readonly code: WpClientErrorCode;
15
+ readonly status?: number;
16
+ readonly wpCode?: string;
17
+ readonly wpMessage?: string;
18
+ readonly wpData?: unknown;
19
+ constructor(code: WpClientErrorCode, message: string, status?: number, details?: WpApiErrorDetails);
20
+ }
21
+
22
+ /**
23
+ * Parses placeholder comments from HTML content.
24
+ *
25
+ * Marker format:
26
+ * - <!-- wpapp:cta {"title":"..."} -->
27
+ * - <!-- wpapp:newsletter -->
28
+ *
29
+ * Invalid placeholders are left as normal HTML content.
30
+ */
31
+ declare function parseContentPlaceholders(contentHtml: string, options?: PlaceholderParseOptions): WpContentPart[];
32
+
33
+ /**
34
+ * Creates an explicit WordPress blog client with the provided options.
35
+ */
36
+ declare function createWpBlogClient(clientOptions?: WpClientOptions): WpBlogClient;
37
+ /**
38
+ * Fetches published posts using a lazily created env-based default client.
39
+ */
40
+ declare function getPosts<TSelect extends readonly BlogPostSummaryField[] | undefined = undefined>(params?: GetPostsParams<TSelect>): Promise<PostListResult<SelectFields<BlogPostSummary, TSelect>>>;
41
+ /**
42
+ * Searches published posts using the default client.
43
+ */
44
+ declare function searchPosts<TSelect extends readonly BlogPostSummaryField[] | undefined = undefined>(params: SearchPostsParams<TSelect>): Promise<PostListResult<SelectFields<BlogPostSummary, TSelect>>>;
45
+ /**
46
+ * Fetches a single published post by slug using the default client.
47
+ */
48
+ declare function getPostBySlug<TSelect extends readonly BlogPostField[] | undefined = undefined>(slug: string, params?: GetPostParams<TSelect>): Promise<SelectFields<BlogPost, TSelect> | null>;
49
+ /**
50
+ * Fetches a single published post by WordPress post ID using the default client.
51
+ */
52
+ declare function getPostById<TSelect extends readonly BlogPostField[] | undefined = undefined>(id: number, params?: GetPostParams<TSelect>): Promise<SelectFields<BlogPost, TSelect> | null>;
53
+ /**
54
+ * Executes a raw request against REST.
55
+ */
56
+ declare function queryRaw<TData = unknown>(params: QueryRawParams): Promise<TData>;
57
+ /**
58
+ * Executes a raw GraphQL request using the default client.
59
+ */
60
+ declare function queryGraphql<TData = unknown>(params: QueryGraphqlParams): Promise<QueryGraphqlResult<TData>>;
61
+ /**
62
+ * Fetches categories from the default client.
63
+ */
64
+ declare function getCategories(params?: GetTermsParams): Promise<BlogTerm[]>;
65
+ /**
66
+ * Fetches tags from the default client.
67
+ */
68
+ declare function getTags(params?: GetTermsParams): Promise<BlogTerm[]>;
69
+ /**
70
+ * Fetches authors from the default client.
71
+ */
72
+ declare function getAuthors(params?: GetAuthorsParams): Promise<WpAuthor[]>;
73
+ /**
74
+ * Fetches a single author by ID from the default client.
75
+ */
76
+ declare function getAuthorById(id: number): Promise<WpAuthor | null>;
77
+
78
+ export { BlogPost, BlogPostField, BlogPostSummary, BlogPostSummaryField, BlogTerm, GetAuthorsParams, GetPostParams, GetPostsParams, GetTermsParams, PlaceholderParseOptions, PostListResult, QueryGraphqlParams, QueryGraphqlResult, QueryRawParams, SearchPostsParams, SelectFields, type WpApiErrorDetails, WpAuthor, WpBlogClient, WpClientError, type WpClientErrorCode, WpClientOptions, WpContentPart, createWpBlogClient, getAuthorById, getAuthors, getCategories, getPostById, getPostBySlug, getPosts, getTags, parseContentPlaceholders, queryGraphql, queryRaw, searchPosts };
@@ -0,0 +1,78 @@
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-BDmCnhFG.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-BDmCnhFG.js';
3
+
4
+ type WpClientErrorCode = "INVALID_CONFIG" | "INVALID_INPUT" | "REQUEST_FAILED" | "INVALID_RESPONSE";
5
+ interface WpApiErrorDetails {
6
+ wpCode?: string;
7
+ wpMessage?: string;
8
+ wpData?: unknown;
9
+ }
10
+ /**
11
+ * Error thrown by the WordPress adapter for config, input, request, or response failures.
12
+ */
13
+ declare class WpClientError extends Error {
14
+ readonly code: WpClientErrorCode;
15
+ readonly status?: number;
16
+ readonly wpCode?: string;
17
+ readonly wpMessage?: string;
18
+ readonly wpData?: unknown;
19
+ constructor(code: WpClientErrorCode, message: string, status?: number, details?: WpApiErrorDetails);
20
+ }
21
+
22
+ /**
23
+ * Parses placeholder comments from HTML content.
24
+ *
25
+ * Marker format:
26
+ * - <!-- wpapp:cta {"title":"..."} -->
27
+ * - <!-- wpapp:newsletter -->
28
+ *
29
+ * Invalid placeholders are left as normal HTML content.
30
+ */
31
+ declare function parseContentPlaceholders(contentHtml: string, options?: PlaceholderParseOptions): WpContentPart[];
32
+
33
+ /**
34
+ * Creates an explicit WordPress blog client with the provided options.
35
+ */
36
+ declare function createWpBlogClient(clientOptions?: WpClientOptions): WpBlogClient;
37
+ /**
38
+ * Fetches published posts using a lazily created env-based default client.
39
+ */
40
+ declare function getPosts<TSelect extends readonly BlogPostSummaryField[] | undefined = undefined>(params?: GetPostsParams<TSelect>): Promise<PostListResult<SelectFields<BlogPostSummary, TSelect>>>;
41
+ /**
42
+ * Searches published posts using the default client.
43
+ */
44
+ declare function searchPosts<TSelect extends readonly BlogPostSummaryField[] | undefined = undefined>(params: SearchPostsParams<TSelect>): Promise<PostListResult<SelectFields<BlogPostSummary, TSelect>>>;
45
+ /**
46
+ * Fetches a single published post by slug using the default client.
47
+ */
48
+ declare function getPostBySlug<TSelect extends readonly BlogPostField[] | undefined = undefined>(slug: string, params?: GetPostParams<TSelect>): Promise<SelectFields<BlogPost, TSelect> | null>;
49
+ /**
50
+ * Fetches a single published post by WordPress post ID using the default client.
51
+ */
52
+ declare function getPostById<TSelect extends readonly BlogPostField[] | undefined = undefined>(id: number, params?: GetPostParams<TSelect>): Promise<SelectFields<BlogPost, TSelect> | null>;
53
+ /**
54
+ * Executes a raw request against REST.
55
+ */
56
+ declare function queryRaw<TData = unknown>(params: QueryRawParams): Promise<TData>;
57
+ /**
58
+ * Executes a raw GraphQL request using the default client.
59
+ */
60
+ declare function queryGraphql<TData = unknown>(params: QueryGraphqlParams): Promise<QueryGraphqlResult<TData>>;
61
+ /**
62
+ * Fetches categories from the default client.
63
+ */
64
+ declare function getCategories(params?: GetTermsParams): Promise<BlogTerm[]>;
65
+ /**
66
+ * Fetches tags from the default client.
67
+ */
68
+ declare function getTags(params?: GetTermsParams): Promise<BlogTerm[]>;
69
+ /**
70
+ * Fetches authors from the default client.
71
+ */
72
+ declare function getAuthors(params?: GetAuthorsParams): Promise<WpAuthor[]>;
73
+ /**
74
+ * Fetches a single author by ID from the default client.
75
+ */
76
+ declare function getAuthorById(id: number): Promise<WpAuthor | null>;
77
+
78
+ export { BlogPost, BlogPostField, BlogPostSummary, BlogPostSummaryField, BlogTerm, GetAuthorsParams, GetPostParams, GetPostsParams, GetTermsParams, PlaceholderParseOptions, PostListResult, QueryGraphqlParams, QueryGraphqlResult, QueryRawParams, SearchPostsParams, SelectFields, type WpApiErrorDetails, WpAuthor, WpBlogClient, WpClientError, type WpClientErrorCode, WpClientOptions, WpContentPart, createWpBlogClient, getAuthorById, getAuthors, getCategories, getPostById, getPostBySlug, getPosts, getTags, parseContentPlaceholders, queryGraphql, queryRaw, searchPosts };