@szymonpiatek/nextwordpress 0.0.4 → 0.0.5

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/dist/index.d.cts CHANGED
@@ -112,6 +112,22 @@ interface CreateCommentInput {
112
112
  parent?: number;
113
113
  }
114
114
 
115
+ type CF7SubmissionStatus = 'mail_sent' | 'mail_failed' | 'validation_failed' | 'spam' | 'aborted';
116
+ interface CF7ValidationError {
117
+ field: string;
118
+ message: string;
119
+ idref: string | null;
120
+ }
121
+ interface CF7SubmissionResponse {
122
+ status: CF7SubmissionStatus;
123
+ message: string;
124
+ invalid_fields?: CF7ValidationError[];
125
+ }
126
+
127
+ declare function createCF7Queries(config: NextWordpressConfig): {
128
+ submitForm: (formId: number, data: Record<string, string>) => Promise<CF7SubmissionResponse>;
129
+ };
130
+
115
131
  type RestPostStatus = 'publish' | 'draft' | 'pending' | 'private' | 'future';
116
132
  interface CreatePostInput {
117
133
  title: string;
@@ -1535,6 +1551,23 @@ interface RevalidationResult {
1535
1551
  }
1536
1552
  declare function createRevalidationHandler(config: RevalidationConfig, revalidateTag: (tag: string) => void): (request: Request) => Promise<Response>;
1537
1553
 
1554
+ interface FaustConfig {
1555
+ wpUrl: string;
1556
+ secretKey: string;
1557
+ cookieName?: string;
1558
+ }
1559
+ interface FaustPreviewConfig {
1560
+ wpUrl: string;
1561
+ secretKey: string;
1562
+ previewPath?: string;
1563
+ }
1564
+ interface FaustPreviewDeps {
1565
+ enableDraftMode: () => Promise<void>;
1566
+ redirect: (url: string) => never;
1567
+ }
1568
+ declare function createFaustAuthHandler(config: FaustConfig): (request: Request, routePath: string) => Promise<Response>;
1569
+ declare function createPreviewHandler(config: FaustPreviewConfig, deps: FaustPreviewDeps): (request: Request) => Promise<Response>;
1570
+
1538
1571
  declare function createApplicationPasswordToken(username: string, appPassword: string): string;
1539
1572
 
1540
1573
  interface JwtAuthCredentials {
@@ -1555,4 +1588,4 @@ declare class AuthenticationError extends Error {
1555
1588
  declare function authenticateJwt(config: NextWordpressConfig, credentials: JwtAuthCredentials): Promise<JwtAuthResponse>;
1556
1589
  declare function validateJwtToken(config: NextWordpressConfig, token: string): Promise<boolean>;
1557
1590
 
1558
- export { AuthenticationError, Author, type Category, type Comment, type CommentAuthorAvatar, type CreateAuthorInput, type CreateCategoryInput, type CreateCommentInput, type CreateCouponInput, type CreateMenuInput, type CreateMenuItemInput, type CreatePageInput, type CreatePostInput, type CreateProductCategoryInput, type CreateProductInput, type CreateProductTagInput, type CreateTagInput, FeaturedMedia, type GQLACFFieldGroup, type GQLAuthor, type GQLCPTNode, type GQLCategory, GQLConnection, type GQLCreateCommentInput, type GQLCreateCommentResult, type GQLCreatePostInput, type GQLCustomer, type GQLDeletePostResult, type GQLLineItem, type GQLMutatedComment, type GQLMutatedPost, type GQLOrder, type GQLOrderAddress, type GQLPage, type GQLPageWithSEO, GQLPost, GQLPostFilter, type GQLPostStatus, type GQLPostWithSEO, type GQLProduct, type GQLProductFilter, type GQLProductVariation, type GQLTag, type GQLUpdatePostInput, type GQLYoastSEO, type JwtAuthCredentials, type JwtAuthResponse, type Menu, type MenuItem, type MenuLocation, type MenuWithItems, NextWordpressConfig, type OmnibusPriceEntry, type OmnibusProductData, type Page, Post, RenderedContent, RenderedTitle, type RestPageStatus, type RestPostStatus, type RevalidationConfig, type RevalidationPayload, type RevalidationResult, type Tag, Taxonomy, type UpdateAuthorInput, type UpdateCategoryInput, type UpdateCommentInput, type UpdateCouponInput, type UpdateCustomerInput, type UpdateMediaInput, type UpdateMenuInput, type UpdateMenuItemInput, type UpdatePageInput, type UpdatePostInput, type UpdateProductCategoryInput, type UpdateProductInput, type UpdateProductTagInput, type UpdateTagInput, type UploadMediaInput, WCAddress, type WCCoupon, type WCCreateOrderInput, type WCCustomer, WCImage, type WCOrder, type WCOrderLineItem, WCProduct, type WCProductCategory, WCProductFilterParams, type WCProductStatus, type WCProductTag, WCProductVariation, type WCProductVariationWithOmnibus, type WCProductWithOmnibus, type WCShippingLine, WPEntity, WPGraphQLConfig, type WPGraphQLFetcher, WooCommerceConfig, type WooCommerceFetcher, WooCommerceResponse, authenticateJwt, buildACFFragment, buildPageWithACFQuery, buildPostWithACFQuery, buildPostsWithACFQuery, createApplicationPasswordToken, createAuthorsMutations, createCPTQueries, createCategoriesMutations, createCommentsMutations, createMediaMutations, createMenusMutations, createPagesMutations, createPostsMutations, createRevalidationHandler, createTagsMutations, createWPGraphQLCoreClient as createWPGraphQLClient, createWPGraphQLCoreClient, createWPGraphQLFetcher, createWPGraphQLMutationsClient, createWPGraphQLWooCommerceClient, createWooCommerceClient, createWooCommerceFetcher, createWordPressClient, createWordPressMutationsClient, createYoastQueries, extractOmnibusData, resolveBaseUrl, validateJwtToken, withOmnibus, withOmnibusVariation };
1591
+ export { AuthenticationError, Author, type CF7SubmissionResponse, type CF7SubmissionStatus, type CF7ValidationError, type Category, type Comment, type CommentAuthorAvatar, type CreateAuthorInput, type CreateCategoryInput, type CreateCommentInput, type CreateCouponInput, type CreateMenuInput, type CreateMenuItemInput, type CreatePageInput, type CreatePostInput, type CreateProductCategoryInput, type CreateProductInput, type CreateProductTagInput, type CreateTagInput, type FaustConfig, type FaustPreviewConfig, type FaustPreviewDeps, FeaturedMedia, type GQLACFFieldGroup, type GQLAuthor, type GQLCPTNode, type GQLCategory, GQLConnection, type GQLCreateCommentInput, type GQLCreateCommentResult, type GQLCreatePostInput, type GQLCustomer, type GQLDeletePostResult, type GQLLineItem, type GQLMutatedComment, type GQLMutatedPost, type GQLOrder, type GQLOrderAddress, type GQLPage, type GQLPageWithSEO, GQLPost, GQLPostFilter, type GQLPostStatus, type GQLPostWithSEO, type GQLProduct, type GQLProductFilter, type GQLProductVariation, type GQLTag, type GQLUpdatePostInput, type GQLYoastSEO, type JwtAuthCredentials, type JwtAuthResponse, type Menu, type MenuItem, type MenuLocation, type MenuWithItems, NextWordpressConfig, type OmnibusPriceEntry, type OmnibusProductData, type Page, Post, RenderedContent, RenderedTitle, type RestPageStatus, type RestPostStatus, type RevalidationConfig, type RevalidationPayload, type RevalidationResult, type Tag, Taxonomy, type UpdateAuthorInput, type UpdateCategoryInput, type UpdateCommentInput, type UpdateCouponInput, type UpdateCustomerInput, type UpdateMediaInput, type UpdateMenuInput, type UpdateMenuItemInput, type UpdatePageInput, type UpdatePostInput, type UpdateProductCategoryInput, type UpdateProductInput, type UpdateProductTagInput, type UpdateTagInput, type UploadMediaInput, WCAddress, type WCCoupon, type WCCreateOrderInput, type WCCustomer, WCImage, type WCOrder, type WCOrderLineItem, WCProduct, type WCProductCategory, WCProductFilterParams, type WCProductStatus, type WCProductTag, WCProductVariation, type WCProductVariationWithOmnibus, type WCProductWithOmnibus, type WCShippingLine, WPEntity, WPGraphQLConfig, type WPGraphQLFetcher, WooCommerceConfig, type WooCommerceFetcher, WooCommerceResponse, authenticateJwt, buildACFFragment, buildPageWithACFQuery, buildPostWithACFQuery, buildPostsWithACFQuery, createApplicationPasswordToken, createAuthorsMutations, createCF7Queries, createCPTQueries, createCategoriesMutations, createCommentsMutations, createFaustAuthHandler, createMediaMutations, createMenusMutations, createPagesMutations, createPostsMutations, createPreviewHandler, createRevalidationHandler, createTagsMutations, createWPGraphQLCoreClient as createWPGraphQLClient, createWPGraphQLCoreClient, createWPGraphQLFetcher, createWPGraphQLMutationsClient, createWPGraphQLWooCommerceClient, createWooCommerceClient, createWooCommerceFetcher, createWordPressClient, createWordPressMutationsClient, createYoastQueries, extractOmnibusData, resolveBaseUrl, validateJwtToken, withOmnibus, withOmnibusVariation };
package/dist/index.d.ts CHANGED
@@ -112,6 +112,22 @@ interface CreateCommentInput {
112
112
  parent?: number;
113
113
  }
114
114
 
115
+ type CF7SubmissionStatus = 'mail_sent' | 'mail_failed' | 'validation_failed' | 'spam' | 'aborted';
116
+ interface CF7ValidationError {
117
+ field: string;
118
+ message: string;
119
+ idref: string | null;
120
+ }
121
+ interface CF7SubmissionResponse {
122
+ status: CF7SubmissionStatus;
123
+ message: string;
124
+ invalid_fields?: CF7ValidationError[];
125
+ }
126
+
127
+ declare function createCF7Queries(config: NextWordpressConfig): {
128
+ submitForm: (formId: number, data: Record<string, string>) => Promise<CF7SubmissionResponse>;
129
+ };
130
+
115
131
  type RestPostStatus = 'publish' | 'draft' | 'pending' | 'private' | 'future';
116
132
  interface CreatePostInput {
117
133
  title: string;
@@ -1535,6 +1551,23 @@ interface RevalidationResult {
1535
1551
  }
1536
1552
  declare function createRevalidationHandler(config: RevalidationConfig, revalidateTag: (tag: string) => void): (request: Request) => Promise<Response>;
1537
1553
 
1554
+ interface FaustConfig {
1555
+ wpUrl: string;
1556
+ secretKey: string;
1557
+ cookieName?: string;
1558
+ }
1559
+ interface FaustPreviewConfig {
1560
+ wpUrl: string;
1561
+ secretKey: string;
1562
+ previewPath?: string;
1563
+ }
1564
+ interface FaustPreviewDeps {
1565
+ enableDraftMode: () => Promise<void>;
1566
+ redirect: (url: string) => never;
1567
+ }
1568
+ declare function createFaustAuthHandler(config: FaustConfig): (request: Request, routePath: string) => Promise<Response>;
1569
+ declare function createPreviewHandler(config: FaustPreviewConfig, deps: FaustPreviewDeps): (request: Request) => Promise<Response>;
1570
+
1538
1571
  declare function createApplicationPasswordToken(username: string, appPassword: string): string;
1539
1572
 
1540
1573
  interface JwtAuthCredentials {
@@ -1555,4 +1588,4 @@ declare class AuthenticationError extends Error {
1555
1588
  declare function authenticateJwt(config: NextWordpressConfig, credentials: JwtAuthCredentials): Promise<JwtAuthResponse>;
1556
1589
  declare function validateJwtToken(config: NextWordpressConfig, token: string): Promise<boolean>;
1557
1590
 
1558
- export { AuthenticationError, Author, type Category, type Comment, type CommentAuthorAvatar, type CreateAuthorInput, type CreateCategoryInput, type CreateCommentInput, type CreateCouponInput, type CreateMenuInput, type CreateMenuItemInput, type CreatePageInput, type CreatePostInput, type CreateProductCategoryInput, type CreateProductInput, type CreateProductTagInput, type CreateTagInput, FeaturedMedia, type GQLACFFieldGroup, type GQLAuthor, type GQLCPTNode, type GQLCategory, GQLConnection, type GQLCreateCommentInput, type GQLCreateCommentResult, type GQLCreatePostInput, type GQLCustomer, type GQLDeletePostResult, type GQLLineItem, type GQLMutatedComment, type GQLMutatedPost, type GQLOrder, type GQLOrderAddress, type GQLPage, type GQLPageWithSEO, GQLPost, GQLPostFilter, type GQLPostStatus, type GQLPostWithSEO, type GQLProduct, type GQLProductFilter, type GQLProductVariation, type GQLTag, type GQLUpdatePostInput, type GQLYoastSEO, type JwtAuthCredentials, type JwtAuthResponse, type Menu, type MenuItem, type MenuLocation, type MenuWithItems, NextWordpressConfig, type OmnibusPriceEntry, type OmnibusProductData, type Page, Post, RenderedContent, RenderedTitle, type RestPageStatus, type RestPostStatus, type RevalidationConfig, type RevalidationPayload, type RevalidationResult, type Tag, Taxonomy, type UpdateAuthorInput, type UpdateCategoryInput, type UpdateCommentInput, type UpdateCouponInput, type UpdateCustomerInput, type UpdateMediaInput, type UpdateMenuInput, type UpdateMenuItemInput, type UpdatePageInput, type UpdatePostInput, type UpdateProductCategoryInput, type UpdateProductInput, type UpdateProductTagInput, type UpdateTagInput, type UploadMediaInput, WCAddress, type WCCoupon, type WCCreateOrderInput, type WCCustomer, WCImage, type WCOrder, type WCOrderLineItem, WCProduct, type WCProductCategory, WCProductFilterParams, type WCProductStatus, type WCProductTag, WCProductVariation, type WCProductVariationWithOmnibus, type WCProductWithOmnibus, type WCShippingLine, WPEntity, WPGraphQLConfig, type WPGraphQLFetcher, WooCommerceConfig, type WooCommerceFetcher, WooCommerceResponse, authenticateJwt, buildACFFragment, buildPageWithACFQuery, buildPostWithACFQuery, buildPostsWithACFQuery, createApplicationPasswordToken, createAuthorsMutations, createCPTQueries, createCategoriesMutations, createCommentsMutations, createMediaMutations, createMenusMutations, createPagesMutations, createPostsMutations, createRevalidationHandler, createTagsMutations, createWPGraphQLCoreClient as createWPGraphQLClient, createWPGraphQLCoreClient, createWPGraphQLFetcher, createWPGraphQLMutationsClient, createWPGraphQLWooCommerceClient, createWooCommerceClient, createWooCommerceFetcher, createWordPressClient, createWordPressMutationsClient, createYoastQueries, extractOmnibusData, resolveBaseUrl, validateJwtToken, withOmnibus, withOmnibusVariation };
1591
+ export { AuthenticationError, Author, type CF7SubmissionResponse, type CF7SubmissionStatus, type CF7ValidationError, type Category, type Comment, type CommentAuthorAvatar, type CreateAuthorInput, type CreateCategoryInput, type CreateCommentInput, type CreateCouponInput, type CreateMenuInput, type CreateMenuItemInput, type CreatePageInput, type CreatePostInput, type CreateProductCategoryInput, type CreateProductInput, type CreateProductTagInput, type CreateTagInput, type FaustConfig, type FaustPreviewConfig, type FaustPreviewDeps, FeaturedMedia, type GQLACFFieldGroup, type GQLAuthor, type GQLCPTNode, type GQLCategory, GQLConnection, type GQLCreateCommentInput, type GQLCreateCommentResult, type GQLCreatePostInput, type GQLCustomer, type GQLDeletePostResult, type GQLLineItem, type GQLMutatedComment, type GQLMutatedPost, type GQLOrder, type GQLOrderAddress, type GQLPage, type GQLPageWithSEO, GQLPost, GQLPostFilter, type GQLPostStatus, type GQLPostWithSEO, type GQLProduct, type GQLProductFilter, type GQLProductVariation, type GQLTag, type GQLUpdatePostInput, type GQLYoastSEO, type JwtAuthCredentials, type JwtAuthResponse, type Menu, type MenuItem, type MenuLocation, type MenuWithItems, NextWordpressConfig, type OmnibusPriceEntry, type OmnibusProductData, type Page, Post, RenderedContent, RenderedTitle, type RestPageStatus, type RestPostStatus, type RevalidationConfig, type RevalidationPayload, type RevalidationResult, type Tag, Taxonomy, type UpdateAuthorInput, type UpdateCategoryInput, type UpdateCommentInput, type UpdateCouponInput, type UpdateCustomerInput, type UpdateMediaInput, type UpdateMenuInput, type UpdateMenuItemInput, type UpdatePageInput, type UpdatePostInput, type UpdateProductCategoryInput, type UpdateProductInput, type UpdateProductTagInput, type UpdateTagInput, type UploadMediaInput, WCAddress, type WCCoupon, type WCCreateOrderInput, type WCCustomer, WCImage, type WCOrder, type WCOrderLineItem, WCProduct, type WCProductCategory, WCProductFilterParams, type WCProductStatus, type WCProductTag, WCProductVariation, type WCProductVariationWithOmnibus, type WCProductWithOmnibus, type WCShippingLine, WPEntity, WPGraphQLConfig, type WPGraphQLFetcher, WooCommerceConfig, type WooCommerceFetcher, WooCommerceResponse, authenticateJwt, buildACFFragment, buildPageWithACFQuery, buildPostWithACFQuery, buildPostsWithACFQuery, createApplicationPasswordToken, createAuthorsMutations, createCF7Queries, createCPTQueries, createCategoriesMutations, createCommentsMutations, createFaustAuthHandler, createMediaMutations, createMenusMutations, createPagesMutations, createPostsMutations, createPreviewHandler, createRevalidationHandler, createTagsMutations, createWPGraphQLCoreClient as createWPGraphQLClient, createWPGraphQLCoreClient, createWPGraphQLFetcher, createWPGraphQLMutationsClient, createWPGraphQLWooCommerceClient, createWooCommerceClient, createWooCommerceFetcher, createWordPressClient, createWordPressMutationsClient, createYoastQueries, extractOmnibusData, resolveBaseUrl, validateJwtToken, withOmnibus, withOmnibusVariation };
package/dist/index.js CHANGED
@@ -7,6 +7,133 @@ function resolveBaseUrl(config) {
7
7
  return typeof window === "undefined" ? config.serverURL : config.clientURL;
8
8
  }
9
9
 
10
+ // src/integrations/restApi/core/client/types.ts
11
+ var WordPressAPIError = class extends Error {
12
+ constructor(message, status, endpoint) {
13
+ super(message);
14
+ __publicField(this, "status", status);
15
+ __publicField(this, "endpoint", endpoint);
16
+ this.name = "WordPressAPIError";
17
+ }
18
+ };
19
+
20
+ // src/integrations/restApi/core/client/url.ts
21
+ function buildUrl(config, path, query) {
22
+ const base = resolveBaseUrl(config);
23
+ if (!query) return `${base}${path}`;
24
+ const params = new URLSearchParams();
25
+ for (const [key, value] of Object.entries(query)) {
26
+ if (value !== void 0 && value !== null) {
27
+ params.set(key, String(value));
28
+ }
29
+ }
30
+ const qs = params.toString();
31
+ return qs ? `${base}${path}?${qs}` : `${base}${path}`;
32
+ }
33
+
34
+ // src/integrations/restApi/core/client/fetcher.ts
35
+ var USER_AGENT = "NextWordpress Client";
36
+ async function doFetch(url, init = {}) {
37
+ const response = await fetch(url, init);
38
+ if (!response.ok) {
39
+ throw new WordPressAPIError(
40
+ `WordPress API request failed: ${response.statusText}`,
41
+ response.status,
42
+ url
43
+ );
44
+ }
45
+ return response;
46
+ }
47
+ function createFetcher(config) {
48
+ const cacheTtl = 300;
49
+ async function wpFetch(path, query, tags = ["wordpress"]) {
50
+ const url = buildUrl(config, path, query);
51
+ const res = await doFetch(url, {
52
+ headers: { "User-Agent": USER_AGENT },
53
+ next: { tags, revalidate: cacheTtl }
54
+ });
55
+ return await res.json();
56
+ }
57
+ async function wpFetchGraceful(path, fallback, query, tags = ["wordpress"]) {
58
+ try {
59
+ return await wpFetch(path, query, tags);
60
+ } catch {
61
+ console.warn(`WordPress fetch failed for ${path}`);
62
+ return fallback;
63
+ }
64
+ }
65
+ async function wpFetchPaginated(path, query, tags = ["wordpress"]) {
66
+ const url = buildUrl(config, path, query);
67
+ const res = await doFetch(url, {
68
+ headers: { "User-Agent": USER_AGENT },
69
+ next: { tags, revalidate: cacheTtl }
70
+ });
71
+ return {
72
+ data: await res.json(),
73
+ headers: {
74
+ total: parseInt(res.headers.get("X-WP-Total") ?? "0", 10),
75
+ totalPages: parseInt(res.headers.get("X-WP-TotalPages") ?? "0", 10)
76
+ }
77
+ };
78
+ }
79
+ async function wpFetchPaginatedGraceful(path, query, tags = ["wordpress"]) {
80
+ const empty = { data: [], headers: { total: 0, totalPages: 0 } };
81
+ try {
82
+ return await wpFetchPaginated(path, query, tags);
83
+ } catch {
84
+ console.warn(`WordPress paginated fetch failed for ${path}`);
85
+ return empty;
86
+ }
87
+ }
88
+ async function wpMutate(path, body, method = "POST", authToken) {
89
+ const url = buildUrl(config, path);
90
+ const headers = {
91
+ "Content-Type": "application/json",
92
+ "User-Agent": USER_AGENT
93
+ };
94
+ if (authToken) {
95
+ headers["Authorization"] = authToken;
96
+ }
97
+ const res = await doFetch(url, {
98
+ method,
99
+ headers,
100
+ body: JSON.stringify(body),
101
+ cache: "no-store"
102
+ });
103
+ return await res.json();
104
+ }
105
+ async function wpUpload(path, file, filename, mimeType, authToken) {
106
+ const url = buildUrl(config, path);
107
+ const res = await doFetch(url, {
108
+ method: "POST",
109
+ headers: {
110
+ "Content-Disposition": `attachment; filename="${filename}"`,
111
+ "Content-Type": mimeType,
112
+ "User-Agent": USER_AGENT,
113
+ "Authorization": authToken
114
+ },
115
+ body: file,
116
+ cache: "no-store"
117
+ });
118
+ return await res.json();
119
+ }
120
+ return { wpFetch, wpFetchGraceful, wpFetchPaginated, wpFetchPaginatedGraceful, wpMutate, wpUpload };
121
+ }
122
+
123
+ // src/integrations/restApi/core/contactForm7/queries.ts
124
+ function createCF7Queries(config) {
125
+ async function submitForm(formId, data) {
126
+ const url = buildUrl(config, `/wp-json/contact-form-7/v1/contact-forms/${formId}/feedback`);
127
+ const body = new FormData();
128
+ for (const [key, value] of Object.entries(data)) {
129
+ body.append(key, value);
130
+ }
131
+ const res = await fetch(url, { method: "POST", body, cache: "no-store" });
132
+ return res.json();
133
+ }
134
+ return { submitForm };
135
+ }
136
+
10
137
  // src/integrations/restApi/core/mutations/posts/mutations.ts
11
138
  function createPostsMutations(fetcher) {
12
139
  const { wpMutate } = fetcher;
@@ -200,119 +327,6 @@ function createMediaMutations(fetcher) {
200
327
  return { uploadMedia, updateMedia, deleteMedia };
201
328
  }
202
329
 
203
- // src/integrations/restApi/core/client/types.ts
204
- var WordPressAPIError = class extends Error {
205
- constructor(message, status, endpoint) {
206
- super(message);
207
- __publicField(this, "status", status);
208
- __publicField(this, "endpoint", endpoint);
209
- this.name = "WordPressAPIError";
210
- }
211
- };
212
-
213
- // src/integrations/restApi/core/client/url.ts
214
- function buildUrl(config, path, query) {
215
- const base = resolveBaseUrl(config);
216
- if (!query) return `${base}${path}`;
217
- const params = new URLSearchParams();
218
- for (const [key, value] of Object.entries(query)) {
219
- if (value !== void 0 && value !== null) {
220
- params.set(key, String(value));
221
- }
222
- }
223
- const qs = params.toString();
224
- return qs ? `${base}${path}?${qs}` : `${base}${path}`;
225
- }
226
-
227
- // src/integrations/restApi/core/client/fetcher.ts
228
- var USER_AGENT = "NextWordpress Client";
229
- async function doFetch(url, init = {}) {
230
- const response = await fetch(url, init);
231
- if (!response.ok) {
232
- throw new WordPressAPIError(
233
- `WordPress API request failed: ${response.statusText}`,
234
- response.status,
235
- url
236
- );
237
- }
238
- return response;
239
- }
240
- function createFetcher(config) {
241
- const cacheTtl = 300;
242
- async function wpFetch(path, query, tags = ["wordpress"]) {
243
- const url = buildUrl(config, path, query);
244
- const res = await doFetch(url, {
245
- headers: { "User-Agent": USER_AGENT },
246
- next: { tags, revalidate: cacheTtl }
247
- });
248
- return await res.json();
249
- }
250
- async function wpFetchGraceful(path, fallback, query, tags = ["wordpress"]) {
251
- try {
252
- return await wpFetch(path, query, tags);
253
- } catch {
254
- console.warn(`WordPress fetch failed for ${path}`);
255
- return fallback;
256
- }
257
- }
258
- async function wpFetchPaginated(path, query, tags = ["wordpress"]) {
259
- const url = buildUrl(config, path, query);
260
- const res = await doFetch(url, {
261
- headers: { "User-Agent": USER_AGENT },
262
- next: { tags, revalidate: cacheTtl }
263
- });
264
- return {
265
- data: await res.json(),
266
- headers: {
267
- total: parseInt(res.headers.get("X-WP-Total") ?? "0", 10),
268
- totalPages: parseInt(res.headers.get("X-WP-TotalPages") ?? "0", 10)
269
- }
270
- };
271
- }
272
- async function wpFetchPaginatedGraceful(path, query, tags = ["wordpress"]) {
273
- const empty = { data: [], headers: { total: 0, totalPages: 0 } };
274
- try {
275
- return await wpFetchPaginated(path, query, tags);
276
- } catch {
277
- console.warn(`WordPress paginated fetch failed for ${path}`);
278
- return empty;
279
- }
280
- }
281
- async function wpMutate(path, body, method = "POST", authToken) {
282
- const url = buildUrl(config, path);
283
- const headers = {
284
- "Content-Type": "application/json",
285
- "User-Agent": USER_AGENT
286
- };
287
- if (authToken) {
288
- headers["Authorization"] = authToken;
289
- }
290
- const res = await doFetch(url, {
291
- method,
292
- headers,
293
- body: JSON.stringify(body),
294
- cache: "no-store"
295
- });
296
- return await res.json();
297
- }
298
- async function wpUpload(path, file, filename, mimeType, authToken) {
299
- const url = buildUrl(config, path);
300
- const res = await doFetch(url, {
301
- method: "POST",
302
- headers: {
303
- "Content-Disposition": `attachment; filename="${filename}"`,
304
- "Content-Type": mimeType,
305
- "User-Agent": USER_AGENT,
306
- "Authorization": authToken
307
- },
308
- body: file,
309
- cache: "no-store"
310
- });
311
- return await res.json();
312
- }
313
- return { wpFetch, wpFetchGraceful, wpFetchPaginated, wpFetchPaginatedGraceful, wpMutate, wpUpload };
314
- }
315
-
316
330
  // src/integrations/restApi/core/mutations/index.ts
317
331
  function createWordPressMutationsClient(config) {
318
332
  const fetcher = createFetcher(config);
@@ -3188,6 +3202,91 @@ function createRevalidationHandler(config, revalidateTag) {
3188
3202
  };
3189
3203
  }
3190
3204
 
3205
+ // src/nextjs/faust.ts
3206
+ function createFaustAuthHandler(config) {
3207
+ const cookieName = config.cookieName ?? "faustwp-rt";
3208
+ return async function handler(request, routePath) {
3209
+ if (routePath === "auth/token") {
3210
+ const url = new URL(request.url);
3211
+ const code = url.searchParams.get("code");
3212
+ const redirectUri = url.searchParams.get("redirect_uri") ?? "/";
3213
+ const refreshToken = parseCookie(request, cookieName);
3214
+ if (!code && !refreshToken) {
3215
+ return Response.json({ error: "Unauthorized" }, { status: 401 });
3216
+ }
3217
+ const wpRes = await fetch(`${config.wpUrl}/?rest_route=/faustwp/v1/authorize`, {
3218
+ method: "POST",
3219
+ headers: {
3220
+ "Content-Type": "application/json",
3221
+ "x-faustwp-secret": config.secretKey
3222
+ },
3223
+ body: JSON.stringify({ code, refreshToken })
3224
+ });
3225
+ if (!wpRes.ok) {
3226
+ const body = await wpRes.text();
3227
+ return new Response(body, { status: wpRes.status });
3228
+ }
3229
+ const data = await wpRes.json();
3230
+ return new Response(null, {
3231
+ status: 302,
3232
+ headers: {
3233
+ Location: new URL(redirectUri, request.url).toString(),
3234
+ "Set-Cookie": buildSetCookie(cookieName, data.refreshToken, 2592e3)
3235
+ }
3236
+ });
3237
+ }
3238
+ if (routePath === "auth/logout") {
3239
+ return new Response(JSON.stringify({}), {
3240
+ status: 200,
3241
+ headers: {
3242
+ "Content-Type": "application/json",
3243
+ "Set-Cookie": `${cookieName}=; Max-Age=0; Path=/; HttpOnly`
3244
+ }
3245
+ });
3246
+ }
3247
+ return Response.json({ error: "Not Found" }, { status: 404 });
3248
+ };
3249
+ }
3250
+ function createPreviewHandler(config, deps) {
3251
+ const previewPath = config.previewPath ?? "posts";
3252
+ return async function handler(request) {
3253
+ const url = new URL(request.url);
3254
+ const postId = url.searchParams.get("postId");
3255
+ const previewPathname = url.searchParams.get("previewPathname");
3256
+ if (!postId) {
3257
+ return new Response("Missing postId", { status: 400 });
3258
+ }
3259
+ const slug = await resolvePreviewSlug(config, postId, previewPathname);
3260
+ if (!slug) {
3261
+ return new Response("Post not found", { status: 404 });
3262
+ }
3263
+ await deps.enableDraftMode();
3264
+ deps.redirect(`/${previewPath}/${slug}?postId=${postId}`);
3265
+ };
3266
+ }
3267
+ function parseCookie(request, name) {
3268
+ const header = request.headers.get("cookie") ?? "";
3269
+ const match = header.match(new RegExp(`(?:^|;\\s*)${name}=([^;]*)`));
3270
+ return match?.[1];
3271
+ }
3272
+ function buildSetCookie(name, value, maxAge) {
3273
+ const secure = process.env.NODE_ENV === "production" ? "; Secure" : "";
3274
+ return `${name}=${value}; HttpOnly; Path=/; SameSite=Strict; Max-Age=${maxAge}${secure}`;
3275
+ }
3276
+ async function resolvePreviewSlug(config, postId, previewPathname) {
3277
+ if (previewPathname && !previewPathname.includes("p=")) {
3278
+ const slug = previewPathname.replace(/\/$/, "").split("/").pop();
3279
+ if (slug) return slug;
3280
+ }
3281
+ const res = await fetch(`${config.wpUrl}/wp-json/wp/v2/posts/${postId}?_fields=slug`, {
3282
+ headers: { "x-faustwp-secret": config.secretKey },
3283
+ cache: "no-store"
3284
+ });
3285
+ if (!res.ok) return null;
3286
+ const data = await res.json();
3287
+ return data.slug ?? `preview-${postId}`;
3288
+ }
3289
+
3191
3290
  // src/auth/applicationPassword.ts
3192
3291
  function createApplicationPasswordToken(username, appPassword) {
3193
3292
  const encoded = Buffer.from(`${username}:${appPassword}`).toString("base64");
@@ -3230,6 +3329,6 @@ async function validateJwtToken(config, token) {
3230
3329
  return response.ok;
3231
3330
  }
3232
3331
 
3233
- export { AuthenticationError, WPGraphQLError, authenticateJwt, buildACFFragment, buildPageWithACFQuery, buildPostWithACFQuery, buildPostsWithACFQuery, createApplicationPasswordToken, createAuthorsMutations, createCPTQueries, createCategoriesMutations, createCommentsMutations, createMediaMutations, createMenusMutations, createPagesMutations, createPostsMutations, createRevalidationHandler, createTagsMutations, createWPGraphQLCoreClient as createWPGraphQLClient, createWPGraphQLCoreClient, createWPGraphQLFetcher, createWPGraphQLMutationsClient, createWPGraphQLWooCommerceClient, createWooCommerceClient, createWooCommerceFetcher, createWordPressClient, createWordPressMutationsClient, createYoastQueries, extractOmnibusData, resolveBaseUrl, validateJwtToken, withOmnibus, withOmnibusVariation };
3332
+ export { AuthenticationError, WPGraphQLError, authenticateJwt, buildACFFragment, buildPageWithACFQuery, buildPostWithACFQuery, buildPostsWithACFQuery, createApplicationPasswordToken, createAuthorsMutations, createCF7Queries, createCPTQueries, createCategoriesMutations, createCommentsMutations, createFaustAuthHandler, createMediaMutations, createMenusMutations, createPagesMutations, createPostsMutations, createPreviewHandler, createRevalidationHandler, createTagsMutations, createWPGraphQLCoreClient as createWPGraphQLClient, createWPGraphQLCoreClient, createWPGraphQLFetcher, createWPGraphQLMutationsClient, createWPGraphQLWooCommerceClient, createWooCommerceClient, createWooCommerceFetcher, createWordPressClient, createWordPressMutationsClient, createYoastQueries, extractOmnibusData, resolveBaseUrl, validateJwtToken, withOmnibus, withOmnibusVariation };
3234
3333
  //# sourceMappingURL=index.js.map
3235
3334
  //# sourceMappingURL=index.js.map