@szymonpiatek/nextwordpress 0.0.12 → 0.0.14
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/client/index.cjs +94 -8
- package/dist/client/index.cjs.map +1 -1
- package/dist/client/index.d.cts +3 -2
- package/dist/client/index.d.ts +3 -2
- package/dist/client/index.js +92 -9
- package/dist/client/index.js.map +1 -1
- package/dist/hooks/index.cjs +94 -8
- package/dist/hooks/index.cjs.map +1 -1
- package/dist/hooks/index.d.cts +16 -2
- package/dist/hooks/index.d.ts +16 -2
- package/dist/hooks/index.js +92 -9
- package/dist/hooks/index.js.map +1 -1
- package/dist/index.cjs +211 -140
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -19
- package/dist/index.d.ts +7 -19
- package/dist/index.js +210 -141
- package/dist/index.js.map +1 -1
- package/dist/server/index.cjs +211 -140
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.d.cts +2 -2
- package/dist/server/index.d.ts +2 -2
- package/dist/server/index.js +210 -141
- package/dist/server/index.js.map +1 -1
- package/dist/{types-WcyioRuq.d.cts → types-COJWPg77.d.cts} +30 -1
- package/dist/{types-WcyioRuq.d.ts → types-COJWPg77.d.ts} +30 -1
- package/package.json +1 -1
package/dist/server/index.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export { y as AuthenticationError, A as Author, B as BlockType, q as CF7SubmissionResponse, z as CF7SubmissionStatus, D as CF7ValidationError, C as CookieConsentCategories, E as CookieConsentConfig, H as EditorBlock, I as EmbeddedAuthor, K as EmbeddedTerm, L as ErrorCode, F as FeaturedMedia, j as GQLConnection, M as GQLError, O as GQLPageInfo, G as GQLPost, i as GQLPostFilter, J as JwtAuthCredentials, r as JwtAuthResponse, Q as MediaDetails, S as MediaSize, N as NextWordpressConfig, P as Post, V as PostEmbedded, t as RenderedContent, R as RenderedTitle, X as SearchResult, T as Taxonomy, Y as TemplatePart, U as UpdateCustomerInput, w as WCAddress, e as WCCreateOrderInput, g as WCCustomer, Z as WCDimensions, u as WCImage, f as WCOrder, _ as WCOrderLineItem, b as WCProduct, $ as WCProductAttribute, a0 as WCProductDefaultAttribute, c as WCProductFilterParams, v as WCProductVariation, a1 as WCShippingLine, s as WPEntity, h as WPGraphQLConfig, a2 as WPGraphQLError, o as WPULikeCheckParams, p as WPULikeCheckResponse, a3 as WPULikeItemType, l as WPULikeStats, k as WPULikeStatsParams, m as WPULikeStatus, x as WPULikeVoteParams, n as WPULikeVoteResponse, a as WooCommerceConfig, a4 as WooCommerceError, a5 as WooCommercePaginationHeaders, d as WooCommerceResponse, a6 as WordPressAPIError, a7 as createCookieConsentHandler, a8 as defaultMessages, a9 as defaultMessagesPl, aa as parseCookieConsent, ab as resolveMessage } from '../types-COJWPg77.cjs';
|
|
2
|
+
export { Category, Comment, CommentAuthorAvatar, CreateAttributeTermInput, CreateAuthorInput, CreateCategoryInput, CreateCommentInput, CreateCouponInput, CreateMenuInput, CreateMenuItemInput, CreatePageInput, CreatePostInput, CreateProductAttributeInput, CreateProductCategoryInput, CreateProductInput, CreateProductReviewInput, CreateProductTagInput, CreateShippingClassInput, CreateShippingZoneInput, CreateShippingZoneMethodInput, CreateTagInput, CreateTaxClassInput, CreateTaxRateInput, CreateWebhookInput, FaustConfig, FaustPreviewConfig, FaustPreviewDeps, GQLACFFieldGroup, GQLAuthor, GQLCPTNode, GQLCategory, GQLCreateCommentInput, GQLCreateCommentResult, GQLCreatePostInput, GQLCustomer, GQLDeletePostResult, GQLLineItem, GQLMutatedComment, GQLMutatedPost, GQLOrder, GQLOrderAddress, GQLPage, GQLPageWithSEO, GQLPostStatus, GQLPostWithSEO, GQLProduct, GQLProductFilter, GQLProductVariation, GQLTag, GQLUpdatePostInput, GQLYoastSEO, Menu, MenuItem, MenuLocation, MenuWithItems, OmnibusPriceEntry, OmnibusProductData, Page, RestPageStatus, RestPostStatus, RevalidationConfig, RevalidationPayload, RevalidationResult, Tag, UpdateAttributeTermInput, UpdateAuthorInput, UpdateCategoryInput, UpdateCommentInput, UpdateCouponInput, UpdateMediaInput, UpdateMenuInput, UpdateMenuItemInput, UpdatePageInput, UpdatePostInput, UpdateProductAttributeInput, UpdateProductCategoryInput, UpdateProductInput, UpdateProductReviewInput, UpdateProductTagInput, UpdateShippingClassInput, UpdateShippingZoneInput, UpdateShippingZoneMethodInput, UpdateTagInput, UpdateTaxRateInput, UpdateWebhookInput, UploadMediaInput, WCAttributeTerm, WCContinent, WCCountry, WCCoupon, WCCreateOrderNoteInput, WCCreateOrderRefundInput, WCCurrency, WCGlobalProductAttribute, WCOrderNote, WCOrderRefund, WCPaymentGateway, WCPaymentGatewaySetting, WCProductCategory, WCProductReview, WCProductReviewFilterParams, WCProductStatus, WCProductTag, WCProductVariationWithOmnibus, WCProductWithOmnibus, WCRefundLineItem, WCReviewStatus, WCSalesReport, WCSalesReportParams, WCSettingGroup, WCSettingOption, WCShippingClass, WCShippingMethod, WCShippingZone, WCShippingZoneLocation, WCShippingZoneMethod, WCStatusCount, WCSystemStatus, WCSystemStatusTool, WCTaxClass, WCTaxRate, WCTopSeller, WCTopSellersParams, WCWebhook, WCWebhookStatus, WCWebhookTopic, WPGraphQLFetcher, WooCommerceFetcher, authenticateJwt, buildACFFragment, buildPageWithACFQuery, buildPostWithACFQuery, buildPostsWithACFQuery, createApplicationPasswordToken, createAuthorsMutations, createCF7Queries, createCPTQueries, createCategoriesMutations, createCommentsMutations, createFaustAuthHandler, createMediaMutations, createMenusMutations, createPagesMutations, createPostsMutations, createPreviewHandler, createRevalidationHandler, createTagsMutations, createWPGraphQLClient, createWPGraphQLClient as createWPGraphQLCoreClient, createWPGraphQLFetcher, createWPGraphQLMutationsClient, createWPGraphQLWooCommerceClient, createWPULikeClient, createWPULikeQueries, createWooCommerceClient, createWooCommerceFetcher, createWordPressClient, createWordPressMutationsClient, createYoastQueries, extractOmnibusData, resolveBaseUrl, validateJwtToken, withOmnibus, withOmnibusVariation } from '../index.cjs';
|
package/dist/server/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export { y as AuthenticationError, A as Author, B as BlockType, q as CF7SubmissionResponse, z as CF7SubmissionStatus, D as CF7ValidationError, C as CookieConsentCategories, E as CookieConsentConfig, H as EditorBlock, I as EmbeddedAuthor, K as EmbeddedTerm, L as ErrorCode, F as FeaturedMedia, j as GQLConnection, M as GQLError, O as GQLPageInfo, G as GQLPost, i as GQLPostFilter, J as JwtAuthCredentials, r as JwtAuthResponse, Q as MediaDetails, S as MediaSize, N as NextWordpressConfig, P as Post, V as PostEmbedded, t as RenderedContent, R as RenderedTitle, X as SearchResult, T as Taxonomy, Y as TemplatePart, U as UpdateCustomerInput, w as WCAddress, e as WCCreateOrderInput, g as WCCustomer, Z as WCDimensions, u as WCImage, f as WCOrder, _ as WCOrderLineItem, b as WCProduct, $ as WCProductAttribute, a0 as WCProductDefaultAttribute, c as WCProductFilterParams, v as WCProductVariation, a1 as WCShippingLine, s as WPEntity, h as WPGraphQLConfig, a2 as WPGraphQLError, o as WPULikeCheckParams, p as WPULikeCheckResponse, a3 as WPULikeItemType, l as WPULikeStats, k as WPULikeStatsParams, m as WPULikeStatus, x as WPULikeVoteParams, n as WPULikeVoteResponse, a as WooCommerceConfig, a4 as WooCommerceError, a5 as WooCommercePaginationHeaders, d as WooCommerceResponse, a6 as WordPressAPIError, a7 as createCookieConsentHandler, a8 as defaultMessages, a9 as defaultMessagesPl, aa as parseCookieConsent, ab as resolveMessage } from '../types-COJWPg77.js';
|
|
2
|
+
export { Category, Comment, CommentAuthorAvatar, CreateAttributeTermInput, CreateAuthorInput, CreateCategoryInput, CreateCommentInput, CreateCouponInput, CreateMenuInput, CreateMenuItemInput, CreatePageInput, CreatePostInput, CreateProductAttributeInput, CreateProductCategoryInput, CreateProductInput, CreateProductReviewInput, CreateProductTagInput, CreateShippingClassInput, CreateShippingZoneInput, CreateShippingZoneMethodInput, CreateTagInput, CreateTaxClassInput, CreateTaxRateInput, CreateWebhookInput, FaustConfig, FaustPreviewConfig, FaustPreviewDeps, GQLACFFieldGroup, GQLAuthor, GQLCPTNode, GQLCategory, GQLCreateCommentInput, GQLCreateCommentResult, GQLCreatePostInput, GQLCustomer, GQLDeletePostResult, GQLLineItem, GQLMutatedComment, GQLMutatedPost, GQLOrder, GQLOrderAddress, GQLPage, GQLPageWithSEO, GQLPostStatus, GQLPostWithSEO, GQLProduct, GQLProductFilter, GQLProductVariation, GQLTag, GQLUpdatePostInput, GQLYoastSEO, Menu, MenuItem, MenuLocation, MenuWithItems, OmnibusPriceEntry, OmnibusProductData, Page, RestPageStatus, RestPostStatus, RevalidationConfig, RevalidationPayload, RevalidationResult, Tag, UpdateAttributeTermInput, UpdateAuthorInput, UpdateCategoryInput, UpdateCommentInput, UpdateCouponInput, UpdateMediaInput, UpdateMenuInput, UpdateMenuItemInput, UpdatePageInput, UpdatePostInput, UpdateProductAttributeInput, UpdateProductCategoryInput, UpdateProductInput, UpdateProductReviewInput, UpdateProductTagInput, UpdateShippingClassInput, UpdateShippingZoneInput, UpdateShippingZoneMethodInput, UpdateTagInput, UpdateTaxRateInput, UpdateWebhookInput, UploadMediaInput, WCAttributeTerm, WCContinent, WCCountry, WCCoupon, WCCreateOrderNoteInput, WCCreateOrderRefundInput, WCCurrency, WCGlobalProductAttribute, WCOrderNote, WCOrderRefund, WCPaymentGateway, WCPaymentGatewaySetting, WCProductCategory, WCProductReview, WCProductReviewFilterParams, WCProductStatus, WCProductTag, WCProductVariationWithOmnibus, WCProductWithOmnibus, WCRefundLineItem, WCReviewStatus, WCSalesReport, WCSalesReportParams, WCSettingGroup, WCSettingOption, WCShippingClass, WCShippingMethod, WCShippingZone, WCShippingZoneLocation, WCShippingZoneMethod, WCStatusCount, WCSystemStatus, WCSystemStatusTool, WCTaxClass, WCTaxRate, WCTopSeller, WCTopSellersParams, WCWebhook, WCWebhookStatus, WCWebhookTopic, WPGraphQLFetcher, WooCommerceFetcher, authenticateJwt, buildACFFragment, buildPageWithACFQuery, buildPostWithACFQuery, buildPostsWithACFQuery, createApplicationPasswordToken, createAuthorsMutations, createCF7Queries, createCPTQueries, createCategoriesMutations, createCommentsMutations, createFaustAuthHandler, createMediaMutations, createMenusMutations, createPagesMutations, createPostsMutations, createPreviewHandler, createRevalidationHandler, createTagsMutations, createWPGraphQLClient, createWPGraphQLClient as createWPGraphQLCoreClient, createWPGraphQLFetcher, createWPGraphQLMutationsClient, createWPGraphQLWooCommerceClient, createWPULikeClient, createWPULikeQueries, createWooCommerceClient, createWooCommerceFetcher, createWordPressClient, createWordPressMutationsClient, createYoastQueries, extractOmnibusData, resolveBaseUrl, validateJwtToken, withOmnibus, withOmnibusVariation } from '../index.js';
|
package/dist/server/index.js
CHANGED
|
@@ -36,7 +36,13 @@ var ErrorCode = {
|
|
|
36
36
|
// Auth
|
|
37
37
|
AUTH_JWT_FAILED: "AUTH_JWT_FAILED",
|
|
38
38
|
AUTH_CREDENTIALS_INVALID: "AUTH_CREDENTIALS_INVALID",
|
|
39
|
-
AUTH_TOKEN_INVALID: "AUTH_TOKEN_INVALID"
|
|
39
|
+
AUTH_TOKEN_INVALID: "AUTH_TOKEN_INVALID",
|
|
40
|
+
// Contact Form 7
|
|
41
|
+
CF7_MAIL_SENT: "CF7_MAIL_SENT",
|
|
42
|
+
CF7_MAIL_FAILED: "CF7_MAIL_FAILED",
|
|
43
|
+
CF7_VALIDATION_FAILED: "CF7_VALIDATION_FAILED",
|
|
44
|
+
CF7_SPAM: "CF7_SPAM",
|
|
45
|
+
CF7_ABORTED: "CF7_ABORTED"
|
|
40
46
|
};
|
|
41
47
|
var defaultMessages = {
|
|
42
48
|
WP_REQUEST_FAILED: "WordPress API request failed",
|
|
@@ -61,7 +67,12 @@ var defaultMessages = {
|
|
|
61
67
|
WOO_SHIPPING_ZONE_NOT_FOUND: "Shipping zone not found",
|
|
62
68
|
AUTH_JWT_FAILED: "JWT authentication failed",
|
|
63
69
|
AUTH_CREDENTIALS_INVALID: "Invalid credentials",
|
|
64
|
-
AUTH_TOKEN_INVALID: "JWT token is invalid or expired"
|
|
70
|
+
AUTH_TOKEN_INVALID: "JWT token is invalid or expired",
|
|
71
|
+
CF7_MAIL_SENT: "Thank you for your message.",
|
|
72
|
+
CF7_MAIL_FAILED: "There was an error trying to send your message.",
|
|
73
|
+
CF7_VALIDATION_FAILED: "One or more fields have an error. Please check and try again.",
|
|
74
|
+
CF7_SPAM: "There was an error trying to send your message. Please try later.",
|
|
75
|
+
CF7_ABORTED: "Message submission has been aborted."
|
|
65
76
|
};
|
|
66
77
|
var defaultMessagesPl = {
|
|
67
78
|
WP_REQUEST_FAILED: "B\u0142\u0105d \u017C\u0105dania do WordPress API",
|
|
@@ -86,149 +97,17 @@ var defaultMessagesPl = {
|
|
|
86
97
|
WOO_SHIPPING_ZONE_NOT_FOUND: "Strefa wysy\u0142ki nie istnieje",
|
|
87
98
|
AUTH_JWT_FAILED: "B\u0142\u0105d uwierzytelnienia JWT",
|
|
88
99
|
AUTH_CREDENTIALS_INVALID: "Nieprawid\u0142owe dane logowania",
|
|
89
|
-
AUTH_TOKEN_INVALID: "Token JWT jest nieprawid\u0142owy lub wygas\u0142"
|
|
100
|
+
AUTH_TOKEN_INVALID: "Token JWT jest nieprawid\u0142owy lub wygas\u0142",
|
|
101
|
+
CF7_MAIL_SENT: "Dzi\u0119kujemy za wiadomo\u015B\u0107.",
|
|
102
|
+
CF7_MAIL_FAILED: "Wyst\u0105pi\u0142 b\u0142\u0105d podczas wysy\u0142ania wiadomo\u015Bci.",
|
|
103
|
+
CF7_VALIDATION_FAILED: "Jedno lub wi\u0119cej p\xF3l zawiera b\u0142\u0105d. Sprawd\u017A i spr\xF3buj ponownie.",
|
|
104
|
+
CF7_SPAM: "Wyst\u0105pi\u0142 b\u0142\u0105d podczas wysy\u0142ania wiadomo\u015Bci. Spr\xF3buj p\xF3\u017Aniej.",
|
|
105
|
+
CF7_ABORTED: "Wysy\u0142anie formularza zosta\u0142o przerwane."
|
|
90
106
|
};
|
|
91
107
|
function resolveMessage(code, overrides) {
|
|
92
108
|
return overrides?.[code] ?? defaultMessages[code];
|
|
93
109
|
}
|
|
94
110
|
|
|
95
|
-
// src/integrations/restApi/core/client/types.ts
|
|
96
|
-
var WordPressAPIError = class extends Error {
|
|
97
|
-
constructor(code, status, endpoint, message, detail) {
|
|
98
|
-
super(detail ? `${message}: ${detail}` : message);
|
|
99
|
-
__publicField(this, "code", code);
|
|
100
|
-
__publicField(this, "status", status);
|
|
101
|
-
__publicField(this, "endpoint", endpoint);
|
|
102
|
-
this.name = "WordPressAPIError";
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
// src/integrations/restApi/core/client/url.ts
|
|
107
|
-
function buildUrl(config, path, query) {
|
|
108
|
-
const base = resolveBaseUrl(config);
|
|
109
|
-
if (!query) return `${base}${path}`;
|
|
110
|
-
const params = new URLSearchParams();
|
|
111
|
-
for (const [key, value] of Object.entries(query)) {
|
|
112
|
-
if (value !== void 0 && value !== null) {
|
|
113
|
-
params.set(key, String(value));
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
const qs = params.toString();
|
|
117
|
-
return qs ? `${base}${path}?${qs}` : `${base}${path}`;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// src/integrations/restApi/core/client/fetcher.ts
|
|
121
|
-
var USER_AGENT = "NextWordpress Client";
|
|
122
|
-
function resolveWpErrorCode(status) {
|
|
123
|
-
if (status === 401) return ErrorCode.WP_UNAUTHORIZED;
|
|
124
|
-
if (status === 403) return ErrorCode.WP_FORBIDDEN;
|
|
125
|
-
if (status === 404) return ErrorCode.WP_NOT_FOUND;
|
|
126
|
-
return ErrorCode.WP_REQUEST_FAILED;
|
|
127
|
-
}
|
|
128
|
-
function createFetcher(config) {
|
|
129
|
-
const cacheTtl = config.cacheTTL ?? 300;
|
|
130
|
-
async function doFetch(url, init = {}) {
|
|
131
|
-
const response = await fetch(url, init);
|
|
132
|
-
if (!response.ok) {
|
|
133
|
-
const code = resolveWpErrorCode(response.status);
|
|
134
|
-
throw new WordPressAPIError(
|
|
135
|
-
code,
|
|
136
|
-
response.status,
|
|
137
|
-
url,
|
|
138
|
-
resolveMessage(code, config.errorMessages),
|
|
139
|
-
response.statusText
|
|
140
|
-
);
|
|
141
|
-
}
|
|
142
|
-
return response;
|
|
143
|
-
}
|
|
144
|
-
async function wpFetch(path, query, tags = ["wordpress"]) {
|
|
145
|
-
const url = buildUrl(config, path, query);
|
|
146
|
-
const res = await doFetch(url, {
|
|
147
|
-
headers: { "User-Agent": USER_AGENT },
|
|
148
|
-
next: { tags, revalidate: cacheTtl }
|
|
149
|
-
});
|
|
150
|
-
return await res.json();
|
|
151
|
-
}
|
|
152
|
-
async function wpFetchGraceful(path, fallback, query, tags = ["wordpress"]) {
|
|
153
|
-
try {
|
|
154
|
-
return await wpFetch(path, query, tags);
|
|
155
|
-
} catch {
|
|
156
|
-
console.warn(`WordPress fetch failed for ${path}`);
|
|
157
|
-
return fallback;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
async function wpFetchPaginated(path, query, tags = ["wordpress"]) {
|
|
161
|
-
const url = buildUrl(config, path, query);
|
|
162
|
-
const res = await doFetch(url, {
|
|
163
|
-
headers: { "User-Agent": USER_AGENT },
|
|
164
|
-
next: { tags, revalidate: cacheTtl }
|
|
165
|
-
});
|
|
166
|
-
return {
|
|
167
|
-
data: await res.json(),
|
|
168
|
-
headers: {
|
|
169
|
-
total: parseInt(res.headers.get("X-WP-Total") ?? "0", 10),
|
|
170
|
-
totalPages: parseInt(res.headers.get("X-WP-TotalPages") ?? "0", 10)
|
|
171
|
-
}
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
async function wpFetchPaginatedGraceful(path, query, tags = ["wordpress"]) {
|
|
175
|
-
const empty = { data: [], headers: { total: 0, totalPages: 0 } };
|
|
176
|
-
try {
|
|
177
|
-
return await wpFetchPaginated(path, query, tags);
|
|
178
|
-
} catch {
|
|
179
|
-
console.warn(`WordPress paginated fetch failed for ${path}`);
|
|
180
|
-
return empty;
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
async function wpMutate(path, body, method = "POST", authToken) {
|
|
184
|
-
const url = buildUrl(config, path);
|
|
185
|
-
const headers = {
|
|
186
|
-
"Content-Type": "application/json",
|
|
187
|
-
"User-Agent": USER_AGENT
|
|
188
|
-
};
|
|
189
|
-
if (authToken) {
|
|
190
|
-
headers["Authorization"] = authToken.startsWith("Basic ") || authToken.startsWith("Bearer ") ? authToken : `Bearer ${authToken}`;
|
|
191
|
-
}
|
|
192
|
-
const res = await doFetch(url, {
|
|
193
|
-
method,
|
|
194
|
-
headers,
|
|
195
|
-
body: JSON.stringify(body),
|
|
196
|
-
cache: "no-store"
|
|
197
|
-
});
|
|
198
|
-
return await res.json();
|
|
199
|
-
}
|
|
200
|
-
async function wpUpload(path, file, filename, mimeType, authToken) {
|
|
201
|
-
const url = buildUrl(config, path);
|
|
202
|
-
const res = await doFetch(url, {
|
|
203
|
-
method: "POST",
|
|
204
|
-
headers: {
|
|
205
|
-
"Content-Disposition": `attachment; filename="${filename}"`,
|
|
206
|
-
"Content-Type": mimeType,
|
|
207
|
-
"User-Agent": USER_AGENT,
|
|
208
|
-
"Authorization": authToken.startsWith("Basic ") || authToken.startsWith("Bearer ") ? authToken : `Bearer ${authToken}`
|
|
209
|
-
},
|
|
210
|
-
body: file,
|
|
211
|
-
cache: "no-store"
|
|
212
|
-
});
|
|
213
|
-
return await res.json();
|
|
214
|
-
}
|
|
215
|
-
return { wpFetch, wpFetchGraceful, wpFetchPaginated, wpFetchPaginatedGraceful, wpMutate, wpUpload };
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
// src/integrations/restApi/core/contactForm7/queries.ts
|
|
219
|
-
function createCF7Queries(config) {
|
|
220
|
-
async function submitForm(formId, data) {
|
|
221
|
-
const url = buildUrl(config, `/wp-json/contact-form-7/v1/contact-forms/${formId}/feedback`);
|
|
222
|
-
const body = new FormData();
|
|
223
|
-
for (const [key, value] of Object.entries(data)) {
|
|
224
|
-
body.append(key, value);
|
|
225
|
-
}
|
|
226
|
-
const res = await fetch(url, { method: "POST", body, cache: "no-store" });
|
|
227
|
-
return res.json();
|
|
228
|
-
}
|
|
229
|
-
return { submitForm };
|
|
230
|
-
}
|
|
231
|
-
|
|
232
111
|
// src/integrations/restApi/core/mutations/posts/mutations.ts
|
|
233
112
|
function createPostsMutations(fetcher) {
|
|
234
113
|
const { wpMutate } = fetcher;
|
|
@@ -422,6 +301,129 @@ function createMediaMutations(fetcher) {
|
|
|
422
301
|
return { uploadMedia, updateMedia, deleteMedia };
|
|
423
302
|
}
|
|
424
303
|
|
|
304
|
+
// src/integrations/restApi/core/client/types.ts
|
|
305
|
+
var WordPressAPIError = class extends Error {
|
|
306
|
+
constructor(code, status, endpoint, message, detail) {
|
|
307
|
+
super(detail ? `${message}: ${detail}` : message);
|
|
308
|
+
__publicField(this, "code", code);
|
|
309
|
+
__publicField(this, "status", status);
|
|
310
|
+
__publicField(this, "endpoint", endpoint);
|
|
311
|
+
this.name = "WordPressAPIError";
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
// src/integrations/restApi/core/client/url.ts
|
|
316
|
+
function buildUrl(config, path, query) {
|
|
317
|
+
const base = resolveBaseUrl(config);
|
|
318
|
+
if (!query) return `${base}${path}`;
|
|
319
|
+
const params = new URLSearchParams();
|
|
320
|
+
for (const [key, value] of Object.entries(query)) {
|
|
321
|
+
if (value !== void 0 && value !== null) {
|
|
322
|
+
params.set(key, String(value));
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
const qs = params.toString();
|
|
326
|
+
return qs ? `${base}${path}?${qs}` : `${base}${path}`;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// src/integrations/restApi/core/client/fetcher.ts
|
|
330
|
+
var USER_AGENT = "NextWordpress Client";
|
|
331
|
+
function resolveWpErrorCode(status) {
|
|
332
|
+
if (status === 401) return ErrorCode.WP_UNAUTHORIZED;
|
|
333
|
+
if (status === 403) return ErrorCode.WP_FORBIDDEN;
|
|
334
|
+
if (status === 404) return ErrorCode.WP_NOT_FOUND;
|
|
335
|
+
return ErrorCode.WP_REQUEST_FAILED;
|
|
336
|
+
}
|
|
337
|
+
function createFetcher(config) {
|
|
338
|
+
const cacheTtl = config.cacheTTL ?? 300;
|
|
339
|
+
async function doFetch(url, init = {}) {
|
|
340
|
+
const response = await fetch(url, init);
|
|
341
|
+
if (!response.ok) {
|
|
342
|
+
const code = resolveWpErrorCode(response.status);
|
|
343
|
+
throw new WordPressAPIError(
|
|
344
|
+
code,
|
|
345
|
+
response.status,
|
|
346
|
+
url,
|
|
347
|
+
resolveMessage(code, config.errorMessages),
|
|
348
|
+
response.statusText
|
|
349
|
+
);
|
|
350
|
+
}
|
|
351
|
+
return response;
|
|
352
|
+
}
|
|
353
|
+
async function wpFetch(path, query, tags = ["wordpress"]) {
|
|
354
|
+
const url = buildUrl(config, path, query);
|
|
355
|
+
const res = await doFetch(url, {
|
|
356
|
+
headers: { "User-Agent": USER_AGENT },
|
|
357
|
+
next: { tags, revalidate: cacheTtl }
|
|
358
|
+
});
|
|
359
|
+
return await res.json();
|
|
360
|
+
}
|
|
361
|
+
async function wpFetchGraceful(path, fallback, query, tags = ["wordpress"]) {
|
|
362
|
+
try {
|
|
363
|
+
return await wpFetch(path, query, tags);
|
|
364
|
+
} catch {
|
|
365
|
+
console.warn(`WordPress fetch failed for ${path}`);
|
|
366
|
+
return fallback;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
async function wpFetchPaginated(path, query, tags = ["wordpress"]) {
|
|
370
|
+
const url = buildUrl(config, path, query);
|
|
371
|
+
const res = await doFetch(url, {
|
|
372
|
+
headers: { "User-Agent": USER_AGENT },
|
|
373
|
+
next: { tags, revalidate: cacheTtl }
|
|
374
|
+
});
|
|
375
|
+
return {
|
|
376
|
+
data: await res.json(),
|
|
377
|
+
headers: {
|
|
378
|
+
total: parseInt(res.headers.get("X-WP-Total") ?? "0", 10),
|
|
379
|
+
totalPages: parseInt(res.headers.get("X-WP-TotalPages") ?? "0", 10)
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
async function wpFetchPaginatedGraceful(path, query, tags = ["wordpress"]) {
|
|
384
|
+
const empty = { data: [], headers: { total: 0, totalPages: 0 } };
|
|
385
|
+
try {
|
|
386
|
+
return await wpFetchPaginated(path, query, tags);
|
|
387
|
+
} catch {
|
|
388
|
+
console.warn(`WordPress paginated fetch failed for ${path}`);
|
|
389
|
+
return empty;
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
async function wpMutate(path, body, method = "POST", authToken) {
|
|
393
|
+
const url = buildUrl(config, path);
|
|
394
|
+
const headers = {
|
|
395
|
+
"Content-Type": "application/json",
|
|
396
|
+
"User-Agent": USER_AGENT
|
|
397
|
+
};
|
|
398
|
+
if (authToken) {
|
|
399
|
+
headers["Authorization"] = authToken.startsWith("Basic ") || authToken.startsWith("Bearer ") ? authToken : `Bearer ${authToken}`;
|
|
400
|
+
}
|
|
401
|
+
const res = await doFetch(url, {
|
|
402
|
+
method,
|
|
403
|
+
headers,
|
|
404
|
+
body: JSON.stringify(body),
|
|
405
|
+
cache: "no-store"
|
|
406
|
+
});
|
|
407
|
+
return await res.json();
|
|
408
|
+
}
|
|
409
|
+
async function wpUpload(path, file, filename, mimeType, authToken) {
|
|
410
|
+
const url = buildUrl(config, path);
|
|
411
|
+
const res = await doFetch(url, {
|
|
412
|
+
method: "POST",
|
|
413
|
+
headers: {
|
|
414
|
+
"Content-Disposition": `attachment; filename="${filename}"`,
|
|
415
|
+
"Content-Type": mimeType,
|
|
416
|
+
"User-Agent": USER_AGENT,
|
|
417
|
+
"Authorization": authToken.startsWith("Basic ") || authToken.startsWith("Bearer ") ? authToken : `Bearer ${authToken}`
|
|
418
|
+
},
|
|
419
|
+
body: file,
|
|
420
|
+
cache: "no-store"
|
|
421
|
+
});
|
|
422
|
+
return await res.json();
|
|
423
|
+
}
|
|
424
|
+
return { wpFetch, wpFetchGraceful, wpFetchPaginated, wpFetchPaginatedGraceful, wpMutate, wpUpload };
|
|
425
|
+
}
|
|
426
|
+
|
|
425
427
|
// src/integrations/restApi/core/mutations/index.ts
|
|
426
428
|
function createWordPressMutationsClient(config) {
|
|
427
429
|
const fetcher = createFetcher(config);
|
|
@@ -2131,6 +2133,20 @@ function createWPULikeClient(config) {
|
|
|
2131
2133
|
return createWPULikeQueries(fetcher);
|
|
2132
2134
|
}
|
|
2133
2135
|
|
|
2136
|
+
// src/integrations/restApi/contactForm7/queries.ts
|
|
2137
|
+
function createCF7Queries(config) {
|
|
2138
|
+
async function submitForm(formId, data) {
|
|
2139
|
+
const url = buildUrl(config, `/wp-json/contact-form-7/v1/contact-forms/${formId}/feedback`);
|
|
2140
|
+
const body = new FormData();
|
|
2141
|
+
for (const [key, value] of Object.entries(data)) {
|
|
2142
|
+
body.append(key, value);
|
|
2143
|
+
}
|
|
2144
|
+
const res = await fetch(url, { method: "POST", body, cache: "no-store" });
|
|
2145
|
+
return res.json();
|
|
2146
|
+
}
|
|
2147
|
+
return { submitForm };
|
|
2148
|
+
}
|
|
2149
|
+
|
|
2134
2150
|
// src/integrations/wpGraphQL/client/types.ts
|
|
2135
2151
|
var WPGraphQLError = class extends Error {
|
|
2136
2152
|
constructor(code, status, endpoint, message, gqlErrors) {
|
|
@@ -4207,6 +4223,59 @@ async function resolvePreviewSlug(config, postId, previewPathname) {
|
|
|
4207
4223
|
return data.slug ?? `preview-${postId}`;
|
|
4208
4224
|
}
|
|
4209
4225
|
|
|
4226
|
+
// src/nextjs/cookieConsent.ts
|
|
4227
|
+
function createCookieConsentHandler(config) {
|
|
4228
|
+
const cookieName = config?.cookieName ?? "cookie_notice_accepted";
|
|
4229
|
+
const maxAge = config?.maxAge ?? 31536e3;
|
|
4230
|
+
return async function handler(request) {
|
|
4231
|
+
if (request.method === "GET") {
|
|
4232
|
+
const consent = parseCookieConsent(request, cookieName);
|
|
4233
|
+
return Response.json(consent ?? null);
|
|
4234
|
+
}
|
|
4235
|
+
if (request.method === "POST") {
|
|
4236
|
+
const body = await request.json();
|
|
4237
|
+
const categories = {
|
|
4238
|
+
necessary: true,
|
|
4239
|
+
analytics: body.analytics ?? false,
|
|
4240
|
+
marketing: body.marketing ?? false
|
|
4241
|
+
};
|
|
4242
|
+
return new Response(JSON.stringify(categories), {
|
|
4243
|
+
status: 200,
|
|
4244
|
+
headers: {
|
|
4245
|
+
"Content-Type": "application/json",
|
|
4246
|
+
"Set-Cookie": buildConsentCookie(cookieName, encodeURIComponent(JSON.stringify(categories)), maxAge)
|
|
4247
|
+
}
|
|
4248
|
+
});
|
|
4249
|
+
}
|
|
4250
|
+
if (request.method === "DELETE") {
|
|
4251
|
+
return new Response(null, {
|
|
4252
|
+
status: 204,
|
|
4253
|
+
headers: {
|
|
4254
|
+
"Set-Cookie": `${cookieName}=; Max-Age=0; Path=/; SameSite=Lax`
|
|
4255
|
+
}
|
|
4256
|
+
});
|
|
4257
|
+
}
|
|
4258
|
+
return Response.json({ error: "Method Not Allowed" }, { status: 405 });
|
|
4259
|
+
};
|
|
4260
|
+
}
|
|
4261
|
+
function parseCookieConsent(request, cookieName = "cookie_notice_accepted") {
|
|
4262
|
+
const header = request.headers.get("cookie") ?? "";
|
|
4263
|
+
const match = header.match(new RegExp(`(?:^|;\\s*)${cookieName}=([^;]*)`));
|
|
4264
|
+
if (!match) return null;
|
|
4265
|
+
if (match[1] === "1") return { necessary: true, analytics: true, marketing: true };
|
|
4266
|
+
try {
|
|
4267
|
+
const parsed = JSON.parse(decodeURIComponent(match[1]));
|
|
4268
|
+
if (typeof parsed !== "object" || parsed === null) return null;
|
|
4269
|
+
return { necessary: true, analytics: parsed.analytics ?? false, marketing: parsed.marketing ?? false };
|
|
4270
|
+
} catch {
|
|
4271
|
+
return null;
|
|
4272
|
+
}
|
|
4273
|
+
}
|
|
4274
|
+
function buildConsentCookie(name, value, maxAge) {
|
|
4275
|
+
const secure = process.env.NODE_ENV === "production" ? "; Secure" : "";
|
|
4276
|
+
return `${name}=${value}; Path=/; SameSite=Lax; Max-Age=${maxAge}${secure}`;
|
|
4277
|
+
}
|
|
4278
|
+
|
|
4210
4279
|
// src/auth/applicationPassword.ts
|
|
4211
4280
|
function createApplicationPasswordToken(username, appPassword) {
|
|
4212
4281
|
const encoded = Buffer.from(`${username}:${appPassword}`).toString("base64");
|
|
@@ -4258,6 +4327,6 @@ async function validateJwtToken(config, token) {
|
|
|
4258
4327
|
return response.ok;
|
|
4259
4328
|
}
|
|
4260
4329
|
|
|
4261
|
-
export { AuthenticationError, ErrorCode, WPGraphQLError, WooCommerceError, WordPressAPIError, 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, createWPULikeClient, createWPULikeQueries, createWooCommerceClient, createWooCommerceFetcher, createWordPressClient, createWordPressMutationsClient, createYoastQueries, defaultMessages, defaultMessagesPl, extractOmnibusData, resolveBaseUrl, resolveMessage, validateJwtToken, withOmnibus, withOmnibusVariation };
|
|
4330
|
+
export { AuthenticationError, ErrorCode, WPGraphQLError, WooCommerceError, WordPressAPIError, authenticateJwt, buildACFFragment, buildPageWithACFQuery, buildPostWithACFQuery, buildPostsWithACFQuery, createApplicationPasswordToken, createAuthorsMutations, createCF7Queries, createCPTQueries, createCategoriesMutations, createCommentsMutations, createCookieConsentHandler, createFaustAuthHandler, createMediaMutations, createMenusMutations, createPagesMutations, createPostsMutations, createPreviewHandler, createRevalidationHandler, createTagsMutations, createWPGraphQLCoreClient as createWPGraphQLClient, createWPGraphQLCoreClient, createWPGraphQLFetcher, createWPGraphQLMutationsClient, createWPGraphQLWooCommerceClient, createWPULikeClient, createWPULikeQueries, createWooCommerceClient, createWooCommerceFetcher, createWordPressClient, createWordPressMutationsClient, createYoastQueries, defaultMessages, defaultMessagesPl, extractOmnibusData, parseCookieConsent, resolveBaseUrl, resolveMessage, validateJwtToken, withOmnibus, withOmnibusVariation };
|
|
4262
4331
|
//# sourceMappingURL=index.js.map
|
|
4263
4332
|
//# sourceMappingURL=index.js.map
|