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