@szymonpiatek/nextwordpress 0.0.10 → 0.0.12

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,4308 @@
1
+ 'use strict';
2
+
3
+ var __defProp = Object.defineProperty;
4
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
5
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
6
+
7
+ // src/shared/url.ts
8
+ function resolveBaseUrl(config) {
9
+ return typeof window === "undefined" ? config.serverURL : config.clientURL;
10
+ }
11
+
12
+ // src/shared/errors/codes.ts
13
+ var ErrorCode = {
14
+ // WordPress REST API
15
+ WP_REQUEST_FAILED: "WP_REQUEST_FAILED",
16
+ WP_NOT_FOUND: "WP_NOT_FOUND",
17
+ WP_UNAUTHORIZED: "WP_UNAUTHORIZED",
18
+ WP_FORBIDDEN: "WP_FORBIDDEN",
19
+ // WPGraphQL
20
+ GQL_REQUEST_FAILED: "GQL_REQUEST_FAILED",
21
+ GQL_NO_DATA: "GQL_NO_DATA",
22
+ GQL_ERRORS_IN_RESPONSE: "GQL_ERRORS_IN_RESPONSE",
23
+ // WooCommerce — generic
24
+ WOO_REQUEST_FAILED: "WOO_REQUEST_FAILED",
25
+ WOO_NOT_FOUND: "WOO_NOT_FOUND",
26
+ WOO_UNAUTHORIZED: "WOO_UNAUTHORIZED",
27
+ WOO_FORBIDDEN: "WOO_FORBIDDEN",
28
+ // WooCommerce — resource-specific
29
+ WOO_COUPON_NOT_FOUND: "WOO_COUPON_NOT_FOUND",
30
+ WOO_PRODUCT_NOT_FOUND: "WOO_PRODUCT_NOT_FOUND",
31
+ WOO_ORDER_NOT_FOUND: "WOO_ORDER_NOT_FOUND",
32
+ WOO_CUSTOMER_NOT_FOUND: "WOO_CUSTOMER_NOT_FOUND",
33
+ WOO_CATEGORY_NOT_FOUND: "WOO_CATEGORY_NOT_FOUND",
34
+ WOO_TAG_NOT_FOUND: "WOO_TAG_NOT_FOUND",
35
+ WOO_REVIEW_NOT_FOUND: "WOO_REVIEW_NOT_FOUND",
36
+ WOO_WEBHOOK_NOT_FOUND: "WOO_WEBHOOK_NOT_FOUND",
37
+ WOO_SHIPPING_ZONE_NOT_FOUND: "WOO_SHIPPING_ZONE_NOT_FOUND",
38
+ // Auth
39
+ AUTH_JWT_FAILED: "AUTH_JWT_FAILED",
40
+ AUTH_CREDENTIALS_INVALID: "AUTH_CREDENTIALS_INVALID",
41
+ AUTH_TOKEN_INVALID: "AUTH_TOKEN_INVALID"
42
+ };
43
+ var defaultMessages = {
44
+ WP_REQUEST_FAILED: "WordPress API request failed",
45
+ WP_NOT_FOUND: "WordPress resource not found",
46
+ WP_UNAUTHORIZED: "WordPress authentication required",
47
+ WP_FORBIDDEN: "WordPress access denied",
48
+ GQL_REQUEST_FAILED: "WPGraphQL request failed",
49
+ GQL_NO_DATA: "No data returned from WPGraphQL",
50
+ GQL_ERRORS_IN_RESPONSE: "WPGraphQL returned errors",
51
+ WOO_REQUEST_FAILED: "WooCommerce API request failed",
52
+ WOO_NOT_FOUND: "WooCommerce resource not found",
53
+ WOO_UNAUTHORIZED: "WooCommerce authentication required",
54
+ WOO_FORBIDDEN: "WooCommerce access denied",
55
+ WOO_COUPON_NOT_FOUND: "Coupon not found",
56
+ WOO_PRODUCT_NOT_FOUND: "Product not found",
57
+ WOO_ORDER_NOT_FOUND: "Order not found",
58
+ WOO_CUSTOMER_NOT_FOUND: "Customer not found",
59
+ WOO_CATEGORY_NOT_FOUND: "Category not found",
60
+ WOO_TAG_NOT_FOUND: "Tag not found",
61
+ WOO_REVIEW_NOT_FOUND: "Product review not found",
62
+ WOO_WEBHOOK_NOT_FOUND: "Webhook not found",
63
+ WOO_SHIPPING_ZONE_NOT_FOUND: "Shipping zone not found",
64
+ AUTH_JWT_FAILED: "JWT authentication failed",
65
+ AUTH_CREDENTIALS_INVALID: "Invalid credentials",
66
+ AUTH_TOKEN_INVALID: "JWT token is invalid or expired"
67
+ };
68
+ var defaultMessagesPl = {
69
+ WP_REQUEST_FAILED: "B\u0142\u0105d \u017C\u0105dania do WordPress API",
70
+ WP_NOT_FOUND: "Zas\xF3b WordPress nie istnieje",
71
+ WP_UNAUTHORIZED: "Wymagane uwierzytelnienie WordPress",
72
+ WP_FORBIDDEN: "Brak dost\u0119pu do zasobu WordPress",
73
+ GQL_REQUEST_FAILED: "B\u0142\u0105d \u017C\u0105dania WPGraphQL",
74
+ GQL_NO_DATA: "WPGraphQL nie zwr\xF3ci\u0142o danych",
75
+ GQL_ERRORS_IN_RESPONSE: "WPGraphQL zwr\xF3ci\u0142o b\u0142\u0119dy",
76
+ WOO_REQUEST_FAILED: "B\u0142\u0105d \u017C\u0105dania do WooCommerce API",
77
+ WOO_NOT_FOUND: "Zas\xF3b WooCommerce nie istnieje",
78
+ WOO_UNAUTHORIZED: "Wymagane uwierzytelnienie WooCommerce",
79
+ WOO_FORBIDDEN: "Brak dost\u0119pu do zasobu WooCommerce",
80
+ WOO_COUPON_NOT_FOUND: "Kupon nie istnieje",
81
+ WOO_PRODUCT_NOT_FOUND: "Produkt nie istnieje",
82
+ WOO_ORDER_NOT_FOUND: "Zam\xF3wienie nie istnieje",
83
+ WOO_CUSTOMER_NOT_FOUND: "Klient nie istnieje",
84
+ WOO_CATEGORY_NOT_FOUND: "Kategoria produkt\xF3w nie istnieje",
85
+ WOO_TAG_NOT_FOUND: "Tag produkt\xF3w nie istnieje",
86
+ WOO_REVIEW_NOT_FOUND: "Opinia o produkcie nie istnieje",
87
+ WOO_WEBHOOK_NOT_FOUND: "Webhook nie istnieje",
88
+ WOO_SHIPPING_ZONE_NOT_FOUND: "Strefa wysy\u0142ki nie istnieje",
89
+ AUTH_JWT_FAILED: "B\u0142\u0105d uwierzytelnienia JWT",
90
+ AUTH_CREDENTIALS_INVALID: "Nieprawid\u0142owe dane logowania",
91
+ AUTH_TOKEN_INVALID: "Token JWT jest nieprawid\u0142owy lub wygas\u0142"
92
+ };
93
+ function resolveMessage(code, overrides) {
94
+ return overrides?.[code] ?? defaultMessages[code];
95
+ }
96
+
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
+ // src/integrations/restApi/core/mutations/posts/mutations.ts
235
+ function createPostsMutations(fetcher) {
236
+ const { wpMutate } = fetcher;
237
+ async function createPost(input, authToken) {
238
+ return wpMutate("/wp-json/wp/v2/posts", input, "POST", authToken);
239
+ }
240
+ async function updatePost(id, input, authToken) {
241
+ return wpMutate(`/wp-json/wp/v2/posts/${id}`, input, "PATCH", authToken);
242
+ }
243
+ async function deletePost(id, authToken, force = false) {
244
+ return wpMutate(
245
+ `/wp-json/wp/v2/posts/${id}`,
246
+ { force },
247
+ "DELETE",
248
+ authToken
249
+ );
250
+ }
251
+ return { createPost, updatePost, deletePost };
252
+ }
253
+
254
+ // src/integrations/restApi/core/mutations/comments/mutations.ts
255
+ function createCommentsMutations(fetcher) {
256
+ const { wpMutate } = fetcher;
257
+ async function createComment(input, authToken) {
258
+ return wpMutate("/wp-json/wp/v2/comments", input, "POST", authToken);
259
+ }
260
+ async function updateComment(id, input, authToken) {
261
+ return wpMutate(`/wp-json/wp/v2/comments/${id}`, input, "PATCH", authToken);
262
+ }
263
+ async function deleteComment(id, authToken, force = false) {
264
+ return wpMutate(
265
+ `/wp-json/wp/v2/comments/${id}`,
266
+ { force },
267
+ "DELETE",
268
+ authToken
269
+ );
270
+ }
271
+ return { createComment, updateComment, deleteComment };
272
+ }
273
+
274
+ // src/integrations/restApi/core/mutations/pages/mutations.ts
275
+ function createPagesMutations(fetcher) {
276
+ const { wpMutate } = fetcher;
277
+ async function createPage(input, authToken) {
278
+ return wpMutate("/wp-json/wp/v2/pages", input, "POST", authToken);
279
+ }
280
+ async function updatePage(id, input, authToken) {
281
+ return wpMutate(`/wp-json/wp/v2/pages/${id}`, input, "PATCH", authToken);
282
+ }
283
+ async function deletePage(id, authToken, force = false) {
284
+ return wpMutate(
285
+ `/wp-json/wp/v2/pages/${id}`,
286
+ { force },
287
+ "DELETE",
288
+ authToken
289
+ );
290
+ }
291
+ return { createPage, updatePage, deletePage };
292
+ }
293
+
294
+ // src/integrations/restApi/core/mutations/categories/mutations.ts
295
+ function createCategoriesMutations(fetcher) {
296
+ const { wpMutate } = fetcher;
297
+ async function createCategory(input, authToken) {
298
+ return wpMutate("/wp-json/wp/v2/categories", input, "POST", authToken);
299
+ }
300
+ async function updateCategory(id, input, authToken) {
301
+ return wpMutate(`/wp-json/wp/v2/categories/${id}`, input, "PATCH", authToken);
302
+ }
303
+ async function deleteCategory(id, authToken, force = false) {
304
+ return wpMutate(
305
+ `/wp-json/wp/v2/categories/${id}`,
306
+ { force },
307
+ "DELETE",
308
+ authToken
309
+ );
310
+ }
311
+ return { createCategory, updateCategory, deleteCategory };
312
+ }
313
+
314
+ // src/integrations/restApi/core/mutations/tags/mutations.ts
315
+ function createTagsMutations(fetcher) {
316
+ const { wpMutate } = fetcher;
317
+ async function createTag(input, authToken) {
318
+ return wpMutate("/wp-json/wp/v2/tags", input, "POST", authToken);
319
+ }
320
+ async function updateTag(id, input, authToken) {
321
+ return wpMutate(`/wp-json/wp/v2/tags/${id}`, input, "PATCH", authToken);
322
+ }
323
+ async function deleteTag(id, authToken, force = false) {
324
+ return wpMutate(
325
+ `/wp-json/wp/v2/tags/${id}`,
326
+ { force },
327
+ "DELETE",
328
+ authToken
329
+ );
330
+ }
331
+ return { createTag, updateTag, deleteTag };
332
+ }
333
+
334
+ // src/integrations/restApi/core/mutations/authors/mutations.ts
335
+ function createAuthorsMutations(fetcher) {
336
+ const { wpMutate } = fetcher;
337
+ async function createAuthor(input, authToken) {
338
+ return wpMutate("/wp-json/wp/v2/users", input, "POST", authToken);
339
+ }
340
+ async function updateAuthor(id, input, authToken) {
341
+ return wpMutate(`/wp-json/wp/v2/users/${id}`, input, "PATCH", authToken);
342
+ }
343
+ async function deleteAuthor(id, authToken, reassign) {
344
+ return wpMutate(
345
+ `/wp-json/wp/v2/users/${id}`,
346
+ { force: true, reassign },
347
+ "DELETE",
348
+ authToken
349
+ );
350
+ }
351
+ return { createAuthor, updateAuthor, deleteAuthor };
352
+ }
353
+
354
+ // src/integrations/restApi/core/mutations/menus/mutations.ts
355
+ function createMenusMutations(fetcher) {
356
+ const { wpMutate } = fetcher;
357
+ async function createMenu(input, authToken) {
358
+ return wpMutate("/wp-json/wp/v2/menus", input, "POST", authToken);
359
+ }
360
+ async function updateMenu(id, input, authToken) {
361
+ return wpMutate(`/wp-json/wp/v2/menus/${id}`, input, "PATCH", authToken);
362
+ }
363
+ async function deleteMenu(id, authToken) {
364
+ return wpMutate(
365
+ `/wp-json/wp/v2/menus/${id}`,
366
+ {},
367
+ "DELETE",
368
+ authToken
369
+ );
370
+ }
371
+ async function createMenuItem(input, authToken) {
372
+ return wpMutate("/wp-json/wp/v2/menu-items", input, "POST", authToken);
373
+ }
374
+ async function updateMenuItem(id, input, authToken) {
375
+ return wpMutate(`/wp-json/wp/v2/menu-items/${id}`, input, "PATCH", authToken);
376
+ }
377
+ async function deleteMenuItem(id, authToken, force = false) {
378
+ return wpMutate(
379
+ `/wp-json/wp/v2/menu-items/${id}`,
380
+ { force },
381
+ "DELETE",
382
+ authToken
383
+ );
384
+ }
385
+ return { createMenu, updateMenu, deleteMenu, createMenuItem, updateMenuItem, deleteMenuItem };
386
+ }
387
+
388
+ // src/integrations/restApi/core/mutations/media/mutations.ts
389
+ function createMediaMutations(fetcher) {
390
+ const { wpMutate, wpUpload } = fetcher;
391
+ async function uploadMedia(input, authToken) {
392
+ const media = await wpUpload(
393
+ "/wp-json/wp/v2/media",
394
+ input.file,
395
+ input.filename,
396
+ input.mimeType,
397
+ authToken
398
+ );
399
+ if (input.title || input.caption || input.alt_text) {
400
+ return wpMutate(
401
+ `/wp-json/wp/v2/media/${media.id}`,
402
+ {
403
+ ...input.title && { title: input.title },
404
+ ...input.caption && { caption: input.caption },
405
+ ...input.alt_text && { alt_text: input.alt_text }
406
+ },
407
+ "PATCH",
408
+ authToken
409
+ );
410
+ }
411
+ return media;
412
+ }
413
+ async function updateMedia(id, input, authToken) {
414
+ return wpMutate(`/wp-json/wp/v2/media/${id}`, input, "PATCH", authToken);
415
+ }
416
+ async function deleteMedia(id, authToken, force = true) {
417
+ return wpMutate(
418
+ `/wp-json/wp/v2/media/${id}`,
419
+ { force },
420
+ "DELETE",
421
+ authToken
422
+ );
423
+ }
424
+ return { uploadMedia, updateMedia, deleteMedia };
425
+ }
426
+
427
+ // src/integrations/restApi/core/mutations/index.ts
428
+ function createWordPressMutationsClient(config) {
429
+ const fetcher = createFetcher(config);
430
+ return {
431
+ ...createPostsMutations(fetcher),
432
+ ...createCommentsMutations(fetcher),
433
+ ...createPagesMutations(fetcher),
434
+ ...createCategoriesMutations(fetcher),
435
+ ...createTagsMutations(fetcher),
436
+ ...createAuthorsMutations(fetcher),
437
+ ...createMenusMutations(fetcher),
438
+ ...createMediaMutations(fetcher)
439
+ };
440
+ }
441
+
442
+ // src/integrations/restApi/core/posts/queries.ts
443
+ function createPostsQueries(fetcher) {
444
+ const { wpFetch, wpFetchGraceful, wpFetchPaginated, wpFetchPaginatedGraceful } = fetcher;
445
+ async function getPostsPaginated(page = 1, perPage = 9, filterParams) {
446
+ const query = { _embed: true, per_page: perPage, page };
447
+ const cacheTags = ["wordpress", "posts", `posts-page-${page}`];
448
+ if (filterParams?.search) {
449
+ query.search = filterParams.search;
450
+ cacheTags.push("posts-search");
451
+ }
452
+ if (filterParams?.author) {
453
+ query.author = filterParams.author;
454
+ cacheTags.push(`posts-author-${filterParams.author}`);
455
+ }
456
+ if (filterParams?.tag) {
457
+ query.tags = filterParams.tag;
458
+ cacheTags.push(`posts-tag-${filterParams.tag}`);
459
+ }
460
+ if (filterParams?.category) {
461
+ query.categories = filterParams.category;
462
+ cacheTags.push(`posts-category-${filterParams.category}`);
463
+ }
464
+ return wpFetchPaginatedGraceful("/wp-json/wp/v2/posts", query, cacheTags);
465
+ }
466
+ async function getRecentPosts(filterParams) {
467
+ const query = { _embed: true, per_page: 100 };
468
+ if (filterParams?.search) query.search = filterParams.search;
469
+ if (filterParams?.author) query.author = filterParams.author;
470
+ if (filterParams?.tag) query.tags = filterParams.tag;
471
+ if (filterParams?.category) query.categories = filterParams.category;
472
+ return wpFetchGraceful("/wp-json/wp/v2/posts", [], query, ["wordpress", "posts"]);
473
+ }
474
+ async function getPostById(id) {
475
+ return wpFetch(`/wp-json/wp/v2/posts/${id}`);
476
+ }
477
+ async function getPostBySlug(slug) {
478
+ const posts = await wpFetchGraceful("/wp-json/wp/v2/posts", [], { slug, _embed: true });
479
+ return posts[0];
480
+ }
481
+ async function getPostsByCategory(categoryId) {
482
+ return wpFetch("/wp-json/wp/v2/posts", { categories: categoryId });
483
+ }
484
+ async function getPostsByTag(tagId) {
485
+ return wpFetch("/wp-json/wp/v2/posts", { tags: tagId });
486
+ }
487
+ async function getPostsByAuthor(authorId) {
488
+ return wpFetch("/wp-json/wp/v2/posts", { author: authorId });
489
+ }
490
+ async function getPostsByCategoryPaginated(categoryId, page = 1, perPage = 9) {
491
+ return wpFetchPaginatedGraceful("/wp-json/wp/v2/posts", {
492
+ _embed: true,
493
+ per_page: perPage,
494
+ page,
495
+ categories: categoryId
496
+ });
497
+ }
498
+ async function getPostsByTagPaginated(tagId, page = 1, perPage = 9) {
499
+ return wpFetchPaginatedGraceful("/wp-json/wp/v2/posts", {
500
+ _embed: true,
501
+ per_page: perPage,
502
+ page,
503
+ tags: tagId
504
+ });
505
+ }
506
+ async function getPostsByAuthorPaginated(authorId, page = 1, perPage = 9) {
507
+ return wpFetchPaginatedGraceful("/wp-json/wp/v2/posts", {
508
+ _embed: true,
509
+ per_page: perPage,
510
+ page,
511
+ author: authorId
512
+ });
513
+ }
514
+ async function getAllPostSlugs() {
515
+ try {
516
+ const allSlugs = [];
517
+ let page = 1;
518
+ let hasMore = true;
519
+ while (hasMore) {
520
+ const response = await wpFetchPaginated(
521
+ "/wp-json/wp/v2/posts",
522
+ { per_page: 100, page, _fields: "slug" }
523
+ );
524
+ allSlugs.push(...response.data.map((post) => ({ slug: post.slug })));
525
+ hasMore = page < response.headers.totalPages;
526
+ page++;
527
+ }
528
+ return allSlugs;
529
+ } catch {
530
+ console.warn("WordPress unavailable, skipping static generation for posts");
531
+ return [];
532
+ }
533
+ }
534
+ async function getAllPostsForSitemap() {
535
+ try {
536
+ const allPosts = [];
537
+ let page = 1;
538
+ let hasMore = true;
539
+ while (hasMore) {
540
+ const response = await wpFetchPaginated(
541
+ "/wp-json/wp/v2/posts",
542
+ { per_page: 100, page, _fields: "slug,modified" }
543
+ );
544
+ allPosts.push(...response.data.map((post) => ({ slug: post.slug, modified: post.modified })));
545
+ hasMore = page < response.headers.totalPages;
546
+ page++;
547
+ }
548
+ return allPosts;
549
+ } catch {
550
+ console.warn("WordPress unavailable, skipping sitemap generation");
551
+ return [];
552
+ }
553
+ }
554
+ return {
555
+ getPostsPaginated,
556
+ getRecentPosts,
557
+ getPostById,
558
+ getPostBySlug,
559
+ getPostsByCategory,
560
+ getPostsByTag,
561
+ getPostsByAuthor,
562
+ getPostsByCategoryPaginated,
563
+ getPostsByTagPaginated,
564
+ getPostsByAuthorPaginated,
565
+ getAllPostSlugs,
566
+ getAllPostsForSitemap
567
+ };
568
+ }
569
+
570
+ // src/integrations/restApi/core/categories/queries.ts
571
+ function createCategoriesQueries(fetcher) {
572
+ const { wpFetch, wpFetchGraceful } = fetcher;
573
+ async function getAllCategories() {
574
+ return wpFetchGraceful("/wp-json/wp/v2/categories", [], { per_page: 100 }, [
575
+ "wordpress",
576
+ "categories"
577
+ ]);
578
+ }
579
+ async function getCategoryById(id) {
580
+ return wpFetch(`/wp-json/wp/v2/categories/${id}`);
581
+ }
582
+ async function getCategoryBySlug(slug) {
583
+ const categories = await wpFetch("/wp-json/wp/v2/categories", { slug });
584
+ return categories[0];
585
+ }
586
+ async function searchCategories(query) {
587
+ return wpFetchGraceful("/wp-json/wp/v2/categories", [], {
588
+ search: query,
589
+ per_page: 100
590
+ });
591
+ }
592
+ return { getAllCategories, getCategoryById, getCategoryBySlug, searchCategories };
593
+ }
594
+
595
+ // src/integrations/restApi/core/tags/queries.ts
596
+ function createTagsQueries(fetcher) {
597
+ const { wpFetch, wpFetchGraceful } = fetcher;
598
+ async function getAllTags() {
599
+ return wpFetchGraceful("/wp-json/wp/v2/tags", [], { per_page: 100 }, [
600
+ "wordpress",
601
+ "tags"
602
+ ]);
603
+ }
604
+ async function getTagById(id) {
605
+ return wpFetch(`/wp-json/wp/v2/tags/${id}`);
606
+ }
607
+ async function getTagBySlug(slug) {
608
+ const tags = await wpFetch("/wp-json/wp/v2/tags", { slug });
609
+ return tags[0];
610
+ }
611
+ async function getTagsByPost(postId) {
612
+ return wpFetch("/wp-json/wp/v2/tags", { post: postId });
613
+ }
614
+ async function searchTags(query) {
615
+ return wpFetchGraceful("/wp-json/wp/v2/tags", [], { search: query, per_page: 100 });
616
+ }
617
+ return { getAllTags, getTagById, getTagBySlug, getTagsByPost, searchTags };
618
+ }
619
+
620
+ // src/integrations/restApi/core/authors/queries.ts
621
+ function createAuthorsQueries(fetcher) {
622
+ const { wpFetch, wpFetchGraceful } = fetcher;
623
+ async function getAllAuthors() {
624
+ return wpFetchGraceful("/wp-json/wp/v2/users", [], { per_page: 100 }, [
625
+ "wordpress",
626
+ "authors"
627
+ ]);
628
+ }
629
+ async function getAuthorById(id) {
630
+ return wpFetch(`/wp-json/wp/v2/users/${id}`);
631
+ }
632
+ async function getAuthorBySlug(slug) {
633
+ const users = await wpFetch("/wp-json/wp/v2/users", { slug });
634
+ return users[0];
635
+ }
636
+ async function searchAuthors(query) {
637
+ return wpFetchGraceful("/wp-json/wp/v2/users", [], { search: query, per_page: 100 });
638
+ }
639
+ return { getAllAuthors, getAuthorById, getAuthorBySlug, searchAuthors };
640
+ }
641
+
642
+ // src/integrations/restApi/core/media/queries.ts
643
+ function createMediaQueries(fetcher) {
644
+ const { wpFetch } = fetcher;
645
+ async function getFeaturedMediaById(id) {
646
+ return wpFetch(`/wp-json/wp/v2/media/${id}`);
647
+ }
648
+ return { getFeaturedMediaById };
649
+ }
650
+
651
+ // src/integrations/restApi/core/pages/queries.ts
652
+ function createPagesQueries(fetcher) {
653
+ const { wpFetch, wpFetchGraceful } = fetcher;
654
+ async function getAllPages() {
655
+ return wpFetchGraceful("/wp-json/wp/v2/pages", [], { per_page: 100 }, [
656
+ "wordpress",
657
+ "pages"
658
+ ]);
659
+ }
660
+ async function getPageById(id) {
661
+ return wpFetch(`/wp-json/wp/v2/pages/${id}`);
662
+ }
663
+ async function getPageBySlug(slug) {
664
+ const pages = await wpFetchGraceful("/wp-json/wp/v2/pages", [], { slug });
665
+ return pages[0];
666
+ }
667
+ return { getAllPages, getPageById, getPageBySlug };
668
+ }
669
+
670
+ // src/integrations/restApi/core/menus/queries.ts
671
+ function createMenusQueries(fetcher) {
672
+ const { wpFetch, wpFetchGraceful } = fetcher;
673
+ async function getMenus() {
674
+ return wpFetchGraceful("/wp-json/wp/v2/menus", [], void 0, ["wordpress", "menus"]);
675
+ }
676
+ async function getMenuById(id) {
677
+ return wpFetch(`/wp-json/wp/v2/menus/${id}`, void 0, ["wordpress", "menus", `menu-${id}`]);
678
+ }
679
+ async function getMenuBySlug(slug) {
680
+ const menus = await wpFetchGraceful("/wp-json/wp/v2/menus", [], { slug }, ["wordpress", "menus"]);
681
+ return menus[0];
682
+ }
683
+ async function getMenuItemsByMenuId(menuId) {
684
+ return wpFetchGraceful(
685
+ "/wp-json/wp/v2/menu-items",
686
+ [],
687
+ { menus: menuId, per_page: 100, orderby: "menu_order", order: "asc" },
688
+ ["wordpress", "menus", `menu-items-${menuId}`]
689
+ );
690
+ }
691
+ async function getMenuLocations() {
692
+ return wpFetchGraceful(
693
+ "/wp-json/wp/v2/menu-locations",
694
+ {},
695
+ void 0,
696
+ ["wordpress", "menus", "menu-locations"]
697
+ );
698
+ }
699
+ async function getMenuByLocation(location) {
700
+ const locations = await getMenuLocations();
701
+ const loc = locations[location];
702
+ if (!loc || !loc.menu) return void 0;
703
+ const [menu, items] = await Promise.all([
704
+ getMenuById(loc.menu),
705
+ getMenuItemsByMenuId(loc.menu)
706
+ ]);
707
+ return { menu, items };
708
+ }
709
+ return {
710
+ getMenus,
711
+ getMenuById,
712
+ getMenuBySlug,
713
+ getMenuItemsByMenuId,
714
+ getMenuLocations,
715
+ getMenuByLocation
716
+ };
717
+ }
718
+
719
+ // src/integrations/restApi/core/comments/queries.ts
720
+ function createCommentsQueries(fetcher) {
721
+ const { wpFetch, wpFetchGraceful, wpFetchPaginatedGraceful, wpMutate } = fetcher;
722
+ async function getCommentsByPostId(postId, page = 1, perPage = 10) {
723
+ return wpFetchPaginatedGraceful(
724
+ "/wp-json/wp/v2/comments",
725
+ { post: postId, per_page: perPage, page, status: "approve" },
726
+ ["wordpress", "comments", `comments-post-${postId}`]
727
+ );
728
+ }
729
+ async function getAllCommentsByPostId(postId) {
730
+ return wpFetchGraceful(
731
+ "/wp-json/wp/v2/comments",
732
+ [],
733
+ { post: postId, per_page: 100, status: "approve" },
734
+ ["wordpress", "comments", `comments-post-${postId}`]
735
+ );
736
+ }
737
+ async function getCommentById(id) {
738
+ return wpFetch(`/wp-json/wp/v2/comments/${id}`, void 0, [
739
+ "wordpress",
740
+ "comments",
741
+ `comment-${id}`
742
+ ]);
743
+ }
744
+ async function getCommentReplies(parentId) {
745
+ return wpFetchGraceful(
746
+ "/wp-json/wp/v2/comments",
747
+ [],
748
+ { parent: parentId, per_page: 100, status: "approve" },
749
+ ["wordpress", "comments", `comments-parent-${parentId}`]
750
+ );
751
+ }
752
+ async function createComment(input) {
753
+ return wpMutate("/wp-json/wp/v2/comments", input, "POST");
754
+ }
755
+ return {
756
+ getCommentsByPostId,
757
+ getAllCommentsByPostId,
758
+ getCommentById,
759
+ getCommentReplies,
760
+ createComment
761
+ };
762
+ }
763
+
764
+ // src/integrations/restApi/core/index.ts
765
+ function createWordPressClient(config) {
766
+ const fetcher = createFetcher(config);
767
+ return {
768
+ ...createPostsQueries(fetcher),
769
+ ...createCategoriesQueries(fetcher),
770
+ ...createTagsQueries(fetcher),
771
+ ...createAuthorsQueries(fetcher),
772
+ ...createMediaQueries(fetcher),
773
+ ...createPagesQueries(fetcher),
774
+ ...createMenusQueries(fetcher),
775
+ ...createCommentsQueries(fetcher)
776
+ };
777
+ }
778
+
779
+ // src/integrations/restApi/woocommerce/omnibus/queries.ts
780
+ var META_KEY_LOWEST_PRICE = "wpo_lowest_price";
781
+ var META_KEY_PRICE_HISTORY = "_alg_wc_price_history";
782
+ function extractMetaValue(meta_data, key) {
783
+ return meta_data.find((m) => m.key === key)?.value;
784
+ }
785
+ function parseHistory(raw) {
786
+ if (!raw || typeof raw !== "object") return [];
787
+ if (Array.isArray(raw)) {
788
+ return raw.filter((e) => e && typeof e.price === "string" && typeof e.date === "string").map((e) => ({ price: e.price, date: e.date }));
789
+ }
790
+ return Object.entries(raw).map(([date, price]) => ({ date, price })).sort((a, b) => a.date.localeCompare(b.date));
791
+ }
792
+ function extractOmnibusData(meta_data) {
793
+ const lowestPrice = extractMetaValue(meta_data, META_KEY_LOWEST_PRICE) ?? null;
794
+ const rawHistory = extractMetaValue(meta_data, META_KEY_PRICE_HISTORY);
795
+ const priceHistory = parseHistory(rawHistory);
796
+ return { lowestPrice, priceHistory };
797
+ }
798
+ function withOmnibus(product) {
799
+ return { ...product, omnibus: extractOmnibusData(product.meta_data) };
800
+ }
801
+ function withOmnibusVariation(variation) {
802
+ return {
803
+ ...variation,
804
+ omnibus: extractOmnibusData(variation.meta_data ?? [])
805
+ };
806
+ }
807
+
808
+ // src/integrations/restApi/woocommerce/client/types.ts
809
+ var WooCommerceError = class extends Error {
810
+ constructor(code, status, endpoint, message, upstreamCode, detail) {
811
+ super(detail ? `${message}: ${detail}` : message);
812
+ __publicField(this, "code", code);
813
+ __publicField(this, "status", status);
814
+ __publicField(this, "endpoint", endpoint);
815
+ __publicField(this, "upstreamCode", upstreamCode);
816
+ this.name = "WooCommerceError";
817
+ }
818
+ };
819
+
820
+ // src/integrations/restApi/woocommerce/client/errorMap.ts
821
+ var upstreamToErrorCode = {
822
+ woocommerce_rest_coupon_invalid_id: ErrorCode.WOO_COUPON_NOT_FOUND,
823
+ woocommerce_rest_product_invalid_id: ErrorCode.WOO_PRODUCT_NOT_FOUND,
824
+ woocommerce_rest_order_invalid_id: ErrorCode.WOO_ORDER_NOT_FOUND,
825
+ woocommerce_rest_customer_invalid_id: ErrorCode.WOO_CUSTOMER_NOT_FOUND,
826
+ woocommerce_rest_term_invalid: ErrorCode.WOO_CATEGORY_NOT_FOUND,
827
+ woocommerce_rest_review_invalid_id: ErrorCode.WOO_REVIEW_NOT_FOUND,
828
+ woocommerce_rest_webhook_invalid_id: ErrorCode.WOO_WEBHOOK_NOT_FOUND,
829
+ woocommerce_rest_shipping_zone_invalid_id: ErrorCode.WOO_SHIPPING_ZONE_NOT_FOUND
830
+ };
831
+ function resolveWooErrorCode(status, upstreamCode) {
832
+ if (status === 401) return ErrorCode.WOO_UNAUTHORIZED;
833
+ if (status === 403) return ErrorCode.WOO_FORBIDDEN;
834
+ if (status === 404) {
835
+ if (upstreamCode) {
836
+ const mapped = upstreamToErrorCode[upstreamCode];
837
+ if (mapped) return mapped;
838
+ }
839
+ return ErrorCode.WOO_NOT_FOUND;
840
+ }
841
+ return ErrorCode.WOO_REQUEST_FAILED;
842
+ }
843
+
844
+ // src/integrations/restApi/woocommerce/client/fetcher.ts
845
+ var USER_AGENT2 = "NextWordpress WooCommerce Client";
846
+ var DEFAULT_CACHE_TTL = 3600;
847
+ function toQueryString(params) {
848
+ const pairs = [];
849
+ for (const [key, value] of Object.entries(params)) {
850
+ if (value === void 0 || value === null) continue;
851
+ pairs.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`);
852
+ }
853
+ return pairs.join("&");
854
+ }
855
+ function createWooCommerceFetcher(config) {
856
+ const cacheTTL = config.cacheTTL ?? DEFAULT_CACHE_TTL;
857
+ function withAuth(query) {
858
+ return { ...query, consumer_key: config.consumerKey, consumer_secret: config.consumerSecret };
859
+ }
860
+ function buildUrl2(path, query) {
861
+ const base = typeof window !== "undefined" && config.clientURL ? config.clientURL : config.serverURL;
862
+ return `${base}${path}?${toQueryString(withAuth(query))}`;
863
+ }
864
+ async function throwWooError(response, url) {
865
+ const body = await response.json().catch(() => ({}));
866
+ const errorCode = resolveWooErrorCode(response.status, body.code);
867
+ throw new WooCommerceError(
868
+ errorCode,
869
+ response.status,
870
+ url,
871
+ resolveMessage(errorCode, config.errorMessages),
872
+ body.code,
873
+ body.message
874
+ );
875
+ }
876
+ async function wcFetch(path, query, tags = ["woocommerce"], options) {
877
+ const url = buildUrl2(path, query);
878
+ const isMutation = options?.method && options.method !== "GET";
879
+ const noStore = options?.cache === "no-store";
880
+ const response = await fetch(url, {
881
+ ...options,
882
+ headers: {
883
+ "User-Agent": USER_AGENT2,
884
+ "Content-Type": "application/json",
885
+ ...options?.headers
886
+ },
887
+ next: isMutation || noStore ? void 0 : { tags, revalidate: cacheTTL }
888
+ });
889
+ if (!response.ok) {
890
+ await throwWooError(response, url);
891
+ }
892
+ return response.json();
893
+ }
894
+ async function wcFetchGraceful(path, fallback, query, tags = ["woocommerce"]) {
895
+ try {
896
+ return await wcFetch(path, query, tags);
897
+ } catch (err) {
898
+ console.warn(`WooCommerce fetch failed for ${path}`, err);
899
+ return fallback;
900
+ }
901
+ }
902
+ async function wcFetchPaginated(path, query, tags = ["woocommerce"]) {
903
+ const url = buildUrl2(path, query);
904
+ const response = await fetch(url, {
905
+ headers: { "User-Agent": USER_AGENT2 },
906
+ next: { tags, revalidate: cacheTTL }
907
+ });
908
+ if (!response.ok) {
909
+ await throwWooError(response, url);
910
+ }
911
+ return {
912
+ data: await response.json(),
913
+ headers: {
914
+ total: parseInt(response.headers.get("X-WP-Total") ?? "0", 10),
915
+ totalPages: parseInt(response.headers.get("X-WP-TotalPages") ?? "0", 10)
916
+ }
917
+ };
918
+ }
919
+ async function wcFetchPaginatedGraceful(path, query, tags = ["woocommerce"]) {
920
+ const empty = { data: [], headers: { total: 0, totalPages: 0 } };
921
+ try {
922
+ return await wcFetchPaginated(path, query, tags);
923
+ } catch (err) {
924
+ console.warn(`WooCommerce paginated fetch failed for ${path}`, err);
925
+ return empty;
926
+ }
927
+ }
928
+ async function wcMutate(path, body, method = "POST") {
929
+ return wcFetch(path, void 0, ["woocommerce"], {
930
+ method,
931
+ body: JSON.stringify(body)
932
+ });
933
+ }
934
+ return { wcFetch, wcFetchGraceful, wcFetchPaginated, wcFetchPaginatedGraceful, wcMutate };
935
+ }
936
+
937
+ // src/integrations/restApi/woocommerce/products/queries.ts
938
+ function buildProductQuery(base, filterParams) {
939
+ const query = { ...base };
940
+ if (!filterParams) return query;
941
+ if (filterParams.category !== void 0) query.category = filterParams.category;
942
+ if (filterParams.tag !== void 0) query.tag = filterParams.tag;
943
+ if (filterParams.featured !== void 0) query.featured = filterParams.featured;
944
+ if (filterParams.on_sale !== void 0) query.on_sale = filterParams.on_sale;
945
+ if (filterParams.min_price !== void 0) query.min_price = filterParams.min_price;
946
+ if (filterParams.max_price !== void 0) query.max_price = filterParams.max_price;
947
+ if (filterParams.search !== void 0) query.search = filterParams.search;
948
+ if (filterParams.orderby !== void 0) query.orderby = filterParams.orderby;
949
+ if (filterParams.order !== void 0) query.order = filterParams.order;
950
+ if (filterParams.stock_status !== void 0) query.stock_status = filterParams.stock_status;
951
+ if (filterParams.type !== void 0) query.type = filterParams.type;
952
+ return query;
953
+ }
954
+ function createProductsQueries(fetcher) {
955
+ const { wcFetch, wcFetchGraceful, wcFetchPaginated, wcFetchPaginatedGraceful } = fetcher;
956
+ async function getProducts(filterParams) {
957
+ const query = buildProductQuery({ per_page: 100, status: "publish" }, filterParams);
958
+ return wcFetchGraceful("/wp-json/wc/v3/products", [], query, [
959
+ "woocommerce",
960
+ "products"
961
+ ]);
962
+ }
963
+ async function getProductsPaginated(page = 1, perPage = 12, filterParams) {
964
+ const query = buildProductQuery({ per_page: perPage, page, status: "publish" }, filterParams);
965
+ const cacheTags = ["woocommerce", "products", `products-page-${page}`];
966
+ if (filterParams?.category) cacheTags.push(`products-category-${filterParams.category}`);
967
+ if (filterParams?.tag) cacheTags.push(`products-tag-${filterParams.tag}`);
968
+ if (filterParams?.search) cacheTags.push("products-search");
969
+ return wcFetchPaginatedGraceful("/wp-json/wc/v3/products", query, cacheTags);
970
+ }
971
+ async function getProductById(id) {
972
+ return wcFetch(`/wp-json/wc/v3/products/${id}`, void 0, [
973
+ "woocommerce",
974
+ "products",
975
+ `product-${id}`
976
+ ]);
977
+ }
978
+ async function getProductBySlug(slug) {
979
+ const products = await wcFetchGraceful(
980
+ "/wp-json/wc/v3/products",
981
+ [],
982
+ { slug },
983
+ ["woocommerce", "products", `product-slug-${slug}`]
984
+ );
985
+ return products[0];
986
+ }
987
+ async function getFeaturedProducts(limit = 10) {
988
+ return wcFetchGraceful(
989
+ "/wp-json/wc/v3/products",
990
+ [],
991
+ { featured: true, per_page: limit, status: "publish" },
992
+ ["woocommerce", "products", "featured"]
993
+ );
994
+ }
995
+ async function getOnSaleProducts(limit = 10) {
996
+ return wcFetchGraceful(
997
+ "/wp-json/wc/v3/products",
998
+ [],
999
+ { on_sale: true, per_page: limit, status: "publish" },
1000
+ ["woocommerce", "products", "on-sale"]
1001
+ );
1002
+ }
1003
+ async function getRelatedProducts(productId) {
1004
+ const product = await getProductById(productId);
1005
+ if (!product.related_ids.length) return [];
1006
+ return wcFetchGraceful(
1007
+ "/wp-json/wc/v3/products",
1008
+ [],
1009
+ { include: product.related_ids.join(","), per_page: 10, status: "publish" },
1010
+ ["woocommerce", "products", `related-${productId}`]
1011
+ );
1012
+ }
1013
+ async function getAllProductSlugs() {
1014
+ try {
1015
+ const allSlugs = [];
1016
+ let page = 1;
1017
+ let hasMore = true;
1018
+ while (hasMore) {
1019
+ const response = await wcFetchPaginated("/wp-json/wc/v3/products", {
1020
+ per_page: 100,
1021
+ page,
1022
+ status: "publish",
1023
+ _fields: "slug"
1024
+ });
1025
+ allSlugs.push(...response.data.map((p) => ({ slug: p.slug })));
1026
+ hasMore = page < response.headers.totalPages;
1027
+ page++;
1028
+ }
1029
+ return allSlugs;
1030
+ } catch {
1031
+ console.warn("WooCommerce unavailable, skipping static generation for products");
1032
+ return [];
1033
+ }
1034
+ }
1035
+ async function getProductVariations(productId) {
1036
+ return wcFetchGraceful(
1037
+ `/wp-json/wc/v3/products/${productId}/variations`,
1038
+ [],
1039
+ { per_page: 100 },
1040
+ ["woocommerce", "products", `product-${productId}`, "variations"]
1041
+ );
1042
+ }
1043
+ async function getProductVariationById(productId, variationId) {
1044
+ return wcFetch(
1045
+ `/wp-json/wc/v3/products/${productId}/variations/${variationId}`,
1046
+ void 0,
1047
+ ["woocommerce", "products", `product-${productId}`, `variation-${variationId}`]
1048
+ );
1049
+ }
1050
+ return {
1051
+ getProducts,
1052
+ getProductsPaginated,
1053
+ getProductById,
1054
+ getProductBySlug,
1055
+ getFeaturedProducts,
1056
+ getOnSaleProducts,
1057
+ getRelatedProducts,
1058
+ getAllProductSlugs,
1059
+ getProductVariations,
1060
+ getProductVariationById
1061
+ };
1062
+ }
1063
+
1064
+ // src/integrations/restApi/woocommerce/products/mutations.ts
1065
+ function createProductsMutations(fetcher) {
1066
+ const { wcMutate } = fetcher;
1067
+ async function createProduct(input) {
1068
+ return wcMutate("/wp-json/wc/v3/products", input, "POST");
1069
+ }
1070
+ async function updateProduct(id, input) {
1071
+ return wcMutate(`/wp-json/wc/v3/products/${id}`, input, "PUT");
1072
+ }
1073
+ async function deleteProduct(id, force = true) {
1074
+ return wcMutate(
1075
+ `/wp-json/wc/v3/products/${id}`,
1076
+ { force },
1077
+ "DELETE"
1078
+ );
1079
+ }
1080
+ return { createProduct, updateProduct, deleteProduct };
1081
+ }
1082
+
1083
+ // src/integrations/restApi/woocommerce/categories/queries.ts
1084
+ function createCategoriesQueries2(fetcher) {
1085
+ const { wcFetch, wcFetchGraceful } = fetcher;
1086
+ async function getAllProductCategories() {
1087
+ return wcFetchGraceful(
1088
+ "/wp-json/wc/v3/products/categories",
1089
+ [],
1090
+ { per_page: 100, hide_empty: false },
1091
+ ["woocommerce", "product-categories"]
1092
+ );
1093
+ }
1094
+ async function getProductCategoryById(id) {
1095
+ return wcFetch(
1096
+ `/wp-json/wc/v3/products/categories/${id}`,
1097
+ void 0,
1098
+ ["woocommerce", "product-categories", `product-category-${id}`]
1099
+ );
1100
+ }
1101
+ async function getProductCategoryBySlug(slug) {
1102
+ const categories = await wcFetchGraceful(
1103
+ "/wp-json/wc/v3/products/categories",
1104
+ [],
1105
+ { slug },
1106
+ ["woocommerce", "product-categories", `product-category-slug-${slug}`]
1107
+ );
1108
+ return categories[0];
1109
+ }
1110
+ async function getProductsByCategory(categoryId, limit = 100) {
1111
+ return wcFetchGraceful(
1112
+ "/wp-json/wc/v3/products",
1113
+ [],
1114
+ { category: categoryId, per_page: limit, status: "publish" },
1115
+ ["woocommerce", "products", `products-category-${categoryId}`]
1116
+ );
1117
+ }
1118
+ async function getProductsByCategorySlug(categorySlug) {
1119
+ const category = await getProductCategoryBySlug(categorySlug);
1120
+ if (!category) return [];
1121
+ return getProductsByCategory(category.id);
1122
+ }
1123
+ return {
1124
+ getAllProductCategories,
1125
+ getProductCategoryById,
1126
+ getProductCategoryBySlug,
1127
+ getProductsByCategory,
1128
+ getProductsByCategorySlug
1129
+ };
1130
+ }
1131
+
1132
+ // src/integrations/restApi/woocommerce/categories/mutations.ts
1133
+ function createCategoriesMutations2(fetcher) {
1134
+ const { wcMutate } = fetcher;
1135
+ async function createProductCategory(input) {
1136
+ return wcMutate("/wp-json/wc/v3/products/categories", input, "POST");
1137
+ }
1138
+ async function updateProductCategory(id, input) {
1139
+ return wcMutate(
1140
+ `/wp-json/wc/v3/products/categories/${id}`,
1141
+ input,
1142
+ "PUT"
1143
+ );
1144
+ }
1145
+ async function deleteProductCategory(id, force = true) {
1146
+ return wcMutate(
1147
+ `/wp-json/wc/v3/products/categories/${id}`,
1148
+ { force },
1149
+ "DELETE"
1150
+ );
1151
+ }
1152
+ return { createProductCategory, updateProductCategory, deleteProductCategory };
1153
+ }
1154
+
1155
+ // src/integrations/restApi/woocommerce/tags/queries.ts
1156
+ function createTagsQueries2(fetcher) {
1157
+ const { wcFetch, wcFetchGraceful } = fetcher;
1158
+ async function getAllProductTags() {
1159
+ return wcFetchGraceful(
1160
+ "/wp-json/wc/v3/products/tags",
1161
+ [],
1162
+ { per_page: 100 },
1163
+ ["woocommerce", "product-tags"]
1164
+ );
1165
+ }
1166
+ async function getProductTagById(id) {
1167
+ return wcFetch(`/wp-json/wc/v3/products/tags/${id}`, void 0, [
1168
+ "woocommerce",
1169
+ "product-tags",
1170
+ `product-tag-${id}`
1171
+ ]);
1172
+ }
1173
+ async function getProductsByTag(tagId, limit = 100) {
1174
+ return wcFetchGraceful(
1175
+ "/wp-json/wc/v3/products",
1176
+ [],
1177
+ { tag: tagId, per_page: limit },
1178
+ ["woocommerce", "products", `products-tag-${tagId}`]
1179
+ );
1180
+ }
1181
+ return {
1182
+ getAllProductTags,
1183
+ getProductTagById,
1184
+ getProductsByTag
1185
+ };
1186
+ }
1187
+
1188
+ // src/integrations/restApi/woocommerce/tags/mutations.ts
1189
+ function createTagsMutations2(fetcher) {
1190
+ const { wcMutate } = fetcher;
1191
+ async function createProductTag(input) {
1192
+ return wcMutate("/wp-json/wc/v3/products/tags", input, "POST");
1193
+ }
1194
+ async function updateProductTag(id, input) {
1195
+ return wcMutate(`/wp-json/wc/v3/products/tags/${id}`, input, "PUT");
1196
+ }
1197
+ async function deleteProductTag(id, force = true) {
1198
+ return wcMutate(
1199
+ `/wp-json/wc/v3/products/tags/${id}`,
1200
+ { force },
1201
+ "DELETE"
1202
+ );
1203
+ }
1204
+ return { createProductTag, updateProductTag, deleteProductTag };
1205
+ }
1206
+
1207
+ // src/integrations/restApi/woocommerce/orders/queries.ts
1208
+ function createOrdersQueries(fetcher) {
1209
+ const { wcFetch, wcFetchGraceful, wcMutate } = fetcher;
1210
+ async function createOrder(input) {
1211
+ return wcMutate("/wp-json/wc/v3/orders", input, "POST");
1212
+ }
1213
+ async function getOrderById(id) {
1214
+ return wcFetch(`/wp-json/wc/v3/orders/${id}`, void 0, [
1215
+ "woocommerce",
1216
+ "orders",
1217
+ `order-${id}`
1218
+ ]);
1219
+ }
1220
+ async function updateOrder(id, data) {
1221
+ return wcMutate(`/wp-json/wc/v3/orders/${id}`, data, "PUT");
1222
+ }
1223
+ async function getOrdersByCustomer(customerId) {
1224
+ return wcFetchGraceful(
1225
+ "/wp-json/wc/v3/orders",
1226
+ [],
1227
+ { customer: customerId, per_page: 100 },
1228
+ ["woocommerce", "orders", `orders-customer-${customerId}`]
1229
+ );
1230
+ }
1231
+ async function deleteOrder(id, force = true) {
1232
+ return wcMutate(
1233
+ `/wp-json/wc/v3/orders/${id}`,
1234
+ { force },
1235
+ "DELETE"
1236
+ );
1237
+ }
1238
+ return {
1239
+ createOrder,
1240
+ getOrderById,
1241
+ updateOrder,
1242
+ getOrdersByCustomer,
1243
+ deleteOrder
1244
+ };
1245
+ }
1246
+
1247
+ // src/integrations/restApi/woocommerce/coupons/queries.ts
1248
+ function createCouponsQueries(fetcher) {
1249
+ const { wcFetchGraceful } = fetcher;
1250
+ async function getCouponByCode(code) {
1251
+ const coupons = await wcFetchGraceful(
1252
+ "/wp-json/wc/v3/coupons",
1253
+ [],
1254
+ { code },
1255
+ ["woocommerce", "coupons"]
1256
+ );
1257
+ return coupons[0];
1258
+ }
1259
+ async function validateCoupon(code) {
1260
+ const coupon = await getCouponByCode(code);
1261
+ if (!coupon) return { valid: false, reason: "Coupon not found" };
1262
+ if (coupon.date_expires) {
1263
+ const expiry = new Date(coupon.date_expires);
1264
+ if (expiry < /* @__PURE__ */ new Date()) return { valid: false, reason: "Coupon has expired", coupon };
1265
+ }
1266
+ if (coupon.usage_limit !== null && coupon.usage_count >= coupon.usage_limit) {
1267
+ return { valid: false, reason: "Coupon usage limit reached", coupon };
1268
+ }
1269
+ return { valid: true, coupon };
1270
+ }
1271
+ return {
1272
+ getCouponByCode,
1273
+ validateCoupon
1274
+ };
1275
+ }
1276
+
1277
+ // src/integrations/restApi/woocommerce/coupons/mutations.ts
1278
+ function createCouponsMutations(fetcher) {
1279
+ const { wcMutate } = fetcher;
1280
+ async function createCoupon(input) {
1281
+ return wcMutate("/wp-json/wc/v3/coupons", input, "POST");
1282
+ }
1283
+ async function updateCoupon(id, input) {
1284
+ return wcMutate(`/wp-json/wc/v3/coupons/${id}`, input, "PUT");
1285
+ }
1286
+ async function deleteCoupon(id, force = true) {
1287
+ return wcMutate(
1288
+ `/wp-json/wc/v3/coupons/${id}`,
1289
+ { force },
1290
+ "DELETE"
1291
+ );
1292
+ }
1293
+ return { createCoupon, updateCoupon, deleteCoupon };
1294
+ }
1295
+
1296
+ // src/integrations/restApi/woocommerce/customers/queries.ts
1297
+ function createCustomersQueries(fetcher) {
1298
+ const { wcFetch, wcFetchGraceful, wcMutate } = fetcher;
1299
+ async function getCustomerById(id) {
1300
+ return wcFetch(`/wp-json/wc/v3/customers/${id}`, void 0, [
1301
+ "woocommerce",
1302
+ "customers",
1303
+ `customer-${id}`
1304
+ ]);
1305
+ }
1306
+ async function getCustomerByEmail(email) {
1307
+ const customers = await wcFetchGraceful(
1308
+ "/wp-json/wc/v3/customers",
1309
+ [],
1310
+ { email },
1311
+ ["woocommerce", "customers"]
1312
+ );
1313
+ return customers[0];
1314
+ }
1315
+ async function getCustomerByEmailNoCache(email) {
1316
+ try {
1317
+ const customers = await wcFetch(
1318
+ "/wp-json/wc/v3/customers",
1319
+ { email },
1320
+ ["woocommerce", "customers"],
1321
+ { cache: "no-store" }
1322
+ );
1323
+ return customers[0];
1324
+ } catch {
1325
+ return void 0;
1326
+ }
1327
+ }
1328
+ async function createCustomer(data) {
1329
+ return wcFetch(
1330
+ "/wp-json/wc/v3/customers",
1331
+ void 0,
1332
+ ["woocommerce", "customers"],
1333
+ { method: "POST", body: JSON.stringify(data) }
1334
+ );
1335
+ }
1336
+ async function updateCustomer(id, data) {
1337
+ return wcMutate(`/wp-json/wc/v3/customers/${id}`, data, "PUT");
1338
+ }
1339
+ async function deleteCustomer(id, reassign) {
1340
+ return wcMutate(
1341
+ `/wp-json/wc/v3/customers/${id}`,
1342
+ { force: true, ...reassign !== void 0 && { reassign } },
1343
+ "DELETE"
1344
+ );
1345
+ }
1346
+ return {
1347
+ getCustomerById,
1348
+ getCustomerByEmail,
1349
+ getCustomerByEmailNoCache,
1350
+ createCustomer,
1351
+ updateCustomer,
1352
+ deleteCustomer
1353
+ };
1354
+ }
1355
+
1356
+ // src/integrations/restApi/woocommerce/payment_gateways/queries.ts
1357
+ function createPaymentGatewaysQueries(fetcher) {
1358
+ const { wcFetch, wcFetchGraceful } = fetcher;
1359
+ async function getPaymentGateways() {
1360
+ return wcFetchGraceful(
1361
+ "/wp-json/wc/v3/payment_gateways",
1362
+ [],
1363
+ void 0,
1364
+ ["woocommerce", "payment_gateways"]
1365
+ );
1366
+ }
1367
+ async function getEnabledPaymentGateways() {
1368
+ const gateways = await wcFetchGraceful(
1369
+ "/wp-json/wc/v3/payment_gateways",
1370
+ [],
1371
+ void 0,
1372
+ ["woocommerce", "payment_gateways"]
1373
+ );
1374
+ return gateways.filter((g) => g.enabled);
1375
+ }
1376
+ async function getPaymentGatewayById(id) {
1377
+ return wcFetch(
1378
+ `/wp-json/wc/v3/payment_gateways/${id}`,
1379
+ void 0,
1380
+ ["woocommerce", "payment_gateways", `payment_gateway-${id}`]
1381
+ );
1382
+ }
1383
+ return {
1384
+ getPaymentGateways,
1385
+ getEnabledPaymentGateways,
1386
+ getPaymentGatewayById
1387
+ };
1388
+ }
1389
+
1390
+ // src/integrations/restApi/woocommerce/order_notes/queries.ts
1391
+ function createOrderNotesQueries(fetcher) {
1392
+ const { wcFetch, wcFetchGraceful, wcMutate } = fetcher;
1393
+ async function getNotesByOrderId(orderId) {
1394
+ return wcFetchGraceful(
1395
+ `/wp-json/wc/v3/orders/${orderId}/notes`,
1396
+ [],
1397
+ void 0,
1398
+ ["woocommerce", "order_notes", `order-${orderId}-notes`]
1399
+ );
1400
+ }
1401
+ async function getOrderNoteById(orderId, noteId) {
1402
+ return wcFetch(
1403
+ `/wp-json/wc/v3/orders/${orderId}/notes/${noteId}`,
1404
+ void 0,
1405
+ ["woocommerce", "order_notes", `order-${orderId}-note-${noteId}`]
1406
+ );
1407
+ }
1408
+ async function createOrderNote(orderId, input) {
1409
+ return wcMutate(
1410
+ `/wp-json/wc/v3/orders/${orderId}/notes`,
1411
+ input,
1412
+ "POST"
1413
+ );
1414
+ }
1415
+ async function deleteOrderNote(orderId, noteId, force = true) {
1416
+ return wcMutate(
1417
+ `/wp-json/wc/v3/orders/${orderId}/notes/${noteId}`,
1418
+ { force },
1419
+ "DELETE"
1420
+ );
1421
+ }
1422
+ return {
1423
+ getNotesByOrderId,
1424
+ getOrderNoteById,
1425
+ createOrderNote,
1426
+ deleteOrderNote
1427
+ };
1428
+ }
1429
+
1430
+ // src/integrations/restApi/woocommerce/order_refunds/queries.ts
1431
+ function createOrderRefundsQueries(fetcher) {
1432
+ const { wcFetch, wcFetchGraceful, wcMutate } = fetcher;
1433
+ async function getRefundsByOrderId(orderId) {
1434
+ return wcFetchGraceful(
1435
+ `/wp-json/wc/v3/orders/${orderId}/refunds`,
1436
+ [],
1437
+ void 0,
1438
+ ["woocommerce", "order_refunds", `order-${orderId}-refunds`]
1439
+ );
1440
+ }
1441
+ async function getOrderRefundById(orderId, refundId) {
1442
+ return wcFetch(
1443
+ `/wp-json/wc/v3/orders/${orderId}/refunds/${refundId}`,
1444
+ void 0,
1445
+ ["woocommerce", "order_refunds", `order-${orderId}-refund-${refundId}`]
1446
+ );
1447
+ }
1448
+ async function createOrderRefund(orderId, input) {
1449
+ return wcMutate(
1450
+ `/wp-json/wc/v3/orders/${orderId}/refunds`,
1451
+ input,
1452
+ "POST"
1453
+ );
1454
+ }
1455
+ async function deleteOrderRefund(orderId, refundId, force = true) {
1456
+ return wcMutate(
1457
+ `/wp-json/wc/v3/orders/${orderId}/refunds/${refundId}`,
1458
+ { force },
1459
+ "DELETE"
1460
+ );
1461
+ }
1462
+ return {
1463
+ getRefundsByOrderId,
1464
+ getOrderRefundById,
1465
+ createOrderRefund,
1466
+ deleteOrderRefund
1467
+ };
1468
+ }
1469
+
1470
+ // src/integrations/restApi/woocommerce/product_attributes/queries.ts
1471
+ function createProductAttributesQueries(fetcher) {
1472
+ const { wcFetch, wcFetchGraceful, wcMutate } = fetcher;
1473
+ async function getProductAttributes() {
1474
+ return wcFetchGraceful(
1475
+ "/wp-json/wc/v3/products/attributes",
1476
+ [],
1477
+ void 0,
1478
+ ["woocommerce", "product_attributes"]
1479
+ );
1480
+ }
1481
+ async function getProductAttributeById(id) {
1482
+ return wcFetch(
1483
+ `/wp-json/wc/v3/products/attributes/${id}`,
1484
+ void 0,
1485
+ ["woocommerce", "product_attributes", `attribute-${id}`]
1486
+ );
1487
+ }
1488
+ async function createProductAttribute(input) {
1489
+ return wcMutate("/wp-json/wc/v3/products/attributes", input, "POST");
1490
+ }
1491
+ async function updateProductAttribute(id, input) {
1492
+ return wcMutate(
1493
+ `/wp-json/wc/v3/products/attributes/${id}`,
1494
+ input,
1495
+ "PUT"
1496
+ );
1497
+ }
1498
+ async function deleteProductAttribute(id, force = true) {
1499
+ return wcMutate(
1500
+ `/wp-json/wc/v3/products/attributes/${id}`,
1501
+ { force },
1502
+ "DELETE"
1503
+ );
1504
+ }
1505
+ async function getAttributeTerms(attributeId) {
1506
+ return wcFetchGraceful(
1507
+ `/wp-json/wc/v3/products/attributes/${attributeId}/terms`,
1508
+ [],
1509
+ void 0,
1510
+ ["woocommerce", "attribute_terms", `attribute-${attributeId}-terms`]
1511
+ );
1512
+ }
1513
+ async function getAttributeTermById(attributeId, termId) {
1514
+ return wcFetch(
1515
+ `/wp-json/wc/v3/products/attributes/${attributeId}/terms/${termId}`,
1516
+ void 0,
1517
+ ["woocommerce", "attribute_terms", `attribute-${attributeId}-term-${termId}`]
1518
+ );
1519
+ }
1520
+ async function createAttributeTerm(attributeId, input) {
1521
+ return wcMutate(
1522
+ `/wp-json/wc/v3/products/attributes/${attributeId}/terms`,
1523
+ input,
1524
+ "POST"
1525
+ );
1526
+ }
1527
+ async function updateAttributeTerm(attributeId, termId, input) {
1528
+ return wcMutate(
1529
+ `/wp-json/wc/v3/products/attributes/${attributeId}/terms/${termId}`,
1530
+ input,
1531
+ "PUT"
1532
+ );
1533
+ }
1534
+ async function deleteAttributeTerm(attributeId, termId, force = true) {
1535
+ return wcMutate(
1536
+ `/wp-json/wc/v3/products/attributes/${attributeId}/terms/${termId}`,
1537
+ { force },
1538
+ "DELETE"
1539
+ );
1540
+ }
1541
+ return {
1542
+ getProductAttributes,
1543
+ getProductAttributeById,
1544
+ createProductAttribute,
1545
+ updateProductAttribute,
1546
+ deleteProductAttribute,
1547
+ getAttributeTerms,
1548
+ getAttributeTermById,
1549
+ createAttributeTerm,
1550
+ updateAttributeTerm,
1551
+ deleteAttributeTerm
1552
+ };
1553
+ }
1554
+
1555
+ // src/integrations/restApi/woocommerce/product_reviews/queries.ts
1556
+ function createProductReviewsQueries(fetcher) {
1557
+ const { wcFetch, wcFetchGraceful, wcMutate } = fetcher;
1558
+ async function getProductReviews(params) {
1559
+ return wcFetchGraceful(
1560
+ "/wp-json/wc/v3/products/reviews",
1561
+ [],
1562
+ params,
1563
+ ["woocommerce", "product_reviews"]
1564
+ );
1565
+ }
1566
+ async function getProductReviewsByProductId(productId) {
1567
+ return wcFetchGraceful(
1568
+ "/wp-json/wc/v3/products/reviews",
1569
+ [],
1570
+ { product: [productId] },
1571
+ ["woocommerce", "product_reviews", `reviews-product-${productId}`]
1572
+ );
1573
+ }
1574
+ async function getProductReviewById(id) {
1575
+ return wcFetch(
1576
+ `/wp-json/wc/v3/products/reviews/${id}`,
1577
+ void 0,
1578
+ ["woocommerce", "product_reviews", `review-${id}`]
1579
+ );
1580
+ }
1581
+ async function createProductReview(input) {
1582
+ return wcMutate("/wp-json/wc/v3/products/reviews", input, "POST");
1583
+ }
1584
+ async function updateProductReview(id, input) {
1585
+ return wcMutate(`/wp-json/wc/v3/products/reviews/${id}`, input, "PUT");
1586
+ }
1587
+ async function deleteProductReview(id, force = true) {
1588
+ return wcMutate(
1589
+ `/wp-json/wc/v3/products/reviews/${id}`,
1590
+ { force },
1591
+ "DELETE"
1592
+ );
1593
+ }
1594
+ return {
1595
+ getProductReviews,
1596
+ getProductReviewsByProductId,
1597
+ getProductReviewById,
1598
+ createProductReview,
1599
+ updateProductReview,
1600
+ deleteProductReview
1601
+ };
1602
+ }
1603
+
1604
+ // src/integrations/restApi/woocommerce/shipping_classes/queries.ts
1605
+ function createShippingClassesQueries(fetcher) {
1606
+ const { wcFetch, wcFetchGraceful, wcMutate } = fetcher;
1607
+ async function getShippingClasses() {
1608
+ return wcFetchGraceful(
1609
+ "/wp-json/wc/v3/products/shipping_classes",
1610
+ [],
1611
+ void 0,
1612
+ ["woocommerce", "shipping_classes"]
1613
+ );
1614
+ }
1615
+ async function getShippingClassById(id) {
1616
+ return wcFetch(
1617
+ `/wp-json/wc/v3/products/shipping_classes/${id}`,
1618
+ void 0,
1619
+ ["woocommerce", "shipping_classes", `shipping-class-${id}`]
1620
+ );
1621
+ }
1622
+ async function createShippingClass(input) {
1623
+ return wcMutate("/wp-json/wc/v3/products/shipping_classes", input, "POST");
1624
+ }
1625
+ async function updateShippingClass(id, input) {
1626
+ return wcMutate(
1627
+ `/wp-json/wc/v3/products/shipping_classes/${id}`,
1628
+ input,
1629
+ "PUT"
1630
+ );
1631
+ }
1632
+ async function deleteShippingClass(id, force = true) {
1633
+ return wcMutate(
1634
+ `/wp-json/wc/v3/products/shipping_classes/${id}`,
1635
+ { force },
1636
+ "DELETE"
1637
+ );
1638
+ }
1639
+ return {
1640
+ getShippingClasses,
1641
+ getShippingClassById,
1642
+ createShippingClass,
1643
+ updateShippingClass,
1644
+ deleteShippingClass
1645
+ };
1646
+ }
1647
+
1648
+ // src/integrations/restApi/woocommerce/taxes/queries.ts
1649
+ function createTaxesQueries(fetcher) {
1650
+ const { wcFetch, wcFetchGraceful, wcMutate } = fetcher;
1651
+ async function getTaxRates(params) {
1652
+ return wcFetchGraceful(
1653
+ "/wp-json/wc/v3/taxes",
1654
+ [],
1655
+ params,
1656
+ ["woocommerce", "tax_rates"]
1657
+ );
1658
+ }
1659
+ async function getTaxRateById(id) {
1660
+ return wcFetch(
1661
+ `/wp-json/wc/v3/taxes/${id}`,
1662
+ void 0,
1663
+ ["woocommerce", "tax_rates", `tax-rate-${id}`]
1664
+ );
1665
+ }
1666
+ async function createTaxRate(input) {
1667
+ return wcMutate("/wp-json/wc/v3/taxes", input, "POST");
1668
+ }
1669
+ async function updateTaxRate(id, input) {
1670
+ return wcMutate(`/wp-json/wc/v3/taxes/${id}`, input, "PUT");
1671
+ }
1672
+ async function deleteTaxRate(id, force = true) {
1673
+ return wcMutate(
1674
+ `/wp-json/wc/v3/taxes/${id}`,
1675
+ { force },
1676
+ "DELETE"
1677
+ );
1678
+ }
1679
+ async function getTaxClasses() {
1680
+ return wcFetchGraceful(
1681
+ "/wp-json/wc/v3/taxes/classes",
1682
+ [],
1683
+ void 0,
1684
+ ["woocommerce", "tax_classes"]
1685
+ );
1686
+ }
1687
+ async function createTaxClass(input) {
1688
+ return wcMutate("/wp-json/wc/v3/taxes/classes", input, "POST");
1689
+ }
1690
+ async function deleteTaxClass(slug, force = true) {
1691
+ return wcMutate(
1692
+ `/wp-json/wc/v3/taxes/classes/${slug}`,
1693
+ { force },
1694
+ "DELETE"
1695
+ );
1696
+ }
1697
+ return {
1698
+ getTaxRates,
1699
+ getTaxRateById,
1700
+ createTaxRate,
1701
+ updateTaxRate,
1702
+ deleteTaxRate,
1703
+ getTaxClasses,
1704
+ createTaxClass,
1705
+ deleteTaxClass
1706
+ };
1707
+ }
1708
+
1709
+ // src/integrations/restApi/woocommerce/shipping/queries.ts
1710
+ function createShippingQueries(fetcher) {
1711
+ const { wcFetch, wcFetchGraceful, wcMutate } = fetcher;
1712
+ async function getShippingZones() {
1713
+ return wcFetchGraceful(
1714
+ "/wp-json/wc/v3/shipping/zones",
1715
+ [],
1716
+ void 0,
1717
+ ["woocommerce", "shipping_zones"]
1718
+ );
1719
+ }
1720
+ async function getShippingZoneById(id) {
1721
+ return wcFetch(
1722
+ `/wp-json/wc/v3/shipping/zones/${id}`,
1723
+ void 0,
1724
+ ["woocommerce", "shipping_zones", `zone-${id}`]
1725
+ );
1726
+ }
1727
+ async function createShippingZone(input) {
1728
+ return wcMutate("/wp-json/wc/v3/shipping/zones", input, "POST");
1729
+ }
1730
+ async function updateShippingZone(id, input) {
1731
+ return wcMutate(`/wp-json/wc/v3/shipping/zones/${id}`, input, "PUT");
1732
+ }
1733
+ async function deleteShippingZone(id, force = true) {
1734
+ return wcMutate(
1735
+ `/wp-json/wc/v3/shipping/zones/${id}`,
1736
+ { force },
1737
+ "DELETE"
1738
+ );
1739
+ }
1740
+ async function getShippingZoneLocations(zoneId) {
1741
+ return wcFetchGraceful(
1742
+ `/wp-json/wc/v3/shipping/zones/${zoneId}/locations`,
1743
+ [],
1744
+ void 0,
1745
+ ["woocommerce", "shipping_zone_locations", `zone-${zoneId}-locations`]
1746
+ );
1747
+ }
1748
+ async function updateShippingZoneLocations(zoneId, locations) {
1749
+ return wcMutate(
1750
+ `/wp-json/wc/v3/shipping/zones/${zoneId}/locations`,
1751
+ locations,
1752
+ "PUT"
1753
+ );
1754
+ }
1755
+ async function getShippingZoneMethods(zoneId) {
1756
+ return wcFetchGraceful(
1757
+ `/wp-json/wc/v3/shipping/zones/${zoneId}/methods`,
1758
+ [],
1759
+ void 0,
1760
+ ["woocommerce", "shipping_zone_methods", `zone-${zoneId}-methods`]
1761
+ );
1762
+ }
1763
+ async function getShippingZoneMethodById(zoneId, instanceId) {
1764
+ return wcFetch(
1765
+ `/wp-json/wc/v3/shipping/zones/${zoneId}/methods/${instanceId}`,
1766
+ void 0,
1767
+ ["woocommerce", "shipping_zone_methods", `zone-${zoneId}-method-${instanceId}`]
1768
+ );
1769
+ }
1770
+ async function createShippingZoneMethod(zoneId, input) {
1771
+ return wcMutate(
1772
+ `/wp-json/wc/v3/shipping/zones/${zoneId}/methods`,
1773
+ input,
1774
+ "POST"
1775
+ );
1776
+ }
1777
+ async function updateShippingZoneMethod(zoneId, instanceId, input) {
1778
+ return wcMutate(
1779
+ `/wp-json/wc/v3/shipping/zones/${zoneId}/methods/${instanceId}`,
1780
+ input,
1781
+ "PUT"
1782
+ );
1783
+ }
1784
+ async function deleteShippingZoneMethod(zoneId, instanceId, force = true) {
1785
+ return wcMutate(
1786
+ `/wp-json/wc/v3/shipping/zones/${zoneId}/methods/${instanceId}`,
1787
+ { force },
1788
+ "DELETE"
1789
+ );
1790
+ }
1791
+ async function getShippingMethods() {
1792
+ return wcFetchGraceful(
1793
+ "/wp-json/wc/v3/shipping_methods",
1794
+ [],
1795
+ void 0,
1796
+ ["woocommerce", "shipping_methods"]
1797
+ );
1798
+ }
1799
+ async function getShippingMethodById(id) {
1800
+ return wcFetch(
1801
+ `/wp-json/wc/v3/shipping_methods/${id}`,
1802
+ void 0,
1803
+ ["woocommerce", "shipping_methods", `shipping-method-${id}`]
1804
+ );
1805
+ }
1806
+ return {
1807
+ getShippingZones,
1808
+ getShippingZoneById,
1809
+ createShippingZone,
1810
+ updateShippingZone,
1811
+ deleteShippingZone,
1812
+ getShippingZoneLocations,
1813
+ updateShippingZoneLocations,
1814
+ getShippingZoneMethods,
1815
+ getShippingZoneMethodById,
1816
+ createShippingZoneMethod,
1817
+ updateShippingZoneMethod,
1818
+ deleteShippingZoneMethod,
1819
+ getShippingMethods,
1820
+ getShippingMethodById
1821
+ };
1822
+ }
1823
+
1824
+ // src/integrations/restApi/woocommerce/webhooks/queries.ts
1825
+ function createWebhooksQueries(fetcher) {
1826
+ const { wcFetch, wcFetchGraceful, wcMutate } = fetcher;
1827
+ async function getWebhooks(params) {
1828
+ return wcFetchGraceful(
1829
+ "/wp-json/wc/v3/webhooks",
1830
+ [],
1831
+ params,
1832
+ ["woocommerce", "webhooks"]
1833
+ );
1834
+ }
1835
+ async function getWebhookById(id) {
1836
+ return wcFetch(
1837
+ `/wp-json/wc/v3/webhooks/${id}`,
1838
+ void 0,
1839
+ ["woocommerce", "webhooks", `webhook-${id}`]
1840
+ );
1841
+ }
1842
+ async function createWebhook(input) {
1843
+ return wcMutate("/wp-json/wc/v3/webhooks", input, "POST");
1844
+ }
1845
+ async function updateWebhook(id, input) {
1846
+ return wcMutate(`/wp-json/wc/v3/webhooks/${id}`, input, "PUT");
1847
+ }
1848
+ async function deleteWebhook(id, force = true) {
1849
+ return wcMutate(
1850
+ `/wp-json/wc/v3/webhooks/${id}`,
1851
+ { force },
1852
+ "DELETE"
1853
+ );
1854
+ }
1855
+ return {
1856
+ getWebhooks,
1857
+ getWebhookById,
1858
+ createWebhook,
1859
+ updateWebhook,
1860
+ deleteWebhook
1861
+ };
1862
+ }
1863
+
1864
+ // src/integrations/restApi/woocommerce/settings/queries.ts
1865
+ function createSettingsQueries(fetcher) {
1866
+ const { wcFetch, wcFetchGraceful, wcMutate } = fetcher;
1867
+ async function getSettingGroups() {
1868
+ return wcFetchGraceful(
1869
+ "/wp-json/wc/v3/settings",
1870
+ [],
1871
+ void 0,
1872
+ ["woocommerce", "settings"]
1873
+ );
1874
+ }
1875
+ async function getSettingOptions(groupId) {
1876
+ return wcFetchGraceful(
1877
+ `/wp-json/wc/v3/settings/${groupId}`,
1878
+ [],
1879
+ void 0,
1880
+ ["woocommerce", "settings", `settings-${groupId}`]
1881
+ );
1882
+ }
1883
+ async function getSettingOption(groupId, optionId) {
1884
+ return wcFetch(
1885
+ `/wp-json/wc/v3/settings/${groupId}/${optionId}`,
1886
+ void 0,
1887
+ ["woocommerce", "settings", `settings-${groupId}-${optionId}`]
1888
+ );
1889
+ }
1890
+ async function updateSettingOption(groupId, optionId, value) {
1891
+ return wcMutate(
1892
+ `/wp-json/wc/v3/settings/${groupId}/${optionId}`,
1893
+ { value },
1894
+ "PUT"
1895
+ );
1896
+ }
1897
+ return {
1898
+ getSettingGroups,
1899
+ getSettingOptions,
1900
+ getSettingOption,
1901
+ updateSettingOption
1902
+ };
1903
+ }
1904
+
1905
+ // src/integrations/restApi/woocommerce/reports/queries.ts
1906
+ function createReportsQueries(fetcher) {
1907
+ const { wcFetchGraceful } = fetcher;
1908
+ async function getSalesReport(params) {
1909
+ return wcFetchGraceful(
1910
+ "/wp-json/wc/v3/reports/sales",
1911
+ [],
1912
+ params,
1913
+ ["woocommerce", "reports", "sales"]
1914
+ );
1915
+ }
1916
+ async function getTopSellers(params) {
1917
+ return wcFetchGraceful(
1918
+ "/wp-json/wc/v3/reports/top_sellers",
1919
+ [],
1920
+ params,
1921
+ ["woocommerce", "reports", "top_sellers"]
1922
+ );
1923
+ }
1924
+ async function getOrdersTotals() {
1925
+ return wcFetchGraceful(
1926
+ "/wp-json/wc/v3/reports/orders/totals",
1927
+ [],
1928
+ void 0,
1929
+ ["woocommerce", "reports", "orders_totals"]
1930
+ );
1931
+ }
1932
+ async function getProductsTotals() {
1933
+ return wcFetchGraceful(
1934
+ "/wp-json/wc/v3/reports/products/totals",
1935
+ [],
1936
+ void 0,
1937
+ ["woocommerce", "reports", "products_totals"]
1938
+ );
1939
+ }
1940
+ async function getCustomersTotals() {
1941
+ return wcFetchGraceful(
1942
+ "/wp-json/wc/v3/reports/customers/totals",
1943
+ [],
1944
+ void 0,
1945
+ ["woocommerce", "reports", "customers_totals"]
1946
+ );
1947
+ }
1948
+ async function getCouponsTotals() {
1949
+ return wcFetchGraceful(
1950
+ "/wp-json/wc/v3/reports/coupons/totals",
1951
+ [],
1952
+ void 0,
1953
+ ["woocommerce", "reports", "coupons_totals"]
1954
+ );
1955
+ }
1956
+ async function getReviewsTotals() {
1957
+ return wcFetchGraceful(
1958
+ "/wp-json/wc/v3/reports/reviews/totals",
1959
+ [],
1960
+ void 0,
1961
+ ["woocommerce", "reports", "reviews_totals"]
1962
+ );
1963
+ }
1964
+ return {
1965
+ getSalesReport,
1966
+ getTopSellers,
1967
+ getOrdersTotals,
1968
+ getProductsTotals,
1969
+ getCustomersTotals,
1970
+ getCouponsTotals,
1971
+ getReviewsTotals
1972
+ };
1973
+ }
1974
+
1975
+ // src/integrations/restApi/woocommerce/data/queries.ts
1976
+ function createDataQueries(fetcher) {
1977
+ const { wcFetch, wcFetchGraceful, wcMutate } = fetcher;
1978
+ async function getCurrencies() {
1979
+ return wcFetchGraceful(
1980
+ "/wp-json/wc/v3/data/currencies",
1981
+ [],
1982
+ void 0,
1983
+ ["woocommerce", "data", "currencies"]
1984
+ );
1985
+ }
1986
+ async function getCurrentCurrency() {
1987
+ return wcFetch(
1988
+ "/wp-json/wc/v3/data/currencies/current",
1989
+ void 0,
1990
+ ["woocommerce", "data", "currency_current"]
1991
+ );
1992
+ }
1993
+ async function getCurrencyByCode(code) {
1994
+ return wcFetch(
1995
+ `/wp-json/wc/v3/data/currencies/${code.toUpperCase()}`,
1996
+ void 0,
1997
+ ["woocommerce", "data", `currency-${code}`]
1998
+ );
1999
+ }
2000
+ async function getContinents() {
2001
+ return wcFetchGraceful(
2002
+ "/wp-json/wc/v3/data/continents",
2003
+ [],
2004
+ void 0,
2005
+ ["woocommerce", "data", "continents"]
2006
+ );
2007
+ }
2008
+ async function getContinentByCode(code) {
2009
+ return wcFetch(
2010
+ `/wp-json/wc/v3/data/continents/${code.toUpperCase()}`,
2011
+ void 0,
2012
+ ["woocommerce", "data", `continent-${code}`]
2013
+ );
2014
+ }
2015
+ async function getCountries() {
2016
+ return wcFetchGraceful(
2017
+ "/wp-json/wc/v3/data/countries",
2018
+ [],
2019
+ void 0,
2020
+ ["woocommerce", "data", "countries"]
2021
+ );
2022
+ }
2023
+ async function getCountryByCode(code) {
2024
+ return wcFetch(
2025
+ `/wp-json/wc/v3/data/countries/${code.toUpperCase()}`,
2026
+ void 0,
2027
+ ["woocommerce", "data", `country-${code}`]
2028
+ );
2029
+ }
2030
+ async function getTimeZones() {
2031
+ return wcFetchGraceful(
2032
+ "/wp-json/wc/v3/data/time_zones",
2033
+ {},
2034
+ void 0,
2035
+ ["woocommerce", "data", "time_zones"]
2036
+ );
2037
+ }
2038
+ async function getSystemStatus() {
2039
+ return wcFetch(
2040
+ "/wp-json/wc/v3/system_status",
2041
+ void 0,
2042
+ ["woocommerce", "system_status"]
2043
+ );
2044
+ }
2045
+ async function getSystemStatusTools() {
2046
+ return wcFetchGraceful(
2047
+ "/wp-json/wc/v3/system_status/tools",
2048
+ [],
2049
+ void 0,
2050
+ ["woocommerce", "system_status_tools"]
2051
+ );
2052
+ }
2053
+ async function runSystemStatusTool(toolId) {
2054
+ return wcMutate(
2055
+ `/wp-json/wc/v3/system_status/tools/${toolId}`,
2056
+ {},
2057
+ "PUT"
2058
+ );
2059
+ }
2060
+ return {
2061
+ getCurrencies,
2062
+ getCurrentCurrency,
2063
+ getCurrencyByCode,
2064
+ getContinents,
2065
+ getContinentByCode,
2066
+ getCountries,
2067
+ getCountryByCode,
2068
+ getTimeZones,
2069
+ getSystemStatus,
2070
+ getSystemStatusTools,
2071
+ runSystemStatusTool
2072
+ };
2073
+ }
2074
+
2075
+ // src/integrations/restApi/woocommerce/index.ts
2076
+ function createWooCommerceClient(config) {
2077
+ const fetcher = createWooCommerceFetcher(config);
2078
+ return {
2079
+ ...createProductsQueries(fetcher),
2080
+ ...createProductsMutations(fetcher),
2081
+ ...createCategoriesQueries2(fetcher),
2082
+ ...createCategoriesMutations2(fetcher),
2083
+ ...createTagsQueries2(fetcher),
2084
+ ...createTagsMutations2(fetcher),
2085
+ ...createOrdersQueries(fetcher),
2086
+ ...createOrderNotesQueries(fetcher),
2087
+ ...createOrderRefundsQueries(fetcher),
2088
+ ...createProductAttributesQueries(fetcher),
2089
+ ...createProductReviewsQueries(fetcher),
2090
+ ...createShippingClassesQueries(fetcher),
2091
+ ...createTaxesQueries(fetcher),
2092
+ ...createShippingQueries(fetcher),
2093
+ ...createWebhooksQueries(fetcher),
2094
+ ...createSettingsQueries(fetcher),
2095
+ ...createReportsQueries(fetcher),
2096
+ ...createDataQueries(fetcher),
2097
+ ...createCouponsQueries(fetcher),
2098
+ ...createCouponsMutations(fetcher),
2099
+ ...createCustomersQueries(fetcher),
2100
+ ...createPaymentGatewaysQueries(fetcher)
2101
+ };
2102
+ }
2103
+
2104
+ // src/integrations/restApi/wpulike/queries.ts
2105
+ function createWPULikeQueries(fetcher) {
2106
+ const { wpFetch, wpMutate } = fetcher;
2107
+ async function getLikeStats(params, tags) {
2108
+ return wpFetch(
2109
+ "/wp-json/wp-ulike/v1/stats",
2110
+ params,
2111
+ tags ?? ["wpulike", `wpulike-${params.id}`]
2112
+ );
2113
+ }
2114
+ async function checkLikeStatus(params, tags) {
2115
+ return wpFetch(
2116
+ "/wp-json/wp-ulike/v1/check",
2117
+ params,
2118
+ tags ?? ["wpulike", `wpulike-${params.id}`]
2119
+ );
2120
+ }
2121
+ async function vote(params, authToken) {
2122
+ return wpMutate(
2123
+ "/wp-json/wp-ulike/v1/vote",
2124
+ params,
2125
+ "POST",
2126
+ authToken
2127
+ );
2128
+ }
2129
+ return { getLikeStats, checkLikeStatus, vote };
2130
+ }
2131
+ function createWPULikeClient(config) {
2132
+ const fetcher = createFetcher(config);
2133
+ return createWPULikeQueries(fetcher);
2134
+ }
2135
+
2136
+ // src/integrations/wpGraphQL/client/types.ts
2137
+ var WPGraphQLError = class extends Error {
2138
+ constructor(code, status, endpoint, message, gqlErrors) {
2139
+ super(message);
2140
+ __publicField(this, "code", code);
2141
+ __publicField(this, "status", status);
2142
+ __publicField(this, "endpoint", endpoint);
2143
+ __publicField(this, "gqlErrors", gqlErrors);
2144
+ this.name = "WPGraphQLError";
2145
+ }
2146
+ };
2147
+
2148
+ // src/integrations/wpGraphQL/client/fetcher.ts
2149
+ var USER_AGENT3 = "NextWordpress WPGraphQL Client";
2150
+ function createWPGraphQLFetcher(config) {
2151
+ const url = `${resolveBaseUrl(config)}/graphql`;
2152
+ const cacheTTL = config.cacheTTL ?? 300;
2153
+ async function gqlFetch(document, variables, tags = ["wpgraphql"]) {
2154
+ const response = await fetch(url, {
2155
+ method: "POST",
2156
+ headers: {
2157
+ "Content-Type": "application/json",
2158
+ "User-Agent": USER_AGENT3
2159
+ },
2160
+ body: JSON.stringify({ query: document, variables }),
2161
+ next: { tags, revalidate: cacheTTL }
2162
+ });
2163
+ if (!response.ok) {
2164
+ throw new WPGraphQLError(
2165
+ ErrorCode.GQL_REQUEST_FAILED,
2166
+ response.status,
2167
+ url,
2168
+ resolveMessage(ErrorCode.GQL_REQUEST_FAILED, config.errorMessages)
2169
+ );
2170
+ }
2171
+ const parsed = await response.json();
2172
+ if (parsed.errors && parsed.errors.length > 0) {
2173
+ throw new WPGraphQLError(
2174
+ ErrorCode.GQL_ERRORS_IN_RESPONSE,
2175
+ 200,
2176
+ url,
2177
+ resolveMessage(ErrorCode.GQL_ERRORS_IN_RESPONSE, config.errorMessages),
2178
+ parsed.errors
2179
+ );
2180
+ }
2181
+ if (parsed.data === void 0) {
2182
+ throw new WPGraphQLError(
2183
+ ErrorCode.GQL_NO_DATA,
2184
+ 200,
2185
+ url,
2186
+ resolveMessage(ErrorCode.GQL_NO_DATA, config.errorMessages)
2187
+ );
2188
+ }
2189
+ return parsed.data;
2190
+ }
2191
+ async function gqlFetchGraceful(document, fallback, variables, tags = ["wpgraphql"]) {
2192
+ try {
2193
+ return await gqlFetch(document, variables, tags);
2194
+ } catch {
2195
+ console.warn(`WPGraphQL fetch failed for query`);
2196
+ return fallback;
2197
+ }
2198
+ }
2199
+ async function gqlMutate(document, variables, authToken) {
2200
+ const headers = {
2201
+ "Content-Type": "application/json",
2202
+ "User-Agent": USER_AGENT3
2203
+ };
2204
+ if (authToken) {
2205
+ headers["Authorization"] = authToken;
2206
+ }
2207
+ const response = await fetch(url, {
2208
+ method: "POST",
2209
+ headers,
2210
+ body: JSON.stringify({ query: document, variables }),
2211
+ cache: "no-store"
2212
+ });
2213
+ if (!response.ok) {
2214
+ throw new WPGraphQLError(
2215
+ ErrorCode.GQL_REQUEST_FAILED,
2216
+ response.status,
2217
+ url,
2218
+ resolveMessage(ErrorCode.GQL_REQUEST_FAILED, config.errorMessages)
2219
+ );
2220
+ }
2221
+ const parsed = await response.json();
2222
+ if (parsed.errors && parsed.errors.length > 0) {
2223
+ throw new WPGraphQLError(
2224
+ ErrorCode.GQL_ERRORS_IN_RESPONSE,
2225
+ 200,
2226
+ url,
2227
+ resolveMessage(ErrorCode.GQL_ERRORS_IN_RESPONSE, config.errorMessages),
2228
+ parsed.errors
2229
+ );
2230
+ }
2231
+ if (parsed.data === void 0) {
2232
+ throw new WPGraphQLError(
2233
+ ErrorCode.GQL_NO_DATA,
2234
+ 200,
2235
+ url,
2236
+ resolveMessage(ErrorCode.GQL_NO_DATA, config.errorMessages)
2237
+ );
2238
+ }
2239
+ return parsed.data;
2240
+ }
2241
+ return { gqlFetch, gqlFetchGraceful, gqlMutate };
2242
+ }
2243
+
2244
+ // src/integrations/wpGraphQL/core/posts/queries.ts
2245
+ var DEFAULT_FIRST = 10;
2246
+ var BATCH_FIRST = 100;
2247
+ var POST_FIELDS = `
2248
+ id
2249
+ databaseId
2250
+ slug
2251
+ title
2252
+ excerpt
2253
+ date
2254
+ modified
2255
+ status
2256
+ uri
2257
+ author {
2258
+ node {
2259
+ databaseId
2260
+ name
2261
+ slug
2262
+ avatar { url }
2263
+ }
2264
+ }
2265
+ featuredImage {
2266
+ node {
2267
+ sourceUrl
2268
+ altText
2269
+ mediaDetails { width height }
2270
+ }
2271
+ }
2272
+ categories {
2273
+ nodes { databaseId name slug }
2274
+ }
2275
+ tags {
2276
+ nodes { databaseId name slug }
2277
+ }
2278
+ `;
2279
+ var POST_FIELDS_WITH_CONTENT = `
2280
+ ${POST_FIELDS}
2281
+ content
2282
+ `;
2283
+ var GQL_GET_POSTS = `
2284
+ query GetPosts($first: Int, $after: String, $where: RootQueryToPostConnectionWhereArgs) {
2285
+ posts(first: $first, after: $after, where: $where) {
2286
+ nodes { ${POST_FIELDS} }
2287
+ pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
2288
+ }
2289
+ }
2290
+ `;
2291
+ var GQL_GET_POST_BY_SLUG = `
2292
+ query GetPostBySlug($slug: ID!) {
2293
+ post(id: $slug, idType: SLUG) { ${POST_FIELDS_WITH_CONTENT} }
2294
+ }
2295
+ `;
2296
+ var GQL_GET_POST_BY_DATABASE_ID = `
2297
+ query GetPostByDatabaseId($id: ID!) {
2298
+ post(id: $id, idType: DATABASE_ID) { ${POST_FIELDS_WITH_CONTENT} }
2299
+ }
2300
+ `;
2301
+ var GQL_GET_ALL_POST_SLUGS = `
2302
+ query GetAllPostSlugs($first: Int, $after: String) {
2303
+ posts(first: $first, after: $after) {
2304
+ nodes { slug }
2305
+ pageInfo { hasNextPage endCursor }
2306
+ }
2307
+ }
2308
+ `;
2309
+ var GQL_GET_ALL_POSTS_FOR_SITEMAP = `
2310
+ query GetAllPostsForSitemap($first: Int, $after: String) {
2311
+ posts(first: $first, after: $after) {
2312
+ nodes { slug modified }
2313
+ pageInfo { hasNextPage endCursor }
2314
+ }
2315
+ }
2316
+ `;
2317
+ function createPostsQueries2(fetcher) {
2318
+ const { gqlFetch, gqlFetchGraceful } = fetcher;
2319
+ async function getPosts(first = DEFAULT_FIRST, after, filter) {
2320
+ const where = {};
2321
+ if (filter?.authorName) where["authorName"] = filter.authorName;
2322
+ if (filter?.categoryName) where["categoryName"] = filter.categoryName;
2323
+ if (filter?.tag) where["tag"] = filter.tag;
2324
+ if (filter?.search) where["search"] = filter.search;
2325
+ if (filter?.status) where["status"] = filter.status;
2326
+ const data = await gqlFetchGraceful(
2327
+ GQL_GET_POSTS,
2328
+ { posts: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
2329
+ { first, after, where: Object.keys(where).length > 0 ? where : void 0 },
2330
+ ["wpgraphql", "gql-posts"]
2331
+ );
2332
+ return data.posts;
2333
+ }
2334
+ async function getPostBySlug(slug) {
2335
+ const data = await gqlFetchGraceful(
2336
+ GQL_GET_POST_BY_SLUG,
2337
+ { post: null },
2338
+ { slug },
2339
+ ["wpgraphql", "gql-posts", `gql-post-${slug}`]
2340
+ );
2341
+ return data.post;
2342
+ }
2343
+ async function getPostByDatabaseId(id) {
2344
+ const data = await gqlFetchGraceful(
2345
+ GQL_GET_POST_BY_DATABASE_ID,
2346
+ { post: null },
2347
+ { id: String(id) },
2348
+ ["wpgraphql", "gql-posts", `gql-post-id-${id}`]
2349
+ );
2350
+ return data.post;
2351
+ }
2352
+ async function getRecentPosts(first = DEFAULT_FIRST) {
2353
+ const connection = await getPosts(first);
2354
+ return connection.nodes;
2355
+ }
2356
+ async function getAllPostSlugs() {
2357
+ try {
2358
+ const all = [];
2359
+ let after = void 0;
2360
+ let hasNextPage = true;
2361
+ while (hasNextPage) {
2362
+ const data = await gqlFetch(GQL_GET_ALL_POST_SLUGS, { first: BATCH_FIRST, after }, ["wpgraphql"]);
2363
+ all.push(...data.posts.nodes);
2364
+ hasNextPage = data.posts.pageInfo.hasNextPage;
2365
+ after = data.posts.pageInfo.endCursor;
2366
+ }
2367
+ return all;
2368
+ } catch {
2369
+ console.warn("WPGraphQL unavailable, skipping static generation for posts");
2370
+ return [];
2371
+ }
2372
+ }
2373
+ async function getAllPostsForSitemap() {
2374
+ try {
2375
+ const all = [];
2376
+ let after = void 0;
2377
+ let hasNextPage = true;
2378
+ while (hasNextPage) {
2379
+ const data = await gqlFetch(
2380
+ GQL_GET_ALL_POSTS_FOR_SITEMAP,
2381
+ { first: BATCH_FIRST, after },
2382
+ ["wpgraphql"]
2383
+ );
2384
+ all.push(...data.posts.nodes);
2385
+ hasNextPage = data.posts.pageInfo.hasNextPage;
2386
+ after = data.posts.pageInfo.endCursor;
2387
+ }
2388
+ return all;
2389
+ } catch {
2390
+ console.warn("WPGraphQL unavailable, skipping sitemap generation");
2391
+ return [];
2392
+ }
2393
+ }
2394
+ return {
2395
+ getPosts,
2396
+ getPostBySlug,
2397
+ getPostByDatabaseId,
2398
+ getRecentPosts,
2399
+ getAllPostSlugs,
2400
+ getAllPostsForSitemap
2401
+ };
2402
+ }
2403
+
2404
+ // src/integrations/wpGraphQL/core/pages/queries.ts
2405
+ var DEFAULT_FIRST2 = 10;
2406
+ var BATCH_FIRST2 = 100;
2407
+ var PAGE_FIELDS = `
2408
+ id
2409
+ databaseId
2410
+ slug
2411
+ title
2412
+ content
2413
+ date
2414
+ modified
2415
+ status
2416
+ uri
2417
+ featuredImage {
2418
+ node {
2419
+ sourceUrl
2420
+ altText
2421
+ mediaDetails { width height }
2422
+ }
2423
+ }
2424
+ `;
2425
+ var GQL_GET_PAGES = `
2426
+ query GetPages($first: Int, $after: String) {
2427
+ pages(first: $first, after: $after) {
2428
+ nodes { ${PAGE_FIELDS} }
2429
+ pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
2430
+ }
2431
+ }
2432
+ `;
2433
+ var GQL_GET_PAGE_BY_SLUG = `
2434
+ query GetPageBySlug($uri: ID!) {
2435
+ page(id: $uri, idType: URI) { ${PAGE_FIELDS} }
2436
+ }
2437
+ `;
2438
+ var GQL_GET_PAGE_BY_URI = `
2439
+ query GetPageByUri($uri: ID!) {
2440
+ page(id: $uri, idType: URI) { ${PAGE_FIELDS} }
2441
+ }
2442
+ `;
2443
+ var GQL_GET_ALL_PAGE_URIS = `
2444
+ query GetAllPageUris($first: Int, $after: String) {
2445
+ pages(first: $first, after: $after) {
2446
+ nodes { uri }
2447
+ pageInfo { hasNextPage endCursor }
2448
+ }
2449
+ }
2450
+ `;
2451
+ function createPagesQueries2(fetcher) {
2452
+ const { gqlFetch, gqlFetchGraceful } = fetcher;
2453
+ async function getPages(first = DEFAULT_FIRST2, after) {
2454
+ const data = await gqlFetchGraceful(
2455
+ GQL_GET_PAGES,
2456
+ { pages: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
2457
+ { first, after },
2458
+ ["wpgraphql", "gql-pages"]
2459
+ );
2460
+ return data.pages;
2461
+ }
2462
+ async function getPageBySlug(slug) {
2463
+ const data = await gqlFetchGraceful(
2464
+ GQL_GET_PAGE_BY_SLUG,
2465
+ { page: null },
2466
+ { uri: `/${slug}/` },
2467
+ ["wpgraphql", "gql-pages", `gql-page-${slug}`]
2468
+ );
2469
+ return data.page;
2470
+ }
2471
+ async function getPageByUri(uri) {
2472
+ const data = await gqlFetchGraceful(
2473
+ GQL_GET_PAGE_BY_URI,
2474
+ { page: null },
2475
+ { uri },
2476
+ ["wpgraphql", "gql-pages", `gql-page-uri-${uri.replace(/\//g, "-")}`]
2477
+ );
2478
+ return data.page;
2479
+ }
2480
+ async function getAllPageUris() {
2481
+ try {
2482
+ const all = [];
2483
+ let after = void 0;
2484
+ let hasNextPage = true;
2485
+ while (hasNextPage) {
2486
+ const data = await gqlFetch(GQL_GET_ALL_PAGE_URIS, { first: BATCH_FIRST2, after }, ["wpgraphql"]);
2487
+ all.push(...data.pages.nodes);
2488
+ hasNextPage = data.pages.pageInfo.hasNextPage;
2489
+ after = data.pages.pageInfo.endCursor;
2490
+ }
2491
+ return all;
2492
+ } catch {
2493
+ console.warn("WPGraphQL unavailable, skipping static generation for pages");
2494
+ return [];
2495
+ }
2496
+ }
2497
+ return { getPages, getPageBySlug, getPageByUri, getAllPageUris };
2498
+ }
2499
+
2500
+ // src/integrations/wpGraphQL/core/categories/queries.ts
2501
+ var DEFAULT_FIRST3 = 100;
2502
+ var CATEGORY_FIELDS = `
2503
+ id
2504
+ databaseId
2505
+ name
2506
+ slug
2507
+ description
2508
+ count
2509
+ uri
2510
+ parent {
2511
+ node { databaseId name slug }
2512
+ }
2513
+ `;
2514
+ var GQL_GET_CATEGORIES = `
2515
+ query GetCategories($first: Int, $after: String) {
2516
+ categories(first: $first, after: $after) {
2517
+ nodes { ${CATEGORY_FIELDS} }
2518
+ pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
2519
+ }
2520
+ }
2521
+ `;
2522
+ var GQL_GET_CATEGORY_BY_SLUG = `
2523
+ query GetCategoryBySlug($slug: ID!) {
2524
+ category(id: $slug, idType: SLUG) { ${CATEGORY_FIELDS} }
2525
+ }
2526
+ `;
2527
+ var GQL_GET_CATEGORY_BY_DATABASE_ID = `
2528
+ query GetCategoryByDatabaseId($id: ID!) {
2529
+ category(id: $id, idType: DATABASE_ID) { ${CATEGORY_FIELDS} }
2530
+ }
2531
+ `;
2532
+ function createCategoriesQueries3(fetcher) {
2533
+ const { gqlFetchGraceful } = fetcher;
2534
+ async function getCategories(first = DEFAULT_FIRST3, after) {
2535
+ const data = await gqlFetchGraceful(
2536
+ GQL_GET_CATEGORIES,
2537
+ { categories: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
2538
+ { first, after },
2539
+ ["wpgraphql", "gql-categories"]
2540
+ );
2541
+ return data.categories;
2542
+ }
2543
+ async function getCategoryBySlug(slug) {
2544
+ const data = await gqlFetchGraceful(
2545
+ GQL_GET_CATEGORY_BY_SLUG,
2546
+ { category: null },
2547
+ { slug },
2548
+ ["wpgraphql", "gql-categories", `gql-category-${slug}`]
2549
+ );
2550
+ return data.category;
2551
+ }
2552
+ async function getCategoryByDatabaseId(id) {
2553
+ const data = await gqlFetchGraceful(
2554
+ GQL_GET_CATEGORY_BY_DATABASE_ID,
2555
+ { category: null },
2556
+ { id: String(id) },
2557
+ ["wpgraphql", "gql-categories", `gql-category-id-${id}`]
2558
+ );
2559
+ return data.category;
2560
+ }
2561
+ return { getCategories, getCategoryBySlug, getCategoryByDatabaseId };
2562
+ }
2563
+
2564
+ // src/integrations/wpGraphQL/core/tags/queries.ts
2565
+ var DEFAULT_FIRST4 = 100;
2566
+ var TAG_FIELDS = `
2567
+ id
2568
+ databaseId
2569
+ name
2570
+ slug
2571
+ description
2572
+ count
2573
+ uri
2574
+ `;
2575
+ var GQL_GET_TAGS = `
2576
+ query GetTags($first: Int, $after: String) {
2577
+ tags(first: $first, after: $after) {
2578
+ nodes { ${TAG_FIELDS} }
2579
+ pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
2580
+ }
2581
+ }
2582
+ `;
2583
+ var GQL_GET_TAG_BY_SLUG = `
2584
+ query GetTagBySlug($slug: ID!) {
2585
+ tag(id: $slug, idType: SLUG) { ${TAG_FIELDS} }
2586
+ }
2587
+ `;
2588
+ function createTagsQueries3(fetcher) {
2589
+ const { gqlFetchGraceful } = fetcher;
2590
+ async function getTags(first = DEFAULT_FIRST4, after) {
2591
+ const data = await gqlFetchGraceful(
2592
+ GQL_GET_TAGS,
2593
+ { tags: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
2594
+ { first, after },
2595
+ ["wpgraphql", "gql-tags"]
2596
+ );
2597
+ return data.tags;
2598
+ }
2599
+ async function getTagBySlug(slug) {
2600
+ const data = await gqlFetchGraceful(
2601
+ GQL_GET_TAG_BY_SLUG,
2602
+ { tag: null },
2603
+ { slug },
2604
+ ["wpgraphql", "gql-tags", `gql-tag-${slug}`]
2605
+ );
2606
+ return data.tag;
2607
+ }
2608
+ return { getTags, getTagBySlug };
2609
+ }
2610
+
2611
+ // src/integrations/wpGraphQL/core/authors/queries.ts
2612
+ var DEFAULT_FIRST5 = 100;
2613
+ var AUTHOR_FIELDS = `
2614
+ id
2615
+ databaseId
2616
+ name
2617
+ slug
2618
+ description
2619
+ email
2620
+ uri
2621
+ avatar { url width height }
2622
+ `;
2623
+ var GQL_GET_AUTHORS = `
2624
+ query GetAuthors($first: Int, $after: String) {
2625
+ users(first: $first, after: $after) {
2626
+ nodes { ${AUTHOR_FIELDS} }
2627
+ pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
2628
+ }
2629
+ }
2630
+ `;
2631
+ var GQL_GET_AUTHOR_BY_SLUG = `
2632
+ query GetAuthorBySlug($slug: String!) {
2633
+ users(where: { login: $slug }) {
2634
+ nodes { ${AUTHOR_FIELDS} }
2635
+ }
2636
+ }
2637
+ `;
2638
+ function createAuthorsQueries2(fetcher) {
2639
+ const { gqlFetchGraceful } = fetcher;
2640
+ async function getAuthors(first = DEFAULT_FIRST5, after) {
2641
+ const data = await gqlFetchGraceful(
2642
+ GQL_GET_AUTHORS,
2643
+ { users: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
2644
+ { first, after },
2645
+ ["wpgraphql", "gql-authors"]
2646
+ );
2647
+ return data.users;
2648
+ }
2649
+ async function getAuthorBySlug(slug) {
2650
+ const data = await gqlFetchGraceful(
2651
+ GQL_GET_AUTHOR_BY_SLUG,
2652
+ { users: { nodes: [] } },
2653
+ { slug },
2654
+ ["wpgraphql", "gql-authors", `gql-author-${slug}`]
2655
+ );
2656
+ return data.users.nodes[0] ?? null;
2657
+ }
2658
+ return { getAuthors, getAuthorBySlug };
2659
+ }
2660
+
2661
+ // src/integrations/wpGraphQL/core/menus/queries.ts
2662
+ var MENU_ITEM_FIELDS = `
2663
+ id
2664
+ databaseId
2665
+ label
2666
+ url
2667
+ parentId
2668
+ order
2669
+ target
2670
+ cssClasses
2671
+ description
2672
+ connectedNode {
2673
+ node {
2674
+ __typename
2675
+ ... on Page { id databaseId slug }
2676
+ ... on Post { id databaseId slug }
2677
+ ... on Category { id databaseId slug }
2678
+ ... on Tag { id databaseId slug }
2679
+ }
2680
+ }
2681
+ `;
2682
+ var MENU_FIELDS = `
2683
+ id
2684
+ databaseId
2685
+ name
2686
+ slug
2687
+ locations
2688
+ menuItems(first: 100) {
2689
+ nodes { ${MENU_ITEM_FIELDS} }
2690
+ }
2691
+ `;
2692
+ var GQL_GET_MENUS = `
2693
+ query GetMenus {
2694
+ menus(first: 100) {
2695
+ nodes { ${MENU_FIELDS} }
2696
+ }
2697
+ }
2698
+ `;
2699
+ var GQL_GET_MENU_BY_ID = `
2700
+ query GetMenuById($id: ID!) {
2701
+ menu(id: $id, idType: DATABASE_ID) { ${MENU_FIELDS} }
2702
+ }
2703
+ `;
2704
+ var GQL_GET_MENU_BY_SLUG = `
2705
+ query GetMenuBySlug($id: ID!) {
2706
+ menu(id: $id, idType: SLUG) { ${MENU_FIELDS} }
2707
+ }
2708
+ `;
2709
+ var GQL_GET_MENUS_BY_LOCATION = `
2710
+ query GetMenusByLocation($location: MenuLocationEnum!) {
2711
+ menus(where: { location: $location }, first: 1) {
2712
+ nodes { ${MENU_FIELDS} }
2713
+ }
2714
+ }
2715
+ `;
2716
+ function createMenusQueries2(fetcher) {
2717
+ const { gqlFetch, gqlFetchGraceful } = fetcher;
2718
+ async function getMenus() {
2719
+ const data = await gqlFetchGraceful(
2720
+ GQL_GET_MENUS,
2721
+ { menus: { nodes: [] } },
2722
+ void 0,
2723
+ ["wpgraphql", "gql-menus"]
2724
+ );
2725
+ return data.menus.nodes;
2726
+ }
2727
+ async function getMenuById(id) {
2728
+ const data = await gqlFetchGraceful(
2729
+ GQL_GET_MENU_BY_ID,
2730
+ { menu: null },
2731
+ { id: String(id) },
2732
+ ["wpgraphql", "gql-menus", `gql-menu-${id}`]
2733
+ );
2734
+ return data.menu;
2735
+ }
2736
+ async function getMenuBySlug(slug) {
2737
+ const data = await gqlFetchGraceful(
2738
+ GQL_GET_MENU_BY_SLUG,
2739
+ { menu: null },
2740
+ { id: slug },
2741
+ ["wpgraphql", "gql-menus", `gql-menu-${slug}`]
2742
+ );
2743
+ return data.menu;
2744
+ }
2745
+ async function getMenuByLocation(location) {
2746
+ const data = await gqlFetch(
2747
+ GQL_GET_MENUS_BY_LOCATION,
2748
+ { location: location.toUpperCase() },
2749
+ ["wpgraphql", "gql-menus", `gql-menu-location-${location}`]
2750
+ );
2751
+ return data.menus.nodes[0] ?? null;
2752
+ }
2753
+ async function getMenuItems(menuSlug) {
2754
+ const menu = await getMenuBySlug(menuSlug);
2755
+ return menu?.menuItems?.nodes ?? [];
2756
+ }
2757
+ return {
2758
+ getMenus,
2759
+ getMenuById,
2760
+ getMenuBySlug,
2761
+ getMenuByLocation,
2762
+ getMenuItems
2763
+ };
2764
+ }
2765
+
2766
+ // src/integrations/wpGraphQL/core/comments/queries.ts
2767
+ var COMMENT_AUTHOR_FIELDS = `
2768
+ name
2769
+ url
2770
+ avatar { url width height }
2771
+ `;
2772
+ var COMMENT_FIELDS = `
2773
+ id
2774
+ databaseId
2775
+ content(format: RENDERED)
2776
+ date
2777
+ parentId
2778
+ status
2779
+ author { node { ${COMMENT_AUTHOR_FIELDS} } }
2780
+ `;
2781
+ var GQL_GET_COMMENTS_BY_POST = `
2782
+ query GetCommentsByPost($contentId: ID!, $first: Int, $after: String) {
2783
+ comments(
2784
+ first: $first
2785
+ after: $after
2786
+ where: { contentId: $contentId, status: "approve", parent: 0 }
2787
+ ) {
2788
+ nodes {
2789
+ ${COMMENT_FIELDS}
2790
+ replies(first: 100) {
2791
+ nodes { ${COMMENT_FIELDS} }
2792
+ }
2793
+ }
2794
+ pageInfo { hasNextPage endCursor }
2795
+ }
2796
+ }
2797
+ `;
2798
+ var GQL_GET_ALL_COMMENTS_BY_POST = `
2799
+ query GetAllCommentsByPost($contentId: ID!) {
2800
+ comments(
2801
+ first: 100
2802
+ where: { contentId: $contentId, status: "approve" }
2803
+ ) {
2804
+ nodes { ${COMMENT_FIELDS} }
2805
+ }
2806
+ }
2807
+ `;
2808
+ var GQL_GET_COMMENT_BY_ID = `
2809
+ query GetCommentById($id: ID!) {
2810
+ comment(id: $id, idType: DATABASE_ID) { ${COMMENT_FIELDS} }
2811
+ }
2812
+ `;
2813
+ function createCommentsQueries2(fetcher) {
2814
+ const { gqlFetchGraceful } = fetcher;
2815
+ async function getCommentsByPostId(postId, first = 10, after) {
2816
+ const data = await gqlFetchGraceful(
2817
+ GQL_GET_COMMENTS_BY_POST,
2818
+ { comments: { nodes: [], pageInfo: { hasNextPage: false } } },
2819
+ { contentId: String(postId), first, after },
2820
+ ["wpgraphql", "gql-comments", `gql-comments-post-${postId}`]
2821
+ );
2822
+ return data.comments;
2823
+ }
2824
+ async function getAllCommentsByPostId(postId) {
2825
+ const data = await gqlFetchGraceful(
2826
+ GQL_GET_ALL_COMMENTS_BY_POST,
2827
+ { comments: { nodes: [] } },
2828
+ { contentId: String(postId) },
2829
+ ["wpgraphql", "gql-comments", `gql-comments-post-${postId}`]
2830
+ );
2831
+ return data.comments.nodes;
2832
+ }
2833
+ async function getCommentById(id) {
2834
+ const data = await gqlFetchGraceful(
2835
+ GQL_GET_COMMENT_BY_ID,
2836
+ { comment: null },
2837
+ { id: String(id) },
2838
+ ["wpgraphql", "gql-comments", `gql-comment-${id}`]
2839
+ );
2840
+ return data.comment;
2841
+ }
2842
+ return {
2843
+ getCommentsByPostId,
2844
+ getAllCommentsByPostId,
2845
+ getCommentById
2846
+ };
2847
+ }
2848
+
2849
+ // src/integrations/wpGraphQL/core/media/queries.ts
2850
+ var DEFAULT_FIRST6 = 10;
2851
+ var MEDIA_FIELDS = `
2852
+ id
2853
+ databaseId
2854
+ slug
2855
+ title
2856
+ date
2857
+ sourceUrl
2858
+ altText
2859
+ caption
2860
+ description
2861
+ mediaType
2862
+ mimeType
2863
+ uri
2864
+ mediaDetails {
2865
+ width
2866
+ height
2867
+ file
2868
+ sizes { name width height mimeType sourceUrl }
2869
+ }
2870
+ `;
2871
+ var GQL_GET_MEDIA_ITEMS = `
2872
+ query GetMediaItems($first: Int, $after: String) {
2873
+ mediaItems(first: $first, after: $after) {
2874
+ nodes { ${MEDIA_FIELDS} }
2875
+ pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
2876
+ }
2877
+ }
2878
+ `;
2879
+ var GQL_GET_MEDIA_ITEM_BY_ID = `
2880
+ query GetMediaItemById($id: ID!) {
2881
+ mediaItem(id: $id, idType: DATABASE_ID) { ${MEDIA_FIELDS} }
2882
+ }
2883
+ `;
2884
+ var GQL_GET_MEDIA_ITEM_BY_SLUG = `
2885
+ query GetMediaItemBySlug($id: ID!) {
2886
+ mediaItem(id: $id, idType: SLUG) { ${MEDIA_FIELDS} }
2887
+ }
2888
+ `;
2889
+ function createMediaQueries2(fetcher) {
2890
+ const { gqlFetchGraceful } = fetcher;
2891
+ async function getMediaItems(first = DEFAULT_FIRST6, after) {
2892
+ const data = await gqlFetchGraceful(
2893
+ GQL_GET_MEDIA_ITEMS,
2894
+ { mediaItems: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
2895
+ { first, after },
2896
+ ["wpgraphql", "gql-media"]
2897
+ );
2898
+ return data.mediaItems;
2899
+ }
2900
+ async function getMediaItemById(id) {
2901
+ const data = await gqlFetchGraceful(
2902
+ GQL_GET_MEDIA_ITEM_BY_ID,
2903
+ { mediaItem: null },
2904
+ { id: String(id) },
2905
+ ["wpgraphql", "gql-media", `gql-media-${id}`]
2906
+ );
2907
+ return data.mediaItem;
2908
+ }
2909
+ async function getMediaItemBySlug(slug) {
2910
+ const data = await gqlFetchGraceful(
2911
+ GQL_GET_MEDIA_ITEM_BY_SLUG,
2912
+ { mediaItem: null },
2913
+ { id: slug },
2914
+ ["wpgraphql", "gql-media", `gql-media-${slug}`]
2915
+ );
2916
+ return data.mediaItem;
2917
+ }
2918
+ return { getMediaItems, getMediaItemById, getMediaItemBySlug };
2919
+ }
2920
+
2921
+ // src/integrations/wpGraphQL/core/mutations/posts/mutations.ts
2922
+ var MUTATED_POST_FIELDS = `
2923
+ id
2924
+ databaseId
2925
+ slug
2926
+ title
2927
+ status
2928
+ `;
2929
+ var GQL_CREATE_POST = `
2930
+ mutation CreatePost($input: CreatePostInput!) {
2931
+ createPost(input: $input) {
2932
+ post { ${MUTATED_POST_FIELDS} }
2933
+ }
2934
+ }
2935
+ `;
2936
+ var GQL_UPDATE_POST = `
2937
+ mutation UpdatePost($input: UpdatePostInput!) {
2938
+ updatePost(input: $input) {
2939
+ post { ${MUTATED_POST_FIELDS} }
2940
+ }
2941
+ }
2942
+ `;
2943
+ var GQL_DELETE_POST = `
2944
+ mutation DeletePost($input: DeletePostInput!) {
2945
+ deletePost(input: $input) {
2946
+ deletedId
2947
+ post { ${MUTATED_POST_FIELDS} }
2948
+ }
2949
+ }
2950
+ `;
2951
+ function createPostsMutations2(fetcher) {
2952
+ const { gqlMutate } = fetcher;
2953
+ async function createPost(input, authToken) {
2954
+ const data = await gqlMutate(
2955
+ GQL_CREATE_POST,
2956
+ { input },
2957
+ authToken
2958
+ );
2959
+ return data.createPost.post;
2960
+ }
2961
+ async function updatePost(input, authToken) {
2962
+ const data = await gqlMutate(
2963
+ GQL_UPDATE_POST,
2964
+ { input },
2965
+ authToken
2966
+ );
2967
+ return data.updatePost.post;
2968
+ }
2969
+ async function deletePost(id, authToken, forceDelete = false) {
2970
+ const data = await gqlMutate(
2971
+ GQL_DELETE_POST,
2972
+ { input: { id, forceDelete } },
2973
+ authToken
2974
+ );
2975
+ return data.deletePost;
2976
+ }
2977
+ return { createPost, updatePost, deletePost };
2978
+ }
2979
+
2980
+ // src/integrations/wpGraphQL/core/mutations/comments/mutations.ts
2981
+ var MUTATED_COMMENT_FIELDS = `
2982
+ id
2983
+ databaseId
2984
+ content(format: RENDERED)
2985
+ date
2986
+ status
2987
+ parentId
2988
+ author { node { name url } }
2989
+ `;
2990
+ var GQL_CREATE_COMMENT = `
2991
+ mutation CreateComment($input: CreateCommentInput!) {
2992
+ createComment(input: $input) {
2993
+ success
2994
+ comment { ${MUTATED_COMMENT_FIELDS} }
2995
+ }
2996
+ }
2997
+ `;
2998
+ var GQL_UPDATE_COMMENT = `
2999
+ mutation UpdateComment($input: UpdateCommentInput!) {
3000
+ updateComment(input: $input) {
3001
+ comment { ${MUTATED_COMMENT_FIELDS} }
3002
+ }
3003
+ }
3004
+ `;
3005
+ var GQL_DELETE_COMMENT = `
3006
+ mutation DeleteComment($input: DeleteCommentInput!) {
3007
+ deleteComment(input: $input) {
3008
+ deletedId
3009
+ comment { ${MUTATED_COMMENT_FIELDS} }
3010
+ }
3011
+ }
3012
+ `;
3013
+ function createCommentsMutations2(fetcher) {
3014
+ const { gqlMutate } = fetcher;
3015
+ async function createComment(input, authToken) {
3016
+ const gqlInput = {
3017
+ commentOn: input.postId,
3018
+ content: input.content
3019
+ };
3020
+ if (input.authorName) gqlInput["author"] = input.authorName;
3021
+ if (input.authorEmail) gqlInput["authorEmail"] = input.authorEmail;
3022
+ if (input.authorUrl) gqlInput["authorUrl"] = input.authorUrl;
3023
+ if (input.parentId) gqlInput["parent"] = input.parentId;
3024
+ const data = await gqlMutate(
3025
+ GQL_CREATE_COMMENT,
3026
+ { input: gqlInput },
3027
+ authToken
3028
+ );
3029
+ return data.createComment;
3030
+ }
3031
+ async function updateComment(input, authToken) {
3032
+ const data = await gqlMutate(
3033
+ GQL_UPDATE_COMMENT,
3034
+ { input },
3035
+ authToken
3036
+ );
3037
+ return data.updateComment.comment;
3038
+ }
3039
+ async function deleteComment(id, authToken, forceDelete = false) {
3040
+ const data = await gqlMutate(
3041
+ GQL_DELETE_COMMENT,
3042
+ { input: { id, forceDelete } },
3043
+ authToken
3044
+ );
3045
+ return data.deleteComment;
3046
+ }
3047
+ return { createComment, updateComment, deleteComment };
3048
+ }
3049
+
3050
+ // src/integrations/wpGraphQL/core/mutations/pages/mutations.ts
3051
+ var MUTATED_PAGE_FIELDS = `
3052
+ id
3053
+ databaseId
3054
+ slug
3055
+ title
3056
+ status
3057
+ uri
3058
+ `;
3059
+ var GQL_CREATE_PAGE = `
3060
+ mutation CreatePage($input: CreatePageInput!) {
3061
+ createPage(input: $input) {
3062
+ page { ${MUTATED_PAGE_FIELDS} }
3063
+ }
3064
+ }
3065
+ `;
3066
+ var GQL_UPDATE_PAGE = `
3067
+ mutation UpdatePage($input: UpdatePageInput!) {
3068
+ updatePage(input: $input) {
3069
+ page { ${MUTATED_PAGE_FIELDS} }
3070
+ }
3071
+ }
3072
+ `;
3073
+ var GQL_DELETE_PAGE = `
3074
+ mutation DeletePage($input: DeletePageInput!) {
3075
+ deletePage(input: $input) {
3076
+ deletedId
3077
+ page { ${MUTATED_PAGE_FIELDS} }
3078
+ }
3079
+ }
3080
+ `;
3081
+ function createPagesMutations2(fetcher) {
3082
+ const { gqlMutate } = fetcher;
3083
+ async function createPage(input, authToken) {
3084
+ const data = await gqlMutate(
3085
+ GQL_CREATE_PAGE,
3086
+ { input },
3087
+ authToken
3088
+ );
3089
+ return data.createPage.page;
3090
+ }
3091
+ async function updatePage(input, authToken) {
3092
+ const data = await gqlMutate(
3093
+ GQL_UPDATE_PAGE,
3094
+ { input },
3095
+ authToken
3096
+ );
3097
+ return data.updatePage.page;
3098
+ }
3099
+ async function deletePage(id, authToken, forceDelete = false) {
3100
+ const data = await gqlMutate(
3101
+ GQL_DELETE_PAGE,
3102
+ { input: { id, forceDelete } },
3103
+ authToken
3104
+ );
3105
+ return data.deletePage;
3106
+ }
3107
+ return { createPage, updatePage, deletePage };
3108
+ }
3109
+
3110
+ // src/integrations/wpGraphQL/core/mutations/categories/mutations.ts
3111
+ var MUTATED_CATEGORY_FIELDS = `
3112
+ id
3113
+ databaseId
3114
+ name
3115
+ slug
3116
+ `;
3117
+ var GQL_CREATE_CATEGORY = `
3118
+ mutation CreateCategory($input: CreateCategoryInput!) {
3119
+ createCategory(input: $input) {
3120
+ category { ${MUTATED_CATEGORY_FIELDS} }
3121
+ }
3122
+ }
3123
+ `;
3124
+ var GQL_UPDATE_CATEGORY = `
3125
+ mutation UpdateCategory($input: UpdateCategoryInput!) {
3126
+ updateCategory(input: $input) {
3127
+ category { ${MUTATED_CATEGORY_FIELDS} }
3128
+ }
3129
+ }
3130
+ `;
3131
+ var GQL_DELETE_CATEGORY = `
3132
+ mutation DeleteCategory($input: DeleteCategoryInput!) {
3133
+ deleteCategory(input: $input) {
3134
+ deletedId
3135
+ category { ${MUTATED_CATEGORY_FIELDS} }
3136
+ }
3137
+ }
3138
+ `;
3139
+ function createCategoriesMutations3(fetcher) {
3140
+ const { gqlMutate } = fetcher;
3141
+ async function createCategory(input, authToken) {
3142
+ const data = await gqlMutate(
3143
+ GQL_CREATE_CATEGORY,
3144
+ { input },
3145
+ authToken
3146
+ );
3147
+ return data.createCategory.category;
3148
+ }
3149
+ async function updateCategory(input, authToken) {
3150
+ const data = await gqlMutate(
3151
+ GQL_UPDATE_CATEGORY,
3152
+ { input },
3153
+ authToken
3154
+ );
3155
+ return data.updateCategory.category;
3156
+ }
3157
+ async function deleteCategory(id, authToken) {
3158
+ const data = await gqlMutate(
3159
+ GQL_DELETE_CATEGORY,
3160
+ { input: { id } },
3161
+ authToken
3162
+ );
3163
+ return data.deleteCategory;
3164
+ }
3165
+ return { createCategory, updateCategory, deleteCategory };
3166
+ }
3167
+
3168
+ // src/integrations/wpGraphQL/core/mutations/tags/mutations.ts
3169
+ var MUTATED_TAG_FIELDS = `
3170
+ id
3171
+ databaseId
3172
+ name
3173
+ slug
3174
+ `;
3175
+ var GQL_CREATE_TAG = `
3176
+ mutation CreateTag($input: CreateTagInput!) {
3177
+ createTag(input: $input) {
3178
+ tag { ${MUTATED_TAG_FIELDS} }
3179
+ }
3180
+ }
3181
+ `;
3182
+ var GQL_UPDATE_TAG = `
3183
+ mutation UpdateTag($input: UpdateTagInput!) {
3184
+ updateTag(input: $input) {
3185
+ tag { ${MUTATED_TAG_FIELDS} }
3186
+ }
3187
+ }
3188
+ `;
3189
+ var GQL_DELETE_TAG = `
3190
+ mutation DeleteTag($input: DeleteTagInput!) {
3191
+ deleteTag(input: $input) {
3192
+ deletedId
3193
+ tag { ${MUTATED_TAG_FIELDS} }
3194
+ }
3195
+ }
3196
+ `;
3197
+ function createTagsMutations3(fetcher) {
3198
+ const { gqlMutate } = fetcher;
3199
+ async function createTag(input, authToken) {
3200
+ const data = await gqlMutate(
3201
+ GQL_CREATE_TAG,
3202
+ { input },
3203
+ authToken
3204
+ );
3205
+ return data.createTag.tag;
3206
+ }
3207
+ async function updateTag(input, authToken) {
3208
+ const data = await gqlMutate(
3209
+ GQL_UPDATE_TAG,
3210
+ { input },
3211
+ authToken
3212
+ );
3213
+ return data.updateTag.tag;
3214
+ }
3215
+ async function deleteTag(id, authToken) {
3216
+ const data = await gqlMutate(
3217
+ GQL_DELETE_TAG,
3218
+ { input: { id } },
3219
+ authToken
3220
+ );
3221
+ return data.deleteTag;
3222
+ }
3223
+ return { createTag, updateTag, deleteTag };
3224
+ }
3225
+
3226
+ // src/integrations/wpGraphQL/core/mutations/authors/mutations.ts
3227
+ var MUTATED_USER_FIELDS = `
3228
+ id
3229
+ databaseId
3230
+ name
3231
+ slug
3232
+ email
3233
+ `;
3234
+ var GQL_REGISTER_USER = `
3235
+ mutation RegisterUser($input: RegisterUserInput!) {
3236
+ registerUser(input: $input) {
3237
+ user { ${MUTATED_USER_FIELDS} }
3238
+ }
3239
+ }
3240
+ `;
3241
+ var GQL_UPDATE_USER = `
3242
+ mutation UpdateUser($input: UpdateUserInput!) {
3243
+ updateUser(input: $input) {
3244
+ user { ${MUTATED_USER_FIELDS} }
3245
+ }
3246
+ }
3247
+ `;
3248
+ var GQL_DELETE_USER = `
3249
+ mutation DeleteUser($input: DeleteUserInput!) {
3250
+ deleteUser(input: $input) {
3251
+ deletedId
3252
+ user { ${MUTATED_USER_FIELDS} }
3253
+ }
3254
+ }
3255
+ `;
3256
+ function createAuthorsMutations2(fetcher) {
3257
+ const { gqlMutate } = fetcher;
3258
+ async function registerUser(input, authToken) {
3259
+ const data = await gqlMutate(
3260
+ GQL_REGISTER_USER,
3261
+ { input },
3262
+ authToken
3263
+ );
3264
+ return data.registerUser.user;
3265
+ }
3266
+ async function updateUser(input, authToken) {
3267
+ const data = await gqlMutate(
3268
+ GQL_UPDATE_USER,
3269
+ { input },
3270
+ authToken
3271
+ );
3272
+ return data.updateUser.user;
3273
+ }
3274
+ async function deleteUser(id, authToken, reassignPosts) {
3275
+ const input = { id };
3276
+ if (reassignPosts) input["reassignId"] = reassignPosts;
3277
+ const data = await gqlMutate(
3278
+ GQL_DELETE_USER,
3279
+ { input },
3280
+ authToken
3281
+ );
3282
+ return data.deleteUser;
3283
+ }
3284
+ return { registerUser, updateUser, deleteUser };
3285
+ }
3286
+
3287
+ // src/integrations/wpGraphQL/core/mutations/media/mutations.ts
3288
+ var MUTATED_MEDIA_FIELDS = `
3289
+ id
3290
+ databaseId
3291
+ slug
3292
+ title
3293
+ sourceUrl
3294
+ altText
3295
+ `;
3296
+ var GQL_CREATE_MEDIA_ITEM = `
3297
+ mutation CreateMediaItem($input: CreateMediaItemInput!) {
3298
+ createMediaItem(input: $input) {
3299
+ mediaItem { ${MUTATED_MEDIA_FIELDS} }
3300
+ }
3301
+ }
3302
+ `;
3303
+ var GQL_UPDATE_MEDIA_ITEM = `
3304
+ mutation UpdateMediaItem($input: UpdateMediaItemInput!) {
3305
+ updateMediaItem(input: $input) {
3306
+ mediaItem { ${MUTATED_MEDIA_FIELDS} }
3307
+ }
3308
+ }
3309
+ `;
3310
+ var GQL_DELETE_MEDIA_ITEM = `
3311
+ mutation DeleteMediaItem($input: DeleteMediaItemInput!) {
3312
+ deleteMediaItem(input: $input) {
3313
+ deletedId
3314
+ mediaItem { ${MUTATED_MEDIA_FIELDS} }
3315
+ }
3316
+ }
3317
+ `;
3318
+ function createMediaMutations2(fetcher) {
3319
+ const { gqlMutate } = fetcher;
3320
+ async function createMediaItem(input, authToken) {
3321
+ const data = await gqlMutate(
3322
+ GQL_CREATE_MEDIA_ITEM,
3323
+ { input },
3324
+ authToken
3325
+ );
3326
+ return data.createMediaItem.mediaItem;
3327
+ }
3328
+ async function updateMediaItem(input, authToken) {
3329
+ const data = await gqlMutate(
3330
+ GQL_UPDATE_MEDIA_ITEM,
3331
+ { input },
3332
+ authToken
3333
+ );
3334
+ return data.updateMediaItem.mediaItem;
3335
+ }
3336
+ async function deleteMediaItem(id, authToken, forceDelete = true) {
3337
+ const data = await gqlMutate(
3338
+ GQL_DELETE_MEDIA_ITEM,
3339
+ { input: { id, forceDelete } },
3340
+ authToken
3341
+ );
3342
+ return data.deleteMediaItem;
3343
+ }
3344
+ return { createMediaItem, updateMediaItem, deleteMediaItem };
3345
+ }
3346
+
3347
+ // src/integrations/wpGraphQL/core/mutations/index.ts
3348
+ function createWPGraphQLMutationsClient(config) {
3349
+ const fetcher = createWPGraphQLFetcher(config);
3350
+ return {
3351
+ ...createPostsMutations2(fetcher),
3352
+ ...createCommentsMutations2(fetcher),
3353
+ ...createPagesMutations2(fetcher),
3354
+ ...createCategoriesMutations3(fetcher),
3355
+ ...createTagsMutations3(fetcher),
3356
+ ...createAuthorsMutations2(fetcher),
3357
+ ...createMediaMutations2(fetcher)
3358
+ };
3359
+ }
3360
+
3361
+ // src/integrations/wpGraphQL/core/index.ts
3362
+ function createWPGraphQLCoreClient(config) {
3363
+ const fetcher = createWPGraphQLFetcher(config);
3364
+ return {
3365
+ ...createPostsQueries2(fetcher),
3366
+ ...createPagesQueries2(fetcher),
3367
+ ...createCategoriesQueries3(fetcher),
3368
+ ...createTagsQueries3(fetcher),
3369
+ ...createAuthorsQueries2(fetcher),
3370
+ ...createMenusQueries2(fetcher),
3371
+ ...createCommentsQueries2(fetcher),
3372
+ ...createMediaQueries2(fetcher)
3373
+ };
3374
+ }
3375
+
3376
+ // src/integrations/wpGraphQL/yoast/queries.ts
3377
+ var SEO_FIELDS = `
3378
+ seo {
3379
+ title
3380
+ metaDesc
3381
+ canonical
3382
+ opengraphTitle
3383
+ opengraphDescription
3384
+ opengraphImage { sourceUrl altText }
3385
+ twitterTitle
3386
+ twitterDescription
3387
+ twitterImage { sourceUrl }
3388
+ schema { raw }
3389
+ }
3390
+ `;
3391
+ var POST_FIELDS_WITH_SEO = `
3392
+ id
3393
+ databaseId
3394
+ slug
3395
+ title
3396
+ content
3397
+ excerpt
3398
+ date
3399
+ modified
3400
+ status
3401
+ uri
3402
+ author {
3403
+ node {
3404
+ databaseId
3405
+ name
3406
+ slug
3407
+ avatar { url }
3408
+ }
3409
+ }
3410
+ featuredImage {
3411
+ node {
3412
+ sourceUrl
3413
+ altText
3414
+ mediaDetails { width height }
3415
+ }
3416
+ }
3417
+ categories {
3418
+ nodes { databaseId name slug }
3419
+ }
3420
+ tags {
3421
+ nodes { databaseId name slug }
3422
+ }
3423
+ ${SEO_FIELDS}
3424
+ `;
3425
+ var PAGE_FIELDS_WITH_SEO = `
3426
+ id
3427
+ databaseId
3428
+ slug
3429
+ title
3430
+ content
3431
+ date
3432
+ modified
3433
+ status
3434
+ uri
3435
+ featuredImage {
3436
+ node {
3437
+ sourceUrl
3438
+ altText
3439
+ mediaDetails { width height }
3440
+ }
3441
+ }
3442
+ ${SEO_FIELDS}
3443
+ `;
3444
+ var GQL_GET_POST_WITH_SEO = `
3445
+ query GetPostWithSEO($slug: ID!) {
3446
+ post(id: $slug, idType: SLUG) { ${POST_FIELDS_WITH_SEO} }
3447
+ }
3448
+ `;
3449
+ var GQL_GET_PAGE_WITH_SEO = `
3450
+ query GetPageWithSEO($slug: ID!) {
3451
+ page(id: $slug, idType: SLUG) { ${PAGE_FIELDS_WITH_SEO} }
3452
+ }
3453
+ `;
3454
+ var GQL_GET_PAGE_WITH_SEO_BY_URI = `
3455
+ query GetPageWithSEOByUri($uri: ID!) {
3456
+ page(id: $uri, idType: URI) { ${PAGE_FIELDS_WITH_SEO} }
3457
+ }
3458
+ `;
3459
+ function createYoastQueries(fetcher) {
3460
+ const { gqlFetchGraceful } = fetcher;
3461
+ async function getPostWithSEO(slug) {
3462
+ const data = await gqlFetchGraceful(
3463
+ GQL_GET_POST_WITH_SEO,
3464
+ { post: null },
3465
+ { slug },
3466
+ ["wpgraphql", "gql-posts", "gql-yoast", `gql-post-${slug}`]
3467
+ );
3468
+ return data.post;
3469
+ }
3470
+ async function getPageWithSEO(slug) {
3471
+ const data = await gqlFetchGraceful(
3472
+ GQL_GET_PAGE_WITH_SEO,
3473
+ { page: null },
3474
+ { slug },
3475
+ ["wpgraphql", "gql-pages", "gql-yoast", `gql-page-${slug}`]
3476
+ );
3477
+ return data.page;
3478
+ }
3479
+ async function getPageWithSEOByUri(uri) {
3480
+ const data = await gqlFetchGraceful(
3481
+ GQL_GET_PAGE_WITH_SEO_BY_URI,
3482
+ { page: null },
3483
+ { uri },
3484
+ ["wpgraphql", "gql-pages", "gql-yoast", `gql-page-uri-${uri.replace(/\//g, "-")}`]
3485
+ );
3486
+ return data.page;
3487
+ }
3488
+ return { getPostWithSEO, getPageWithSEO, getPageWithSEOByUri };
3489
+ }
3490
+
3491
+ // src/integrations/wpGraphQL/acf/helpers.ts
3492
+ var BASE_POST_FIELDS = `
3493
+ id databaseId slug title content excerpt date modified status uri
3494
+ author { node { databaseId name slug avatar { url } } }
3495
+ featuredImage { node { sourceUrl altText mediaDetails { width height } } }
3496
+ categories { nodes { databaseId name slug } }
3497
+ tags { nodes { databaseId name slug } }
3498
+ `;
3499
+ var BASE_PAGE_FIELDS = `
3500
+ id databaseId slug title content date modified status uri
3501
+ featuredImage { node { sourceUrl altText mediaDetails { width height } } }
3502
+ `;
3503
+ function buildACFFragment(fieldGroupName, fields) {
3504
+ return `${fieldGroupName} { ${fields.join(" ")} }`;
3505
+ }
3506
+ function buildPostWithACFQuery(fieldGroupName, fields) {
3507
+ return `
3508
+ query GetPostWithACF($slug: ID!) {
3509
+ post(id: $slug, idType: SLUG) {
3510
+ ${BASE_POST_FIELDS}
3511
+ ${buildACFFragment(fieldGroupName, fields)}
3512
+ }
3513
+ }
3514
+ `;
3515
+ }
3516
+ function buildPageWithACFQuery(fieldGroupName, fields) {
3517
+ return `
3518
+ query GetPageWithACF($slug: ID!) {
3519
+ page(id: $slug, idType: SLUG) {
3520
+ ${BASE_PAGE_FIELDS}
3521
+ ${buildACFFragment(fieldGroupName, fields)}
3522
+ }
3523
+ }
3524
+ `;
3525
+ }
3526
+ function buildPostsWithACFQuery(fieldGroupName, fields) {
3527
+ return `
3528
+ query GetPostsWithACF($first: Int, $after: String) {
3529
+ posts(first: $first, after: $after) {
3530
+ nodes {
3531
+ ${BASE_POST_FIELDS}
3532
+ ${buildACFFragment(fieldGroupName, fields)}
3533
+ }
3534
+ pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
3535
+ }
3536
+ }
3537
+ `;
3538
+ }
3539
+
3540
+ // src/integrations/wpGraphQL/woocommerce/products/queries.ts
3541
+ var DEFAULT_FIRST7 = 10;
3542
+ var BATCH_FIRST3 = 100;
3543
+ var PRODUCT_FIELDS = `
3544
+ id
3545
+ databaseId
3546
+ slug
3547
+ name
3548
+ status
3549
+ description
3550
+ shortDescription
3551
+ type
3552
+ onSale
3553
+ featuredImage { node { sourceUrl altText } }
3554
+ galleryImages { nodes { sourceUrl altText } }
3555
+ productCategories { nodes { databaseId name slug } }
3556
+ productTags { nodes { databaseId name slug } }
3557
+ ... on SimpleProduct {
3558
+ sku
3559
+ price
3560
+ regularPrice
3561
+ salePrice
3562
+ stockStatus
3563
+ stockQuantity
3564
+ manageStock
3565
+ }
3566
+ ... on VariableProduct {
3567
+ price
3568
+ regularPrice
3569
+ salePrice
3570
+ stockStatus
3571
+ stockQuantity
3572
+ manageStock
3573
+ variations {
3574
+ nodes {
3575
+ id
3576
+ databaseId
3577
+ slug
3578
+ sku
3579
+ price
3580
+ regularPrice
3581
+ salePrice
3582
+ onSale
3583
+ stockStatus
3584
+ stockQuantity
3585
+ image { sourceUrl altText }
3586
+ attributes { nodes { name value } }
3587
+ }
3588
+ }
3589
+ }
3590
+ `;
3591
+ var GQL_GET_PRODUCTS = `
3592
+ query GetProducts($first: Int, $after: String, $where: RootQueryToProductConnectionWhereArgs) {
3593
+ products(first: $first, after: $after, where: $where) {
3594
+ nodes { ${PRODUCT_FIELDS} }
3595
+ pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
3596
+ }
3597
+ }
3598
+ `;
3599
+ var GQL_GET_PRODUCT_BY_SLUG = `
3600
+ query GetProductBySlug($slug: ID!) {
3601
+ product(id: $slug, idType: SLUG) { ${PRODUCT_FIELDS} }
3602
+ }
3603
+ `;
3604
+ var GQL_GET_PRODUCT_BY_DATABASE_ID = `
3605
+ query GetProductByDatabaseId($id: ID!) {
3606
+ product(id: $id, idType: DATABASE_ID) { ${PRODUCT_FIELDS} }
3607
+ }
3608
+ `;
3609
+ var GQL_GET_ALL_PRODUCT_SLUGS = `
3610
+ query GetAllProductSlugs($first: Int, $after: String) {
3611
+ products(first: $first, after: $after) {
3612
+ nodes { slug }
3613
+ pageInfo { hasNextPage endCursor }
3614
+ }
3615
+ }
3616
+ `;
3617
+ function createProductsQueries2(fetcher) {
3618
+ const { gqlFetch, gqlFetchGraceful } = fetcher;
3619
+ async function getProducts(first = DEFAULT_FIRST7, after, filter) {
3620
+ const where = {};
3621
+ if (filter?.search) where["search"] = filter.search;
3622
+ if (filter?.onSale !== void 0) where["onSale"] = filter.onSale;
3623
+ if (filter?.featured !== void 0) where["featured"] = filter.featured;
3624
+ if (filter?.stockStatus) where["stockStatus"] = filter.stockStatus;
3625
+ if (filter?.minPrice) where["minPrice"] = filter.minPrice;
3626
+ if (filter?.maxPrice) where["maxPrice"] = filter.maxPrice;
3627
+ if (filter?.categoryId) where["categoryIdIn"] = [filter.categoryId];
3628
+ if (filter?.tagId) where["tagIdIn"] = [filter.tagId];
3629
+ const data = await gqlFetchGraceful(
3630
+ GQL_GET_PRODUCTS,
3631
+ { products: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
3632
+ { first, after, where: Object.keys(where).length > 0 ? where : void 0 },
3633
+ ["wpgraphql", "gql-products"]
3634
+ );
3635
+ return data.products;
3636
+ }
3637
+ async function getProductBySlug(slug) {
3638
+ const data = await gqlFetchGraceful(
3639
+ GQL_GET_PRODUCT_BY_SLUG,
3640
+ { product: null },
3641
+ { slug },
3642
+ ["wpgraphql", "gql-products", `gql-product-${slug}`]
3643
+ );
3644
+ return data.product;
3645
+ }
3646
+ async function getProductByDatabaseId(id) {
3647
+ const data = await gqlFetchGraceful(
3648
+ GQL_GET_PRODUCT_BY_DATABASE_ID,
3649
+ { product: null },
3650
+ { id: String(id) },
3651
+ ["wpgraphql", "gql-products", `gql-product-id-${id}`]
3652
+ );
3653
+ return data.product;
3654
+ }
3655
+ async function getFeaturedProducts(first = DEFAULT_FIRST7) {
3656
+ const connection = await getProducts(first, void 0, { featured: true });
3657
+ return connection.nodes;
3658
+ }
3659
+ async function getOnSaleProducts(first = DEFAULT_FIRST7) {
3660
+ const connection = await getProducts(first, void 0, { onSale: true });
3661
+ return connection.nodes;
3662
+ }
3663
+ async function getAllProductSlugs() {
3664
+ try {
3665
+ const all = [];
3666
+ let after = void 0;
3667
+ let hasNextPage = true;
3668
+ while (hasNextPage) {
3669
+ const data = await gqlFetch(GQL_GET_ALL_PRODUCT_SLUGS, { first: BATCH_FIRST3, after }, ["wpgraphql"]);
3670
+ all.push(...data.products.nodes);
3671
+ hasNextPage = data.products.pageInfo.hasNextPage;
3672
+ after = data.products.pageInfo.endCursor;
3673
+ }
3674
+ return all;
3675
+ } catch {
3676
+ console.warn("WPGraphQL unavailable, skipping static generation for products");
3677
+ return [];
3678
+ }
3679
+ }
3680
+ return {
3681
+ getProducts,
3682
+ getProductBySlug,
3683
+ getProductByDatabaseId,
3684
+ getFeaturedProducts,
3685
+ getOnSaleProducts,
3686
+ getAllProductSlugs
3687
+ };
3688
+ }
3689
+
3690
+ // src/integrations/wpGraphQL/woocommerce/orders/queries.ts
3691
+ var DEFAULT_FIRST8 = 10;
3692
+ var ADDRESS_FIELDS = `
3693
+ firstName lastName address1 address2 city postcode country email phone
3694
+ `;
3695
+ var ORDER_FIELDS = `
3696
+ id
3697
+ databaseId
3698
+ orderNumber
3699
+ status
3700
+ date
3701
+ modified
3702
+ total
3703
+ subtotal
3704
+ totalTax
3705
+ shippingTotal
3706
+ currency
3707
+ billing { ${ADDRESS_FIELDS} }
3708
+ shipping { ${ADDRESS_FIELDS} }
3709
+ lineItems {
3710
+ nodes {
3711
+ productId
3712
+ variationId
3713
+ quantity
3714
+ subtotal
3715
+ total
3716
+ product { node { databaseId name slug } }
3717
+ }
3718
+ }
3719
+ `;
3720
+ var GQL_GET_ORDER = `
3721
+ query GetOrder($id: ID!) {
3722
+ order(id: $id, idType: DATABASE_ID) { ${ORDER_FIELDS} }
3723
+ }
3724
+ `;
3725
+ var GQL_GET_MY_ORDERS = `
3726
+ query GetMyOrders($first: Int, $after: String) {
3727
+ orders(first: $first, after: $after) {
3728
+ nodes { ${ORDER_FIELDS} }
3729
+ pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
3730
+ }
3731
+ }
3732
+ `;
3733
+ function createOrdersQueries2(fetcher) {
3734
+ const { gqlFetchGraceful } = fetcher;
3735
+ async function getOrder(id) {
3736
+ const data = await gqlFetchGraceful(
3737
+ GQL_GET_ORDER,
3738
+ { order: null },
3739
+ { id: String(id) },
3740
+ ["wpgraphql", "gql-orders", `gql-order-${id}`]
3741
+ );
3742
+ return data.order;
3743
+ }
3744
+ async function getMyOrders(first = DEFAULT_FIRST8, after) {
3745
+ const data = await gqlFetchGraceful(
3746
+ GQL_GET_MY_ORDERS,
3747
+ { orders: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
3748
+ { first, after },
3749
+ ["wpgraphql", "gql-orders"]
3750
+ );
3751
+ return data.orders;
3752
+ }
3753
+ return { getOrder, getMyOrders };
3754
+ }
3755
+
3756
+ // src/integrations/wpGraphQL/woocommerce/customers/queries.ts
3757
+ var ADDRESS_FIELDS2 = `
3758
+ firstName lastName address1 address2 city postcode country
3759
+ `;
3760
+ var CUSTOMER_FIELDS = `
3761
+ id
3762
+ databaseId
3763
+ email
3764
+ firstName
3765
+ lastName
3766
+ username
3767
+ billing { ${ADDRESS_FIELDS2} phone }
3768
+ shipping { ${ADDRESS_FIELDS2} }
3769
+ `;
3770
+ var GQL_GET_CUSTOMER = `
3771
+ query GetCustomer {
3772
+ customer { ${CUSTOMER_FIELDS} }
3773
+ }
3774
+ `;
3775
+ var GQL_GET_CUSTOMER_BY_ID = `
3776
+ query GetCustomerById($id: ID!) {
3777
+ customer(customerId: $id) { ${CUSTOMER_FIELDS} }
3778
+ }
3779
+ `;
3780
+ function createCustomersQueries2(fetcher) {
3781
+ const { gqlFetchGraceful } = fetcher;
3782
+ async function getCustomer() {
3783
+ const data = await gqlFetchGraceful(
3784
+ GQL_GET_CUSTOMER,
3785
+ { customer: null },
3786
+ void 0,
3787
+ ["wpgraphql", "gql-customer"]
3788
+ );
3789
+ return data.customer;
3790
+ }
3791
+ async function getCustomerById(id) {
3792
+ const data = await gqlFetchGraceful(
3793
+ GQL_GET_CUSTOMER_BY_ID,
3794
+ { customer: null },
3795
+ { id: String(id) },
3796
+ ["wpgraphql", "gql-customer", `gql-customer-${id}`]
3797
+ );
3798
+ return data.customer;
3799
+ }
3800
+ return { getCustomer, getCustomerById };
3801
+ }
3802
+
3803
+ // src/integrations/wpGraphQL/woocommerce/categories/queries.ts
3804
+ var DEFAULT_FIRST9 = 100;
3805
+ var CATEGORY_FIELDS2 = `
3806
+ id
3807
+ databaseId
3808
+ name
3809
+ slug
3810
+ description
3811
+ count
3812
+ parent { node { id databaseId name slug } }
3813
+ image { sourceUrl altText }
3814
+ `;
3815
+ var GQL_GET_PRODUCT_CATEGORIES = `
3816
+ query GetProductCategories($first: Int, $after: String) {
3817
+ productCategories(first: $first, after: $after) {
3818
+ nodes { ${CATEGORY_FIELDS2} }
3819
+ pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
3820
+ }
3821
+ }
3822
+ `;
3823
+ var GQL_GET_PRODUCT_CATEGORY_BY_SLUG = `
3824
+ query GetProductCategoryBySlug($id: ID!) {
3825
+ productCategory(id: $id, idType: SLUG) { ${CATEGORY_FIELDS2} }
3826
+ }
3827
+ `;
3828
+ var GQL_GET_PRODUCT_CATEGORY_BY_ID = `
3829
+ query GetProductCategoryById($id: ID!) {
3830
+ productCategory(id: $id, idType: DATABASE_ID) { ${CATEGORY_FIELDS2} }
3831
+ }
3832
+ `;
3833
+ function createCategoriesQueries4(fetcher) {
3834
+ const { gqlFetchGraceful } = fetcher;
3835
+ async function getProductCategories(first = DEFAULT_FIRST9, after) {
3836
+ const data = await gqlFetchGraceful(
3837
+ GQL_GET_PRODUCT_CATEGORIES,
3838
+ { productCategories: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
3839
+ { first, after },
3840
+ ["wpgraphql", "gql-product-categories"]
3841
+ );
3842
+ return data.productCategories;
3843
+ }
3844
+ async function getProductCategoryBySlug(slug) {
3845
+ const data = await gqlFetchGraceful(
3846
+ GQL_GET_PRODUCT_CATEGORY_BY_SLUG,
3847
+ { productCategory: null },
3848
+ { id: slug },
3849
+ ["wpgraphql", "gql-product-categories", `gql-product-category-${slug}`]
3850
+ );
3851
+ return data.productCategory;
3852
+ }
3853
+ async function getProductCategoryById(id) {
3854
+ const data = await gqlFetchGraceful(
3855
+ GQL_GET_PRODUCT_CATEGORY_BY_ID,
3856
+ { productCategory: null },
3857
+ { id: String(id) },
3858
+ ["wpgraphql", "gql-product-categories", `gql-product-category-${id}`]
3859
+ );
3860
+ return data.productCategory;
3861
+ }
3862
+ return { getProductCategories, getProductCategoryBySlug, getProductCategoryById };
3863
+ }
3864
+
3865
+ // src/integrations/wpGraphQL/woocommerce/tags/queries.ts
3866
+ var DEFAULT_FIRST10 = 100;
3867
+ var TAG_FIELDS2 = `
3868
+ id
3869
+ databaseId
3870
+ name
3871
+ slug
3872
+ description
3873
+ count
3874
+ `;
3875
+ var GQL_GET_PRODUCT_TAGS = `
3876
+ query GetProductTags($first: Int, $after: String) {
3877
+ productTags(first: $first, after: $after) {
3878
+ nodes { ${TAG_FIELDS2} }
3879
+ pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
3880
+ }
3881
+ }
3882
+ `;
3883
+ var GQL_GET_PRODUCT_TAG_BY_SLUG = `
3884
+ query GetProductTagBySlug($id: ID!) {
3885
+ productTag(id: $id, idType: SLUG) { ${TAG_FIELDS2} }
3886
+ }
3887
+ `;
3888
+ var GQL_GET_PRODUCT_TAG_BY_ID = `
3889
+ query GetProductTagById($id: ID!) {
3890
+ productTag(id: $id, idType: DATABASE_ID) { ${TAG_FIELDS2} }
3891
+ }
3892
+ `;
3893
+ function createTagsQueries4(fetcher) {
3894
+ const { gqlFetchGraceful } = fetcher;
3895
+ async function getProductTags(first = DEFAULT_FIRST10, after) {
3896
+ const data = await gqlFetchGraceful(
3897
+ GQL_GET_PRODUCT_TAGS,
3898
+ { productTags: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
3899
+ { first, after },
3900
+ ["wpgraphql", "gql-product-tags"]
3901
+ );
3902
+ return data.productTags;
3903
+ }
3904
+ async function getProductTagBySlug(slug) {
3905
+ const data = await gqlFetchGraceful(
3906
+ GQL_GET_PRODUCT_TAG_BY_SLUG,
3907
+ { productTag: null },
3908
+ { id: slug },
3909
+ ["wpgraphql", "gql-product-tags", `gql-product-tag-${slug}`]
3910
+ );
3911
+ return data.productTag;
3912
+ }
3913
+ async function getProductTagById(id) {
3914
+ const data = await gqlFetchGraceful(
3915
+ GQL_GET_PRODUCT_TAG_BY_ID,
3916
+ { productTag: null },
3917
+ { id: String(id) },
3918
+ ["wpgraphql", "gql-product-tags", `gql-product-tag-${id}`]
3919
+ );
3920
+ return data.productTag;
3921
+ }
3922
+ return { getProductTags, getProductTagBySlug, getProductTagById };
3923
+ }
3924
+
3925
+ // src/integrations/wpGraphQL/woocommerce/coupons/queries.ts
3926
+ var DEFAULT_FIRST11 = 100;
3927
+ var COUPON_FIELDS = `
3928
+ id
3929
+ databaseId
3930
+ code
3931
+ discountType
3932
+ amount
3933
+ dateExpiry
3934
+ usageCount
3935
+ usageLimit
3936
+ usageLimitPerUser
3937
+ individualUse
3938
+ freeShipping
3939
+ minimumAmount
3940
+ maximumAmount
3941
+ description
3942
+ `;
3943
+ var GQL_GET_COUPONS = `
3944
+ query GetCoupons($first: Int, $after: String) {
3945
+ coupons(first: $first, after: $after) {
3946
+ nodes { ${COUPON_FIELDS} }
3947
+ pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
3948
+ }
3949
+ }
3950
+ `;
3951
+ var GQL_GET_COUPON_BY_CODE = `
3952
+ query GetCouponByCode($id: ID!) {
3953
+ coupon(id: $id, idType: CODE) { ${COUPON_FIELDS} }
3954
+ }
3955
+ `;
3956
+ var GQL_GET_COUPON_BY_ID = `
3957
+ query GetCouponById($id: ID!) {
3958
+ coupon(id: $id, idType: DATABASE_ID) { ${COUPON_FIELDS} }
3959
+ }
3960
+ `;
3961
+ function createCouponsQueries2(fetcher) {
3962
+ const { gqlFetchGraceful } = fetcher;
3963
+ async function getCoupons(first = DEFAULT_FIRST11, after) {
3964
+ const data = await gqlFetchGraceful(
3965
+ GQL_GET_COUPONS,
3966
+ { coupons: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
3967
+ { first, after },
3968
+ ["wpgraphql", "gql-coupons"]
3969
+ );
3970
+ return data.coupons;
3971
+ }
3972
+ async function getCouponByCode(code) {
3973
+ const data = await gqlFetchGraceful(
3974
+ GQL_GET_COUPON_BY_CODE,
3975
+ { coupon: null },
3976
+ { id: code },
3977
+ ["wpgraphql", "gql-coupons", `gql-coupon-${code}`]
3978
+ );
3979
+ return data.coupon;
3980
+ }
3981
+ async function getCouponById(id) {
3982
+ const data = await gqlFetchGraceful(
3983
+ GQL_GET_COUPON_BY_ID,
3984
+ { coupon: null },
3985
+ { id: String(id) },
3986
+ ["wpgraphql", "gql-coupons", `gql-coupon-${id}`]
3987
+ );
3988
+ return data.coupon;
3989
+ }
3990
+ return { getCoupons, getCouponByCode, getCouponById };
3991
+ }
3992
+
3993
+ // src/integrations/wpGraphQL/woocommerce/index.ts
3994
+ function createWPGraphQLWooCommerceClient(config) {
3995
+ const fetcher = createWPGraphQLFetcher(config);
3996
+ return {
3997
+ ...createProductsQueries2(fetcher),
3998
+ ...createOrdersQueries2(fetcher),
3999
+ ...createCustomersQueries2(fetcher),
4000
+ ...createCategoriesQueries4(fetcher),
4001
+ ...createTagsQueries4(fetcher),
4002
+ ...createCouponsQueries2(fetcher)
4003
+ };
4004
+ }
4005
+
4006
+ // src/integrations/wpGraphQL/cpt/queries.ts
4007
+ var DEFAULT_FIRST12 = 10;
4008
+ var BATCH_FIRST4 = 100;
4009
+ var BASE_CPT_FIELDS = `
4010
+ id databaseId slug title date modified status uri
4011
+ `;
4012
+ function createCPTQueries(fetcher, typeName, singularTypeName, extraFields) {
4013
+ const { gqlFetch, gqlFetchGraceful } = fetcher;
4014
+ const fields = extraFields ? `${BASE_CPT_FIELDS} ${extraFields}` : BASE_CPT_FIELDS;
4015
+ const GQL_GET_ITEMS = `
4016
+ query GetCPT_${typeName}($first: Int, $after: String) {
4017
+ ${typeName}(first: $first, after: $after) {
4018
+ nodes { ${fields} }
4019
+ pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
4020
+ }
4021
+ }
4022
+ `;
4023
+ const GQL_GET_ITEM_BY_SLUG = `
4024
+ query GetCPT_${singularTypeName}BySlug($slug: ID!) {
4025
+ ${singularTypeName}(id: $slug, idType: SLUG) { ${fields} }
4026
+ }
4027
+ `;
4028
+ const GQL_GET_ALL_SLUGS = `
4029
+ query GetAllCPT_${typeName}Slugs($first: Int, $after: String) {
4030
+ ${typeName}(first: $first, after: $after) {
4031
+ nodes { slug }
4032
+ pageInfo { hasNextPage endCursor }
4033
+ }
4034
+ }
4035
+ `;
4036
+ async function getItems(first = DEFAULT_FIRST12, after) {
4037
+ const data = await gqlFetchGraceful(
4038
+ GQL_GET_ITEMS,
4039
+ { [typeName]: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
4040
+ { first, after },
4041
+ ["wpgraphql", `gql-${typeName}`]
4042
+ );
4043
+ return data[typeName] ?? { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } };
4044
+ }
4045
+ async function getItemBySlug(slug) {
4046
+ const data = await gqlFetchGraceful(
4047
+ GQL_GET_ITEM_BY_SLUG,
4048
+ { [singularTypeName]: null },
4049
+ { slug },
4050
+ ["wpgraphql", `gql-${typeName}`, `gql-${singularTypeName}-${slug}`]
4051
+ );
4052
+ return data[singularTypeName] ?? null;
4053
+ }
4054
+ async function getAllSlugs() {
4055
+ try {
4056
+ const all = [];
4057
+ let after = void 0;
4058
+ let hasNextPage = true;
4059
+ while (hasNextPage) {
4060
+ const data = await gqlFetch(GQL_GET_ALL_SLUGS, { first: BATCH_FIRST4, after }, ["wpgraphql"]);
4061
+ const connection = data[typeName];
4062
+ if (!connection) break;
4063
+ all.push(...connection.nodes);
4064
+ hasNextPage = connection.pageInfo.hasNextPage;
4065
+ after = connection.pageInfo.endCursor;
4066
+ }
4067
+ return all;
4068
+ } catch {
4069
+ console.warn(`WPGraphQL unavailable, skipping static generation for ${typeName}`);
4070
+ return [];
4071
+ }
4072
+ }
4073
+ return { getItems, getItemBySlug, getAllSlugs };
4074
+ }
4075
+
4076
+ // src/nextjs/revalidation.ts
4077
+ var ACTION_TAG_MAP = {
4078
+ save_post: ["wordpress", "posts"],
4079
+ save_post_post: ["wordpress", "posts"],
4080
+ save_post_page: ["wordpress", "pages"],
4081
+ delete_post: ["wordpress", "posts", "pages"],
4082
+ created_term: ["wordpress", "categories", "tags"],
4083
+ edited_term: ["wordpress", "categories", "tags"],
4084
+ delete_term: ["wordpress", "categories", "tags"],
4085
+ wp_update_nav_menu: ["wordpress", "menus"],
4086
+ woocommerce_product_updated: ["woocommerce", "products"],
4087
+ woocommerce_new_product: ["woocommerce", "products"],
4088
+ woocommerce_delete_product: ["woocommerce", "products"],
4089
+ woocommerce_new_order: ["woocommerce", "orders"],
4090
+ woocommerce_order_status_changed: ["woocommerce", "orders"],
4091
+ woocommerce_update_order: ["woocommerce", "orders"],
4092
+ woocommerce_product_category_updated: ["woocommerce", "categories"],
4093
+ woocommerce_product_tag_updated: ["woocommerce", "tags"]
4094
+ };
4095
+ function extractSecret(request) {
4096
+ const auth = request.headers.get("Authorization");
4097
+ if (auth?.startsWith("Bearer ")) return auth.slice(7);
4098
+ return new URL(request.url).searchParams.get("secret");
4099
+ }
4100
+ function createRevalidationHandler(config, revalidateTag) {
4101
+ return async function handler(request) {
4102
+ if (extractSecret(request) !== config.secret) {
4103
+ return Response.json({ revalidated: false, tags: [], message: "Unauthorized" }, { status: 401 });
4104
+ }
4105
+ let payload;
4106
+ try {
4107
+ payload = await request.json();
4108
+ } catch {
4109
+ return Response.json({ revalidated: false, tags: [], message: "Invalid JSON body" }, { status: 400 });
4110
+ }
4111
+ const { action } = payload;
4112
+ const matched = ACTION_TAG_MAP[action];
4113
+ if (!matched) {
4114
+ return Response.json(
4115
+ { revalidated: false, tags: [], message: `Unknown action: ${action}` },
4116
+ { status: 400 }
4117
+ );
4118
+ }
4119
+ const tags = [...new Set(matched)];
4120
+ for (const tag of tags) {
4121
+ revalidateTag(tag);
4122
+ }
4123
+ return Response.json({ revalidated: true, tags });
4124
+ };
4125
+ }
4126
+
4127
+ // src/nextjs/faust.ts
4128
+ function createFaustAuthHandler(config) {
4129
+ const cookieName = config.cookieName ?? "faustwp-rt";
4130
+ return async function handler(request, routePath) {
4131
+ if (routePath === "auth/token") {
4132
+ const url = new URL(request.url);
4133
+ const code = url.searchParams.get("code");
4134
+ const redirectUri = url.searchParams.get("redirect_uri") ?? "/";
4135
+ const refreshToken = parseCookie(request, cookieName);
4136
+ if (!code && !refreshToken) {
4137
+ return Response.json({ error: "Unauthorized" }, { status: 401 });
4138
+ }
4139
+ const wpRes = await fetch(`${config.wpUrl}/?rest_route=/faustwp/v1/authorize`, {
4140
+ method: "POST",
4141
+ headers: {
4142
+ "Content-Type": "application/json",
4143
+ "x-faustwp-secret": config.secretKey
4144
+ },
4145
+ body: JSON.stringify({ code, refreshToken })
4146
+ });
4147
+ if (!wpRes.ok) {
4148
+ const body = await wpRes.text();
4149
+ return new Response(body, { status: wpRes.status });
4150
+ }
4151
+ const data = await wpRes.json();
4152
+ return new Response(null, {
4153
+ status: 302,
4154
+ headers: {
4155
+ Location: new URL(redirectUri, request.url).toString(),
4156
+ "Set-Cookie": buildSetCookie(cookieName, data.refreshToken, 2592e3)
4157
+ }
4158
+ });
4159
+ }
4160
+ if (routePath === "auth/logout") {
4161
+ return new Response(JSON.stringify({}), {
4162
+ status: 200,
4163
+ headers: {
4164
+ "Content-Type": "application/json",
4165
+ "Set-Cookie": `${cookieName}=; Max-Age=0; Path=/; HttpOnly`
4166
+ }
4167
+ });
4168
+ }
4169
+ return Response.json({ error: "Not Found" }, { status: 404 });
4170
+ };
4171
+ }
4172
+ function createPreviewHandler(config, deps) {
4173
+ const previewPath = config.previewPath ?? "posts";
4174
+ return async function handler(request) {
4175
+ const url = new URL(request.url);
4176
+ const postId = url.searchParams.get("postId");
4177
+ const previewPathname = url.searchParams.get("previewPathname");
4178
+ if (!postId) {
4179
+ return new Response("Missing postId", { status: 400 });
4180
+ }
4181
+ const slug = await resolvePreviewSlug(config, postId, previewPathname);
4182
+ if (!slug) {
4183
+ return new Response("Post not found", { status: 404 });
4184
+ }
4185
+ await deps.enableDraftMode();
4186
+ deps.redirect(`/${previewPath}/${slug}?postId=${postId}`);
4187
+ };
4188
+ }
4189
+ function parseCookie(request, name) {
4190
+ const header = request.headers.get("cookie") ?? "";
4191
+ const match = header.match(new RegExp(`(?:^|;\\s*)${name}=([^;]*)`));
4192
+ return match?.[1];
4193
+ }
4194
+ function buildSetCookie(name, value, maxAge) {
4195
+ const secure = process.env.NODE_ENV === "production" ? "; Secure" : "";
4196
+ return `${name}=${value}; HttpOnly; Path=/; SameSite=Strict; Max-Age=${maxAge}${secure}`;
4197
+ }
4198
+ async function resolvePreviewSlug(config, postId, previewPathname) {
4199
+ if (previewPathname && !previewPathname.includes("p=")) {
4200
+ const slug = previewPathname.replace(/\/$/, "").split("/").pop();
4201
+ if (slug) return slug;
4202
+ }
4203
+ const res = await fetch(`${config.wpUrl}/wp-json/wp/v2/posts/${postId}?_fields=slug`, {
4204
+ headers: { "x-faustwp-secret": config.secretKey },
4205
+ cache: "no-store"
4206
+ });
4207
+ if (!res.ok) return null;
4208
+ const data = await res.json();
4209
+ return data.slug ?? `preview-${postId}`;
4210
+ }
4211
+
4212
+ // src/auth/applicationPassword.ts
4213
+ function createApplicationPasswordToken(username, appPassword) {
4214
+ const encoded = Buffer.from(`${username}:${appPassword}`).toString("base64");
4215
+ return `Basic ${encoded}`;
4216
+ }
4217
+
4218
+ // src/auth/types.ts
4219
+ var AuthenticationError = class extends Error {
4220
+ constructor(code, status, message, detail) {
4221
+ super(detail ? `${message}: ${detail}` : message);
4222
+ __publicField(this, "code", code);
4223
+ __publicField(this, "status", status);
4224
+ this.name = "AuthenticationError";
4225
+ }
4226
+ };
4227
+
4228
+ // src/auth/jwt.ts
4229
+ function resolveAuthErrorCode(status) {
4230
+ if (status === 401) return ErrorCode.AUTH_CREDENTIALS_INVALID;
4231
+ if (status === 403) return ErrorCode.AUTH_TOKEN_INVALID;
4232
+ return ErrorCode.AUTH_JWT_FAILED;
4233
+ }
4234
+ async function authenticateJwt(config, credentials) {
4235
+ const url = `${resolveBaseUrl(config)}/wp-json/jwt-auth/v1/token`;
4236
+ const response = await fetch(url, {
4237
+ method: "POST",
4238
+ headers: { "Content-Type": "application/json" },
4239
+ body: JSON.stringify(credentials),
4240
+ cache: "no-store"
4241
+ });
4242
+ if (!response.ok) {
4243
+ const code = resolveAuthErrorCode(response.status);
4244
+ throw new AuthenticationError(
4245
+ code,
4246
+ response.status,
4247
+ resolveMessage(code, config.errorMessages),
4248
+ response.statusText
4249
+ );
4250
+ }
4251
+ return response.json();
4252
+ }
4253
+ async function validateJwtToken(config, token) {
4254
+ const url = `${resolveBaseUrl(config)}/wp-json/jwt-auth/v1/token/validate`;
4255
+ const response = await fetch(url, {
4256
+ method: "POST",
4257
+ headers: { Authorization: `Bearer ${token}` },
4258
+ cache: "no-store"
4259
+ });
4260
+ return response.ok;
4261
+ }
4262
+
4263
+ exports.AuthenticationError = AuthenticationError;
4264
+ exports.ErrorCode = ErrorCode;
4265
+ exports.WPGraphQLError = WPGraphQLError;
4266
+ exports.WooCommerceError = WooCommerceError;
4267
+ exports.WordPressAPIError = WordPressAPIError;
4268
+ exports.authenticateJwt = authenticateJwt;
4269
+ exports.buildACFFragment = buildACFFragment;
4270
+ exports.buildPageWithACFQuery = buildPageWithACFQuery;
4271
+ exports.buildPostWithACFQuery = buildPostWithACFQuery;
4272
+ exports.buildPostsWithACFQuery = buildPostsWithACFQuery;
4273
+ exports.createApplicationPasswordToken = createApplicationPasswordToken;
4274
+ exports.createAuthorsMutations = createAuthorsMutations;
4275
+ exports.createCF7Queries = createCF7Queries;
4276
+ exports.createCPTQueries = createCPTQueries;
4277
+ exports.createCategoriesMutations = createCategoriesMutations;
4278
+ exports.createCommentsMutations = createCommentsMutations;
4279
+ exports.createFaustAuthHandler = createFaustAuthHandler;
4280
+ exports.createMediaMutations = createMediaMutations;
4281
+ exports.createMenusMutations = createMenusMutations;
4282
+ exports.createPagesMutations = createPagesMutations;
4283
+ exports.createPostsMutations = createPostsMutations;
4284
+ exports.createPreviewHandler = createPreviewHandler;
4285
+ exports.createRevalidationHandler = createRevalidationHandler;
4286
+ exports.createTagsMutations = createTagsMutations;
4287
+ exports.createWPGraphQLClient = createWPGraphQLCoreClient;
4288
+ exports.createWPGraphQLCoreClient = createWPGraphQLCoreClient;
4289
+ exports.createWPGraphQLFetcher = createWPGraphQLFetcher;
4290
+ exports.createWPGraphQLMutationsClient = createWPGraphQLMutationsClient;
4291
+ exports.createWPGraphQLWooCommerceClient = createWPGraphQLWooCommerceClient;
4292
+ exports.createWPULikeClient = createWPULikeClient;
4293
+ exports.createWPULikeQueries = createWPULikeQueries;
4294
+ exports.createWooCommerceClient = createWooCommerceClient;
4295
+ exports.createWooCommerceFetcher = createWooCommerceFetcher;
4296
+ exports.createWordPressClient = createWordPressClient;
4297
+ exports.createWordPressMutationsClient = createWordPressMutationsClient;
4298
+ exports.createYoastQueries = createYoastQueries;
4299
+ exports.defaultMessages = defaultMessages;
4300
+ exports.defaultMessagesPl = defaultMessagesPl;
4301
+ exports.extractOmnibusData = extractOmnibusData;
4302
+ exports.resolveBaseUrl = resolveBaseUrl;
4303
+ exports.resolveMessage = resolveMessage;
4304
+ exports.validateJwtToken = validateJwtToken;
4305
+ exports.withOmnibus = withOmnibus;
4306
+ exports.withOmnibusVariation = withOmnibusVariation;
4307
+ //# sourceMappingURL=index.cjs.map
4308
+ //# sourceMappingURL=index.cjs.map