@szymonpiatek/nextwordpress 0.0.13 → 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.
@@ -38,7 +38,13 @@ var ErrorCode = {
38
38
  // Auth
39
39
  AUTH_JWT_FAILED: "AUTH_JWT_FAILED",
40
40
  AUTH_CREDENTIALS_INVALID: "AUTH_CREDENTIALS_INVALID",
41
- AUTH_TOKEN_INVALID: "AUTH_TOKEN_INVALID"
41
+ AUTH_TOKEN_INVALID: "AUTH_TOKEN_INVALID",
42
+ // Contact Form 7
43
+ CF7_MAIL_SENT: "CF7_MAIL_SENT",
44
+ CF7_MAIL_FAILED: "CF7_MAIL_FAILED",
45
+ CF7_VALIDATION_FAILED: "CF7_VALIDATION_FAILED",
46
+ CF7_SPAM: "CF7_SPAM",
47
+ CF7_ABORTED: "CF7_ABORTED"
42
48
  };
43
49
  var defaultMessages = {
44
50
  WP_REQUEST_FAILED: "WordPress API request failed",
@@ -63,7 +69,12 @@ var defaultMessages = {
63
69
  WOO_SHIPPING_ZONE_NOT_FOUND: "Shipping zone not found",
64
70
  AUTH_JWT_FAILED: "JWT authentication failed",
65
71
  AUTH_CREDENTIALS_INVALID: "Invalid credentials",
66
- AUTH_TOKEN_INVALID: "JWT token is invalid or expired"
72
+ AUTH_TOKEN_INVALID: "JWT token is invalid or expired",
73
+ CF7_MAIL_SENT: "Thank you for your message.",
74
+ CF7_MAIL_FAILED: "There was an error trying to send your message.",
75
+ CF7_VALIDATION_FAILED: "One or more fields have an error. Please check and try again.",
76
+ CF7_SPAM: "There was an error trying to send your message. Please try later.",
77
+ CF7_ABORTED: "Message submission has been aborted."
67
78
  };
68
79
  var defaultMessagesPl = {
69
80
  WP_REQUEST_FAILED: "B\u0142\u0105d \u017C\u0105dania do WordPress API",
@@ -88,149 +99,17 @@ var defaultMessagesPl = {
88
99
  WOO_SHIPPING_ZONE_NOT_FOUND: "Strefa wysy\u0142ki nie istnieje",
89
100
  AUTH_JWT_FAILED: "B\u0142\u0105d uwierzytelnienia JWT",
90
101
  AUTH_CREDENTIALS_INVALID: "Nieprawid\u0142owe dane logowania",
91
- AUTH_TOKEN_INVALID: "Token JWT jest nieprawid\u0142owy lub wygas\u0142"
102
+ AUTH_TOKEN_INVALID: "Token JWT jest nieprawid\u0142owy lub wygas\u0142",
103
+ CF7_MAIL_SENT: "Dzi\u0119kujemy za wiadomo\u015B\u0107.",
104
+ CF7_MAIL_FAILED: "Wyst\u0105pi\u0142 b\u0142\u0105d podczas wysy\u0142ania wiadomo\u015Bci.",
105
+ CF7_VALIDATION_FAILED: "Jedno lub wi\u0119cej p\xF3l zawiera b\u0142\u0105d. Sprawd\u017A i spr\xF3buj ponownie.",
106
+ CF7_SPAM: "Wyst\u0105pi\u0142 b\u0142\u0105d podczas wysy\u0142ania wiadomo\u015Bci. Spr\xF3buj p\xF3\u017Aniej.",
107
+ CF7_ABORTED: "Wysy\u0142anie formularza zosta\u0142o przerwane."
92
108
  };
93
109
  function resolveMessage(code, overrides) {
94
110
  return overrides?.[code] ?? defaultMessages[code];
95
111
  }
96
112
 
97
- // src/integrations/restApi/core/client/types.ts
98
- var WordPressAPIError = class extends Error {
99
- constructor(code, status, endpoint, message, detail) {
100
- super(detail ? `${message}: ${detail}` : message);
101
- __publicField(this, "code", code);
102
- __publicField(this, "status", status);
103
- __publicField(this, "endpoint", endpoint);
104
- this.name = "WordPressAPIError";
105
- }
106
- };
107
-
108
- // src/integrations/restApi/core/client/url.ts
109
- function buildUrl(config, path, query) {
110
- const base = resolveBaseUrl(config);
111
- if (!query) return `${base}${path}`;
112
- const params = new URLSearchParams();
113
- for (const [key, value] of Object.entries(query)) {
114
- if (value !== void 0 && value !== null) {
115
- params.set(key, String(value));
116
- }
117
- }
118
- const qs = params.toString();
119
- return qs ? `${base}${path}?${qs}` : `${base}${path}`;
120
- }
121
-
122
- // src/integrations/restApi/core/client/fetcher.ts
123
- var USER_AGENT = "NextWordpress Client";
124
- function resolveWpErrorCode(status) {
125
- if (status === 401) return ErrorCode.WP_UNAUTHORIZED;
126
- if (status === 403) return ErrorCode.WP_FORBIDDEN;
127
- if (status === 404) return ErrorCode.WP_NOT_FOUND;
128
- return ErrorCode.WP_REQUEST_FAILED;
129
- }
130
- function createFetcher(config) {
131
- const cacheTtl = config.cacheTTL ?? 300;
132
- async function doFetch(url, init = {}) {
133
- const response = await fetch(url, init);
134
- if (!response.ok) {
135
- const code = resolveWpErrorCode(response.status);
136
- throw new WordPressAPIError(
137
- code,
138
- response.status,
139
- url,
140
- resolveMessage(code, config.errorMessages),
141
- response.statusText
142
- );
143
- }
144
- return response;
145
- }
146
- async function wpFetch(path, query, tags = ["wordpress"]) {
147
- const url = buildUrl(config, path, query);
148
- const res = await doFetch(url, {
149
- headers: { "User-Agent": USER_AGENT },
150
- next: { tags, revalidate: cacheTtl }
151
- });
152
- return await res.json();
153
- }
154
- async function wpFetchGraceful(path, fallback, query, tags = ["wordpress"]) {
155
- try {
156
- return await wpFetch(path, query, tags);
157
- } catch {
158
- console.warn(`WordPress fetch failed for ${path}`);
159
- return fallback;
160
- }
161
- }
162
- async function wpFetchPaginated(path, query, tags = ["wordpress"]) {
163
- const url = buildUrl(config, path, query);
164
- const res = await doFetch(url, {
165
- headers: { "User-Agent": USER_AGENT },
166
- next: { tags, revalidate: cacheTtl }
167
- });
168
- return {
169
- data: await res.json(),
170
- headers: {
171
- total: parseInt(res.headers.get("X-WP-Total") ?? "0", 10),
172
- totalPages: parseInt(res.headers.get("X-WP-TotalPages") ?? "0", 10)
173
- }
174
- };
175
- }
176
- async function wpFetchPaginatedGraceful(path, query, tags = ["wordpress"]) {
177
- const empty = { data: [], headers: { total: 0, totalPages: 0 } };
178
- try {
179
- return await wpFetchPaginated(path, query, tags);
180
- } catch {
181
- console.warn(`WordPress paginated fetch failed for ${path}`);
182
- return empty;
183
- }
184
- }
185
- async function wpMutate(path, body, method = "POST", authToken) {
186
- const url = buildUrl(config, path);
187
- const headers = {
188
- "Content-Type": "application/json",
189
- "User-Agent": USER_AGENT
190
- };
191
- if (authToken) {
192
- headers["Authorization"] = authToken.startsWith("Basic ") || authToken.startsWith("Bearer ") ? authToken : `Bearer ${authToken}`;
193
- }
194
- const res = await doFetch(url, {
195
- method,
196
- headers,
197
- body: JSON.stringify(body),
198
- cache: "no-store"
199
- });
200
- return await res.json();
201
- }
202
- async function wpUpload(path, file, filename, mimeType, authToken) {
203
- const url = buildUrl(config, path);
204
- const res = await doFetch(url, {
205
- method: "POST",
206
- headers: {
207
- "Content-Disposition": `attachment; filename="${filename}"`,
208
- "Content-Type": mimeType,
209
- "User-Agent": USER_AGENT,
210
- "Authorization": authToken.startsWith("Basic ") || authToken.startsWith("Bearer ") ? authToken : `Bearer ${authToken}`
211
- },
212
- body: file,
213
- cache: "no-store"
214
- });
215
- return await res.json();
216
- }
217
- return { wpFetch, wpFetchGraceful, wpFetchPaginated, wpFetchPaginatedGraceful, wpMutate, wpUpload };
218
- }
219
-
220
- // src/integrations/restApi/core/contactForm7/queries.ts
221
- function createCF7Queries(config) {
222
- async function submitForm(formId, data) {
223
- const url = buildUrl(config, `/wp-json/contact-form-7/v1/contact-forms/${formId}/feedback`);
224
- const body = new FormData();
225
- for (const [key, value] of Object.entries(data)) {
226
- body.append(key, value);
227
- }
228
- const res = await fetch(url, { method: "POST", body, cache: "no-store" });
229
- return res.json();
230
- }
231
- return { submitForm };
232
- }
233
-
234
113
  // src/integrations/restApi/core/mutations/posts/mutations.ts
235
114
  function createPostsMutations(fetcher) {
236
115
  const { wpMutate } = fetcher;
@@ -424,6 +303,129 @@ function createMediaMutations(fetcher) {
424
303
  return { uploadMedia, updateMedia, deleteMedia };
425
304
  }
426
305
 
306
+ // src/integrations/restApi/core/client/types.ts
307
+ var WordPressAPIError = class extends Error {
308
+ constructor(code, status, endpoint, message, detail) {
309
+ super(detail ? `${message}: ${detail}` : message);
310
+ __publicField(this, "code", code);
311
+ __publicField(this, "status", status);
312
+ __publicField(this, "endpoint", endpoint);
313
+ this.name = "WordPressAPIError";
314
+ }
315
+ };
316
+
317
+ // src/integrations/restApi/core/client/url.ts
318
+ function buildUrl(config, path, query) {
319
+ const base = resolveBaseUrl(config);
320
+ if (!query) return `${base}${path}`;
321
+ const params = new URLSearchParams();
322
+ for (const [key, value] of Object.entries(query)) {
323
+ if (value !== void 0 && value !== null) {
324
+ params.set(key, String(value));
325
+ }
326
+ }
327
+ const qs = params.toString();
328
+ return qs ? `${base}${path}?${qs}` : `${base}${path}`;
329
+ }
330
+
331
+ // src/integrations/restApi/core/client/fetcher.ts
332
+ var USER_AGENT = "NextWordpress Client";
333
+ function resolveWpErrorCode(status) {
334
+ if (status === 401) return ErrorCode.WP_UNAUTHORIZED;
335
+ if (status === 403) return ErrorCode.WP_FORBIDDEN;
336
+ if (status === 404) return ErrorCode.WP_NOT_FOUND;
337
+ return ErrorCode.WP_REQUEST_FAILED;
338
+ }
339
+ function createFetcher(config) {
340
+ const cacheTtl = config.cacheTTL ?? 300;
341
+ async function doFetch(url, init = {}) {
342
+ const response = await fetch(url, init);
343
+ if (!response.ok) {
344
+ const code = resolveWpErrorCode(response.status);
345
+ throw new WordPressAPIError(
346
+ code,
347
+ response.status,
348
+ url,
349
+ resolveMessage(code, config.errorMessages),
350
+ response.statusText
351
+ );
352
+ }
353
+ return response;
354
+ }
355
+ async function wpFetch(path, query, tags = ["wordpress"]) {
356
+ const url = buildUrl(config, path, query);
357
+ const res = await doFetch(url, {
358
+ headers: { "User-Agent": USER_AGENT },
359
+ next: { tags, revalidate: cacheTtl }
360
+ });
361
+ return await res.json();
362
+ }
363
+ async function wpFetchGraceful(path, fallback, query, tags = ["wordpress"]) {
364
+ try {
365
+ return await wpFetch(path, query, tags);
366
+ } catch {
367
+ console.warn(`WordPress fetch failed for ${path}`);
368
+ return fallback;
369
+ }
370
+ }
371
+ async function wpFetchPaginated(path, query, tags = ["wordpress"]) {
372
+ const url = buildUrl(config, path, query);
373
+ const res = await doFetch(url, {
374
+ headers: { "User-Agent": USER_AGENT },
375
+ next: { tags, revalidate: cacheTtl }
376
+ });
377
+ return {
378
+ data: await res.json(),
379
+ headers: {
380
+ total: parseInt(res.headers.get("X-WP-Total") ?? "0", 10),
381
+ totalPages: parseInt(res.headers.get("X-WP-TotalPages") ?? "0", 10)
382
+ }
383
+ };
384
+ }
385
+ async function wpFetchPaginatedGraceful(path, query, tags = ["wordpress"]) {
386
+ const empty = { data: [], headers: { total: 0, totalPages: 0 } };
387
+ try {
388
+ return await wpFetchPaginated(path, query, tags);
389
+ } catch {
390
+ console.warn(`WordPress paginated fetch failed for ${path}`);
391
+ return empty;
392
+ }
393
+ }
394
+ async function wpMutate(path, body, method = "POST", authToken) {
395
+ const url = buildUrl(config, path);
396
+ const headers = {
397
+ "Content-Type": "application/json",
398
+ "User-Agent": USER_AGENT
399
+ };
400
+ if (authToken) {
401
+ headers["Authorization"] = authToken.startsWith("Basic ") || authToken.startsWith("Bearer ") ? authToken : `Bearer ${authToken}`;
402
+ }
403
+ const res = await doFetch(url, {
404
+ method,
405
+ headers,
406
+ body: JSON.stringify(body),
407
+ cache: "no-store"
408
+ });
409
+ return await res.json();
410
+ }
411
+ async function wpUpload(path, file, filename, mimeType, authToken) {
412
+ const url = buildUrl(config, path);
413
+ const res = await doFetch(url, {
414
+ method: "POST",
415
+ headers: {
416
+ "Content-Disposition": `attachment; filename="${filename}"`,
417
+ "Content-Type": mimeType,
418
+ "User-Agent": USER_AGENT,
419
+ "Authorization": authToken.startsWith("Basic ") || authToken.startsWith("Bearer ") ? authToken : `Bearer ${authToken}`
420
+ },
421
+ body: file,
422
+ cache: "no-store"
423
+ });
424
+ return await res.json();
425
+ }
426
+ return { wpFetch, wpFetchGraceful, wpFetchPaginated, wpFetchPaginatedGraceful, wpMutate, wpUpload };
427
+ }
428
+
427
429
  // src/integrations/restApi/core/mutations/index.ts
428
430
  function createWordPressMutationsClient(config) {
429
431
  const fetcher = createFetcher(config);
@@ -2133,6 +2135,20 @@ function createWPULikeClient(config) {
2133
2135
  return createWPULikeQueries(fetcher);
2134
2136
  }
2135
2137
 
2138
+ // src/integrations/restApi/contactForm7/queries.ts
2139
+ function createCF7Queries(config) {
2140
+ async function submitForm(formId, data) {
2141
+ const url = buildUrl(config, `/wp-json/contact-form-7/v1/contact-forms/${formId}/feedback`);
2142
+ const body = new FormData();
2143
+ for (const [key, value] of Object.entries(data)) {
2144
+ body.append(key, value);
2145
+ }
2146
+ const res = await fetch(url, { method: "POST", body, cache: "no-store" });
2147
+ return res.json();
2148
+ }
2149
+ return { submitForm };
2150
+ }
2151
+
2136
2152
  // src/integrations/wpGraphQL/client/types.ts
2137
2153
  var WPGraphQLError = class extends Error {
2138
2154
  constructor(code, status, endpoint, message, gqlErrors) {