@szymonpiatek/nextwordpress 0.0.10 → 0.0.11

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,4231 @@
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/wpGraphQL/client/types.ts
2103
+ var WPGraphQLError = class extends Error {
2104
+ constructor(code, status, endpoint, message, gqlErrors) {
2105
+ super(message);
2106
+ __publicField(this, "code", code);
2107
+ __publicField(this, "status", status);
2108
+ __publicField(this, "endpoint", endpoint);
2109
+ __publicField(this, "gqlErrors", gqlErrors);
2110
+ this.name = "WPGraphQLError";
2111
+ }
2112
+ };
2113
+
2114
+ // src/integrations/wpGraphQL/client/fetcher.ts
2115
+ var USER_AGENT3 = "NextWordpress WPGraphQL Client";
2116
+ function createWPGraphQLFetcher(config) {
2117
+ const url = `${resolveBaseUrl(config)}/graphql`;
2118
+ const cacheTTL = config.cacheTTL ?? 300;
2119
+ async function gqlFetch(document, variables, tags = ["wpgraphql"]) {
2120
+ const response = await fetch(url, {
2121
+ method: "POST",
2122
+ headers: {
2123
+ "Content-Type": "application/json",
2124
+ "User-Agent": USER_AGENT3
2125
+ },
2126
+ body: JSON.stringify({ query: document, variables }),
2127
+ next: { tags, revalidate: cacheTTL }
2128
+ });
2129
+ if (!response.ok) {
2130
+ throw new WPGraphQLError(
2131
+ ErrorCode.GQL_REQUEST_FAILED,
2132
+ response.status,
2133
+ url,
2134
+ resolveMessage(ErrorCode.GQL_REQUEST_FAILED, config.errorMessages)
2135
+ );
2136
+ }
2137
+ const parsed = await response.json();
2138
+ if (parsed.errors && parsed.errors.length > 0) {
2139
+ throw new WPGraphQLError(
2140
+ ErrorCode.GQL_ERRORS_IN_RESPONSE,
2141
+ 200,
2142
+ url,
2143
+ resolveMessage(ErrorCode.GQL_ERRORS_IN_RESPONSE, config.errorMessages),
2144
+ parsed.errors
2145
+ );
2146
+ }
2147
+ if (parsed.data === void 0) {
2148
+ throw new WPGraphQLError(
2149
+ ErrorCode.GQL_NO_DATA,
2150
+ 200,
2151
+ url,
2152
+ resolveMessage(ErrorCode.GQL_NO_DATA, config.errorMessages)
2153
+ );
2154
+ }
2155
+ return parsed.data;
2156
+ }
2157
+ async function gqlFetchGraceful(document, fallback, variables, tags = ["wpgraphql"]) {
2158
+ try {
2159
+ return await gqlFetch(document, variables, tags);
2160
+ } catch {
2161
+ console.warn(`WPGraphQL fetch failed for query`);
2162
+ return fallback;
2163
+ }
2164
+ }
2165
+ async function gqlMutate(document, variables, authToken) {
2166
+ const headers = {
2167
+ "Content-Type": "application/json",
2168
+ "User-Agent": USER_AGENT3
2169
+ };
2170
+ if (authToken) {
2171
+ headers["Authorization"] = authToken;
2172
+ }
2173
+ const response = await fetch(url, {
2174
+ method: "POST",
2175
+ headers,
2176
+ body: JSON.stringify({ query: document, variables }),
2177
+ cache: "no-store"
2178
+ });
2179
+ if (!response.ok) {
2180
+ throw new WPGraphQLError(
2181
+ ErrorCode.GQL_REQUEST_FAILED,
2182
+ response.status,
2183
+ url,
2184
+ resolveMessage(ErrorCode.GQL_REQUEST_FAILED, config.errorMessages)
2185
+ );
2186
+ }
2187
+ const parsed = await response.json();
2188
+ if (parsed.errors && parsed.errors.length > 0) {
2189
+ throw new WPGraphQLError(
2190
+ ErrorCode.GQL_ERRORS_IN_RESPONSE,
2191
+ 200,
2192
+ url,
2193
+ resolveMessage(ErrorCode.GQL_ERRORS_IN_RESPONSE, config.errorMessages),
2194
+ parsed.errors
2195
+ );
2196
+ }
2197
+ if (parsed.data === void 0) {
2198
+ throw new WPGraphQLError(
2199
+ ErrorCode.GQL_NO_DATA,
2200
+ 200,
2201
+ url,
2202
+ resolveMessage(ErrorCode.GQL_NO_DATA, config.errorMessages)
2203
+ );
2204
+ }
2205
+ return parsed.data;
2206
+ }
2207
+ return { gqlFetch, gqlFetchGraceful, gqlMutate };
2208
+ }
2209
+
2210
+ // src/integrations/wpGraphQL/core/posts/queries.ts
2211
+ var DEFAULT_FIRST = 10;
2212
+ var BATCH_FIRST = 100;
2213
+ var POST_FIELDS = `
2214
+ id
2215
+ databaseId
2216
+ slug
2217
+ title
2218
+ excerpt
2219
+ date
2220
+ modified
2221
+ status
2222
+ uri
2223
+ author {
2224
+ node {
2225
+ databaseId
2226
+ name
2227
+ slug
2228
+ avatar { url }
2229
+ }
2230
+ }
2231
+ featuredImage {
2232
+ node {
2233
+ sourceUrl
2234
+ altText
2235
+ mediaDetails { width height }
2236
+ }
2237
+ }
2238
+ categories {
2239
+ nodes { databaseId name slug }
2240
+ }
2241
+ tags {
2242
+ nodes { databaseId name slug }
2243
+ }
2244
+ `;
2245
+ var POST_FIELDS_WITH_CONTENT = `
2246
+ ${POST_FIELDS}
2247
+ content
2248
+ `;
2249
+ var GQL_GET_POSTS = `
2250
+ query GetPosts($first: Int, $after: String, $where: RootQueryToPostConnectionWhereArgs) {
2251
+ posts(first: $first, after: $after, where: $where) {
2252
+ nodes { ${POST_FIELDS} }
2253
+ pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
2254
+ }
2255
+ }
2256
+ `;
2257
+ var GQL_GET_POST_BY_SLUG = `
2258
+ query GetPostBySlug($slug: ID!) {
2259
+ post(id: $slug, idType: SLUG) { ${POST_FIELDS_WITH_CONTENT} }
2260
+ }
2261
+ `;
2262
+ var GQL_GET_POST_BY_DATABASE_ID = `
2263
+ query GetPostByDatabaseId($id: ID!) {
2264
+ post(id: $id, idType: DATABASE_ID) { ${POST_FIELDS_WITH_CONTENT} }
2265
+ }
2266
+ `;
2267
+ var GQL_GET_ALL_POST_SLUGS = `
2268
+ query GetAllPostSlugs($first: Int, $after: String) {
2269
+ posts(first: $first, after: $after) {
2270
+ nodes { slug }
2271
+ pageInfo { hasNextPage endCursor }
2272
+ }
2273
+ }
2274
+ `;
2275
+ var GQL_GET_ALL_POSTS_FOR_SITEMAP = `
2276
+ query GetAllPostsForSitemap($first: Int, $after: String) {
2277
+ posts(first: $first, after: $after) {
2278
+ nodes { slug modified }
2279
+ pageInfo { hasNextPage endCursor }
2280
+ }
2281
+ }
2282
+ `;
2283
+ function createPostsQueries2(fetcher) {
2284
+ const { gqlFetch, gqlFetchGraceful } = fetcher;
2285
+ async function getPosts(first = DEFAULT_FIRST, after, filter) {
2286
+ const where = {};
2287
+ if (filter?.authorName) where["authorName"] = filter.authorName;
2288
+ if (filter?.categoryName) where["categoryName"] = filter.categoryName;
2289
+ if (filter?.tag) where["tag"] = filter.tag;
2290
+ if (filter?.search) where["search"] = filter.search;
2291
+ if (filter?.status) where["status"] = filter.status;
2292
+ const data = await gqlFetchGraceful(
2293
+ GQL_GET_POSTS,
2294
+ { posts: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
2295
+ { first, after, where: Object.keys(where).length > 0 ? where : void 0 },
2296
+ ["wpgraphql", "gql-posts"]
2297
+ );
2298
+ return data.posts;
2299
+ }
2300
+ async function getPostBySlug(slug) {
2301
+ const data = await gqlFetchGraceful(
2302
+ GQL_GET_POST_BY_SLUG,
2303
+ { post: null },
2304
+ { slug },
2305
+ ["wpgraphql", "gql-posts", `gql-post-${slug}`]
2306
+ );
2307
+ return data.post;
2308
+ }
2309
+ async function getPostByDatabaseId(id) {
2310
+ const data = await gqlFetchGraceful(
2311
+ GQL_GET_POST_BY_DATABASE_ID,
2312
+ { post: null },
2313
+ { id: String(id) },
2314
+ ["wpgraphql", "gql-posts", `gql-post-id-${id}`]
2315
+ );
2316
+ return data.post;
2317
+ }
2318
+ async function getRecentPosts(first = DEFAULT_FIRST) {
2319
+ const connection = await getPosts(first);
2320
+ return connection.nodes;
2321
+ }
2322
+ async function getAllPostSlugs() {
2323
+ try {
2324
+ const all = [];
2325
+ let after = void 0;
2326
+ let hasNextPage = true;
2327
+ while (hasNextPage) {
2328
+ const data = await gqlFetch(GQL_GET_ALL_POST_SLUGS, { first: BATCH_FIRST, after }, ["wpgraphql"]);
2329
+ all.push(...data.posts.nodes);
2330
+ hasNextPage = data.posts.pageInfo.hasNextPage;
2331
+ after = data.posts.pageInfo.endCursor;
2332
+ }
2333
+ return all;
2334
+ } catch {
2335
+ console.warn("WPGraphQL unavailable, skipping static generation for posts");
2336
+ return [];
2337
+ }
2338
+ }
2339
+ async function getAllPostsForSitemap() {
2340
+ try {
2341
+ const all = [];
2342
+ let after = void 0;
2343
+ let hasNextPage = true;
2344
+ while (hasNextPage) {
2345
+ const data = await gqlFetch(
2346
+ GQL_GET_ALL_POSTS_FOR_SITEMAP,
2347
+ { first: BATCH_FIRST, after },
2348
+ ["wpgraphql"]
2349
+ );
2350
+ all.push(...data.posts.nodes);
2351
+ hasNextPage = data.posts.pageInfo.hasNextPage;
2352
+ after = data.posts.pageInfo.endCursor;
2353
+ }
2354
+ return all;
2355
+ } catch {
2356
+ console.warn("WPGraphQL unavailable, skipping sitemap generation");
2357
+ return [];
2358
+ }
2359
+ }
2360
+ return {
2361
+ getPosts,
2362
+ getPostBySlug,
2363
+ getPostByDatabaseId,
2364
+ getRecentPosts,
2365
+ getAllPostSlugs,
2366
+ getAllPostsForSitemap
2367
+ };
2368
+ }
2369
+
2370
+ // src/integrations/wpGraphQL/core/pages/queries.ts
2371
+ var DEFAULT_FIRST2 = 10;
2372
+ var BATCH_FIRST2 = 100;
2373
+ var PAGE_FIELDS = `
2374
+ id
2375
+ databaseId
2376
+ slug
2377
+ title
2378
+ content
2379
+ date
2380
+ modified
2381
+ status
2382
+ uri
2383
+ featuredImage {
2384
+ node {
2385
+ sourceUrl
2386
+ altText
2387
+ mediaDetails { width height }
2388
+ }
2389
+ }
2390
+ `;
2391
+ var GQL_GET_PAGES = `
2392
+ query GetPages($first: Int, $after: String) {
2393
+ pages(first: $first, after: $after) {
2394
+ nodes { ${PAGE_FIELDS} }
2395
+ pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
2396
+ }
2397
+ }
2398
+ `;
2399
+ var GQL_GET_PAGE_BY_SLUG = `
2400
+ query GetPageBySlug($uri: ID!) {
2401
+ page(id: $uri, idType: URI) { ${PAGE_FIELDS} }
2402
+ }
2403
+ `;
2404
+ var GQL_GET_PAGE_BY_URI = `
2405
+ query GetPageByUri($uri: ID!) {
2406
+ page(id: $uri, idType: URI) { ${PAGE_FIELDS} }
2407
+ }
2408
+ `;
2409
+ var GQL_GET_ALL_PAGE_URIS = `
2410
+ query GetAllPageUris($first: Int, $after: String) {
2411
+ pages(first: $first, after: $after) {
2412
+ nodes { uri }
2413
+ pageInfo { hasNextPage endCursor }
2414
+ }
2415
+ }
2416
+ `;
2417
+ function createPagesQueries2(fetcher) {
2418
+ const { gqlFetch, gqlFetchGraceful } = fetcher;
2419
+ async function getPages(first = DEFAULT_FIRST2, after) {
2420
+ const data = await gqlFetchGraceful(
2421
+ GQL_GET_PAGES,
2422
+ { pages: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
2423
+ { first, after },
2424
+ ["wpgraphql", "gql-pages"]
2425
+ );
2426
+ return data.pages;
2427
+ }
2428
+ async function getPageBySlug(slug) {
2429
+ const data = await gqlFetchGraceful(
2430
+ GQL_GET_PAGE_BY_SLUG,
2431
+ { page: null },
2432
+ { uri: `/${slug}/` },
2433
+ ["wpgraphql", "gql-pages", `gql-page-${slug}`]
2434
+ );
2435
+ return data.page;
2436
+ }
2437
+ async function getPageByUri(uri) {
2438
+ const data = await gqlFetchGraceful(
2439
+ GQL_GET_PAGE_BY_URI,
2440
+ { page: null },
2441
+ { uri },
2442
+ ["wpgraphql", "gql-pages", `gql-page-uri-${uri.replace(/\//g, "-")}`]
2443
+ );
2444
+ return data.page;
2445
+ }
2446
+ async function getAllPageUris() {
2447
+ try {
2448
+ const all = [];
2449
+ let after = void 0;
2450
+ let hasNextPage = true;
2451
+ while (hasNextPage) {
2452
+ const data = await gqlFetch(GQL_GET_ALL_PAGE_URIS, { first: BATCH_FIRST2, after }, ["wpgraphql"]);
2453
+ all.push(...data.pages.nodes);
2454
+ hasNextPage = data.pages.pageInfo.hasNextPage;
2455
+ after = data.pages.pageInfo.endCursor;
2456
+ }
2457
+ return all;
2458
+ } catch {
2459
+ console.warn("WPGraphQL unavailable, skipping static generation for pages");
2460
+ return [];
2461
+ }
2462
+ }
2463
+ return { getPages, getPageBySlug, getPageByUri, getAllPageUris };
2464
+ }
2465
+
2466
+ // src/integrations/wpGraphQL/core/categories/queries.ts
2467
+ var DEFAULT_FIRST3 = 100;
2468
+ var CATEGORY_FIELDS = `
2469
+ id
2470
+ databaseId
2471
+ name
2472
+ slug
2473
+ description
2474
+ count
2475
+ uri
2476
+ parent {
2477
+ node { databaseId name slug }
2478
+ }
2479
+ `;
2480
+ var GQL_GET_CATEGORIES = `
2481
+ query GetCategories($first: Int, $after: String) {
2482
+ categories(first: $first, after: $after) {
2483
+ nodes { ${CATEGORY_FIELDS} }
2484
+ pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
2485
+ }
2486
+ }
2487
+ `;
2488
+ var GQL_GET_CATEGORY_BY_SLUG = `
2489
+ query GetCategoryBySlug($slug: ID!) {
2490
+ category(id: $slug, idType: SLUG) { ${CATEGORY_FIELDS} }
2491
+ }
2492
+ `;
2493
+ var GQL_GET_CATEGORY_BY_DATABASE_ID = `
2494
+ query GetCategoryByDatabaseId($id: ID!) {
2495
+ category(id: $id, idType: DATABASE_ID) { ${CATEGORY_FIELDS} }
2496
+ }
2497
+ `;
2498
+ function createCategoriesQueries3(fetcher) {
2499
+ const { gqlFetchGraceful } = fetcher;
2500
+ async function getCategories(first = DEFAULT_FIRST3, after) {
2501
+ const data = await gqlFetchGraceful(
2502
+ GQL_GET_CATEGORIES,
2503
+ { categories: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
2504
+ { first, after },
2505
+ ["wpgraphql", "gql-categories"]
2506
+ );
2507
+ return data.categories;
2508
+ }
2509
+ async function getCategoryBySlug(slug) {
2510
+ const data = await gqlFetchGraceful(
2511
+ GQL_GET_CATEGORY_BY_SLUG,
2512
+ { category: null },
2513
+ { slug },
2514
+ ["wpgraphql", "gql-categories", `gql-category-${slug}`]
2515
+ );
2516
+ return data.category;
2517
+ }
2518
+ async function getCategoryByDatabaseId(id) {
2519
+ const data = await gqlFetchGraceful(
2520
+ GQL_GET_CATEGORY_BY_DATABASE_ID,
2521
+ { category: null },
2522
+ { id: String(id) },
2523
+ ["wpgraphql", "gql-categories", `gql-category-id-${id}`]
2524
+ );
2525
+ return data.category;
2526
+ }
2527
+ return { getCategories, getCategoryBySlug, getCategoryByDatabaseId };
2528
+ }
2529
+
2530
+ // src/integrations/wpGraphQL/core/tags/queries.ts
2531
+ var DEFAULT_FIRST4 = 100;
2532
+ var TAG_FIELDS = `
2533
+ id
2534
+ databaseId
2535
+ name
2536
+ slug
2537
+ description
2538
+ count
2539
+ uri
2540
+ `;
2541
+ var GQL_GET_TAGS = `
2542
+ query GetTags($first: Int, $after: String) {
2543
+ tags(first: $first, after: $after) {
2544
+ nodes { ${TAG_FIELDS} }
2545
+ pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
2546
+ }
2547
+ }
2548
+ `;
2549
+ var GQL_GET_TAG_BY_SLUG = `
2550
+ query GetTagBySlug($slug: ID!) {
2551
+ tag(id: $slug, idType: SLUG) { ${TAG_FIELDS} }
2552
+ }
2553
+ `;
2554
+ function createTagsQueries3(fetcher) {
2555
+ const { gqlFetchGraceful } = fetcher;
2556
+ async function getTags(first = DEFAULT_FIRST4, after) {
2557
+ const data = await gqlFetchGraceful(
2558
+ GQL_GET_TAGS,
2559
+ { tags: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
2560
+ { first, after },
2561
+ ["wpgraphql", "gql-tags"]
2562
+ );
2563
+ return data.tags;
2564
+ }
2565
+ async function getTagBySlug(slug) {
2566
+ const data = await gqlFetchGraceful(
2567
+ GQL_GET_TAG_BY_SLUG,
2568
+ { tag: null },
2569
+ { slug },
2570
+ ["wpgraphql", "gql-tags", `gql-tag-${slug}`]
2571
+ );
2572
+ return data.tag;
2573
+ }
2574
+ return { getTags, getTagBySlug };
2575
+ }
2576
+
2577
+ // src/integrations/wpGraphQL/core/authors/queries.ts
2578
+ var DEFAULT_FIRST5 = 100;
2579
+ var AUTHOR_FIELDS = `
2580
+ id
2581
+ databaseId
2582
+ name
2583
+ slug
2584
+ description
2585
+ email
2586
+ uri
2587
+ avatar { url width height }
2588
+ `;
2589
+ var GQL_GET_AUTHORS = `
2590
+ query GetAuthors($first: Int, $after: String) {
2591
+ users(first: $first, after: $after) {
2592
+ nodes { ${AUTHOR_FIELDS} }
2593
+ pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
2594
+ }
2595
+ }
2596
+ `;
2597
+ var GQL_GET_AUTHOR_BY_SLUG = `
2598
+ query GetAuthorBySlug($slug: String!) {
2599
+ users(where: { login: $slug }) {
2600
+ nodes { ${AUTHOR_FIELDS} }
2601
+ }
2602
+ }
2603
+ `;
2604
+ function createAuthorsQueries2(fetcher) {
2605
+ const { gqlFetchGraceful } = fetcher;
2606
+ async function getAuthors(first = DEFAULT_FIRST5, after) {
2607
+ const data = await gqlFetchGraceful(
2608
+ GQL_GET_AUTHORS,
2609
+ { users: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
2610
+ { first, after },
2611
+ ["wpgraphql", "gql-authors"]
2612
+ );
2613
+ return data.users;
2614
+ }
2615
+ async function getAuthorBySlug(slug) {
2616
+ const data = await gqlFetchGraceful(
2617
+ GQL_GET_AUTHOR_BY_SLUG,
2618
+ { users: { nodes: [] } },
2619
+ { slug },
2620
+ ["wpgraphql", "gql-authors", `gql-author-${slug}`]
2621
+ );
2622
+ return data.users.nodes[0] ?? null;
2623
+ }
2624
+ return { getAuthors, getAuthorBySlug };
2625
+ }
2626
+
2627
+ // src/integrations/wpGraphQL/core/menus/queries.ts
2628
+ var MENU_ITEM_FIELDS = `
2629
+ id
2630
+ databaseId
2631
+ label
2632
+ url
2633
+ parentId
2634
+ order
2635
+ target
2636
+ cssClasses
2637
+ description
2638
+ connectedNode {
2639
+ node {
2640
+ __typename
2641
+ ... on Page { id databaseId slug }
2642
+ ... on Post { id databaseId slug }
2643
+ ... on Category { id databaseId slug }
2644
+ ... on Tag { id databaseId slug }
2645
+ }
2646
+ }
2647
+ `;
2648
+ var MENU_FIELDS = `
2649
+ id
2650
+ databaseId
2651
+ name
2652
+ slug
2653
+ locations
2654
+ menuItems(first: 100) {
2655
+ nodes { ${MENU_ITEM_FIELDS} }
2656
+ }
2657
+ `;
2658
+ var GQL_GET_MENUS = `
2659
+ query GetMenus {
2660
+ menus(first: 100) {
2661
+ nodes { ${MENU_FIELDS} }
2662
+ }
2663
+ }
2664
+ `;
2665
+ var GQL_GET_MENU_BY_ID = `
2666
+ query GetMenuById($id: ID!) {
2667
+ menu(id: $id, idType: DATABASE_ID) { ${MENU_FIELDS} }
2668
+ }
2669
+ `;
2670
+ var GQL_GET_MENU_BY_SLUG = `
2671
+ query GetMenuBySlug($id: ID!) {
2672
+ menu(id: $id, idType: SLUG) { ${MENU_FIELDS} }
2673
+ }
2674
+ `;
2675
+ var GQL_GET_MENUS_BY_LOCATION = `
2676
+ query GetMenusByLocation($location: MenuLocationEnum!) {
2677
+ menus(where: { location: $location }, first: 1) {
2678
+ nodes { ${MENU_FIELDS} }
2679
+ }
2680
+ }
2681
+ `;
2682
+ function createMenusQueries2(fetcher) {
2683
+ const { gqlFetch, gqlFetchGraceful } = fetcher;
2684
+ async function getMenus() {
2685
+ const data = await gqlFetchGraceful(
2686
+ GQL_GET_MENUS,
2687
+ { menus: { nodes: [] } },
2688
+ void 0,
2689
+ ["wpgraphql", "gql-menus"]
2690
+ );
2691
+ return data.menus.nodes;
2692
+ }
2693
+ async function getMenuById(id) {
2694
+ const data = await gqlFetchGraceful(
2695
+ GQL_GET_MENU_BY_ID,
2696
+ { menu: null },
2697
+ { id: String(id) },
2698
+ ["wpgraphql", "gql-menus", `gql-menu-${id}`]
2699
+ );
2700
+ return data.menu;
2701
+ }
2702
+ async function getMenuBySlug(slug) {
2703
+ const data = await gqlFetchGraceful(
2704
+ GQL_GET_MENU_BY_SLUG,
2705
+ { menu: null },
2706
+ { id: slug },
2707
+ ["wpgraphql", "gql-menus", `gql-menu-${slug}`]
2708
+ );
2709
+ return data.menu;
2710
+ }
2711
+ async function getMenuByLocation(location) {
2712
+ const data = await gqlFetch(
2713
+ GQL_GET_MENUS_BY_LOCATION,
2714
+ { location: location.toUpperCase() },
2715
+ ["wpgraphql", "gql-menus", `gql-menu-location-${location}`]
2716
+ );
2717
+ return data.menus.nodes[0] ?? null;
2718
+ }
2719
+ async function getMenuItems(menuSlug) {
2720
+ const menu = await getMenuBySlug(menuSlug);
2721
+ return menu?.menuItems?.nodes ?? [];
2722
+ }
2723
+ return {
2724
+ getMenus,
2725
+ getMenuById,
2726
+ getMenuBySlug,
2727
+ getMenuByLocation,
2728
+ getMenuItems
2729
+ };
2730
+ }
2731
+
2732
+ // src/integrations/wpGraphQL/core/comments/queries.ts
2733
+ var COMMENT_AUTHOR_FIELDS = `
2734
+ name
2735
+ url
2736
+ avatar { url width height }
2737
+ `;
2738
+ var COMMENT_FIELDS = `
2739
+ id
2740
+ databaseId
2741
+ content(format: RENDERED)
2742
+ date
2743
+ parentId
2744
+ status
2745
+ author { node { ${COMMENT_AUTHOR_FIELDS} } }
2746
+ `;
2747
+ var GQL_GET_COMMENTS_BY_POST = `
2748
+ query GetCommentsByPost($contentId: ID!, $first: Int, $after: String) {
2749
+ comments(
2750
+ first: $first
2751
+ after: $after
2752
+ where: { contentId: $contentId, status: "approve", parent: 0 }
2753
+ ) {
2754
+ nodes {
2755
+ ${COMMENT_FIELDS}
2756
+ replies(first: 100) {
2757
+ nodes { ${COMMENT_FIELDS} }
2758
+ }
2759
+ }
2760
+ pageInfo { hasNextPage endCursor }
2761
+ }
2762
+ }
2763
+ `;
2764
+ var GQL_GET_ALL_COMMENTS_BY_POST = `
2765
+ query GetAllCommentsByPost($contentId: ID!) {
2766
+ comments(
2767
+ first: 100
2768
+ where: { contentId: $contentId, status: "approve" }
2769
+ ) {
2770
+ nodes { ${COMMENT_FIELDS} }
2771
+ }
2772
+ }
2773
+ `;
2774
+ var GQL_GET_COMMENT_BY_ID = `
2775
+ query GetCommentById($id: ID!) {
2776
+ comment(id: $id, idType: DATABASE_ID) { ${COMMENT_FIELDS} }
2777
+ }
2778
+ `;
2779
+ function createCommentsQueries2(fetcher) {
2780
+ const { gqlFetchGraceful } = fetcher;
2781
+ async function getCommentsByPostId(postId, first = 10, after) {
2782
+ const data = await gqlFetchGraceful(
2783
+ GQL_GET_COMMENTS_BY_POST,
2784
+ { comments: { nodes: [], pageInfo: { hasNextPage: false } } },
2785
+ { contentId: String(postId), first, after },
2786
+ ["wpgraphql", "gql-comments", `gql-comments-post-${postId}`]
2787
+ );
2788
+ return data.comments;
2789
+ }
2790
+ async function getAllCommentsByPostId(postId) {
2791
+ const data = await gqlFetchGraceful(
2792
+ GQL_GET_ALL_COMMENTS_BY_POST,
2793
+ { comments: { nodes: [] } },
2794
+ { contentId: String(postId) },
2795
+ ["wpgraphql", "gql-comments", `gql-comments-post-${postId}`]
2796
+ );
2797
+ return data.comments.nodes;
2798
+ }
2799
+ async function getCommentById(id) {
2800
+ const data = await gqlFetchGraceful(
2801
+ GQL_GET_COMMENT_BY_ID,
2802
+ { comment: null },
2803
+ { id: String(id) },
2804
+ ["wpgraphql", "gql-comments", `gql-comment-${id}`]
2805
+ );
2806
+ return data.comment;
2807
+ }
2808
+ return {
2809
+ getCommentsByPostId,
2810
+ getAllCommentsByPostId,
2811
+ getCommentById
2812
+ };
2813
+ }
2814
+
2815
+ // src/integrations/wpGraphQL/core/media/queries.ts
2816
+ var DEFAULT_FIRST6 = 10;
2817
+ var MEDIA_FIELDS = `
2818
+ id
2819
+ databaseId
2820
+ slug
2821
+ title
2822
+ date
2823
+ sourceUrl
2824
+ altText
2825
+ caption
2826
+ description
2827
+ mediaType
2828
+ mimeType
2829
+ uri
2830
+ mediaDetails {
2831
+ width
2832
+ height
2833
+ file
2834
+ sizes { name width height mimeType sourceUrl }
2835
+ }
2836
+ `;
2837
+ var GQL_GET_MEDIA_ITEMS = `
2838
+ query GetMediaItems($first: Int, $after: String) {
2839
+ mediaItems(first: $first, after: $after) {
2840
+ nodes { ${MEDIA_FIELDS} }
2841
+ pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
2842
+ }
2843
+ }
2844
+ `;
2845
+ var GQL_GET_MEDIA_ITEM_BY_ID = `
2846
+ query GetMediaItemById($id: ID!) {
2847
+ mediaItem(id: $id, idType: DATABASE_ID) { ${MEDIA_FIELDS} }
2848
+ }
2849
+ `;
2850
+ var GQL_GET_MEDIA_ITEM_BY_SLUG = `
2851
+ query GetMediaItemBySlug($id: ID!) {
2852
+ mediaItem(id: $id, idType: SLUG) { ${MEDIA_FIELDS} }
2853
+ }
2854
+ `;
2855
+ function createMediaQueries2(fetcher) {
2856
+ const { gqlFetchGraceful } = fetcher;
2857
+ async function getMediaItems(first = DEFAULT_FIRST6, after) {
2858
+ const data = await gqlFetchGraceful(
2859
+ GQL_GET_MEDIA_ITEMS,
2860
+ { mediaItems: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
2861
+ { first, after },
2862
+ ["wpgraphql", "gql-media"]
2863
+ );
2864
+ return data.mediaItems;
2865
+ }
2866
+ async function getMediaItemById(id) {
2867
+ const data = await gqlFetchGraceful(
2868
+ GQL_GET_MEDIA_ITEM_BY_ID,
2869
+ { mediaItem: null },
2870
+ { id: String(id) },
2871
+ ["wpgraphql", "gql-media", `gql-media-${id}`]
2872
+ );
2873
+ return data.mediaItem;
2874
+ }
2875
+ async function getMediaItemBySlug(slug) {
2876
+ const data = await gqlFetchGraceful(
2877
+ GQL_GET_MEDIA_ITEM_BY_SLUG,
2878
+ { mediaItem: null },
2879
+ { id: slug },
2880
+ ["wpgraphql", "gql-media", `gql-media-${slug}`]
2881
+ );
2882
+ return data.mediaItem;
2883
+ }
2884
+ return { getMediaItems, getMediaItemById, getMediaItemBySlug };
2885
+ }
2886
+
2887
+ // src/integrations/wpGraphQL/core/mutations/posts/mutations.ts
2888
+ var MUTATED_POST_FIELDS = `
2889
+ id
2890
+ databaseId
2891
+ slug
2892
+ title
2893
+ status
2894
+ `;
2895
+ var GQL_CREATE_POST = `
2896
+ mutation CreatePost($input: CreatePostInput!) {
2897
+ createPost(input: $input) {
2898
+ post { ${MUTATED_POST_FIELDS} }
2899
+ }
2900
+ }
2901
+ `;
2902
+ var GQL_UPDATE_POST = `
2903
+ mutation UpdatePost($input: UpdatePostInput!) {
2904
+ updatePost(input: $input) {
2905
+ post { ${MUTATED_POST_FIELDS} }
2906
+ }
2907
+ }
2908
+ `;
2909
+ var GQL_DELETE_POST = `
2910
+ mutation DeletePost($input: DeletePostInput!) {
2911
+ deletePost(input: $input) {
2912
+ deletedId
2913
+ post { ${MUTATED_POST_FIELDS} }
2914
+ }
2915
+ }
2916
+ `;
2917
+ function createPostsMutations2(fetcher) {
2918
+ const { gqlMutate } = fetcher;
2919
+ async function createPost(input, authToken) {
2920
+ const data = await gqlMutate(
2921
+ GQL_CREATE_POST,
2922
+ { input },
2923
+ authToken
2924
+ );
2925
+ return data.createPost.post;
2926
+ }
2927
+ async function updatePost(input, authToken) {
2928
+ const data = await gqlMutate(
2929
+ GQL_UPDATE_POST,
2930
+ { input },
2931
+ authToken
2932
+ );
2933
+ return data.updatePost.post;
2934
+ }
2935
+ async function deletePost(id, authToken, forceDelete = false) {
2936
+ const data = await gqlMutate(
2937
+ GQL_DELETE_POST,
2938
+ { input: { id, forceDelete } },
2939
+ authToken
2940
+ );
2941
+ return data.deletePost;
2942
+ }
2943
+ return { createPost, updatePost, deletePost };
2944
+ }
2945
+
2946
+ // src/integrations/wpGraphQL/core/mutations/comments/mutations.ts
2947
+ var MUTATED_COMMENT_FIELDS = `
2948
+ id
2949
+ databaseId
2950
+ content(format: RENDERED)
2951
+ date
2952
+ status
2953
+ parentId
2954
+ author { node { name url } }
2955
+ `;
2956
+ var GQL_CREATE_COMMENT = `
2957
+ mutation CreateComment($input: CreateCommentInput!) {
2958
+ createComment(input: $input) {
2959
+ success
2960
+ comment { ${MUTATED_COMMENT_FIELDS} }
2961
+ }
2962
+ }
2963
+ `;
2964
+ var GQL_UPDATE_COMMENT = `
2965
+ mutation UpdateComment($input: UpdateCommentInput!) {
2966
+ updateComment(input: $input) {
2967
+ comment { ${MUTATED_COMMENT_FIELDS} }
2968
+ }
2969
+ }
2970
+ `;
2971
+ var GQL_DELETE_COMMENT = `
2972
+ mutation DeleteComment($input: DeleteCommentInput!) {
2973
+ deleteComment(input: $input) {
2974
+ deletedId
2975
+ comment { ${MUTATED_COMMENT_FIELDS} }
2976
+ }
2977
+ }
2978
+ `;
2979
+ function createCommentsMutations2(fetcher) {
2980
+ const { gqlMutate } = fetcher;
2981
+ async function createComment(input, authToken) {
2982
+ const gqlInput = {
2983
+ commentOn: input.postId,
2984
+ content: input.content
2985
+ };
2986
+ if (input.authorName) gqlInput["author"] = input.authorName;
2987
+ if (input.authorEmail) gqlInput["authorEmail"] = input.authorEmail;
2988
+ if (input.authorUrl) gqlInput["authorUrl"] = input.authorUrl;
2989
+ if (input.parentId) gqlInput["parent"] = input.parentId;
2990
+ const data = await gqlMutate(
2991
+ GQL_CREATE_COMMENT,
2992
+ { input: gqlInput },
2993
+ authToken
2994
+ );
2995
+ return data.createComment;
2996
+ }
2997
+ async function updateComment(input, authToken) {
2998
+ const data = await gqlMutate(
2999
+ GQL_UPDATE_COMMENT,
3000
+ { input },
3001
+ authToken
3002
+ );
3003
+ return data.updateComment.comment;
3004
+ }
3005
+ async function deleteComment(id, authToken, forceDelete = false) {
3006
+ const data = await gqlMutate(
3007
+ GQL_DELETE_COMMENT,
3008
+ { input: { id, forceDelete } },
3009
+ authToken
3010
+ );
3011
+ return data.deleteComment;
3012
+ }
3013
+ return { createComment, updateComment, deleteComment };
3014
+ }
3015
+
3016
+ // src/integrations/wpGraphQL/core/mutations/pages/mutations.ts
3017
+ var MUTATED_PAGE_FIELDS = `
3018
+ id
3019
+ databaseId
3020
+ slug
3021
+ title
3022
+ status
3023
+ uri
3024
+ `;
3025
+ var GQL_CREATE_PAGE = `
3026
+ mutation CreatePage($input: CreatePageInput!) {
3027
+ createPage(input: $input) {
3028
+ page { ${MUTATED_PAGE_FIELDS} }
3029
+ }
3030
+ }
3031
+ `;
3032
+ var GQL_UPDATE_PAGE = `
3033
+ mutation UpdatePage($input: UpdatePageInput!) {
3034
+ updatePage(input: $input) {
3035
+ page { ${MUTATED_PAGE_FIELDS} }
3036
+ }
3037
+ }
3038
+ `;
3039
+ var GQL_DELETE_PAGE = `
3040
+ mutation DeletePage($input: DeletePageInput!) {
3041
+ deletePage(input: $input) {
3042
+ deletedId
3043
+ page { ${MUTATED_PAGE_FIELDS} }
3044
+ }
3045
+ }
3046
+ `;
3047
+ function createPagesMutations2(fetcher) {
3048
+ const { gqlMutate } = fetcher;
3049
+ async function createPage(input, authToken) {
3050
+ const data = await gqlMutate(
3051
+ GQL_CREATE_PAGE,
3052
+ { input },
3053
+ authToken
3054
+ );
3055
+ return data.createPage.page;
3056
+ }
3057
+ async function updatePage(input, authToken) {
3058
+ const data = await gqlMutate(
3059
+ GQL_UPDATE_PAGE,
3060
+ { input },
3061
+ authToken
3062
+ );
3063
+ return data.updatePage.page;
3064
+ }
3065
+ async function deletePage(id, authToken, forceDelete = false) {
3066
+ const data = await gqlMutate(
3067
+ GQL_DELETE_PAGE,
3068
+ { input: { id, forceDelete } },
3069
+ authToken
3070
+ );
3071
+ return data.deletePage;
3072
+ }
3073
+ return { createPage, updatePage, deletePage };
3074
+ }
3075
+
3076
+ // src/integrations/wpGraphQL/core/mutations/categories/mutations.ts
3077
+ var MUTATED_CATEGORY_FIELDS = `
3078
+ id
3079
+ databaseId
3080
+ name
3081
+ slug
3082
+ `;
3083
+ var GQL_CREATE_CATEGORY = `
3084
+ mutation CreateCategory($input: CreateCategoryInput!) {
3085
+ createCategory(input: $input) {
3086
+ category { ${MUTATED_CATEGORY_FIELDS} }
3087
+ }
3088
+ }
3089
+ `;
3090
+ var GQL_UPDATE_CATEGORY = `
3091
+ mutation UpdateCategory($input: UpdateCategoryInput!) {
3092
+ updateCategory(input: $input) {
3093
+ category { ${MUTATED_CATEGORY_FIELDS} }
3094
+ }
3095
+ }
3096
+ `;
3097
+ var GQL_DELETE_CATEGORY = `
3098
+ mutation DeleteCategory($input: DeleteCategoryInput!) {
3099
+ deleteCategory(input: $input) {
3100
+ deletedId
3101
+ category { ${MUTATED_CATEGORY_FIELDS} }
3102
+ }
3103
+ }
3104
+ `;
3105
+ function createCategoriesMutations3(fetcher) {
3106
+ const { gqlMutate } = fetcher;
3107
+ async function createCategory(input, authToken) {
3108
+ const data = await gqlMutate(
3109
+ GQL_CREATE_CATEGORY,
3110
+ { input },
3111
+ authToken
3112
+ );
3113
+ return data.createCategory.category;
3114
+ }
3115
+ async function updateCategory(input, authToken) {
3116
+ const data = await gqlMutate(
3117
+ GQL_UPDATE_CATEGORY,
3118
+ { input },
3119
+ authToken
3120
+ );
3121
+ return data.updateCategory.category;
3122
+ }
3123
+ async function deleteCategory(id, authToken) {
3124
+ const data = await gqlMutate(
3125
+ GQL_DELETE_CATEGORY,
3126
+ { input: { id } },
3127
+ authToken
3128
+ );
3129
+ return data.deleteCategory;
3130
+ }
3131
+ return { createCategory, updateCategory, deleteCategory };
3132
+ }
3133
+
3134
+ // src/integrations/wpGraphQL/core/mutations/tags/mutations.ts
3135
+ var MUTATED_TAG_FIELDS = `
3136
+ id
3137
+ databaseId
3138
+ name
3139
+ slug
3140
+ `;
3141
+ var GQL_CREATE_TAG = `
3142
+ mutation CreateTag($input: CreateTagInput!) {
3143
+ createTag(input: $input) {
3144
+ tag { ${MUTATED_TAG_FIELDS} }
3145
+ }
3146
+ }
3147
+ `;
3148
+ var GQL_UPDATE_TAG = `
3149
+ mutation UpdateTag($input: UpdateTagInput!) {
3150
+ updateTag(input: $input) {
3151
+ tag { ${MUTATED_TAG_FIELDS} }
3152
+ }
3153
+ }
3154
+ `;
3155
+ var GQL_DELETE_TAG = `
3156
+ mutation DeleteTag($input: DeleteTagInput!) {
3157
+ deleteTag(input: $input) {
3158
+ deletedId
3159
+ tag { ${MUTATED_TAG_FIELDS} }
3160
+ }
3161
+ }
3162
+ `;
3163
+ function createTagsMutations3(fetcher) {
3164
+ const { gqlMutate } = fetcher;
3165
+ async function createTag(input, authToken) {
3166
+ const data = await gqlMutate(
3167
+ GQL_CREATE_TAG,
3168
+ { input },
3169
+ authToken
3170
+ );
3171
+ return data.createTag.tag;
3172
+ }
3173
+ async function updateTag(input, authToken) {
3174
+ const data = await gqlMutate(
3175
+ GQL_UPDATE_TAG,
3176
+ { input },
3177
+ authToken
3178
+ );
3179
+ return data.updateTag.tag;
3180
+ }
3181
+ async function deleteTag(id, authToken) {
3182
+ const data = await gqlMutate(
3183
+ GQL_DELETE_TAG,
3184
+ { input: { id } },
3185
+ authToken
3186
+ );
3187
+ return data.deleteTag;
3188
+ }
3189
+ return { createTag, updateTag, deleteTag };
3190
+ }
3191
+
3192
+ // src/integrations/wpGraphQL/core/mutations/authors/mutations.ts
3193
+ var MUTATED_USER_FIELDS = `
3194
+ id
3195
+ databaseId
3196
+ name
3197
+ slug
3198
+ email
3199
+ `;
3200
+ var GQL_REGISTER_USER = `
3201
+ mutation RegisterUser($input: RegisterUserInput!) {
3202
+ registerUser(input: $input) {
3203
+ user { ${MUTATED_USER_FIELDS} }
3204
+ }
3205
+ }
3206
+ `;
3207
+ var GQL_UPDATE_USER = `
3208
+ mutation UpdateUser($input: UpdateUserInput!) {
3209
+ updateUser(input: $input) {
3210
+ user { ${MUTATED_USER_FIELDS} }
3211
+ }
3212
+ }
3213
+ `;
3214
+ var GQL_DELETE_USER = `
3215
+ mutation DeleteUser($input: DeleteUserInput!) {
3216
+ deleteUser(input: $input) {
3217
+ deletedId
3218
+ user { ${MUTATED_USER_FIELDS} }
3219
+ }
3220
+ }
3221
+ `;
3222
+ function createAuthorsMutations2(fetcher) {
3223
+ const { gqlMutate } = fetcher;
3224
+ async function registerUser(input, authToken) {
3225
+ const data = await gqlMutate(
3226
+ GQL_REGISTER_USER,
3227
+ { input },
3228
+ authToken
3229
+ );
3230
+ return data.registerUser.user;
3231
+ }
3232
+ async function updateUser(input, authToken) {
3233
+ const data = await gqlMutate(
3234
+ GQL_UPDATE_USER,
3235
+ { input },
3236
+ authToken
3237
+ );
3238
+ return data.updateUser.user;
3239
+ }
3240
+ async function deleteUser(id, authToken, reassignPosts) {
3241
+ const input = { id };
3242
+ if (reassignPosts) input["reassignId"] = reassignPosts;
3243
+ const data = await gqlMutate(
3244
+ GQL_DELETE_USER,
3245
+ { input },
3246
+ authToken
3247
+ );
3248
+ return data.deleteUser;
3249
+ }
3250
+ return { registerUser, updateUser, deleteUser };
3251
+ }
3252
+
3253
+ // src/integrations/wpGraphQL/core/mutations/media/mutations.ts
3254
+ var MUTATED_MEDIA_FIELDS = `
3255
+ id
3256
+ databaseId
3257
+ slug
3258
+ title
3259
+ sourceUrl
3260
+ altText
3261
+ `;
3262
+ var GQL_CREATE_MEDIA_ITEM = `
3263
+ mutation CreateMediaItem($input: CreateMediaItemInput!) {
3264
+ createMediaItem(input: $input) {
3265
+ mediaItem { ${MUTATED_MEDIA_FIELDS} }
3266
+ }
3267
+ }
3268
+ `;
3269
+ var GQL_UPDATE_MEDIA_ITEM = `
3270
+ mutation UpdateMediaItem($input: UpdateMediaItemInput!) {
3271
+ updateMediaItem(input: $input) {
3272
+ mediaItem { ${MUTATED_MEDIA_FIELDS} }
3273
+ }
3274
+ }
3275
+ `;
3276
+ var GQL_DELETE_MEDIA_ITEM = `
3277
+ mutation DeleteMediaItem($input: DeleteMediaItemInput!) {
3278
+ deleteMediaItem(input: $input) {
3279
+ deletedId
3280
+ mediaItem { ${MUTATED_MEDIA_FIELDS} }
3281
+ }
3282
+ }
3283
+ `;
3284
+ function createMediaMutations2(fetcher) {
3285
+ const { gqlMutate } = fetcher;
3286
+ async function createMediaItem(input, authToken) {
3287
+ const data = await gqlMutate(
3288
+ GQL_CREATE_MEDIA_ITEM,
3289
+ { input },
3290
+ authToken
3291
+ );
3292
+ return data.createMediaItem.mediaItem;
3293
+ }
3294
+ async function updateMediaItem(input, authToken) {
3295
+ const data = await gqlMutate(
3296
+ GQL_UPDATE_MEDIA_ITEM,
3297
+ { input },
3298
+ authToken
3299
+ );
3300
+ return data.updateMediaItem.mediaItem;
3301
+ }
3302
+ async function deleteMediaItem(id, authToken, forceDelete = true) {
3303
+ const data = await gqlMutate(
3304
+ GQL_DELETE_MEDIA_ITEM,
3305
+ { input: { id, forceDelete } },
3306
+ authToken
3307
+ );
3308
+ return data.deleteMediaItem;
3309
+ }
3310
+ return { createMediaItem, updateMediaItem, deleteMediaItem };
3311
+ }
3312
+
3313
+ // src/integrations/wpGraphQL/core/mutations/index.ts
3314
+ function createWPGraphQLMutationsClient(config) {
3315
+ const fetcher = createWPGraphQLFetcher(config);
3316
+ return {
3317
+ ...createPostsMutations2(fetcher),
3318
+ ...createCommentsMutations2(fetcher),
3319
+ ...createPagesMutations2(fetcher),
3320
+ ...createCategoriesMutations3(fetcher),
3321
+ ...createTagsMutations3(fetcher),
3322
+ ...createAuthorsMutations2(fetcher),
3323
+ ...createMediaMutations2(fetcher)
3324
+ };
3325
+ }
3326
+
3327
+ // src/integrations/wpGraphQL/core/index.ts
3328
+ function createWPGraphQLCoreClient(config) {
3329
+ const fetcher = createWPGraphQLFetcher(config);
3330
+ return {
3331
+ ...createPostsQueries2(fetcher),
3332
+ ...createPagesQueries2(fetcher),
3333
+ ...createCategoriesQueries3(fetcher),
3334
+ ...createTagsQueries3(fetcher),
3335
+ ...createAuthorsQueries2(fetcher),
3336
+ ...createMenusQueries2(fetcher),
3337
+ ...createCommentsQueries2(fetcher),
3338
+ ...createMediaQueries2(fetcher)
3339
+ };
3340
+ }
3341
+
3342
+ // src/integrations/wpGraphQL/yoast/queries.ts
3343
+ var SEO_FIELDS = `
3344
+ seo {
3345
+ title
3346
+ metaDesc
3347
+ canonical
3348
+ opengraphTitle
3349
+ opengraphDescription
3350
+ opengraphImage { sourceUrl altText }
3351
+ twitterTitle
3352
+ twitterDescription
3353
+ twitterImage { sourceUrl }
3354
+ schema { raw }
3355
+ }
3356
+ `;
3357
+ var POST_FIELDS_WITH_SEO = `
3358
+ id
3359
+ databaseId
3360
+ slug
3361
+ title
3362
+ content
3363
+ excerpt
3364
+ date
3365
+ modified
3366
+ status
3367
+ uri
3368
+ author {
3369
+ node {
3370
+ databaseId
3371
+ name
3372
+ slug
3373
+ avatar { url }
3374
+ }
3375
+ }
3376
+ featuredImage {
3377
+ node {
3378
+ sourceUrl
3379
+ altText
3380
+ mediaDetails { width height }
3381
+ }
3382
+ }
3383
+ categories {
3384
+ nodes { databaseId name slug }
3385
+ }
3386
+ tags {
3387
+ nodes { databaseId name slug }
3388
+ }
3389
+ ${SEO_FIELDS}
3390
+ `;
3391
+ var PAGE_FIELDS_WITH_SEO = `
3392
+ id
3393
+ databaseId
3394
+ slug
3395
+ title
3396
+ content
3397
+ date
3398
+ modified
3399
+ status
3400
+ uri
3401
+ featuredImage {
3402
+ node {
3403
+ sourceUrl
3404
+ altText
3405
+ mediaDetails { width height }
3406
+ }
3407
+ }
3408
+ ${SEO_FIELDS}
3409
+ `;
3410
+ var GQL_GET_POST_WITH_SEO = `
3411
+ query GetPostWithSEO($slug: ID!) {
3412
+ post(id: $slug, idType: SLUG) { ${POST_FIELDS_WITH_SEO} }
3413
+ }
3414
+ `;
3415
+ var GQL_GET_PAGE_WITH_SEO = `
3416
+ query GetPageWithSEO($slug: ID!) {
3417
+ page(id: $slug, idType: SLUG) { ${PAGE_FIELDS_WITH_SEO} }
3418
+ }
3419
+ `;
3420
+ var GQL_GET_PAGE_WITH_SEO_BY_URI = `
3421
+ query GetPageWithSEOByUri($uri: ID!) {
3422
+ page(id: $uri, idType: URI) { ${PAGE_FIELDS_WITH_SEO} }
3423
+ }
3424
+ `;
3425
+ function createYoastQueries(fetcher) {
3426
+ const { gqlFetchGraceful } = fetcher;
3427
+ async function getPostWithSEO(slug) {
3428
+ const data = await gqlFetchGraceful(
3429
+ GQL_GET_POST_WITH_SEO,
3430
+ { post: null },
3431
+ { slug },
3432
+ ["wpgraphql", "gql-posts", "gql-yoast", `gql-post-${slug}`]
3433
+ );
3434
+ return data.post;
3435
+ }
3436
+ async function getPageWithSEO(slug) {
3437
+ const data = await gqlFetchGraceful(
3438
+ GQL_GET_PAGE_WITH_SEO,
3439
+ { page: null },
3440
+ { slug },
3441
+ ["wpgraphql", "gql-pages", "gql-yoast", `gql-page-${slug}`]
3442
+ );
3443
+ return data.page;
3444
+ }
3445
+ async function getPageWithSEOByUri(uri) {
3446
+ const data = await gqlFetchGraceful(
3447
+ GQL_GET_PAGE_WITH_SEO_BY_URI,
3448
+ { page: null },
3449
+ { uri },
3450
+ ["wpgraphql", "gql-pages", "gql-yoast", `gql-page-uri-${uri.replace(/\//g, "-")}`]
3451
+ );
3452
+ return data.page;
3453
+ }
3454
+ return { getPostWithSEO, getPageWithSEO, getPageWithSEOByUri };
3455
+ }
3456
+
3457
+ // src/integrations/wpGraphQL/acf/helpers.ts
3458
+ var BASE_POST_FIELDS = `
3459
+ id databaseId slug title content excerpt date modified status uri
3460
+ author { node { databaseId name slug avatar { url } } }
3461
+ featuredImage { node { sourceUrl altText mediaDetails { width height } } }
3462
+ categories { nodes { databaseId name slug } }
3463
+ tags { nodes { databaseId name slug } }
3464
+ `;
3465
+ var BASE_PAGE_FIELDS = `
3466
+ id databaseId slug title content date modified status uri
3467
+ featuredImage { node { sourceUrl altText mediaDetails { width height } } }
3468
+ `;
3469
+ function buildACFFragment(fieldGroupName, fields) {
3470
+ return `${fieldGroupName} { ${fields.join(" ")} }`;
3471
+ }
3472
+ function buildPostWithACFQuery(fieldGroupName, fields) {
3473
+ return `
3474
+ query GetPostWithACF($slug: ID!) {
3475
+ post(id: $slug, idType: SLUG) {
3476
+ ${BASE_POST_FIELDS}
3477
+ ${buildACFFragment(fieldGroupName, fields)}
3478
+ }
3479
+ }
3480
+ `;
3481
+ }
3482
+ function buildPageWithACFQuery(fieldGroupName, fields) {
3483
+ return `
3484
+ query GetPageWithACF($slug: ID!) {
3485
+ page(id: $slug, idType: SLUG) {
3486
+ ${BASE_PAGE_FIELDS}
3487
+ ${buildACFFragment(fieldGroupName, fields)}
3488
+ }
3489
+ }
3490
+ `;
3491
+ }
3492
+ function buildPostsWithACFQuery(fieldGroupName, fields) {
3493
+ return `
3494
+ query GetPostsWithACF($first: Int, $after: String) {
3495
+ posts(first: $first, after: $after) {
3496
+ nodes {
3497
+ ${BASE_POST_FIELDS}
3498
+ ${buildACFFragment(fieldGroupName, fields)}
3499
+ }
3500
+ pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
3501
+ }
3502
+ }
3503
+ `;
3504
+ }
3505
+
3506
+ // src/integrations/wpGraphQL/woocommerce/products/queries.ts
3507
+ var DEFAULT_FIRST7 = 10;
3508
+ var BATCH_FIRST3 = 100;
3509
+ var PRODUCT_FIELDS = `
3510
+ id
3511
+ databaseId
3512
+ slug
3513
+ name
3514
+ status
3515
+ description
3516
+ shortDescription
3517
+ type
3518
+ onSale
3519
+ featuredImage { node { sourceUrl altText } }
3520
+ galleryImages { nodes { sourceUrl altText } }
3521
+ productCategories { nodes { databaseId name slug } }
3522
+ productTags { nodes { databaseId name slug } }
3523
+ ... on SimpleProduct {
3524
+ sku
3525
+ price
3526
+ regularPrice
3527
+ salePrice
3528
+ stockStatus
3529
+ stockQuantity
3530
+ manageStock
3531
+ }
3532
+ ... on VariableProduct {
3533
+ price
3534
+ regularPrice
3535
+ salePrice
3536
+ stockStatus
3537
+ stockQuantity
3538
+ manageStock
3539
+ variations {
3540
+ nodes {
3541
+ id
3542
+ databaseId
3543
+ slug
3544
+ sku
3545
+ price
3546
+ regularPrice
3547
+ salePrice
3548
+ onSale
3549
+ stockStatus
3550
+ stockQuantity
3551
+ image { sourceUrl altText }
3552
+ attributes { nodes { name value } }
3553
+ }
3554
+ }
3555
+ }
3556
+ `;
3557
+ var GQL_GET_PRODUCTS = `
3558
+ query GetProducts($first: Int, $after: String, $where: RootQueryToProductConnectionWhereArgs) {
3559
+ products(first: $first, after: $after, where: $where) {
3560
+ nodes { ${PRODUCT_FIELDS} }
3561
+ pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
3562
+ }
3563
+ }
3564
+ `;
3565
+ var GQL_GET_PRODUCT_BY_SLUG = `
3566
+ query GetProductBySlug($slug: ID!) {
3567
+ product(id: $slug, idType: SLUG) { ${PRODUCT_FIELDS} }
3568
+ }
3569
+ `;
3570
+ var GQL_GET_PRODUCT_BY_DATABASE_ID = `
3571
+ query GetProductByDatabaseId($id: ID!) {
3572
+ product(id: $id, idType: DATABASE_ID) { ${PRODUCT_FIELDS} }
3573
+ }
3574
+ `;
3575
+ var GQL_GET_ALL_PRODUCT_SLUGS = `
3576
+ query GetAllProductSlugs($first: Int, $after: String) {
3577
+ products(first: $first, after: $after) {
3578
+ nodes { slug }
3579
+ pageInfo { hasNextPage endCursor }
3580
+ }
3581
+ }
3582
+ `;
3583
+ function createProductsQueries2(fetcher) {
3584
+ const { gqlFetch, gqlFetchGraceful } = fetcher;
3585
+ async function getProducts(first = DEFAULT_FIRST7, after, filter) {
3586
+ const where = {};
3587
+ if (filter?.search) where["search"] = filter.search;
3588
+ if (filter?.onSale !== void 0) where["onSale"] = filter.onSale;
3589
+ if (filter?.featured !== void 0) where["featured"] = filter.featured;
3590
+ if (filter?.stockStatus) where["stockStatus"] = filter.stockStatus;
3591
+ if (filter?.minPrice) where["minPrice"] = filter.minPrice;
3592
+ if (filter?.maxPrice) where["maxPrice"] = filter.maxPrice;
3593
+ if (filter?.categoryId) where["categoryIdIn"] = [filter.categoryId];
3594
+ if (filter?.tagId) where["tagIdIn"] = [filter.tagId];
3595
+ const data = await gqlFetchGraceful(
3596
+ GQL_GET_PRODUCTS,
3597
+ { products: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
3598
+ { first, after, where: Object.keys(where).length > 0 ? where : void 0 },
3599
+ ["wpgraphql", "gql-products"]
3600
+ );
3601
+ return data.products;
3602
+ }
3603
+ async function getProductBySlug(slug) {
3604
+ const data = await gqlFetchGraceful(
3605
+ GQL_GET_PRODUCT_BY_SLUG,
3606
+ { product: null },
3607
+ { slug },
3608
+ ["wpgraphql", "gql-products", `gql-product-${slug}`]
3609
+ );
3610
+ return data.product;
3611
+ }
3612
+ async function getProductByDatabaseId(id) {
3613
+ const data = await gqlFetchGraceful(
3614
+ GQL_GET_PRODUCT_BY_DATABASE_ID,
3615
+ { product: null },
3616
+ { id: String(id) },
3617
+ ["wpgraphql", "gql-products", `gql-product-id-${id}`]
3618
+ );
3619
+ return data.product;
3620
+ }
3621
+ async function getFeaturedProducts(first = DEFAULT_FIRST7) {
3622
+ const connection = await getProducts(first, void 0, { featured: true });
3623
+ return connection.nodes;
3624
+ }
3625
+ async function getOnSaleProducts(first = DEFAULT_FIRST7) {
3626
+ const connection = await getProducts(first, void 0, { onSale: true });
3627
+ return connection.nodes;
3628
+ }
3629
+ async function getAllProductSlugs() {
3630
+ try {
3631
+ const all = [];
3632
+ let after = void 0;
3633
+ let hasNextPage = true;
3634
+ while (hasNextPage) {
3635
+ const data = await gqlFetch(GQL_GET_ALL_PRODUCT_SLUGS, { first: BATCH_FIRST3, after }, ["wpgraphql"]);
3636
+ all.push(...data.products.nodes);
3637
+ hasNextPage = data.products.pageInfo.hasNextPage;
3638
+ after = data.products.pageInfo.endCursor;
3639
+ }
3640
+ return all;
3641
+ } catch {
3642
+ console.warn("WPGraphQL unavailable, skipping static generation for products");
3643
+ return [];
3644
+ }
3645
+ }
3646
+ return {
3647
+ getProducts,
3648
+ getProductBySlug,
3649
+ getProductByDatabaseId,
3650
+ getFeaturedProducts,
3651
+ getOnSaleProducts,
3652
+ getAllProductSlugs
3653
+ };
3654
+ }
3655
+
3656
+ // src/integrations/wpGraphQL/woocommerce/orders/queries.ts
3657
+ var DEFAULT_FIRST8 = 10;
3658
+ var ADDRESS_FIELDS = `
3659
+ firstName lastName address1 address2 city postcode country email phone
3660
+ `;
3661
+ var ORDER_FIELDS = `
3662
+ id
3663
+ databaseId
3664
+ orderNumber
3665
+ status
3666
+ date
3667
+ modified
3668
+ total
3669
+ subtotal
3670
+ totalTax
3671
+ shippingTotal
3672
+ currency
3673
+ billing { ${ADDRESS_FIELDS} }
3674
+ shipping { ${ADDRESS_FIELDS} }
3675
+ lineItems {
3676
+ nodes {
3677
+ productId
3678
+ variationId
3679
+ quantity
3680
+ subtotal
3681
+ total
3682
+ product { node { databaseId name slug } }
3683
+ }
3684
+ }
3685
+ `;
3686
+ var GQL_GET_ORDER = `
3687
+ query GetOrder($id: ID!) {
3688
+ order(id: $id, idType: DATABASE_ID) { ${ORDER_FIELDS} }
3689
+ }
3690
+ `;
3691
+ var GQL_GET_MY_ORDERS = `
3692
+ query GetMyOrders($first: Int, $after: String) {
3693
+ orders(first: $first, after: $after) {
3694
+ nodes { ${ORDER_FIELDS} }
3695
+ pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
3696
+ }
3697
+ }
3698
+ `;
3699
+ function createOrdersQueries2(fetcher) {
3700
+ const { gqlFetchGraceful } = fetcher;
3701
+ async function getOrder(id) {
3702
+ const data = await gqlFetchGraceful(
3703
+ GQL_GET_ORDER,
3704
+ { order: null },
3705
+ { id: String(id) },
3706
+ ["wpgraphql", "gql-orders", `gql-order-${id}`]
3707
+ );
3708
+ return data.order;
3709
+ }
3710
+ async function getMyOrders(first = DEFAULT_FIRST8, after) {
3711
+ const data = await gqlFetchGraceful(
3712
+ GQL_GET_MY_ORDERS,
3713
+ { orders: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
3714
+ { first, after },
3715
+ ["wpgraphql", "gql-orders"]
3716
+ );
3717
+ return data.orders;
3718
+ }
3719
+ return { getOrder, getMyOrders };
3720
+ }
3721
+
3722
+ // src/integrations/wpGraphQL/woocommerce/customers/queries.ts
3723
+ var ADDRESS_FIELDS2 = `
3724
+ firstName lastName address1 address2 city postcode country
3725
+ `;
3726
+ var CUSTOMER_FIELDS = `
3727
+ id
3728
+ databaseId
3729
+ email
3730
+ firstName
3731
+ lastName
3732
+ username
3733
+ billing { ${ADDRESS_FIELDS2} phone }
3734
+ shipping { ${ADDRESS_FIELDS2} }
3735
+ `;
3736
+ var GQL_GET_CUSTOMER = `
3737
+ query GetCustomer {
3738
+ customer { ${CUSTOMER_FIELDS} }
3739
+ }
3740
+ `;
3741
+ var GQL_GET_CUSTOMER_BY_ID = `
3742
+ query GetCustomerById($id: ID!) {
3743
+ customer(customerId: $id) { ${CUSTOMER_FIELDS} }
3744
+ }
3745
+ `;
3746
+ function createCustomersQueries2(fetcher) {
3747
+ const { gqlFetchGraceful } = fetcher;
3748
+ async function getCustomer() {
3749
+ const data = await gqlFetchGraceful(
3750
+ GQL_GET_CUSTOMER,
3751
+ { customer: null },
3752
+ void 0,
3753
+ ["wpgraphql", "gql-customer"]
3754
+ );
3755
+ return data.customer;
3756
+ }
3757
+ async function getCustomerById(id) {
3758
+ const data = await gqlFetchGraceful(
3759
+ GQL_GET_CUSTOMER_BY_ID,
3760
+ { customer: null },
3761
+ { id: String(id) },
3762
+ ["wpgraphql", "gql-customer", `gql-customer-${id}`]
3763
+ );
3764
+ return data.customer;
3765
+ }
3766
+ return { getCustomer, getCustomerById };
3767
+ }
3768
+
3769
+ // src/integrations/wpGraphQL/woocommerce/categories/queries.ts
3770
+ var DEFAULT_FIRST9 = 100;
3771
+ var CATEGORY_FIELDS2 = `
3772
+ id
3773
+ databaseId
3774
+ name
3775
+ slug
3776
+ description
3777
+ count
3778
+ parent { node { id databaseId name slug } }
3779
+ image { sourceUrl altText }
3780
+ `;
3781
+ var GQL_GET_PRODUCT_CATEGORIES = `
3782
+ query GetProductCategories($first: Int, $after: String) {
3783
+ productCategories(first: $first, after: $after) {
3784
+ nodes { ${CATEGORY_FIELDS2} }
3785
+ pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
3786
+ }
3787
+ }
3788
+ `;
3789
+ var GQL_GET_PRODUCT_CATEGORY_BY_SLUG = `
3790
+ query GetProductCategoryBySlug($id: ID!) {
3791
+ productCategory(id: $id, idType: SLUG) { ${CATEGORY_FIELDS2} }
3792
+ }
3793
+ `;
3794
+ var GQL_GET_PRODUCT_CATEGORY_BY_ID = `
3795
+ query GetProductCategoryById($id: ID!) {
3796
+ productCategory(id: $id, idType: DATABASE_ID) { ${CATEGORY_FIELDS2} }
3797
+ }
3798
+ `;
3799
+ function createCategoriesQueries4(fetcher) {
3800
+ const { gqlFetchGraceful } = fetcher;
3801
+ async function getProductCategories(first = DEFAULT_FIRST9, after) {
3802
+ const data = await gqlFetchGraceful(
3803
+ GQL_GET_PRODUCT_CATEGORIES,
3804
+ { productCategories: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
3805
+ { first, after },
3806
+ ["wpgraphql", "gql-product-categories"]
3807
+ );
3808
+ return data.productCategories;
3809
+ }
3810
+ async function getProductCategoryBySlug(slug) {
3811
+ const data = await gqlFetchGraceful(
3812
+ GQL_GET_PRODUCT_CATEGORY_BY_SLUG,
3813
+ { productCategory: null },
3814
+ { id: slug },
3815
+ ["wpgraphql", "gql-product-categories", `gql-product-category-${slug}`]
3816
+ );
3817
+ return data.productCategory;
3818
+ }
3819
+ async function getProductCategoryById(id) {
3820
+ const data = await gqlFetchGraceful(
3821
+ GQL_GET_PRODUCT_CATEGORY_BY_ID,
3822
+ { productCategory: null },
3823
+ { id: String(id) },
3824
+ ["wpgraphql", "gql-product-categories", `gql-product-category-${id}`]
3825
+ );
3826
+ return data.productCategory;
3827
+ }
3828
+ return { getProductCategories, getProductCategoryBySlug, getProductCategoryById };
3829
+ }
3830
+
3831
+ // src/integrations/wpGraphQL/woocommerce/tags/queries.ts
3832
+ var DEFAULT_FIRST10 = 100;
3833
+ var TAG_FIELDS2 = `
3834
+ id
3835
+ databaseId
3836
+ name
3837
+ slug
3838
+ description
3839
+ count
3840
+ `;
3841
+ var GQL_GET_PRODUCT_TAGS = `
3842
+ query GetProductTags($first: Int, $after: String) {
3843
+ productTags(first: $first, after: $after) {
3844
+ nodes { ${TAG_FIELDS2} }
3845
+ pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
3846
+ }
3847
+ }
3848
+ `;
3849
+ var GQL_GET_PRODUCT_TAG_BY_SLUG = `
3850
+ query GetProductTagBySlug($id: ID!) {
3851
+ productTag(id: $id, idType: SLUG) { ${TAG_FIELDS2} }
3852
+ }
3853
+ `;
3854
+ var GQL_GET_PRODUCT_TAG_BY_ID = `
3855
+ query GetProductTagById($id: ID!) {
3856
+ productTag(id: $id, idType: DATABASE_ID) { ${TAG_FIELDS2} }
3857
+ }
3858
+ `;
3859
+ function createTagsQueries4(fetcher) {
3860
+ const { gqlFetchGraceful } = fetcher;
3861
+ async function getProductTags(first = DEFAULT_FIRST10, after) {
3862
+ const data = await gqlFetchGraceful(
3863
+ GQL_GET_PRODUCT_TAGS,
3864
+ { productTags: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
3865
+ { first, after },
3866
+ ["wpgraphql", "gql-product-tags"]
3867
+ );
3868
+ return data.productTags;
3869
+ }
3870
+ async function getProductTagBySlug(slug) {
3871
+ const data = await gqlFetchGraceful(
3872
+ GQL_GET_PRODUCT_TAG_BY_SLUG,
3873
+ { productTag: null },
3874
+ { id: slug },
3875
+ ["wpgraphql", "gql-product-tags", `gql-product-tag-${slug}`]
3876
+ );
3877
+ return data.productTag;
3878
+ }
3879
+ async function getProductTagById(id) {
3880
+ const data = await gqlFetchGraceful(
3881
+ GQL_GET_PRODUCT_TAG_BY_ID,
3882
+ { productTag: null },
3883
+ { id: String(id) },
3884
+ ["wpgraphql", "gql-product-tags", `gql-product-tag-${id}`]
3885
+ );
3886
+ return data.productTag;
3887
+ }
3888
+ return { getProductTags, getProductTagBySlug, getProductTagById };
3889
+ }
3890
+
3891
+ // src/integrations/wpGraphQL/woocommerce/coupons/queries.ts
3892
+ var DEFAULT_FIRST11 = 100;
3893
+ var COUPON_FIELDS = `
3894
+ id
3895
+ databaseId
3896
+ code
3897
+ discountType
3898
+ amount
3899
+ dateExpiry
3900
+ usageCount
3901
+ usageLimit
3902
+ usageLimitPerUser
3903
+ individualUse
3904
+ freeShipping
3905
+ minimumAmount
3906
+ maximumAmount
3907
+ description
3908
+ `;
3909
+ var GQL_GET_COUPONS = `
3910
+ query GetCoupons($first: Int, $after: String) {
3911
+ coupons(first: $first, after: $after) {
3912
+ nodes { ${COUPON_FIELDS} }
3913
+ pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
3914
+ }
3915
+ }
3916
+ `;
3917
+ var GQL_GET_COUPON_BY_CODE = `
3918
+ query GetCouponByCode($id: ID!) {
3919
+ coupon(id: $id, idType: CODE) { ${COUPON_FIELDS} }
3920
+ }
3921
+ `;
3922
+ var GQL_GET_COUPON_BY_ID = `
3923
+ query GetCouponById($id: ID!) {
3924
+ coupon(id: $id, idType: DATABASE_ID) { ${COUPON_FIELDS} }
3925
+ }
3926
+ `;
3927
+ function createCouponsQueries2(fetcher) {
3928
+ const { gqlFetchGraceful } = fetcher;
3929
+ async function getCoupons(first = DEFAULT_FIRST11, after) {
3930
+ const data = await gqlFetchGraceful(
3931
+ GQL_GET_COUPONS,
3932
+ { coupons: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
3933
+ { first, after },
3934
+ ["wpgraphql", "gql-coupons"]
3935
+ );
3936
+ return data.coupons;
3937
+ }
3938
+ async function getCouponByCode(code) {
3939
+ const data = await gqlFetchGraceful(
3940
+ GQL_GET_COUPON_BY_CODE,
3941
+ { coupon: null },
3942
+ { id: code },
3943
+ ["wpgraphql", "gql-coupons", `gql-coupon-${code}`]
3944
+ );
3945
+ return data.coupon;
3946
+ }
3947
+ async function getCouponById(id) {
3948
+ const data = await gqlFetchGraceful(
3949
+ GQL_GET_COUPON_BY_ID,
3950
+ { coupon: null },
3951
+ { id: String(id) },
3952
+ ["wpgraphql", "gql-coupons", `gql-coupon-${id}`]
3953
+ );
3954
+ return data.coupon;
3955
+ }
3956
+ return { getCoupons, getCouponByCode, getCouponById };
3957
+ }
3958
+
3959
+ // src/integrations/wpGraphQL/woocommerce/index.ts
3960
+ function createWPGraphQLWooCommerceClient(config) {
3961
+ const fetcher = createWPGraphQLFetcher(config);
3962
+ return {
3963
+ ...createProductsQueries2(fetcher),
3964
+ ...createOrdersQueries2(fetcher),
3965
+ ...createCustomersQueries2(fetcher),
3966
+ ...createCategoriesQueries4(fetcher),
3967
+ ...createTagsQueries4(fetcher),
3968
+ ...createCouponsQueries2(fetcher)
3969
+ };
3970
+ }
3971
+
3972
+ // src/integrations/wpGraphQL/cpt/queries.ts
3973
+ var DEFAULT_FIRST12 = 10;
3974
+ var BATCH_FIRST4 = 100;
3975
+ var BASE_CPT_FIELDS = `
3976
+ id databaseId slug title date modified status uri
3977
+ `;
3978
+ function createCPTQueries(fetcher, typeName, singularTypeName, extraFields) {
3979
+ const { gqlFetch, gqlFetchGraceful } = fetcher;
3980
+ const fields = extraFields ? `${BASE_CPT_FIELDS} ${extraFields}` : BASE_CPT_FIELDS;
3981
+ const GQL_GET_ITEMS = `
3982
+ query GetCPT_${typeName}($first: Int, $after: String) {
3983
+ ${typeName}(first: $first, after: $after) {
3984
+ nodes { ${fields} }
3985
+ pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
3986
+ }
3987
+ }
3988
+ `;
3989
+ const GQL_GET_ITEM_BY_SLUG = `
3990
+ query GetCPT_${singularTypeName}BySlug($slug: ID!) {
3991
+ ${singularTypeName}(id: $slug, idType: SLUG) { ${fields} }
3992
+ }
3993
+ `;
3994
+ const GQL_GET_ALL_SLUGS = `
3995
+ query GetAllCPT_${typeName}Slugs($first: Int, $after: String) {
3996
+ ${typeName}(first: $first, after: $after) {
3997
+ nodes { slug }
3998
+ pageInfo { hasNextPage endCursor }
3999
+ }
4000
+ }
4001
+ `;
4002
+ async function getItems(first = DEFAULT_FIRST12, after) {
4003
+ const data = await gqlFetchGraceful(
4004
+ GQL_GET_ITEMS,
4005
+ { [typeName]: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
4006
+ { first, after },
4007
+ ["wpgraphql", `gql-${typeName}`]
4008
+ );
4009
+ return data[typeName] ?? { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } };
4010
+ }
4011
+ async function getItemBySlug(slug) {
4012
+ const data = await gqlFetchGraceful(
4013
+ GQL_GET_ITEM_BY_SLUG,
4014
+ { [singularTypeName]: null },
4015
+ { slug },
4016
+ ["wpgraphql", `gql-${typeName}`, `gql-${singularTypeName}-${slug}`]
4017
+ );
4018
+ return data[singularTypeName] ?? null;
4019
+ }
4020
+ async function getAllSlugs() {
4021
+ try {
4022
+ const all = [];
4023
+ let after = void 0;
4024
+ let hasNextPage = true;
4025
+ while (hasNextPage) {
4026
+ const data = await gqlFetch(GQL_GET_ALL_SLUGS, { first: BATCH_FIRST4, after }, ["wpgraphql"]);
4027
+ const connection = data[typeName];
4028
+ if (!connection) break;
4029
+ all.push(...connection.nodes);
4030
+ hasNextPage = connection.pageInfo.hasNextPage;
4031
+ after = connection.pageInfo.endCursor;
4032
+ }
4033
+ return all;
4034
+ } catch {
4035
+ console.warn(`WPGraphQL unavailable, skipping static generation for ${typeName}`);
4036
+ return [];
4037
+ }
4038
+ }
4039
+ return { getItems, getItemBySlug, getAllSlugs };
4040
+ }
4041
+
4042
+ // src/nextjs/revalidation.ts
4043
+ var ACTION_TAG_MAP = {
4044
+ save_post: ["wordpress", "posts"],
4045
+ save_post_post: ["wordpress", "posts"],
4046
+ save_post_page: ["wordpress", "pages"],
4047
+ delete_post: ["wordpress", "posts", "pages"],
4048
+ created_term: ["wordpress", "categories", "tags"],
4049
+ edited_term: ["wordpress", "categories", "tags"],
4050
+ delete_term: ["wordpress", "categories", "tags"],
4051
+ wp_update_nav_menu: ["wordpress", "menus"],
4052
+ woocommerce_product_updated: ["woocommerce", "products"],
4053
+ woocommerce_new_product: ["woocommerce", "products"],
4054
+ woocommerce_delete_product: ["woocommerce", "products"],
4055
+ woocommerce_new_order: ["woocommerce", "orders"],
4056
+ woocommerce_order_status_changed: ["woocommerce", "orders"],
4057
+ woocommerce_update_order: ["woocommerce", "orders"],
4058
+ woocommerce_product_category_updated: ["woocommerce", "categories"],
4059
+ woocommerce_product_tag_updated: ["woocommerce", "tags"]
4060
+ };
4061
+ function extractSecret(request) {
4062
+ const auth = request.headers.get("Authorization");
4063
+ if (auth?.startsWith("Bearer ")) return auth.slice(7);
4064
+ return new URL(request.url).searchParams.get("secret");
4065
+ }
4066
+ function createRevalidationHandler(config, revalidateTag) {
4067
+ return async function handler(request) {
4068
+ if (extractSecret(request) !== config.secret) {
4069
+ return Response.json({ revalidated: false, tags: [], message: "Unauthorized" }, { status: 401 });
4070
+ }
4071
+ let payload;
4072
+ try {
4073
+ payload = await request.json();
4074
+ } catch {
4075
+ return Response.json({ revalidated: false, tags: [], message: "Invalid JSON body" }, { status: 400 });
4076
+ }
4077
+ const { action } = payload;
4078
+ const matched = ACTION_TAG_MAP[action];
4079
+ if (!matched) {
4080
+ return Response.json(
4081
+ { revalidated: false, tags: [], message: `Unknown action: ${action}` },
4082
+ { status: 400 }
4083
+ );
4084
+ }
4085
+ const tags = [...new Set(matched)];
4086
+ for (const tag of tags) {
4087
+ revalidateTag(tag);
4088
+ }
4089
+ return Response.json({ revalidated: true, tags });
4090
+ };
4091
+ }
4092
+
4093
+ // src/nextjs/faust.ts
4094
+ function createFaustAuthHandler(config) {
4095
+ const cookieName = config.cookieName ?? "faustwp-rt";
4096
+ return async function handler(request, routePath) {
4097
+ if (routePath === "auth/token") {
4098
+ const url = new URL(request.url);
4099
+ const code = url.searchParams.get("code");
4100
+ const redirectUri = url.searchParams.get("redirect_uri") ?? "/";
4101
+ const refreshToken = parseCookie(request, cookieName);
4102
+ if (!code && !refreshToken) {
4103
+ return Response.json({ error: "Unauthorized" }, { status: 401 });
4104
+ }
4105
+ const wpRes = await fetch(`${config.wpUrl}/?rest_route=/faustwp/v1/authorize`, {
4106
+ method: "POST",
4107
+ headers: {
4108
+ "Content-Type": "application/json",
4109
+ "x-faustwp-secret": config.secretKey
4110
+ },
4111
+ body: JSON.stringify({ code, refreshToken })
4112
+ });
4113
+ if (!wpRes.ok) {
4114
+ const body = await wpRes.text();
4115
+ return new Response(body, { status: wpRes.status });
4116
+ }
4117
+ const data = await wpRes.json();
4118
+ return new Response(null, {
4119
+ status: 302,
4120
+ headers: {
4121
+ Location: new URL(redirectUri, request.url).toString(),
4122
+ "Set-Cookie": buildSetCookie(cookieName, data.refreshToken, 2592e3)
4123
+ }
4124
+ });
4125
+ }
4126
+ if (routePath === "auth/logout") {
4127
+ return new Response(JSON.stringify({}), {
4128
+ status: 200,
4129
+ headers: {
4130
+ "Content-Type": "application/json",
4131
+ "Set-Cookie": `${cookieName}=; Max-Age=0; Path=/; HttpOnly`
4132
+ }
4133
+ });
4134
+ }
4135
+ return Response.json({ error: "Not Found" }, { status: 404 });
4136
+ };
4137
+ }
4138
+ function createPreviewHandler(config, deps) {
4139
+ const previewPath = config.previewPath ?? "posts";
4140
+ return async function handler(request) {
4141
+ const url = new URL(request.url);
4142
+ const postId = url.searchParams.get("postId");
4143
+ const previewPathname = url.searchParams.get("previewPathname");
4144
+ if (!postId) {
4145
+ return new Response("Missing postId", { status: 400 });
4146
+ }
4147
+ const slug = await resolvePreviewSlug(config, postId, previewPathname);
4148
+ if (!slug) {
4149
+ return new Response("Post not found", { status: 404 });
4150
+ }
4151
+ await deps.enableDraftMode();
4152
+ deps.redirect(`/${previewPath}/${slug}?postId=${postId}`);
4153
+ };
4154
+ }
4155
+ function parseCookie(request, name) {
4156
+ const header = request.headers.get("cookie") ?? "";
4157
+ const match = header.match(new RegExp(`(?:^|;\\s*)${name}=([^;]*)`));
4158
+ return match?.[1];
4159
+ }
4160
+ function buildSetCookie(name, value, maxAge) {
4161
+ const secure = process.env.NODE_ENV === "production" ? "; Secure" : "";
4162
+ return `${name}=${value}; HttpOnly; Path=/; SameSite=Strict; Max-Age=${maxAge}${secure}`;
4163
+ }
4164
+ async function resolvePreviewSlug(config, postId, previewPathname) {
4165
+ if (previewPathname && !previewPathname.includes("p=")) {
4166
+ const slug = previewPathname.replace(/\/$/, "").split("/").pop();
4167
+ if (slug) return slug;
4168
+ }
4169
+ const res = await fetch(`${config.wpUrl}/wp-json/wp/v2/posts/${postId}?_fields=slug`, {
4170
+ headers: { "x-faustwp-secret": config.secretKey },
4171
+ cache: "no-store"
4172
+ });
4173
+ if (!res.ok) return null;
4174
+ const data = await res.json();
4175
+ return data.slug ?? `preview-${postId}`;
4176
+ }
4177
+
4178
+ // src/auth/applicationPassword.ts
4179
+ function createApplicationPasswordToken(username, appPassword) {
4180
+ const encoded = Buffer.from(`${username}:${appPassword}`).toString("base64");
4181
+ return `Basic ${encoded}`;
4182
+ }
4183
+
4184
+ // src/auth/types.ts
4185
+ var AuthenticationError = class extends Error {
4186
+ constructor(code, status, message, detail) {
4187
+ super(detail ? `${message}: ${detail}` : message);
4188
+ __publicField(this, "code", code);
4189
+ __publicField(this, "status", status);
4190
+ this.name = "AuthenticationError";
4191
+ }
4192
+ };
4193
+
4194
+ // src/auth/jwt.ts
4195
+ function resolveAuthErrorCode(status) {
4196
+ if (status === 401) return ErrorCode.AUTH_CREDENTIALS_INVALID;
4197
+ if (status === 403) return ErrorCode.AUTH_TOKEN_INVALID;
4198
+ return ErrorCode.AUTH_JWT_FAILED;
4199
+ }
4200
+ async function authenticateJwt(config, credentials) {
4201
+ const url = `${resolveBaseUrl(config)}/wp-json/jwt-auth/v1/token`;
4202
+ const response = await fetch(url, {
4203
+ method: "POST",
4204
+ headers: { "Content-Type": "application/json" },
4205
+ body: JSON.stringify(credentials),
4206
+ cache: "no-store"
4207
+ });
4208
+ if (!response.ok) {
4209
+ const code = resolveAuthErrorCode(response.status);
4210
+ throw new AuthenticationError(
4211
+ code,
4212
+ response.status,
4213
+ resolveMessage(code, config.errorMessages),
4214
+ response.statusText
4215
+ );
4216
+ }
4217
+ return response.json();
4218
+ }
4219
+ async function validateJwtToken(config, token) {
4220
+ const url = `${resolveBaseUrl(config)}/wp-json/jwt-auth/v1/token/validate`;
4221
+ const response = await fetch(url, {
4222
+ method: "POST",
4223
+ headers: { Authorization: `Bearer ${token}` },
4224
+ cache: "no-store"
4225
+ });
4226
+ return response.ok;
4227
+ }
4228
+
4229
+ 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, createWooCommerceClient, createWooCommerceFetcher, createWordPressClient, createWordPressMutationsClient, createYoastQueries, defaultMessages, defaultMessagesPl, extractOmnibusData, resolveBaseUrl, resolveMessage, validateJwtToken, withOmnibus, withOmnibusVariation };
4230
+ //# sourceMappingURL=index.js.map
4231
+ //# sourceMappingURL=index.js.map