@szymonpiatek/nextwordpress 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -7,6 +7,199 @@ function resolveBaseUrl(config) {
7
7
  return typeof window === "undefined" ? config.serverURL : config.clientURL;
8
8
  }
9
9
 
10
+ // src/integrations/restApi/core/mutations/posts/mutations.ts
11
+ function createPostsMutations(fetcher) {
12
+ const { wpMutate } = fetcher;
13
+ async function createPost(input, authToken) {
14
+ return wpMutate("/wp/v2/posts", input, "POST", authToken);
15
+ }
16
+ async function updatePost(id, input, authToken) {
17
+ return wpMutate(`/wp/v2/posts/${id}`, input, "PATCH", authToken);
18
+ }
19
+ async function deletePost(id, authToken, force = false) {
20
+ return wpMutate(
21
+ `/wp/v2/posts/${id}`,
22
+ { force },
23
+ "DELETE",
24
+ authToken
25
+ );
26
+ }
27
+ return { createPost, updatePost, deletePost };
28
+ }
29
+
30
+ // src/integrations/restApi/core/mutations/comments/mutations.ts
31
+ function createCommentsMutations(fetcher) {
32
+ const { wpMutate } = fetcher;
33
+ async function createComment(input, authToken) {
34
+ return wpMutate("/wp/v2/comments", input, "POST", authToken);
35
+ }
36
+ async function updateComment(id, input, authToken) {
37
+ return wpMutate(`/wp/v2/comments/${id}`, input, "PATCH", authToken);
38
+ }
39
+ async function deleteComment(id, authToken, force = false) {
40
+ return wpMutate(
41
+ `/wp/v2/comments/${id}`,
42
+ { force },
43
+ "DELETE",
44
+ authToken
45
+ );
46
+ }
47
+ return { createComment, updateComment, deleteComment };
48
+ }
49
+
50
+ // src/integrations/restApi/core/mutations/pages/mutations.ts
51
+ function createPagesMutations(fetcher) {
52
+ const { wpMutate } = fetcher;
53
+ async function createPage(input, authToken) {
54
+ return wpMutate("/wp/v2/pages", input, "POST", authToken);
55
+ }
56
+ async function updatePage(id, input, authToken) {
57
+ return wpMutate(`/wp/v2/pages/${id}`, input, "PATCH", authToken);
58
+ }
59
+ async function deletePage(id, authToken, force = false) {
60
+ return wpMutate(
61
+ `/wp/v2/pages/${id}`,
62
+ { force },
63
+ "DELETE",
64
+ authToken
65
+ );
66
+ }
67
+ return { createPage, updatePage, deletePage };
68
+ }
69
+
70
+ // src/integrations/restApi/core/mutations/categories/mutations.ts
71
+ function createCategoriesMutations(fetcher) {
72
+ const { wpMutate } = fetcher;
73
+ async function createCategory(input, authToken) {
74
+ return wpMutate("/wp/v2/categories", input, "POST", authToken);
75
+ }
76
+ async function updateCategory(id, input, authToken) {
77
+ return wpMutate(`/wp/v2/categories/${id}`, input, "PATCH", authToken);
78
+ }
79
+ async function deleteCategory(id, authToken, force = false) {
80
+ return wpMutate(
81
+ `/wp/v2/categories/${id}`,
82
+ { force },
83
+ "DELETE",
84
+ authToken
85
+ );
86
+ }
87
+ return { createCategory, updateCategory, deleteCategory };
88
+ }
89
+
90
+ // src/integrations/restApi/core/mutations/tags/mutations.ts
91
+ function createTagsMutations(fetcher) {
92
+ const { wpMutate } = fetcher;
93
+ async function createTag(input, authToken) {
94
+ return wpMutate("/wp/v2/tags", input, "POST", authToken);
95
+ }
96
+ async function updateTag(id, input, authToken) {
97
+ return wpMutate(`/wp/v2/tags/${id}`, input, "PATCH", authToken);
98
+ }
99
+ async function deleteTag(id, authToken, force = false) {
100
+ return wpMutate(
101
+ `/wp/v2/tags/${id}`,
102
+ { force },
103
+ "DELETE",
104
+ authToken
105
+ );
106
+ }
107
+ return { createTag, updateTag, deleteTag };
108
+ }
109
+
110
+ // src/integrations/restApi/core/mutations/authors/mutations.ts
111
+ function createAuthorsMutations(fetcher) {
112
+ const { wpMutate } = fetcher;
113
+ async function createAuthor(input, authToken) {
114
+ return wpMutate("/wp/v2/users", input, "POST", authToken);
115
+ }
116
+ async function updateAuthor(id, input, authToken) {
117
+ return wpMutate(`/wp/v2/users/${id}`, input, "PATCH", authToken);
118
+ }
119
+ async function deleteAuthor(id, authToken, reassign) {
120
+ return wpMutate(
121
+ `/wp/v2/users/${id}`,
122
+ { force: true, reassign },
123
+ "DELETE",
124
+ authToken
125
+ );
126
+ }
127
+ return { createAuthor, updateAuthor, deleteAuthor };
128
+ }
129
+
130
+ // src/integrations/restApi/core/mutations/menus/mutations.ts
131
+ function createMenusMutations(fetcher) {
132
+ const { wpMutate } = fetcher;
133
+ async function createMenu(input, authToken) {
134
+ return wpMutate("/wp/v2/menus", input, "POST", authToken);
135
+ }
136
+ async function updateMenu(id, input, authToken) {
137
+ return wpMutate(`/wp/v2/menus/${id}`, input, "PATCH", authToken);
138
+ }
139
+ async function deleteMenu(id, authToken) {
140
+ return wpMutate(
141
+ `/wp/v2/menus/${id}`,
142
+ {},
143
+ "DELETE",
144
+ authToken
145
+ );
146
+ }
147
+ async function createMenuItem(input, authToken) {
148
+ return wpMutate("/wp/v2/menu-items", input, "POST", authToken);
149
+ }
150
+ async function updateMenuItem(id, input, authToken) {
151
+ return wpMutate(`/wp/v2/menu-items/${id}`, input, "PATCH", authToken);
152
+ }
153
+ async function deleteMenuItem(id, authToken, force = false) {
154
+ return wpMutate(
155
+ `/wp/v2/menu-items/${id}`,
156
+ { force },
157
+ "DELETE",
158
+ authToken
159
+ );
160
+ }
161
+ return { createMenu, updateMenu, deleteMenu, createMenuItem, updateMenuItem, deleteMenuItem };
162
+ }
163
+
164
+ // src/integrations/restApi/core/mutations/media/mutations.ts
165
+ function createMediaMutations(fetcher) {
166
+ const { wpMutate, wpUpload } = fetcher;
167
+ async function uploadMedia(input, authToken) {
168
+ const media = await wpUpload(
169
+ "/wp/v2/media",
170
+ input.file,
171
+ input.filename,
172
+ input.mimeType,
173
+ authToken
174
+ );
175
+ if (input.title || input.caption || input.alt_text) {
176
+ return wpMutate(
177
+ `/wp/v2/media/${media.id}`,
178
+ {
179
+ ...input.title && { title: input.title },
180
+ ...input.caption && { caption: input.caption },
181
+ ...input.alt_text && { alt_text: input.alt_text }
182
+ },
183
+ "PATCH",
184
+ authToken
185
+ );
186
+ }
187
+ return media;
188
+ }
189
+ async function updateMedia(id, input, authToken) {
190
+ return wpMutate(`/wp/v2/media/${id}`, input, "PATCH", authToken);
191
+ }
192
+ async function deleteMedia(id, authToken, force = true) {
193
+ return wpMutate(
194
+ `/wp/v2/media/${id}`,
195
+ { force },
196
+ "DELETE",
197
+ authToken
198
+ );
199
+ }
200
+ return { uploadMedia, updateMedia, deleteMedia };
201
+ }
202
+
10
203
  // src/integrations/restApi/core/client/types.ts
11
204
  var WordPressAPIError = class extends Error {
12
205
  constructor(message, status, endpoint) {
@@ -85,20 +278,54 @@ function createFetcher(config) {
85
278
  return empty;
86
279
  }
87
280
  }
88
- async function wpMutate(path, body, method = "POST") {
281
+ async function wpMutate(path, body, method = "POST", authToken) {
89
282
  const url = buildUrl(config, path);
283
+ const headers = {
284
+ "Content-Type": "application/json",
285
+ "User-Agent": USER_AGENT
286
+ };
287
+ if (authToken) {
288
+ headers["Authorization"] = authToken;
289
+ }
90
290
  const res = await doFetch(url, {
91
291
  method,
292
+ headers,
293
+ body: JSON.stringify(body),
294
+ cache: "no-store"
295
+ });
296
+ return await res.json();
297
+ }
298
+ async function wpUpload(path, file, filename, mimeType, authToken) {
299
+ const url = buildUrl(config, path);
300
+ const res = await doFetch(url, {
301
+ method: "POST",
92
302
  headers: {
93
- "Content-Type": "application/json",
94
- "User-Agent": USER_AGENT
303
+ "Content-Disposition": `attachment; filename="${filename}"`,
304
+ "Content-Type": mimeType,
305
+ "User-Agent": USER_AGENT,
306
+ "Authorization": authToken
95
307
  },
96
- body: JSON.stringify(body),
308
+ body: file,
97
309
  cache: "no-store"
98
310
  });
99
311
  return await res.json();
100
312
  }
101
- return { wpFetch, wpFetchGraceful, wpFetchPaginated, wpFetchPaginatedGraceful, wpMutate };
313
+ return { wpFetch, wpFetchGraceful, wpFetchPaginated, wpFetchPaginatedGraceful, wpMutate, wpUpload };
314
+ }
315
+
316
+ // src/integrations/restApi/core/mutations/index.ts
317
+ function createWordPressMutationsClient(config) {
318
+ const fetcher = createFetcher(config);
319
+ return {
320
+ ...createPostsMutations(fetcher),
321
+ ...createCommentsMutations(fetcher),
322
+ ...createPagesMutations(fetcher),
323
+ ...createCategoriesMutations(fetcher),
324
+ ...createTagsMutations(fetcher),
325
+ ...createAuthorsMutations(fetcher),
326
+ ...createMenusMutations(fetcher),
327
+ ...createMediaMutations(fetcher)
328
+ };
102
329
  }
103
330
 
104
331
  // src/integrations/restApi/core/posts/queries.ts
@@ -329,6 +556,100 @@ function createPagesQueries(fetcher) {
329
556
  return { getAllPages, getPageById, getPageBySlug };
330
557
  }
331
558
 
559
+ // src/integrations/restApi/core/menus/queries.ts
560
+ function createMenusQueries(fetcher) {
561
+ const { wpFetch, wpFetchGraceful } = fetcher;
562
+ async function getMenus() {
563
+ return wpFetchGraceful("/wp-json/wp/v2/menus", [], void 0, ["wordpress", "menus"]);
564
+ }
565
+ async function getMenuById(id) {
566
+ return wpFetch(`/wp-json/wp/v2/menus/${id}`, void 0, ["wordpress", "menus", `menu-${id}`]);
567
+ }
568
+ async function getMenuBySlug(slug) {
569
+ const menus = await wpFetchGraceful("/wp-json/wp/v2/menus", [], { slug }, ["wordpress", "menus"]);
570
+ return menus[0];
571
+ }
572
+ async function getMenuItemsByMenuId(menuId) {
573
+ return wpFetchGraceful(
574
+ "/wp-json/wp/v2/menu-items",
575
+ [],
576
+ { menus: menuId, per_page: 100, orderby: "menu_order", order: "asc" },
577
+ ["wordpress", "menus", `menu-items-${menuId}`]
578
+ );
579
+ }
580
+ async function getMenuLocations() {
581
+ return wpFetchGraceful(
582
+ "/wp-json/wp/v2/menu-locations",
583
+ {},
584
+ void 0,
585
+ ["wordpress", "menus", "menu-locations"]
586
+ );
587
+ }
588
+ async function getMenuByLocation(location) {
589
+ const locations = await getMenuLocations();
590
+ const loc = locations[location];
591
+ if (!loc || !loc.menu) return void 0;
592
+ const [menu, items] = await Promise.all([
593
+ getMenuById(loc.menu),
594
+ getMenuItemsByMenuId(loc.menu)
595
+ ]);
596
+ return { menu, items };
597
+ }
598
+ return {
599
+ getMenus,
600
+ getMenuById,
601
+ getMenuBySlug,
602
+ getMenuItemsByMenuId,
603
+ getMenuLocations,
604
+ getMenuByLocation
605
+ };
606
+ }
607
+
608
+ // src/integrations/restApi/core/comments/queries.ts
609
+ function createCommentsQueries(fetcher) {
610
+ const { wpFetch, wpFetchGraceful, wpFetchPaginatedGraceful, wpMutate } = fetcher;
611
+ async function getCommentsByPostId(postId, page = 1, perPage = 10) {
612
+ return wpFetchPaginatedGraceful(
613
+ "/wp-json/wp/v2/comments",
614
+ { post: postId, per_page: perPage, page, status: "approve" },
615
+ ["wordpress", "comments", `comments-post-${postId}`]
616
+ );
617
+ }
618
+ async function getAllCommentsByPostId(postId) {
619
+ return wpFetchGraceful(
620
+ "/wp-json/wp/v2/comments",
621
+ [],
622
+ { post: postId, per_page: 100, status: "approve" },
623
+ ["wordpress", "comments", `comments-post-${postId}`]
624
+ );
625
+ }
626
+ async function getCommentById(id) {
627
+ return wpFetch(`/wp-json/wp/v2/comments/${id}`, void 0, [
628
+ "wordpress",
629
+ "comments",
630
+ `comment-${id}`
631
+ ]);
632
+ }
633
+ async function getCommentReplies(parentId) {
634
+ return wpFetchGraceful(
635
+ "/wp-json/wp/v2/comments",
636
+ [],
637
+ { parent: parentId, per_page: 100, status: "approve" },
638
+ ["wordpress", "comments", `comments-parent-${parentId}`]
639
+ );
640
+ }
641
+ async function createComment(input) {
642
+ return wpMutate("/wp-json/wp/v2/comments", input, "POST");
643
+ }
644
+ return {
645
+ getCommentsByPostId,
646
+ getAllCommentsByPostId,
647
+ getCommentById,
648
+ getCommentReplies,
649
+ createComment
650
+ };
651
+ }
652
+
332
653
  // src/integrations/restApi/core/index.ts
333
654
  function createWordPressClient(config) {
334
655
  const fetcher = createFetcher(config);
@@ -338,7 +659,9 @@ function createWordPressClient(config) {
338
659
  ...createTagsQueries(fetcher),
339
660
  ...createAuthorsQueries(fetcher),
340
661
  ...createMediaQueries(fetcher),
341
- ...createPagesQueries(fetcher)
662
+ ...createPagesQueries(fetcher),
663
+ ...createMenusQueries(fetcher),
664
+ ...createCommentsQueries(fetcher)
342
665
  };
343
666
  }
344
667
 
@@ -580,6 +903,25 @@ function createProductsQueries(fetcher) {
580
903
  };
581
904
  }
582
905
 
906
+ // src/integrations/restApi/woocommerce/products/mutations.ts
907
+ function createProductsMutations(fetcher) {
908
+ const { wcMutate } = fetcher;
909
+ async function createProduct(input) {
910
+ return wcMutate("/wp-json/wc/v3/products", input, "POST");
911
+ }
912
+ async function updateProduct(id, input) {
913
+ return wcMutate(`/wp-json/wc/v3/products/${id}`, input, "PUT");
914
+ }
915
+ async function deleteProduct(id, force = true) {
916
+ return wcMutate(
917
+ `/wp-json/wc/v3/products/${id}`,
918
+ { force },
919
+ "DELETE"
920
+ );
921
+ }
922
+ return { createProduct, updateProduct, deleteProduct };
923
+ }
924
+
583
925
  // src/integrations/restApi/woocommerce/categories/queries.ts
584
926
  function createCategoriesQueries2(fetcher) {
585
927
  const { wcFetch, wcFetchGraceful } = fetcher;
@@ -629,6 +971,29 @@ function createCategoriesQueries2(fetcher) {
629
971
  };
630
972
  }
631
973
 
974
+ // src/integrations/restApi/woocommerce/categories/mutations.ts
975
+ function createCategoriesMutations2(fetcher) {
976
+ const { wcMutate } = fetcher;
977
+ async function createProductCategory(input) {
978
+ return wcMutate("/wp-json/wc/v3/products/categories", input, "POST");
979
+ }
980
+ async function updateProductCategory(id, input) {
981
+ return wcMutate(
982
+ `/wp-json/wc/v3/products/categories/${id}`,
983
+ input,
984
+ "PUT"
985
+ );
986
+ }
987
+ async function deleteProductCategory(id, force = true) {
988
+ return wcMutate(
989
+ `/wp-json/wc/v3/products/categories/${id}`,
990
+ { force },
991
+ "DELETE"
992
+ );
993
+ }
994
+ return { createProductCategory, updateProductCategory, deleteProductCategory };
995
+ }
996
+
632
997
  // src/integrations/restApi/woocommerce/tags/queries.ts
633
998
  function createTagsQueries2(fetcher) {
634
999
  const { wcFetch, wcFetchGraceful } = fetcher;
@@ -662,6 +1027,25 @@ function createTagsQueries2(fetcher) {
662
1027
  };
663
1028
  }
664
1029
 
1030
+ // src/integrations/restApi/woocommerce/tags/mutations.ts
1031
+ function createTagsMutations2(fetcher) {
1032
+ const { wcMutate } = fetcher;
1033
+ async function createProductTag(input) {
1034
+ return wcMutate("/wp-json/wc/v3/products/tags", input, "POST");
1035
+ }
1036
+ async function updateProductTag(id, input) {
1037
+ return wcMutate(`/wp-json/wc/v3/products/tags/${id}`, input, "PUT");
1038
+ }
1039
+ async function deleteProductTag(id, force = true) {
1040
+ return wcMutate(
1041
+ `/wp-json/wc/v3/products/tags/${id}`,
1042
+ { force },
1043
+ "DELETE"
1044
+ );
1045
+ }
1046
+ return { createProductTag, updateProductTag, deleteProductTag };
1047
+ }
1048
+
665
1049
  // src/integrations/restApi/woocommerce/orders/queries.ts
666
1050
  function createOrdersQueries(fetcher) {
667
1051
  const { wcFetch, wcFetchGraceful, wcMutate } = fetcher;
@@ -686,11 +1070,19 @@ function createOrdersQueries(fetcher) {
686
1070
  ["woocommerce", "orders", `orders-customer-${customerId}`]
687
1071
  );
688
1072
  }
1073
+ async function deleteOrder(id, force = true) {
1074
+ return wcMutate(
1075
+ `/wp-json/wc/v3/orders/${id}`,
1076
+ { force },
1077
+ "DELETE"
1078
+ );
1079
+ }
689
1080
  return {
690
1081
  createOrder,
691
1082
  getOrderById,
692
1083
  updateOrder,
693
- getOrdersByCustomer
1084
+ getOrdersByCustomer,
1085
+ deleteOrder
694
1086
  };
695
1087
  }
696
1088
 
@@ -724,9 +1116,28 @@ function createCouponsQueries(fetcher) {
724
1116
  };
725
1117
  }
726
1118
 
1119
+ // src/integrations/restApi/woocommerce/coupons/mutations.ts
1120
+ function createCouponsMutations(fetcher) {
1121
+ const { wcMutate } = fetcher;
1122
+ async function createCoupon(input) {
1123
+ return wcMutate("/wp-json/wc/v3/coupons", input, "POST");
1124
+ }
1125
+ async function updateCoupon(id, input) {
1126
+ return wcMutate(`/wp-json/wc/v3/coupons/${id}`, input, "PUT");
1127
+ }
1128
+ async function deleteCoupon(id, force = true) {
1129
+ return wcMutate(
1130
+ `/wp-json/wc/v3/coupons/${id}`,
1131
+ { force },
1132
+ "DELETE"
1133
+ );
1134
+ }
1135
+ return { createCoupon, updateCoupon, deleteCoupon };
1136
+ }
1137
+
727
1138
  // src/integrations/restApi/woocommerce/customers/queries.ts
728
1139
  function createCustomersQueries(fetcher) {
729
- const { wcFetch, wcFetchGraceful } = fetcher;
1140
+ const { wcFetch, wcFetchGraceful, wcMutate } = fetcher;
730
1141
  async function getCustomerById(id) {
731
1142
  return wcFetch(`/wp-json/wc/v3/customers/${id}`, void 0, [
732
1143
  "woocommerce",
@@ -764,11 +1175,23 @@ function createCustomersQueries(fetcher) {
764
1175
  { method: "POST", body: JSON.stringify(data) }
765
1176
  );
766
1177
  }
1178
+ async function updateCustomer(id, data) {
1179
+ return wcMutate(`/wp-json/wc/v3/customers/${id}`, data, "PUT");
1180
+ }
1181
+ async function deleteCustomer(id, reassign) {
1182
+ return wcMutate(
1183
+ `/wp-json/wc/v3/customers/${id}`,
1184
+ { force: true, ...reassign !== void 0 && { reassign } },
1185
+ "DELETE"
1186
+ );
1187
+ }
767
1188
  return {
768
1189
  getCustomerById,
769
1190
  getCustomerByEmail,
770
1191
  getCustomerByEmailNoCache,
771
- createCustomer
1192
+ createCustomer,
1193
+ updateCustomer,
1194
+ deleteCustomer
772
1195
  };
773
1196
  }
774
1197
 
@@ -777,10 +1200,14 @@ function createWooCommerceClient(config) {
777
1200
  const fetcher = createWooCommerceFetcher(config);
778
1201
  return {
779
1202
  ...createProductsQueries(fetcher),
1203
+ ...createProductsMutations(fetcher),
780
1204
  ...createCategoriesQueries2(fetcher),
1205
+ ...createCategoriesMutations2(fetcher),
781
1206
  ...createTagsQueries2(fetcher),
1207
+ ...createTagsMutations2(fetcher),
782
1208
  ...createOrdersQueries(fetcher),
783
1209
  ...createCouponsQueries(fetcher),
1210
+ ...createCouponsMutations(fetcher),
784
1211
  ...createCustomersQueries(fetcher)
785
1212
  };
786
1213
  }
@@ -840,7 +1267,42 @@ function createWPGraphQLFetcher(config) {
840
1267
  return fallback;
841
1268
  }
842
1269
  }
843
- return { gqlFetch, gqlFetchGraceful };
1270
+ async function gqlMutate(document, variables, authToken) {
1271
+ const headers = {
1272
+ "Content-Type": "application/json",
1273
+ "User-Agent": USER_AGENT3
1274
+ };
1275
+ if (authToken) {
1276
+ headers["Authorization"] = authToken;
1277
+ }
1278
+ const response = await fetch(url, {
1279
+ method: "POST",
1280
+ headers,
1281
+ body: JSON.stringify({ query: document, variables }),
1282
+ cache: "no-store"
1283
+ });
1284
+ if (!response.ok) {
1285
+ throw new WPGraphQLError(
1286
+ `WPGraphQL mutation failed: ${response.statusText}`,
1287
+ response.status,
1288
+ url
1289
+ );
1290
+ }
1291
+ const parsed = await response.json();
1292
+ if (parsed.errors && parsed.errors.length > 0) {
1293
+ throw new WPGraphQLError(
1294
+ parsed.errors[0].message,
1295
+ 200,
1296
+ url,
1297
+ parsed.errors
1298
+ );
1299
+ }
1300
+ if (parsed.data === void 0) {
1301
+ throw new WPGraphQLError("No data returned from WPGraphQL mutation", 200, url);
1302
+ }
1303
+ return parsed.data;
1304
+ }
1305
+ return { gqlFetch, gqlFetchGraceful, gqlMutate };
844
1306
  }
845
1307
 
846
1308
  // src/integrations/wpGraphQL/core/posts/queries.ts
@@ -1260,136 +1722,839 @@ function createAuthorsQueries2(fetcher) {
1260
1722
  return { getAuthors, getAuthorBySlug };
1261
1723
  }
1262
1724
 
1263
- // src/integrations/wpGraphQL/core/index.ts
1264
- function createWPGraphQLCoreClient(config) {
1265
- const fetcher = createWPGraphQLFetcher(config);
1266
- return {
1267
- ...createPostsQueries2(fetcher),
1268
- ...createPagesQueries2(fetcher),
1269
- ...createCategoriesQueries3(fetcher),
1270
- ...createTagsQueries3(fetcher),
1271
- ...createAuthorsQueries2(fetcher)
1272
- };
1273
- }
1274
-
1275
- // src/integrations/wpGraphQL/yoast/queries.ts
1276
- var SEO_FIELDS = `
1277
- seo {
1278
- title
1279
- metaDesc
1280
- canonical
1281
- opengraphTitle
1282
- opengraphDescription
1283
- opengraphImage { sourceUrl altText }
1284
- twitterTitle
1285
- twitterDescription
1286
- twitterImage { sourceUrl }
1287
- schema { raw }
1288
- }
1289
- `;
1290
- var POST_FIELDS_WITH_SEO = `
1725
+ // src/integrations/wpGraphQL/core/menus/queries.ts
1726
+ var MENU_ITEM_FIELDS = `
1291
1727
  id
1292
1728
  databaseId
1293
- slug
1294
- title
1295
- content
1296
- excerpt
1297
- date
1298
- modified
1299
- status
1300
- uri
1301
- author {
1302
- node {
1303
- databaseId
1304
- name
1305
- slug
1306
- avatar { url }
1307
- }
1308
- }
1309
- featuredImage {
1729
+ label
1730
+ url
1731
+ parentId
1732
+ order
1733
+ target
1734
+ cssClasses
1735
+ description
1736
+ connectedNode {
1310
1737
  node {
1311
- sourceUrl
1312
- altText
1313
- mediaDetails { width height }
1738
+ __typename
1739
+ ... on Page { id databaseId slug }
1740
+ ... on Post { id databaseId slug }
1741
+ ... on Category { id databaseId slug }
1742
+ ... on Tag { id databaseId slug }
1314
1743
  }
1315
1744
  }
1316
- categories {
1317
- nodes { databaseId name slug }
1318
- }
1319
- tags {
1320
- nodes { databaseId name slug }
1321
- }
1322
- ${SEO_FIELDS}
1323
1745
  `;
1324
- var PAGE_FIELDS_WITH_SEO = `
1746
+ var MENU_FIELDS = `
1325
1747
  id
1326
1748
  databaseId
1749
+ name
1327
1750
  slug
1328
- title
1329
- content
1330
- date
1331
- modified
1332
- status
1333
- uri
1334
- featuredImage {
1335
- node {
1336
- sourceUrl
1337
- altText
1338
- mediaDetails { width height }
1751
+ locations
1752
+ menuItems(first: 100) {
1753
+ nodes { ${MENU_ITEM_FIELDS} }
1754
+ }
1755
+ `;
1756
+ var GQL_GET_MENUS = `
1757
+ query GetMenus {
1758
+ menus(first: 100) {
1759
+ nodes { ${MENU_FIELDS} }
1339
1760
  }
1340
1761
  }
1341
- ${SEO_FIELDS}
1342
1762
  `;
1343
- var GQL_GET_POST_WITH_SEO = `
1344
- query GetPostWithSEO($slug: ID!) {
1345
- post(id: $slug, idType: SLUG) { ${POST_FIELDS_WITH_SEO} }
1763
+ var GQL_GET_MENU_BY_ID = `
1764
+ query GetMenuById($id: ID!) {
1765
+ menu(id: $id, idType: DATABASE_ID) { ${MENU_FIELDS} }
1346
1766
  }
1347
1767
  `;
1348
- var GQL_GET_PAGE_WITH_SEO = `
1349
- query GetPageWithSEO($slug: ID!) {
1350
- page(id: $slug, idType: SLUG) { ${PAGE_FIELDS_WITH_SEO} }
1768
+ var GQL_GET_MENU_BY_SLUG = `
1769
+ query GetMenuBySlug($id: ID!) {
1770
+ menu(id: $id, idType: SLUG) { ${MENU_FIELDS} }
1351
1771
  }
1352
1772
  `;
1353
- var GQL_GET_PAGE_WITH_SEO_BY_URI = `
1354
- query GetPageWithSEOByUri($uri: ID!) {
1355
- page(id: $uri, idType: URI) { ${PAGE_FIELDS_WITH_SEO} }
1773
+ var GQL_GET_MENUS_BY_LOCATION = `
1774
+ query GetMenusByLocation($location: MenuLocationEnum!) {
1775
+ menus(where: { location: $location }, first: 1) {
1776
+ nodes { ${MENU_FIELDS} }
1777
+ }
1356
1778
  }
1357
1779
  `;
1358
- function createYoastQueries(fetcher) {
1359
- const { gqlFetchGraceful } = fetcher;
1360
- async function getPostWithSEO(slug) {
1780
+ function createMenusQueries2(fetcher) {
1781
+ const { gqlFetch, gqlFetchGraceful } = fetcher;
1782
+ async function getMenus() {
1361
1783
  const data = await gqlFetchGraceful(
1362
- GQL_GET_POST_WITH_SEO,
1363
- { post: null },
1364
- { slug },
1365
- ["wpgraphql", "gql-posts", "gql-yoast", `gql-post-${slug}`]
1784
+ GQL_GET_MENUS,
1785
+ { menus: { nodes: [] } },
1786
+ void 0,
1787
+ ["wpgraphql", "gql-menus"]
1366
1788
  );
1367
- return data.post;
1789
+ return data.menus.nodes;
1368
1790
  }
1369
- async function getPageWithSEO(slug) {
1791
+ async function getMenuById(id) {
1370
1792
  const data = await gqlFetchGraceful(
1371
- GQL_GET_PAGE_WITH_SEO,
1372
- { page: null },
1373
- { slug },
1374
- ["wpgraphql", "gql-pages", "gql-yoast", `gql-page-${slug}`]
1793
+ GQL_GET_MENU_BY_ID,
1794
+ { menu: null },
1795
+ { id: String(id) },
1796
+ ["wpgraphql", "gql-menus", `gql-menu-${id}`]
1375
1797
  );
1376
- return data.page;
1798
+ return data.menu;
1377
1799
  }
1378
- async function getPageWithSEOByUri(uri) {
1800
+ async function getMenuBySlug(slug) {
1379
1801
  const data = await gqlFetchGraceful(
1380
- GQL_GET_PAGE_WITH_SEO_BY_URI,
1381
- { page: null },
1382
- { uri },
1383
- ["wpgraphql", "gql-pages", "gql-yoast", `gql-page-uri-${uri.replace(/\//g, "-")}`]
1802
+ GQL_GET_MENU_BY_SLUG,
1803
+ { menu: null },
1804
+ { id: slug },
1805
+ ["wpgraphql", "gql-menus", `gql-menu-${slug}`]
1384
1806
  );
1385
- return data.page;
1807
+ return data.menu;
1386
1808
  }
1387
- return { getPostWithSEO, getPageWithSEO, getPageWithSEOByUri };
1809
+ async function getMenuByLocation(location) {
1810
+ const data = await gqlFetch(
1811
+ GQL_GET_MENUS_BY_LOCATION,
1812
+ { location: location.toUpperCase() },
1813
+ ["wpgraphql", "gql-menus", `gql-menu-location-${location}`]
1814
+ );
1815
+ return data.menus.nodes[0] ?? null;
1816
+ }
1817
+ async function getMenuItems(menuSlug) {
1818
+ const menu = await getMenuBySlug(menuSlug);
1819
+ return menu?.menuItems?.nodes ?? [];
1820
+ }
1821
+ return {
1822
+ getMenus,
1823
+ getMenuById,
1824
+ getMenuBySlug,
1825
+ getMenuByLocation,
1826
+ getMenuItems
1827
+ };
1388
1828
  }
1389
1829
 
1390
- // src/integrations/wpGraphQL/acf/helpers.ts
1391
- var BASE_POST_FIELDS = `
1392
- id databaseId slug title content excerpt date modified status uri
1830
+ // src/integrations/wpGraphQL/core/comments/queries.ts
1831
+ var COMMENT_AUTHOR_FIELDS = `
1832
+ name
1833
+ url
1834
+ avatar { url width height }
1835
+ `;
1836
+ var COMMENT_FIELDS = `
1837
+ id
1838
+ databaseId
1839
+ content(format: RENDERED)
1840
+ date
1841
+ parentId
1842
+ status
1843
+ author { node { ${COMMENT_AUTHOR_FIELDS} } }
1844
+ `;
1845
+ var GQL_GET_COMMENTS_BY_POST = `
1846
+ query GetCommentsByPost($contentId: ID!, $first: Int, $after: String) {
1847
+ comments(
1848
+ first: $first
1849
+ after: $after
1850
+ where: { contentId: $contentId, status: "approve", parent: 0 }
1851
+ ) {
1852
+ nodes {
1853
+ ${COMMENT_FIELDS}
1854
+ replies(first: 100) {
1855
+ nodes { ${COMMENT_FIELDS} }
1856
+ }
1857
+ }
1858
+ pageInfo { hasNextPage endCursor }
1859
+ }
1860
+ }
1861
+ `;
1862
+ var GQL_GET_ALL_COMMENTS_BY_POST = `
1863
+ query GetAllCommentsByPost($contentId: ID!) {
1864
+ comments(
1865
+ first: 100
1866
+ where: { contentId: $contentId, status: "approve" }
1867
+ ) {
1868
+ nodes { ${COMMENT_FIELDS} }
1869
+ }
1870
+ }
1871
+ `;
1872
+ var GQL_GET_COMMENT_BY_ID = `
1873
+ query GetCommentById($id: ID!) {
1874
+ comment(id: $id, idType: DATABASE_ID) { ${COMMENT_FIELDS} }
1875
+ }
1876
+ `;
1877
+ function createCommentsQueries2(fetcher) {
1878
+ const { gqlFetchGraceful } = fetcher;
1879
+ async function getCommentsByPostId(postId, first = 10, after) {
1880
+ const data = await gqlFetchGraceful(
1881
+ GQL_GET_COMMENTS_BY_POST,
1882
+ { comments: { nodes: [], pageInfo: { hasNextPage: false } } },
1883
+ { contentId: String(postId), first, after },
1884
+ ["wpgraphql", "gql-comments", `gql-comments-post-${postId}`]
1885
+ );
1886
+ return data.comments;
1887
+ }
1888
+ async function getAllCommentsByPostId(postId) {
1889
+ const data = await gqlFetchGraceful(
1890
+ GQL_GET_ALL_COMMENTS_BY_POST,
1891
+ { comments: { nodes: [] } },
1892
+ { contentId: String(postId) },
1893
+ ["wpgraphql", "gql-comments", `gql-comments-post-${postId}`]
1894
+ );
1895
+ return data.comments.nodes;
1896
+ }
1897
+ async function getCommentById(id) {
1898
+ const data = await gqlFetchGraceful(
1899
+ GQL_GET_COMMENT_BY_ID,
1900
+ { comment: null },
1901
+ { id: String(id) },
1902
+ ["wpgraphql", "gql-comments", `gql-comment-${id}`]
1903
+ );
1904
+ return data.comment;
1905
+ }
1906
+ return {
1907
+ getCommentsByPostId,
1908
+ getAllCommentsByPostId,
1909
+ getCommentById
1910
+ };
1911
+ }
1912
+
1913
+ // src/integrations/wpGraphQL/core/media/queries.ts
1914
+ var DEFAULT_FIRST6 = 10;
1915
+ var MEDIA_FIELDS = `
1916
+ id
1917
+ databaseId
1918
+ slug
1919
+ title
1920
+ date
1921
+ sourceUrl
1922
+ altText
1923
+ caption
1924
+ description
1925
+ mediaType
1926
+ mimeType
1927
+ uri
1928
+ mediaDetails {
1929
+ width
1930
+ height
1931
+ file
1932
+ sizes { name width height mimeType sourceUrl }
1933
+ }
1934
+ `;
1935
+ var GQL_GET_MEDIA_ITEMS = `
1936
+ query GetMediaItems($first: Int, $after: String) {
1937
+ mediaItems(first: $first, after: $after) {
1938
+ nodes { ${MEDIA_FIELDS} }
1939
+ pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
1940
+ }
1941
+ }
1942
+ `;
1943
+ var GQL_GET_MEDIA_ITEM_BY_ID = `
1944
+ query GetMediaItemById($id: ID!) {
1945
+ mediaItem(id: $id, idType: DATABASE_ID) { ${MEDIA_FIELDS} }
1946
+ }
1947
+ `;
1948
+ var GQL_GET_MEDIA_ITEM_BY_SLUG = `
1949
+ query GetMediaItemBySlug($id: ID!) {
1950
+ mediaItem(id: $id, idType: SLUG) { ${MEDIA_FIELDS} }
1951
+ }
1952
+ `;
1953
+ function createMediaQueries2(fetcher) {
1954
+ const { gqlFetchGraceful } = fetcher;
1955
+ async function getMediaItems(first = DEFAULT_FIRST6, after) {
1956
+ const data = await gqlFetchGraceful(
1957
+ GQL_GET_MEDIA_ITEMS,
1958
+ { mediaItems: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
1959
+ { first, after },
1960
+ ["wpgraphql", "gql-media"]
1961
+ );
1962
+ return data.mediaItems;
1963
+ }
1964
+ async function getMediaItemById(id) {
1965
+ const data = await gqlFetchGraceful(
1966
+ GQL_GET_MEDIA_ITEM_BY_ID,
1967
+ { mediaItem: null },
1968
+ { id: String(id) },
1969
+ ["wpgraphql", "gql-media", `gql-media-${id}`]
1970
+ );
1971
+ return data.mediaItem;
1972
+ }
1973
+ async function getMediaItemBySlug(slug) {
1974
+ const data = await gqlFetchGraceful(
1975
+ GQL_GET_MEDIA_ITEM_BY_SLUG,
1976
+ { mediaItem: null },
1977
+ { id: slug },
1978
+ ["wpgraphql", "gql-media", `gql-media-${slug}`]
1979
+ );
1980
+ return data.mediaItem;
1981
+ }
1982
+ return { getMediaItems, getMediaItemById, getMediaItemBySlug };
1983
+ }
1984
+
1985
+ // src/integrations/wpGraphQL/core/mutations/posts/mutations.ts
1986
+ var MUTATED_POST_FIELDS = `
1987
+ id
1988
+ databaseId
1989
+ slug
1990
+ title
1991
+ status
1992
+ `;
1993
+ var GQL_CREATE_POST = `
1994
+ mutation CreatePost($input: CreatePostInput!) {
1995
+ createPost(input: $input) {
1996
+ post { ${MUTATED_POST_FIELDS} }
1997
+ }
1998
+ }
1999
+ `;
2000
+ var GQL_UPDATE_POST = `
2001
+ mutation UpdatePost($input: UpdatePostInput!) {
2002
+ updatePost(input: $input) {
2003
+ post { ${MUTATED_POST_FIELDS} }
2004
+ }
2005
+ }
2006
+ `;
2007
+ var GQL_DELETE_POST = `
2008
+ mutation DeletePost($input: DeletePostInput!) {
2009
+ deletePost(input: $input) {
2010
+ deletedId
2011
+ post { ${MUTATED_POST_FIELDS} }
2012
+ }
2013
+ }
2014
+ `;
2015
+ function createPostsMutations2(fetcher) {
2016
+ const { gqlMutate } = fetcher;
2017
+ async function createPost(input, authToken) {
2018
+ const data = await gqlMutate(
2019
+ GQL_CREATE_POST,
2020
+ { input },
2021
+ authToken
2022
+ );
2023
+ return data.createPost.post;
2024
+ }
2025
+ async function updatePost(input, authToken) {
2026
+ const data = await gqlMutate(
2027
+ GQL_UPDATE_POST,
2028
+ { input },
2029
+ authToken
2030
+ );
2031
+ return data.updatePost.post;
2032
+ }
2033
+ async function deletePost(id, authToken, forceDelete = false) {
2034
+ const data = await gqlMutate(
2035
+ GQL_DELETE_POST,
2036
+ { input: { id, forceDelete } },
2037
+ authToken
2038
+ );
2039
+ return data.deletePost;
2040
+ }
2041
+ return { createPost, updatePost, deletePost };
2042
+ }
2043
+
2044
+ // src/integrations/wpGraphQL/core/mutations/comments/mutations.ts
2045
+ var MUTATED_COMMENT_FIELDS = `
2046
+ id
2047
+ databaseId
2048
+ content(format: RENDERED)
2049
+ date
2050
+ status
2051
+ parentId
2052
+ author { node { name url } }
2053
+ `;
2054
+ var GQL_CREATE_COMMENT = `
2055
+ mutation CreateComment($input: CreateCommentInput!) {
2056
+ createComment(input: $input) {
2057
+ success
2058
+ comment { ${MUTATED_COMMENT_FIELDS} }
2059
+ }
2060
+ }
2061
+ `;
2062
+ var GQL_UPDATE_COMMENT = `
2063
+ mutation UpdateComment($input: UpdateCommentInput!) {
2064
+ updateComment(input: $input) {
2065
+ comment { ${MUTATED_COMMENT_FIELDS} }
2066
+ }
2067
+ }
2068
+ `;
2069
+ var GQL_DELETE_COMMENT = `
2070
+ mutation DeleteComment($input: DeleteCommentInput!) {
2071
+ deleteComment(input: $input) {
2072
+ deletedId
2073
+ comment { ${MUTATED_COMMENT_FIELDS} }
2074
+ }
2075
+ }
2076
+ `;
2077
+ function createCommentsMutations2(fetcher) {
2078
+ const { gqlMutate } = fetcher;
2079
+ async function createComment(input, authToken) {
2080
+ const gqlInput = {
2081
+ commentOn: input.postId,
2082
+ content: input.content
2083
+ };
2084
+ if (input.authorName) gqlInput["author"] = input.authorName;
2085
+ if (input.authorEmail) gqlInput["authorEmail"] = input.authorEmail;
2086
+ if (input.authorUrl) gqlInput["authorUrl"] = input.authorUrl;
2087
+ if (input.parentId) gqlInput["parent"] = input.parentId;
2088
+ const data = await gqlMutate(
2089
+ GQL_CREATE_COMMENT,
2090
+ { input: gqlInput },
2091
+ authToken
2092
+ );
2093
+ return data.createComment;
2094
+ }
2095
+ async function updateComment(input, authToken) {
2096
+ const data = await gqlMutate(
2097
+ GQL_UPDATE_COMMENT,
2098
+ { input },
2099
+ authToken
2100
+ );
2101
+ return data.updateComment.comment;
2102
+ }
2103
+ async function deleteComment(id, authToken, forceDelete = false) {
2104
+ const data = await gqlMutate(
2105
+ GQL_DELETE_COMMENT,
2106
+ { input: { id, forceDelete } },
2107
+ authToken
2108
+ );
2109
+ return data.deleteComment;
2110
+ }
2111
+ return { createComment, updateComment, deleteComment };
2112
+ }
2113
+
2114
+ // src/integrations/wpGraphQL/core/mutations/pages/mutations.ts
2115
+ var MUTATED_PAGE_FIELDS = `
2116
+ id
2117
+ databaseId
2118
+ slug
2119
+ title
2120
+ status
2121
+ uri
2122
+ `;
2123
+ var GQL_CREATE_PAGE = `
2124
+ mutation CreatePage($input: CreatePageInput!) {
2125
+ createPage(input: $input) {
2126
+ page { ${MUTATED_PAGE_FIELDS} }
2127
+ }
2128
+ }
2129
+ `;
2130
+ var GQL_UPDATE_PAGE = `
2131
+ mutation UpdatePage($input: UpdatePageInput!) {
2132
+ updatePage(input: $input) {
2133
+ page { ${MUTATED_PAGE_FIELDS} }
2134
+ }
2135
+ }
2136
+ `;
2137
+ var GQL_DELETE_PAGE = `
2138
+ mutation DeletePage($input: DeletePageInput!) {
2139
+ deletePage(input: $input) {
2140
+ deletedId
2141
+ page { ${MUTATED_PAGE_FIELDS} }
2142
+ }
2143
+ }
2144
+ `;
2145
+ function createPagesMutations2(fetcher) {
2146
+ const { gqlMutate } = fetcher;
2147
+ async function createPage(input, authToken) {
2148
+ const data = await gqlMutate(
2149
+ GQL_CREATE_PAGE,
2150
+ { input },
2151
+ authToken
2152
+ );
2153
+ return data.createPage.page;
2154
+ }
2155
+ async function updatePage(input, authToken) {
2156
+ const data = await gqlMutate(
2157
+ GQL_UPDATE_PAGE,
2158
+ { input },
2159
+ authToken
2160
+ );
2161
+ return data.updatePage.page;
2162
+ }
2163
+ async function deletePage(id, authToken, forceDelete = false) {
2164
+ const data = await gqlMutate(
2165
+ GQL_DELETE_PAGE,
2166
+ { input: { id, forceDelete } },
2167
+ authToken
2168
+ );
2169
+ return data.deletePage;
2170
+ }
2171
+ return { createPage, updatePage, deletePage };
2172
+ }
2173
+
2174
+ // src/integrations/wpGraphQL/core/mutations/categories/mutations.ts
2175
+ var MUTATED_CATEGORY_FIELDS = `
2176
+ id
2177
+ databaseId
2178
+ name
2179
+ slug
2180
+ `;
2181
+ var GQL_CREATE_CATEGORY = `
2182
+ mutation CreateCategory($input: CreateCategoryInput!) {
2183
+ createCategory(input: $input) {
2184
+ category { ${MUTATED_CATEGORY_FIELDS} }
2185
+ }
2186
+ }
2187
+ `;
2188
+ var GQL_UPDATE_CATEGORY = `
2189
+ mutation UpdateCategory($input: UpdateCategoryInput!) {
2190
+ updateCategory(input: $input) {
2191
+ category { ${MUTATED_CATEGORY_FIELDS} }
2192
+ }
2193
+ }
2194
+ `;
2195
+ var GQL_DELETE_CATEGORY = `
2196
+ mutation DeleteCategory($input: DeleteCategoryInput!) {
2197
+ deleteCategory(input: $input) {
2198
+ deletedId
2199
+ category { ${MUTATED_CATEGORY_FIELDS} }
2200
+ }
2201
+ }
2202
+ `;
2203
+ function createCategoriesMutations3(fetcher) {
2204
+ const { gqlMutate } = fetcher;
2205
+ async function createCategory(input, authToken) {
2206
+ const data = await gqlMutate(
2207
+ GQL_CREATE_CATEGORY,
2208
+ { input },
2209
+ authToken
2210
+ );
2211
+ return data.createCategory.category;
2212
+ }
2213
+ async function updateCategory(input, authToken) {
2214
+ const data = await gqlMutate(
2215
+ GQL_UPDATE_CATEGORY,
2216
+ { input },
2217
+ authToken
2218
+ );
2219
+ return data.updateCategory.category;
2220
+ }
2221
+ async function deleteCategory(id, authToken) {
2222
+ const data = await gqlMutate(
2223
+ GQL_DELETE_CATEGORY,
2224
+ { input: { id } },
2225
+ authToken
2226
+ );
2227
+ return data.deleteCategory;
2228
+ }
2229
+ return { createCategory, updateCategory, deleteCategory };
2230
+ }
2231
+
2232
+ // src/integrations/wpGraphQL/core/mutations/tags/mutations.ts
2233
+ var MUTATED_TAG_FIELDS = `
2234
+ id
2235
+ databaseId
2236
+ name
2237
+ slug
2238
+ `;
2239
+ var GQL_CREATE_TAG = `
2240
+ mutation CreateTag($input: CreateTagInput!) {
2241
+ createTag(input: $input) {
2242
+ tag { ${MUTATED_TAG_FIELDS} }
2243
+ }
2244
+ }
2245
+ `;
2246
+ var GQL_UPDATE_TAG = `
2247
+ mutation UpdateTag($input: UpdateTagInput!) {
2248
+ updateTag(input: $input) {
2249
+ tag { ${MUTATED_TAG_FIELDS} }
2250
+ }
2251
+ }
2252
+ `;
2253
+ var GQL_DELETE_TAG = `
2254
+ mutation DeleteTag($input: DeleteTagInput!) {
2255
+ deleteTag(input: $input) {
2256
+ deletedId
2257
+ tag { ${MUTATED_TAG_FIELDS} }
2258
+ }
2259
+ }
2260
+ `;
2261
+ function createTagsMutations3(fetcher) {
2262
+ const { gqlMutate } = fetcher;
2263
+ async function createTag(input, authToken) {
2264
+ const data = await gqlMutate(
2265
+ GQL_CREATE_TAG,
2266
+ { input },
2267
+ authToken
2268
+ );
2269
+ return data.createTag.tag;
2270
+ }
2271
+ async function updateTag(input, authToken) {
2272
+ const data = await gqlMutate(
2273
+ GQL_UPDATE_TAG,
2274
+ { input },
2275
+ authToken
2276
+ );
2277
+ return data.updateTag.tag;
2278
+ }
2279
+ async function deleteTag(id, authToken) {
2280
+ const data = await gqlMutate(
2281
+ GQL_DELETE_TAG,
2282
+ { input: { id } },
2283
+ authToken
2284
+ );
2285
+ return data.deleteTag;
2286
+ }
2287
+ return { createTag, updateTag, deleteTag };
2288
+ }
2289
+
2290
+ // src/integrations/wpGraphQL/core/mutations/authors/mutations.ts
2291
+ var MUTATED_USER_FIELDS = `
2292
+ id
2293
+ databaseId
2294
+ name
2295
+ slug
2296
+ email
2297
+ `;
2298
+ var GQL_REGISTER_USER = `
2299
+ mutation RegisterUser($input: RegisterUserInput!) {
2300
+ registerUser(input: $input) {
2301
+ user { ${MUTATED_USER_FIELDS} }
2302
+ }
2303
+ }
2304
+ `;
2305
+ var GQL_UPDATE_USER = `
2306
+ mutation UpdateUser($input: UpdateUserInput!) {
2307
+ updateUser(input: $input) {
2308
+ user { ${MUTATED_USER_FIELDS} }
2309
+ }
2310
+ }
2311
+ `;
2312
+ var GQL_DELETE_USER = `
2313
+ mutation DeleteUser($input: DeleteUserInput!) {
2314
+ deleteUser(input: $input) {
2315
+ deletedId
2316
+ user { ${MUTATED_USER_FIELDS} }
2317
+ }
2318
+ }
2319
+ `;
2320
+ function createAuthorsMutations2(fetcher) {
2321
+ const { gqlMutate } = fetcher;
2322
+ async function registerUser(input, authToken) {
2323
+ const data = await gqlMutate(
2324
+ GQL_REGISTER_USER,
2325
+ { input },
2326
+ authToken
2327
+ );
2328
+ return data.registerUser.user;
2329
+ }
2330
+ async function updateUser(input, authToken) {
2331
+ const data = await gqlMutate(
2332
+ GQL_UPDATE_USER,
2333
+ { input },
2334
+ authToken
2335
+ );
2336
+ return data.updateUser.user;
2337
+ }
2338
+ async function deleteUser(id, authToken, reassignPosts) {
2339
+ const input = { id };
2340
+ if (reassignPosts) input["reassignId"] = reassignPosts;
2341
+ const data = await gqlMutate(
2342
+ GQL_DELETE_USER,
2343
+ { input },
2344
+ authToken
2345
+ );
2346
+ return data.deleteUser;
2347
+ }
2348
+ return { registerUser, updateUser, deleteUser };
2349
+ }
2350
+
2351
+ // src/integrations/wpGraphQL/core/mutations/media/mutations.ts
2352
+ var MUTATED_MEDIA_FIELDS = `
2353
+ id
2354
+ databaseId
2355
+ slug
2356
+ title
2357
+ sourceUrl
2358
+ altText
2359
+ `;
2360
+ var GQL_CREATE_MEDIA_ITEM = `
2361
+ mutation CreateMediaItem($input: CreateMediaItemInput!) {
2362
+ createMediaItem(input: $input) {
2363
+ mediaItem { ${MUTATED_MEDIA_FIELDS} }
2364
+ }
2365
+ }
2366
+ `;
2367
+ var GQL_UPDATE_MEDIA_ITEM = `
2368
+ mutation UpdateMediaItem($input: UpdateMediaItemInput!) {
2369
+ updateMediaItem(input: $input) {
2370
+ mediaItem { ${MUTATED_MEDIA_FIELDS} }
2371
+ }
2372
+ }
2373
+ `;
2374
+ var GQL_DELETE_MEDIA_ITEM = `
2375
+ mutation DeleteMediaItem($input: DeleteMediaItemInput!) {
2376
+ deleteMediaItem(input: $input) {
2377
+ deletedId
2378
+ mediaItem { ${MUTATED_MEDIA_FIELDS} }
2379
+ }
2380
+ }
2381
+ `;
2382
+ function createMediaMutations2(fetcher) {
2383
+ const { gqlMutate } = fetcher;
2384
+ async function createMediaItem(input, authToken) {
2385
+ const data = await gqlMutate(
2386
+ GQL_CREATE_MEDIA_ITEM,
2387
+ { input },
2388
+ authToken
2389
+ );
2390
+ return data.createMediaItem.mediaItem;
2391
+ }
2392
+ async function updateMediaItem(input, authToken) {
2393
+ const data = await gqlMutate(
2394
+ GQL_UPDATE_MEDIA_ITEM,
2395
+ { input },
2396
+ authToken
2397
+ );
2398
+ return data.updateMediaItem.mediaItem;
2399
+ }
2400
+ async function deleteMediaItem(id, authToken, forceDelete = true) {
2401
+ const data = await gqlMutate(
2402
+ GQL_DELETE_MEDIA_ITEM,
2403
+ { input: { id, forceDelete } },
2404
+ authToken
2405
+ );
2406
+ return data.deleteMediaItem;
2407
+ }
2408
+ return { createMediaItem, updateMediaItem, deleteMediaItem };
2409
+ }
2410
+
2411
+ // src/integrations/wpGraphQL/core/mutations/index.ts
2412
+ function createWPGraphQLMutationsClient(config) {
2413
+ const fetcher = createWPGraphQLFetcher(config);
2414
+ return {
2415
+ ...createPostsMutations2(fetcher),
2416
+ ...createCommentsMutations2(fetcher),
2417
+ ...createPagesMutations2(fetcher),
2418
+ ...createCategoriesMutations3(fetcher),
2419
+ ...createTagsMutations3(fetcher),
2420
+ ...createAuthorsMutations2(fetcher),
2421
+ ...createMediaMutations2(fetcher)
2422
+ };
2423
+ }
2424
+
2425
+ // src/integrations/wpGraphQL/core/index.ts
2426
+ function createWPGraphQLCoreClient(config) {
2427
+ const fetcher = createWPGraphQLFetcher(config);
2428
+ return {
2429
+ ...createPostsQueries2(fetcher),
2430
+ ...createPagesQueries2(fetcher),
2431
+ ...createCategoriesQueries3(fetcher),
2432
+ ...createTagsQueries3(fetcher),
2433
+ ...createAuthorsQueries2(fetcher),
2434
+ ...createMenusQueries2(fetcher),
2435
+ ...createCommentsQueries2(fetcher),
2436
+ ...createMediaQueries2(fetcher)
2437
+ };
2438
+ }
2439
+
2440
+ // src/integrations/wpGraphQL/yoast/queries.ts
2441
+ var SEO_FIELDS = `
2442
+ seo {
2443
+ title
2444
+ metaDesc
2445
+ canonical
2446
+ opengraphTitle
2447
+ opengraphDescription
2448
+ opengraphImage { sourceUrl altText }
2449
+ twitterTitle
2450
+ twitterDescription
2451
+ twitterImage { sourceUrl }
2452
+ schema { raw }
2453
+ }
2454
+ `;
2455
+ var POST_FIELDS_WITH_SEO = `
2456
+ id
2457
+ databaseId
2458
+ slug
2459
+ title
2460
+ content
2461
+ excerpt
2462
+ date
2463
+ modified
2464
+ status
2465
+ uri
2466
+ author {
2467
+ node {
2468
+ databaseId
2469
+ name
2470
+ slug
2471
+ avatar { url }
2472
+ }
2473
+ }
2474
+ featuredImage {
2475
+ node {
2476
+ sourceUrl
2477
+ altText
2478
+ mediaDetails { width height }
2479
+ }
2480
+ }
2481
+ categories {
2482
+ nodes { databaseId name slug }
2483
+ }
2484
+ tags {
2485
+ nodes { databaseId name slug }
2486
+ }
2487
+ ${SEO_FIELDS}
2488
+ `;
2489
+ var PAGE_FIELDS_WITH_SEO = `
2490
+ id
2491
+ databaseId
2492
+ slug
2493
+ title
2494
+ content
2495
+ date
2496
+ modified
2497
+ status
2498
+ uri
2499
+ featuredImage {
2500
+ node {
2501
+ sourceUrl
2502
+ altText
2503
+ mediaDetails { width height }
2504
+ }
2505
+ }
2506
+ ${SEO_FIELDS}
2507
+ `;
2508
+ var GQL_GET_POST_WITH_SEO = `
2509
+ query GetPostWithSEO($slug: ID!) {
2510
+ post(id: $slug, idType: SLUG) { ${POST_FIELDS_WITH_SEO} }
2511
+ }
2512
+ `;
2513
+ var GQL_GET_PAGE_WITH_SEO = `
2514
+ query GetPageWithSEO($slug: ID!) {
2515
+ page(id: $slug, idType: SLUG) { ${PAGE_FIELDS_WITH_SEO} }
2516
+ }
2517
+ `;
2518
+ var GQL_GET_PAGE_WITH_SEO_BY_URI = `
2519
+ query GetPageWithSEOByUri($uri: ID!) {
2520
+ page(id: $uri, idType: URI) { ${PAGE_FIELDS_WITH_SEO} }
2521
+ }
2522
+ `;
2523
+ function createYoastQueries(fetcher) {
2524
+ const { gqlFetchGraceful } = fetcher;
2525
+ async function getPostWithSEO(slug) {
2526
+ const data = await gqlFetchGraceful(
2527
+ GQL_GET_POST_WITH_SEO,
2528
+ { post: null },
2529
+ { slug },
2530
+ ["wpgraphql", "gql-posts", "gql-yoast", `gql-post-${slug}`]
2531
+ );
2532
+ return data.post;
2533
+ }
2534
+ async function getPageWithSEO(slug) {
2535
+ const data = await gqlFetchGraceful(
2536
+ GQL_GET_PAGE_WITH_SEO,
2537
+ { page: null },
2538
+ { slug },
2539
+ ["wpgraphql", "gql-pages", "gql-yoast", `gql-page-${slug}`]
2540
+ );
2541
+ return data.page;
2542
+ }
2543
+ async function getPageWithSEOByUri(uri) {
2544
+ const data = await gqlFetchGraceful(
2545
+ GQL_GET_PAGE_WITH_SEO_BY_URI,
2546
+ { page: null },
2547
+ { uri },
2548
+ ["wpgraphql", "gql-pages", "gql-yoast", `gql-page-uri-${uri.replace(/\//g, "-")}`]
2549
+ );
2550
+ return data.page;
2551
+ }
2552
+ return { getPostWithSEO, getPageWithSEO, getPageWithSEOByUri };
2553
+ }
2554
+
2555
+ // src/integrations/wpGraphQL/acf/helpers.ts
2556
+ var BASE_POST_FIELDS = `
2557
+ id databaseId slug title content excerpt date modified status uri
1393
2558
  author { node { databaseId name slug avatar { url } } }
1394
2559
  featuredImage { node { sourceUrl altText mediaDetails { width height } } }
1395
2560
  categories { nodes { databaseId name slug } }
@@ -1437,29 +2602,38 @@ function buildPostsWithACFQuery(fieldGroupName, fields) {
1437
2602
  }
1438
2603
 
1439
2604
  // src/integrations/wpGraphQL/woocommerce/products/queries.ts
1440
- var DEFAULT_FIRST6 = 10;
2605
+ var DEFAULT_FIRST7 = 10;
1441
2606
  var BATCH_FIRST3 = 100;
1442
2607
  var PRODUCT_FIELDS = `
1443
2608
  id
1444
2609
  databaseId
1445
2610
  slug
1446
2611
  name
2612
+ status
1447
2613
  description
1448
2614
  shortDescription
1449
- sku
1450
- price
1451
- regularPrice
1452
- salePrice
1453
- onSale
1454
- stockStatus
1455
- stockQuantity
1456
- manageStock
1457
2615
  type
2616
+ onSale
1458
2617
  featuredImage { node { sourceUrl altText } }
1459
2618
  galleryImages { nodes { sourceUrl altText } }
1460
2619
  productCategories { nodes { databaseId name slug } }
1461
2620
  productTags { nodes { databaseId name slug } }
2621
+ ... on SimpleProduct {
2622
+ sku
2623
+ price
2624
+ regularPrice
2625
+ salePrice
2626
+ stockStatus
2627
+ stockQuantity
2628
+ manageStock
2629
+ }
1462
2630
  ... on VariableProduct {
2631
+ price
2632
+ regularPrice
2633
+ salePrice
2634
+ stockStatus
2635
+ stockQuantity
2636
+ manageStock
1463
2637
  variations {
1464
2638
  nodes {
1465
2639
  id
@@ -1506,7 +2680,7 @@ var GQL_GET_ALL_PRODUCT_SLUGS = `
1506
2680
  `;
1507
2681
  function createProductsQueries2(fetcher) {
1508
2682
  const { gqlFetch, gqlFetchGraceful } = fetcher;
1509
- async function getProducts(first = DEFAULT_FIRST6, after, filter) {
2683
+ async function getProducts(first = DEFAULT_FIRST7, after, filter) {
1510
2684
  const where = {};
1511
2685
  if (filter?.search) where["search"] = filter.search;
1512
2686
  if (filter?.onSale !== void 0) where["onSale"] = filter.onSale;
@@ -1542,11 +2716,11 @@ function createProductsQueries2(fetcher) {
1542
2716
  );
1543
2717
  return data.product;
1544
2718
  }
1545
- async function getFeaturedProducts(first = DEFAULT_FIRST6) {
2719
+ async function getFeaturedProducts(first = DEFAULT_FIRST7) {
1546
2720
  const connection = await getProducts(first, void 0, { featured: true });
1547
2721
  return connection.nodes;
1548
2722
  }
1549
- async function getOnSaleProducts(first = DEFAULT_FIRST6) {
2723
+ async function getOnSaleProducts(first = DEFAULT_FIRST7) {
1550
2724
  const connection = await getProducts(first, void 0, { onSale: true });
1551
2725
  return connection.nodes;
1552
2726
  }
@@ -1578,7 +2752,7 @@ function createProductsQueries2(fetcher) {
1578
2752
  }
1579
2753
 
1580
2754
  // src/integrations/wpGraphQL/woocommerce/orders/queries.ts
1581
- var DEFAULT_FIRST7 = 10;
2755
+ var DEFAULT_FIRST8 = 10;
1582
2756
  var ADDRESS_FIELDS = `
1583
2757
  firstName lastName address1 address2 city postcode country email phone
1584
2758
  `;
@@ -1631,7 +2805,7 @@ function createOrdersQueries2(fetcher) {
1631
2805
  );
1632
2806
  return data.order;
1633
2807
  }
1634
- async function getMyOrders(first = DEFAULT_FIRST7, after) {
2808
+ async function getMyOrders(first = DEFAULT_FIRST8, after) {
1635
2809
  const data = await gqlFetchGraceful(
1636
2810
  GQL_GET_MY_ORDERS,
1637
2811
  { orders: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
@@ -1690,18 +2864,211 @@ function createCustomersQueries2(fetcher) {
1690
2864
  return { getCustomer, getCustomerById };
1691
2865
  }
1692
2866
 
2867
+ // src/integrations/wpGraphQL/woocommerce/categories/queries.ts
2868
+ var DEFAULT_FIRST9 = 100;
2869
+ var CATEGORY_FIELDS2 = `
2870
+ id
2871
+ databaseId
2872
+ name
2873
+ slug
2874
+ description
2875
+ count
2876
+ parent { node { id databaseId name slug } }
2877
+ image { sourceUrl altText }
2878
+ `;
2879
+ var GQL_GET_PRODUCT_CATEGORIES = `
2880
+ query GetProductCategories($first: Int, $after: String) {
2881
+ productCategories(first: $first, after: $after) {
2882
+ nodes { ${CATEGORY_FIELDS2} }
2883
+ pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
2884
+ }
2885
+ }
2886
+ `;
2887
+ var GQL_GET_PRODUCT_CATEGORY_BY_SLUG = `
2888
+ query GetProductCategoryBySlug($id: ID!) {
2889
+ productCategory(id: $id, idType: SLUG) { ${CATEGORY_FIELDS2} }
2890
+ }
2891
+ `;
2892
+ var GQL_GET_PRODUCT_CATEGORY_BY_ID = `
2893
+ query GetProductCategoryById($id: ID!) {
2894
+ productCategory(id: $id, idType: DATABASE_ID) { ${CATEGORY_FIELDS2} }
2895
+ }
2896
+ `;
2897
+ function createCategoriesQueries4(fetcher) {
2898
+ const { gqlFetchGraceful } = fetcher;
2899
+ async function getProductCategories(first = DEFAULT_FIRST9, after) {
2900
+ const data = await gqlFetchGraceful(
2901
+ GQL_GET_PRODUCT_CATEGORIES,
2902
+ { productCategories: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
2903
+ { first, after },
2904
+ ["wpgraphql", "gql-product-categories"]
2905
+ );
2906
+ return data.productCategories;
2907
+ }
2908
+ async function getProductCategoryBySlug(slug) {
2909
+ const data = await gqlFetchGraceful(
2910
+ GQL_GET_PRODUCT_CATEGORY_BY_SLUG,
2911
+ { productCategory: null },
2912
+ { id: slug },
2913
+ ["wpgraphql", "gql-product-categories", `gql-product-category-${slug}`]
2914
+ );
2915
+ return data.productCategory;
2916
+ }
2917
+ async function getProductCategoryById(id) {
2918
+ const data = await gqlFetchGraceful(
2919
+ GQL_GET_PRODUCT_CATEGORY_BY_ID,
2920
+ { productCategory: null },
2921
+ { id: String(id) },
2922
+ ["wpgraphql", "gql-product-categories", `gql-product-category-${id}`]
2923
+ );
2924
+ return data.productCategory;
2925
+ }
2926
+ return { getProductCategories, getProductCategoryBySlug, getProductCategoryById };
2927
+ }
2928
+
2929
+ // src/integrations/wpGraphQL/woocommerce/tags/queries.ts
2930
+ var DEFAULT_FIRST10 = 100;
2931
+ var TAG_FIELDS2 = `
2932
+ id
2933
+ databaseId
2934
+ name
2935
+ slug
2936
+ description
2937
+ count
2938
+ `;
2939
+ var GQL_GET_PRODUCT_TAGS = `
2940
+ query GetProductTags($first: Int, $after: String) {
2941
+ productTags(first: $first, after: $after) {
2942
+ nodes { ${TAG_FIELDS2} }
2943
+ pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
2944
+ }
2945
+ }
2946
+ `;
2947
+ var GQL_GET_PRODUCT_TAG_BY_SLUG = `
2948
+ query GetProductTagBySlug($id: ID!) {
2949
+ productTag(id: $id, idType: SLUG) { ${TAG_FIELDS2} }
2950
+ }
2951
+ `;
2952
+ var GQL_GET_PRODUCT_TAG_BY_ID = `
2953
+ query GetProductTagById($id: ID!) {
2954
+ productTag(id: $id, idType: DATABASE_ID) { ${TAG_FIELDS2} }
2955
+ }
2956
+ `;
2957
+ function createTagsQueries4(fetcher) {
2958
+ const { gqlFetchGraceful } = fetcher;
2959
+ async function getProductTags(first = DEFAULT_FIRST10, after) {
2960
+ const data = await gqlFetchGraceful(
2961
+ GQL_GET_PRODUCT_TAGS,
2962
+ { productTags: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
2963
+ { first, after },
2964
+ ["wpgraphql", "gql-product-tags"]
2965
+ );
2966
+ return data.productTags;
2967
+ }
2968
+ async function getProductTagBySlug(slug) {
2969
+ const data = await gqlFetchGraceful(
2970
+ GQL_GET_PRODUCT_TAG_BY_SLUG,
2971
+ { productTag: null },
2972
+ { id: slug },
2973
+ ["wpgraphql", "gql-product-tags", `gql-product-tag-${slug}`]
2974
+ );
2975
+ return data.productTag;
2976
+ }
2977
+ async function getProductTagById(id) {
2978
+ const data = await gqlFetchGraceful(
2979
+ GQL_GET_PRODUCT_TAG_BY_ID,
2980
+ { productTag: null },
2981
+ { id: String(id) },
2982
+ ["wpgraphql", "gql-product-tags", `gql-product-tag-${id}`]
2983
+ );
2984
+ return data.productTag;
2985
+ }
2986
+ return { getProductTags, getProductTagBySlug, getProductTagById };
2987
+ }
2988
+
2989
+ // src/integrations/wpGraphQL/woocommerce/coupons/queries.ts
2990
+ var DEFAULT_FIRST11 = 100;
2991
+ var COUPON_FIELDS = `
2992
+ id
2993
+ databaseId
2994
+ code
2995
+ discountType
2996
+ amount
2997
+ dateExpiry
2998
+ usageCount
2999
+ usageLimit
3000
+ usageLimitPerUser
3001
+ individualUse
3002
+ freeShipping
3003
+ minimumAmount
3004
+ maximumAmount
3005
+ description
3006
+ `;
3007
+ var GQL_GET_COUPONS = `
3008
+ query GetCoupons($first: Int, $after: String) {
3009
+ coupons(first: $first, after: $after) {
3010
+ nodes { ${COUPON_FIELDS} }
3011
+ pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
3012
+ }
3013
+ }
3014
+ `;
3015
+ var GQL_GET_COUPON_BY_CODE = `
3016
+ query GetCouponByCode($id: ID!) {
3017
+ coupon(id: $id, idType: CODE) { ${COUPON_FIELDS} }
3018
+ }
3019
+ `;
3020
+ var GQL_GET_COUPON_BY_ID = `
3021
+ query GetCouponById($id: ID!) {
3022
+ coupon(id: $id, idType: DATABASE_ID) { ${COUPON_FIELDS} }
3023
+ }
3024
+ `;
3025
+ function createCouponsQueries2(fetcher) {
3026
+ const { gqlFetchGraceful } = fetcher;
3027
+ async function getCoupons(first = DEFAULT_FIRST11, after) {
3028
+ const data = await gqlFetchGraceful(
3029
+ GQL_GET_COUPONS,
3030
+ { coupons: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
3031
+ { first, after },
3032
+ ["wpgraphql", "gql-coupons"]
3033
+ );
3034
+ return data.coupons;
3035
+ }
3036
+ async function getCouponByCode(code) {
3037
+ const data = await gqlFetchGraceful(
3038
+ GQL_GET_COUPON_BY_CODE,
3039
+ { coupon: null },
3040
+ { id: code },
3041
+ ["wpgraphql", "gql-coupons", `gql-coupon-${code}`]
3042
+ );
3043
+ return data.coupon;
3044
+ }
3045
+ async function getCouponById(id) {
3046
+ const data = await gqlFetchGraceful(
3047
+ GQL_GET_COUPON_BY_ID,
3048
+ { coupon: null },
3049
+ { id: String(id) },
3050
+ ["wpgraphql", "gql-coupons", `gql-coupon-${id}`]
3051
+ );
3052
+ return data.coupon;
3053
+ }
3054
+ return { getCoupons, getCouponByCode, getCouponById };
3055
+ }
3056
+
1693
3057
  // src/integrations/wpGraphQL/woocommerce/index.ts
1694
3058
  function createWPGraphQLWooCommerceClient(config) {
1695
3059
  const fetcher = createWPGraphQLFetcher(config);
1696
3060
  return {
1697
3061
  ...createProductsQueries2(fetcher),
1698
3062
  ...createOrdersQueries2(fetcher),
1699
- ...createCustomersQueries2(fetcher)
3063
+ ...createCustomersQueries2(fetcher),
3064
+ ...createCategoriesQueries4(fetcher),
3065
+ ...createTagsQueries4(fetcher),
3066
+ ...createCouponsQueries2(fetcher)
1700
3067
  };
1701
3068
  }
1702
3069
 
1703
3070
  // src/integrations/wpGraphQL/cpt/queries.ts
1704
- var DEFAULT_FIRST8 = 10;
3071
+ var DEFAULT_FIRST12 = 10;
1705
3072
  var BATCH_FIRST4 = 100;
1706
3073
  var BASE_CPT_FIELDS = `
1707
3074
  id databaseId slug title date modified status uri
@@ -1730,7 +3097,7 @@ function createCPTQueries(fetcher, typeName, singularTypeName, extraFields) {
1730
3097
  }
1731
3098
  }
1732
3099
  `;
1733
- async function getItems(first = DEFAULT_FIRST8, after) {
3100
+ async function getItems(first = DEFAULT_FIRST12, after) {
1734
3101
  const data = await gqlFetchGraceful(
1735
3102
  GQL_GET_ITEMS,
1736
3103
  { [typeName]: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
@@ -1770,6 +3137,99 @@ function createCPTQueries(fetcher, typeName, singularTypeName, extraFields) {
1770
3137
  return { getItems, getItemBySlug, getAllSlugs };
1771
3138
  }
1772
3139
 
1773
- export { WPGraphQLError, buildACFFragment, buildPageWithACFQuery, buildPostWithACFQuery, buildPostsWithACFQuery, createCPTQueries, createWPGraphQLCoreClient as createWPGraphQLClient, createWPGraphQLCoreClient, createWPGraphQLFetcher, createWPGraphQLWooCommerceClient, createWooCommerceClient, createWooCommerceFetcher, createWordPressClient, createYoastQueries, extractOmnibusData, resolveBaseUrl, withOmnibus, withOmnibusVariation };
3140
+ // src/nextjs/revalidation.ts
3141
+ var ACTION_TAG_MAP = {
3142
+ save_post: ["wordpress", "posts"],
3143
+ save_post_post: ["wordpress", "posts"],
3144
+ save_post_page: ["wordpress", "pages"],
3145
+ delete_post: ["wordpress", "posts", "pages"],
3146
+ created_term: ["wordpress", "categories", "tags"],
3147
+ edited_term: ["wordpress", "categories", "tags"],
3148
+ delete_term: ["wordpress", "categories", "tags"],
3149
+ wp_update_nav_menu: ["wordpress", "menus"],
3150
+ woocommerce_product_updated: ["woocommerce", "products"],
3151
+ woocommerce_new_product: ["woocommerce", "products"],
3152
+ woocommerce_delete_product: ["woocommerce", "products"],
3153
+ woocommerce_new_order: ["woocommerce", "orders"],
3154
+ woocommerce_order_status_changed: ["woocommerce", "orders"],
3155
+ woocommerce_update_order: ["woocommerce", "orders"],
3156
+ woocommerce_product_category_updated: ["woocommerce", "categories"],
3157
+ woocommerce_product_tag_updated: ["woocommerce", "tags"]
3158
+ };
3159
+ function extractSecret(request) {
3160
+ const auth = request.headers.get("Authorization");
3161
+ if (auth?.startsWith("Bearer ")) return auth.slice(7);
3162
+ return new URL(request.url).searchParams.get("secret");
3163
+ }
3164
+ function createRevalidationHandler(config, revalidateTag) {
3165
+ return async function handler(request) {
3166
+ if (extractSecret(request) !== config.secret) {
3167
+ return Response.json({ revalidated: false, tags: [], message: "Unauthorized" }, { status: 401 });
3168
+ }
3169
+ let payload;
3170
+ try {
3171
+ payload = await request.json();
3172
+ } catch {
3173
+ return Response.json({ revalidated: false, tags: [], message: "Invalid JSON body" }, { status: 400 });
3174
+ }
3175
+ const { action } = payload;
3176
+ const matched = ACTION_TAG_MAP[action];
3177
+ if (!matched) {
3178
+ return Response.json(
3179
+ { revalidated: false, tags: [], message: `Unknown action: ${action}` },
3180
+ { status: 400 }
3181
+ );
3182
+ }
3183
+ const tags = [...new Set(matched)];
3184
+ for (const tag of tags) {
3185
+ revalidateTag(tag);
3186
+ }
3187
+ return Response.json({ revalidated: true, tags });
3188
+ };
3189
+ }
3190
+
3191
+ // src/auth/applicationPassword.ts
3192
+ function createApplicationPasswordToken(username, appPassword) {
3193
+ const encoded = Buffer.from(`${username}:${appPassword}`).toString("base64");
3194
+ return `Basic ${encoded}`;
3195
+ }
3196
+
3197
+ // src/auth/types.ts
3198
+ var AuthenticationError = class extends Error {
3199
+ constructor(message, status) {
3200
+ super(message);
3201
+ __publicField(this, "status", status);
3202
+ this.name = "AuthenticationError";
3203
+ }
3204
+ };
3205
+
3206
+ // src/auth/jwt.ts
3207
+ async function authenticateJwt(config, credentials) {
3208
+ const url = `${resolveBaseUrl(config)}/wp-json/jwt-auth/v1/token`;
3209
+ const response = await fetch(url, {
3210
+ method: "POST",
3211
+ headers: { "Content-Type": "application/json" },
3212
+ body: JSON.stringify(credentials),
3213
+ cache: "no-store"
3214
+ });
3215
+ if (!response.ok) {
3216
+ throw new AuthenticationError(
3217
+ `JWT authentication failed: ${response.statusText}`,
3218
+ response.status
3219
+ );
3220
+ }
3221
+ return response.json();
3222
+ }
3223
+ async function validateJwtToken(config, token) {
3224
+ const url = `${resolveBaseUrl(config)}/wp-json/jwt-auth/v1/token/validate`;
3225
+ const response = await fetch(url, {
3226
+ method: "POST",
3227
+ headers: { Authorization: `Bearer ${token}` },
3228
+ cache: "no-store"
3229
+ });
3230
+ return response.ok;
3231
+ }
3232
+
3233
+ export { AuthenticationError, WPGraphQLError, authenticateJwt, buildACFFragment, buildPageWithACFQuery, buildPostWithACFQuery, buildPostsWithACFQuery, createApplicationPasswordToken, createAuthorsMutations, createCPTQueries, createCategoriesMutations, createCommentsMutations, createMediaMutations, createMenusMutations, createPagesMutations, createPostsMutations, createRevalidationHandler, createTagsMutations, createWPGraphQLCoreClient as createWPGraphQLClient, createWPGraphQLCoreClient, createWPGraphQLFetcher, createWPGraphQLMutationsClient, createWPGraphQLWooCommerceClient, createWooCommerceClient, createWooCommerceFetcher, createWordPressClient, createWordPressMutationsClient, createYoastQueries, extractOmnibusData, resolveBaseUrl, validateJwtToken, withOmnibus, withOmnibusVariation };
1774
3234
  //# sourceMappingURL=index.js.map
1775
3235
  //# sourceMappingURL=index.js.map