@szymonpiatek/nextwordpress 0.0.3 → 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.cjs CHANGED
@@ -9,6 +9,199 @@ function resolveBaseUrl(config) {
9
9
  return typeof window === "undefined" ? config.serverURL : config.clientURL;
10
10
  }
11
11
 
12
+ // src/integrations/restApi/core/mutations/posts/mutations.ts
13
+ function createPostsMutations(fetcher) {
14
+ const { wpMutate } = fetcher;
15
+ async function createPost(input, authToken) {
16
+ return wpMutate("/wp/v2/posts", input, "POST", authToken);
17
+ }
18
+ async function updatePost(id, input, authToken) {
19
+ return wpMutate(`/wp/v2/posts/${id}`, input, "PATCH", authToken);
20
+ }
21
+ async function deletePost(id, authToken, force = false) {
22
+ return wpMutate(
23
+ `/wp/v2/posts/${id}`,
24
+ { force },
25
+ "DELETE",
26
+ authToken
27
+ );
28
+ }
29
+ return { createPost, updatePost, deletePost };
30
+ }
31
+
32
+ // src/integrations/restApi/core/mutations/comments/mutations.ts
33
+ function createCommentsMutations(fetcher) {
34
+ const { wpMutate } = fetcher;
35
+ async function createComment(input, authToken) {
36
+ return wpMutate("/wp/v2/comments", input, "POST", authToken);
37
+ }
38
+ async function updateComment(id, input, authToken) {
39
+ return wpMutate(`/wp/v2/comments/${id}`, input, "PATCH", authToken);
40
+ }
41
+ async function deleteComment(id, authToken, force = false) {
42
+ return wpMutate(
43
+ `/wp/v2/comments/${id}`,
44
+ { force },
45
+ "DELETE",
46
+ authToken
47
+ );
48
+ }
49
+ return { createComment, updateComment, deleteComment };
50
+ }
51
+
52
+ // src/integrations/restApi/core/mutations/pages/mutations.ts
53
+ function createPagesMutations(fetcher) {
54
+ const { wpMutate } = fetcher;
55
+ async function createPage(input, authToken) {
56
+ return wpMutate("/wp/v2/pages", input, "POST", authToken);
57
+ }
58
+ async function updatePage(id, input, authToken) {
59
+ return wpMutate(`/wp/v2/pages/${id}`, input, "PATCH", authToken);
60
+ }
61
+ async function deletePage(id, authToken, force = false) {
62
+ return wpMutate(
63
+ `/wp/v2/pages/${id}`,
64
+ { force },
65
+ "DELETE",
66
+ authToken
67
+ );
68
+ }
69
+ return { createPage, updatePage, deletePage };
70
+ }
71
+
72
+ // src/integrations/restApi/core/mutations/categories/mutations.ts
73
+ function createCategoriesMutations(fetcher) {
74
+ const { wpMutate } = fetcher;
75
+ async function createCategory(input, authToken) {
76
+ return wpMutate("/wp/v2/categories", input, "POST", authToken);
77
+ }
78
+ async function updateCategory(id, input, authToken) {
79
+ return wpMutate(`/wp/v2/categories/${id}`, input, "PATCH", authToken);
80
+ }
81
+ async function deleteCategory(id, authToken, force = false) {
82
+ return wpMutate(
83
+ `/wp/v2/categories/${id}`,
84
+ { force },
85
+ "DELETE",
86
+ authToken
87
+ );
88
+ }
89
+ return { createCategory, updateCategory, deleteCategory };
90
+ }
91
+
92
+ // src/integrations/restApi/core/mutations/tags/mutations.ts
93
+ function createTagsMutations(fetcher) {
94
+ const { wpMutate } = fetcher;
95
+ async function createTag(input, authToken) {
96
+ return wpMutate("/wp/v2/tags", input, "POST", authToken);
97
+ }
98
+ async function updateTag(id, input, authToken) {
99
+ return wpMutate(`/wp/v2/tags/${id}`, input, "PATCH", authToken);
100
+ }
101
+ async function deleteTag(id, authToken, force = false) {
102
+ return wpMutate(
103
+ `/wp/v2/tags/${id}`,
104
+ { force },
105
+ "DELETE",
106
+ authToken
107
+ );
108
+ }
109
+ return { createTag, updateTag, deleteTag };
110
+ }
111
+
112
+ // src/integrations/restApi/core/mutations/authors/mutations.ts
113
+ function createAuthorsMutations(fetcher) {
114
+ const { wpMutate } = fetcher;
115
+ async function createAuthor(input, authToken) {
116
+ return wpMutate("/wp/v2/users", input, "POST", authToken);
117
+ }
118
+ async function updateAuthor(id, input, authToken) {
119
+ return wpMutate(`/wp/v2/users/${id}`, input, "PATCH", authToken);
120
+ }
121
+ async function deleteAuthor(id, authToken, reassign) {
122
+ return wpMutate(
123
+ `/wp/v2/users/${id}`,
124
+ { force: true, reassign },
125
+ "DELETE",
126
+ authToken
127
+ );
128
+ }
129
+ return { createAuthor, updateAuthor, deleteAuthor };
130
+ }
131
+
132
+ // src/integrations/restApi/core/mutations/menus/mutations.ts
133
+ function createMenusMutations(fetcher) {
134
+ const { wpMutate } = fetcher;
135
+ async function createMenu(input, authToken) {
136
+ return wpMutate("/wp/v2/menus", input, "POST", authToken);
137
+ }
138
+ async function updateMenu(id, input, authToken) {
139
+ return wpMutate(`/wp/v2/menus/${id}`, input, "PATCH", authToken);
140
+ }
141
+ async function deleteMenu(id, authToken) {
142
+ return wpMutate(
143
+ `/wp/v2/menus/${id}`,
144
+ {},
145
+ "DELETE",
146
+ authToken
147
+ );
148
+ }
149
+ async function createMenuItem(input, authToken) {
150
+ return wpMutate("/wp/v2/menu-items", input, "POST", authToken);
151
+ }
152
+ async function updateMenuItem(id, input, authToken) {
153
+ return wpMutate(`/wp/v2/menu-items/${id}`, input, "PATCH", authToken);
154
+ }
155
+ async function deleteMenuItem(id, authToken, force = false) {
156
+ return wpMutate(
157
+ `/wp/v2/menu-items/${id}`,
158
+ { force },
159
+ "DELETE",
160
+ authToken
161
+ );
162
+ }
163
+ return { createMenu, updateMenu, deleteMenu, createMenuItem, updateMenuItem, deleteMenuItem };
164
+ }
165
+
166
+ // src/integrations/restApi/core/mutations/media/mutations.ts
167
+ function createMediaMutations(fetcher) {
168
+ const { wpMutate, wpUpload } = fetcher;
169
+ async function uploadMedia(input, authToken) {
170
+ const media = await wpUpload(
171
+ "/wp/v2/media",
172
+ input.file,
173
+ input.filename,
174
+ input.mimeType,
175
+ authToken
176
+ );
177
+ if (input.title || input.caption || input.alt_text) {
178
+ return wpMutate(
179
+ `/wp/v2/media/${media.id}`,
180
+ {
181
+ ...input.title && { title: input.title },
182
+ ...input.caption && { caption: input.caption },
183
+ ...input.alt_text && { alt_text: input.alt_text }
184
+ },
185
+ "PATCH",
186
+ authToken
187
+ );
188
+ }
189
+ return media;
190
+ }
191
+ async function updateMedia(id, input, authToken) {
192
+ return wpMutate(`/wp/v2/media/${id}`, input, "PATCH", authToken);
193
+ }
194
+ async function deleteMedia(id, authToken, force = true) {
195
+ return wpMutate(
196
+ `/wp/v2/media/${id}`,
197
+ { force },
198
+ "DELETE",
199
+ authToken
200
+ );
201
+ }
202
+ return { uploadMedia, updateMedia, deleteMedia };
203
+ }
204
+
12
205
  // src/integrations/restApi/core/client/types.ts
13
206
  var WordPressAPIError = class extends Error {
14
207
  constructor(message, status, endpoint) {
@@ -87,20 +280,54 @@ function createFetcher(config) {
87
280
  return empty;
88
281
  }
89
282
  }
90
- async function wpMutate(path, body, method = "POST") {
283
+ async function wpMutate(path, body, method = "POST", authToken) {
91
284
  const url = buildUrl(config, path);
285
+ const headers = {
286
+ "Content-Type": "application/json",
287
+ "User-Agent": USER_AGENT
288
+ };
289
+ if (authToken) {
290
+ headers["Authorization"] = authToken;
291
+ }
92
292
  const res = await doFetch(url, {
93
293
  method,
294
+ headers,
295
+ body: JSON.stringify(body),
296
+ cache: "no-store"
297
+ });
298
+ return await res.json();
299
+ }
300
+ async function wpUpload(path, file, filename, mimeType, authToken) {
301
+ const url = buildUrl(config, path);
302
+ const res = await doFetch(url, {
303
+ method: "POST",
94
304
  headers: {
95
- "Content-Type": "application/json",
96
- "User-Agent": USER_AGENT
305
+ "Content-Disposition": `attachment; filename="${filename}"`,
306
+ "Content-Type": mimeType,
307
+ "User-Agent": USER_AGENT,
308
+ "Authorization": authToken
97
309
  },
98
- body: JSON.stringify(body),
310
+ body: file,
99
311
  cache: "no-store"
100
312
  });
101
313
  return await res.json();
102
314
  }
103
- return { wpFetch, wpFetchGraceful, wpFetchPaginated, wpFetchPaginatedGraceful, wpMutate };
315
+ return { wpFetch, wpFetchGraceful, wpFetchPaginated, wpFetchPaginatedGraceful, wpMutate, wpUpload };
316
+ }
317
+
318
+ // src/integrations/restApi/core/mutations/index.ts
319
+ function createWordPressMutationsClient(config) {
320
+ const fetcher = createFetcher(config);
321
+ return {
322
+ ...createPostsMutations(fetcher),
323
+ ...createCommentsMutations(fetcher),
324
+ ...createPagesMutations(fetcher),
325
+ ...createCategoriesMutations(fetcher),
326
+ ...createTagsMutations(fetcher),
327
+ ...createAuthorsMutations(fetcher),
328
+ ...createMenusMutations(fetcher),
329
+ ...createMediaMutations(fetcher)
330
+ };
104
331
  }
105
332
 
106
333
  // src/integrations/restApi/core/posts/queries.ts
@@ -678,6 +905,25 @@ function createProductsQueries(fetcher) {
678
905
  };
679
906
  }
680
907
 
908
+ // src/integrations/restApi/woocommerce/products/mutations.ts
909
+ function createProductsMutations(fetcher) {
910
+ const { wcMutate } = fetcher;
911
+ async function createProduct(input) {
912
+ return wcMutate("/wp-json/wc/v3/products", input, "POST");
913
+ }
914
+ async function updateProduct(id, input) {
915
+ return wcMutate(`/wp-json/wc/v3/products/${id}`, input, "PUT");
916
+ }
917
+ async function deleteProduct(id, force = true) {
918
+ return wcMutate(
919
+ `/wp-json/wc/v3/products/${id}`,
920
+ { force },
921
+ "DELETE"
922
+ );
923
+ }
924
+ return { createProduct, updateProduct, deleteProduct };
925
+ }
926
+
681
927
  // src/integrations/restApi/woocommerce/categories/queries.ts
682
928
  function createCategoriesQueries2(fetcher) {
683
929
  const { wcFetch, wcFetchGraceful } = fetcher;
@@ -727,6 +973,29 @@ function createCategoriesQueries2(fetcher) {
727
973
  };
728
974
  }
729
975
 
976
+ // src/integrations/restApi/woocommerce/categories/mutations.ts
977
+ function createCategoriesMutations2(fetcher) {
978
+ const { wcMutate } = fetcher;
979
+ async function createProductCategory(input) {
980
+ return wcMutate("/wp-json/wc/v3/products/categories", input, "POST");
981
+ }
982
+ async function updateProductCategory(id, input) {
983
+ return wcMutate(
984
+ `/wp-json/wc/v3/products/categories/${id}`,
985
+ input,
986
+ "PUT"
987
+ );
988
+ }
989
+ async function deleteProductCategory(id, force = true) {
990
+ return wcMutate(
991
+ `/wp-json/wc/v3/products/categories/${id}`,
992
+ { force },
993
+ "DELETE"
994
+ );
995
+ }
996
+ return { createProductCategory, updateProductCategory, deleteProductCategory };
997
+ }
998
+
730
999
  // src/integrations/restApi/woocommerce/tags/queries.ts
731
1000
  function createTagsQueries2(fetcher) {
732
1001
  const { wcFetch, wcFetchGraceful } = fetcher;
@@ -760,6 +1029,25 @@ function createTagsQueries2(fetcher) {
760
1029
  };
761
1030
  }
762
1031
 
1032
+ // src/integrations/restApi/woocommerce/tags/mutations.ts
1033
+ function createTagsMutations2(fetcher) {
1034
+ const { wcMutate } = fetcher;
1035
+ async function createProductTag(input) {
1036
+ return wcMutate("/wp-json/wc/v3/products/tags", input, "POST");
1037
+ }
1038
+ async function updateProductTag(id, input) {
1039
+ return wcMutate(`/wp-json/wc/v3/products/tags/${id}`, input, "PUT");
1040
+ }
1041
+ async function deleteProductTag(id, force = true) {
1042
+ return wcMutate(
1043
+ `/wp-json/wc/v3/products/tags/${id}`,
1044
+ { force },
1045
+ "DELETE"
1046
+ );
1047
+ }
1048
+ return { createProductTag, updateProductTag, deleteProductTag };
1049
+ }
1050
+
763
1051
  // src/integrations/restApi/woocommerce/orders/queries.ts
764
1052
  function createOrdersQueries(fetcher) {
765
1053
  const { wcFetch, wcFetchGraceful, wcMutate } = fetcher;
@@ -784,11 +1072,19 @@ function createOrdersQueries(fetcher) {
784
1072
  ["woocommerce", "orders", `orders-customer-${customerId}`]
785
1073
  );
786
1074
  }
1075
+ async function deleteOrder(id, force = true) {
1076
+ return wcMutate(
1077
+ `/wp-json/wc/v3/orders/${id}`,
1078
+ { force },
1079
+ "DELETE"
1080
+ );
1081
+ }
787
1082
  return {
788
1083
  createOrder,
789
1084
  getOrderById,
790
1085
  updateOrder,
791
- getOrdersByCustomer
1086
+ getOrdersByCustomer,
1087
+ deleteOrder
792
1088
  };
793
1089
  }
794
1090
 
@@ -822,9 +1118,28 @@ function createCouponsQueries(fetcher) {
822
1118
  };
823
1119
  }
824
1120
 
1121
+ // src/integrations/restApi/woocommerce/coupons/mutations.ts
1122
+ function createCouponsMutations(fetcher) {
1123
+ const { wcMutate } = fetcher;
1124
+ async function createCoupon(input) {
1125
+ return wcMutate("/wp-json/wc/v3/coupons", input, "POST");
1126
+ }
1127
+ async function updateCoupon(id, input) {
1128
+ return wcMutate(`/wp-json/wc/v3/coupons/${id}`, input, "PUT");
1129
+ }
1130
+ async function deleteCoupon(id, force = true) {
1131
+ return wcMutate(
1132
+ `/wp-json/wc/v3/coupons/${id}`,
1133
+ { force },
1134
+ "DELETE"
1135
+ );
1136
+ }
1137
+ return { createCoupon, updateCoupon, deleteCoupon };
1138
+ }
1139
+
825
1140
  // src/integrations/restApi/woocommerce/customers/queries.ts
826
1141
  function createCustomersQueries(fetcher) {
827
- const { wcFetch, wcFetchGraceful } = fetcher;
1142
+ const { wcFetch, wcFetchGraceful, wcMutate } = fetcher;
828
1143
  async function getCustomerById(id) {
829
1144
  return wcFetch(`/wp-json/wc/v3/customers/${id}`, void 0, [
830
1145
  "woocommerce",
@@ -862,11 +1177,23 @@ function createCustomersQueries(fetcher) {
862
1177
  { method: "POST", body: JSON.stringify(data) }
863
1178
  );
864
1179
  }
1180
+ async function updateCustomer(id, data) {
1181
+ return wcMutate(`/wp-json/wc/v3/customers/${id}`, data, "PUT");
1182
+ }
1183
+ async function deleteCustomer(id, reassign) {
1184
+ return wcMutate(
1185
+ `/wp-json/wc/v3/customers/${id}`,
1186
+ { force: true, ...reassign !== void 0 && { reassign } },
1187
+ "DELETE"
1188
+ );
1189
+ }
865
1190
  return {
866
1191
  getCustomerById,
867
1192
  getCustomerByEmail,
868
1193
  getCustomerByEmailNoCache,
869
- createCustomer
1194
+ createCustomer,
1195
+ updateCustomer,
1196
+ deleteCustomer
870
1197
  };
871
1198
  }
872
1199
 
@@ -875,10 +1202,14 @@ function createWooCommerceClient(config) {
875
1202
  const fetcher = createWooCommerceFetcher(config);
876
1203
  return {
877
1204
  ...createProductsQueries(fetcher),
1205
+ ...createProductsMutations(fetcher),
878
1206
  ...createCategoriesQueries2(fetcher),
1207
+ ...createCategoriesMutations2(fetcher),
879
1208
  ...createTagsQueries2(fetcher),
1209
+ ...createTagsMutations2(fetcher),
880
1210
  ...createOrdersQueries(fetcher),
881
1211
  ...createCouponsQueries(fetcher),
1212
+ ...createCouponsMutations(fetcher),
882
1213
  ...createCustomersQueries(fetcher)
883
1214
  };
884
1215
  }
@@ -938,7 +1269,42 @@ function createWPGraphQLFetcher(config) {
938
1269
  return fallback;
939
1270
  }
940
1271
  }
941
- return { gqlFetch, gqlFetchGraceful };
1272
+ async function gqlMutate(document, variables, authToken) {
1273
+ const headers = {
1274
+ "Content-Type": "application/json",
1275
+ "User-Agent": USER_AGENT3
1276
+ };
1277
+ if (authToken) {
1278
+ headers["Authorization"] = authToken;
1279
+ }
1280
+ const response = await fetch(url, {
1281
+ method: "POST",
1282
+ headers,
1283
+ body: JSON.stringify({ query: document, variables }),
1284
+ cache: "no-store"
1285
+ });
1286
+ if (!response.ok) {
1287
+ throw new WPGraphQLError(
1288
+ `WPGraphQL mutation failed: ${response.statusText}`,
1289
+ response.status,
1290
+ url
1291
+ );
1292
+ }
1293
+ const parsed = await response.json();
1294
+ if (parsed.errors && parsed.errors.length > 0) {
1295
+ throw new WPGraphQLError(
1296
+ parsed.errors[0].message,
1297
+ 200,
1298
+ url,
1299
+ parsed.errors
1300
+ );
1301
+ }
1302
+ if (parsed.data === void 0) {
1303
+ throw new WPGraphQLError("No data returned from WPGraphQL mutation", 200, url);
1304
+ }
1305
+ return parsed.data;
1306
+ }
1307
+ return { gqlFetch, gqlFetchGraceful, gqlMutate };
942
1308
  }
943
1309
 
944
1310
  // src/integrations/wpGraphQL/core/posts/queries.ts
@@ -1546,6 +1912,518 @@ function createCommentsQueries2(fetcher) {
1546
1912
  };
1547
1913
  }
1548
1914
 
1915
+ // src/integrations/wpGraphQL/core/media/queries.ts
1916
+ var DEFAULT_FIRST6 = 10;
1917
+ var MEDIA_FIELDS = `
1918
+ id
1919
+ databaseId
1920
+ slug
1921
+ title
1922
+ date
1923
+ sourceUrl
1924
+ altText
1925
+ caption
1926
+ description
1927
+ mediaType
1928
+ mimeType
1929
+ uri
1930
+ mediaDetails {
1931
+ width
1932
+ height
1933
+ file
1934
+ sizes { name width height mimeType sourceUrl }
1935
+ }
1936
+ `;
1937
+ var GQL_GET_MEDIA_ITEMS = `
1938
+ query GetMediaItems($first: Int, $after: String) {
1939
+ mediaItems(first: $first, after: $after) {
1940
+ nodes { ${MEDIA_FIELDS} }
1941
+ pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
1942
+ }
1943
+ }
1944
+ `;
1945
+ var GQL_GET_MEDIA_ITEM_BY_ID = `
1946
+ query GetMediaItemById($id: ID!) {
1947
+ mediaItem(id: $id, idType: DATABASE_ID) { ${MEDIA_FIELDS} }
1948
+ }
1949
+ `;
1950
+ var GQL_GET_MEDIA_ITEM_BY_SLUG = `
1951
+ query GetMediaItemBySlug($id: ID!) {
1952
+ mediaItem(id: $id, idType: SLUG) { ${MEDIA_FIELDS} }
1953
+ }
1954
+ `;
1955
+ function createMediaQueries2(fetcher) {
1956
+ const { gqlFetchGraceful } = fetcher;
1957
+ async function getMediaItems(first = DEFAULT_FIRST6, after) {
1958
+ const data = await gqlFetchGraceful(
1959
+ GQL_GET_MEDIA_ITEMS,
1960
+ { mediaItems: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
1961
+ { first, after },
1962
+ ["wpgraphql", "gql-media"]
1963
+ );
1964
+ return data.mediaItems;
1965
+ }
1966
+ async function getMediaItemById(id) {
1967
+ const data = await gqlFetchGraceful(
1968
+ GQL_GET_MEDIA_ITEM_BY_ID,
1969
+ { mediaItem: null },
1970
+ { id: String(id) },
1971
+ ["wpgraphql", "gql-media", `gql-media-${id}`]
1972
+ );
1973
+ return data.mediaItem;
1974
+ }
1975
+ async function getMediaItemBySlug(slug) {
1976
+ const data = await gqlFetchGraceful(
1977
+ GQL_GET_MEDIA_ITEM_BY_SLUG,
1978
+ { mediaItem: null },
1979
+ { id: slug },
1980
+ ["wpgraphql", "gql-media", `gql-media-${slug}`]
1981
+ );
1982
+ return data.mediaItem;
1983
+ }
1984
+ return { getMediaItems, getMediaItemById, getMediaItemBySlug };
1985
+ }
1986
+
1987
+ // src/integrations/wpGraphQL/core/mutations/posts/mutations.ts
1988
+ var MUTATED_POST_FIELDS = `
1989
+ id
1990
+ databaseId
1991
+ slug
1992
+ title
1993
+ status
1994
+ `;
1995
+ var GQL_CREATE_POST = `
1996
+ mutation CreatePost($input: CreatePostInput!) {
1997
+ createPost(input: $input) {
1998
+ post { ${MUTATED_POST_FIELDS} }
1999
+ }
2000
+ }
2001
+ `;
2002
+ var GQL_UPDATE_POST = `
2003
+ mutation UpdatePost($input: UpdatePostInput!) {
2004
+ updatePost(input: $input) {
2005
+ post { ${MUTATED_POST_FIELDS} }
2006
+ }
2007
+ }
2008
+ `;
2009
+ var GQL_DELETE_POST = `
2010
+ mutation DeletePost($input: DeletePostInput!) {
2011
+ deletePost(input: $input) {
2012
+ deletedId
2013
+ post { ${MUTATED_POST_FIELDS} }
2014
+ }
2015
+ }
2016
+ `;
2017
+ function createPostsMutations2(fetcher) {
2018
+ const { gqlMutate } = fetcher;
2019
+ async function createPost(input, authToken) {
2020
+ const data = await gqlMutate(
2021
+ GQL_CREATE_POST,
2022
+ { input },
2023
+ authToken
2024
+ );
2025
+ return data.createPost.post;
2026
+ }
2027
+ async function updatePost(input, authToken) {
2028
+ const data = await gqlMutate(
2029
+ GQL_UPDATE_POST,
2030
+ { input },
2031
+ authToken
2032
+ );
2033
+ return data.updatePost.post;
2034
+ }
2035
+ async function deletePost(id, authToken, forceDelete = false) {
2036
+ const data = await gqlMutate(
2037
+ GQL_DELETE_POST,
2038
+ { input: { id, forceDelete } },
2039
+ authToken
2040
+ );
2041
+ return data.deletePost;
2042
+ }
2043
+ return { createPost, updatePost, deletePost };
2044
+ }
2045
+
2046
+ // src/integrations/wpGraphQL/core/mutations/comments/mutations.ts
2047
+ var MUTATED_COMMENT_FIELDS = `
2048
+ id
2049
+ databaseId
2050
+ content(format: RENDERED)
2051
+ date
2052
+ status
2053
+ parentId
2054
+ author { node { name url } }
2055
+ `;
2056
+ var GQL_CREATE_COMMENT = `
2057
+ mutation CreateComment($input: CreateCommentInput!) {
2058
+ createComment(input: $input) {
2059
+ success
2060
+ comment { ${MUTATED_COMMENT_FIELDS} }
2061
+ }
2062
+ }
2063
+ `;
2064
+ var GQL_UPDATE_COMMENT = `
2065
+ mutation UpdateComment($input: UpdateCommentInput!) {
2066
+ updateComment(input: $input) {
2067
+ comment { ${MUTATED_COMMENT_FIELDS} }
2068
+ }
2069
+ }
2070
+ `;
2071
+ var GQL_DELETE_COMMENT = `
2072
+ mutation DeleteComment($input: DeleteCommentInput!) {
2073
+ deleteComment(input: $input) {
2074
+ deletedId
2075
+ comment { ${MUTATED_COMMENT_FIELDS} }
2076
+ }
2077
+ }
2078
+ `;
2079
+ function createCommentsMutations2(fetcher) {
2080
+ const { gqlMutate } = fetcher;
2081
+ async function createComment(input, authToken) {
2082
+ const gqlInput = {
2083
+ commentOn: input.postId,
2084
+ content: input.content
2085
+ };
2086
+ if (input.authorName) gqlInput["author"] = input.authorName;
2087
+ if (input.authorEmail) gqlInput["authorEmail"] = input.authorEmail;
2088
+ if (input.authorUrl) gqlInput["authorUrl"] = input.authorUrl;
2089
+ if (input.parentId) gqlInput["parent"] = input.parentId;
2090
+ const data = await gqlMutate(
2091
+ GQL_CREATE_COMMENT,
2092
+ { input: gqlInput },
2093
+ authToken
2094
+ );
2095
+ return data.createComment;
2096
+ }
2097
+ async function updateComment(input, authToken) {
2098
+ const data = await gqlMutate(
2099
+ GQL_UPDATE_COMMENT,
2100
+ { input },
2101
+ authToken
2102
+ );
2103
+ return data.updateComment.comment;
2104
+ }
2105
+ async function deleteComment(id, authToken, forceDelete = false) {
2106
+ const data = await gqlMutate(
2107
+ GQL_DELETE_COMMENT,
2108
+ { input: { id, forceDelete } },
2109
+ authToken
2110
+ );
2111
+ return data.deleteComment;
2112
+ }
2113
+ return { createComment, updateComment, deleteComment };
2114
+ }
2115
+
2116
+ // src/integrations/wpGraphQL/core/mutations/pages/mutations.ts
2117
+ var MUTATED_PAGE_FIELDS = `
2118
+ id
2119
+ databaseId
2120
+ slug
2121
+ title
2122
+ status
2123
+ uri
2124
+ `;
2125
+ var GQL_CREATE_PAGE = `
2126
+ mutation CreatePage($input: CreatePageInput!) {
2127
+ createPage(input: $input) {
2128
+ page { ${MUTATED_PAGE_FIELDS} }
2129
+ }
2130
+ }
2131
+ `;
2132
+ var GQL_UPDATE_PAGE = `
2133
+ mutation UpdatePage($input: UpdatePageInput!) {
2134
+ updatePage(input: $input) {
2135
+ page { ${MUTATED_PAGE_FIELDS} }
2136
+ }
2137
+ }
2138
+ `;
2139
+ var GQL_DELETE_PAGE = `
2140
+ mutation DeletePage($input: DeletePageInput!) {
2141
+ deletePage(input: $input) {
2142
+ deletedId
2143
+ page { ${MUTATED_PAGE_FIELDS} }
2144
+ }
2145
+ }
2146
+ `;
2147
+ function createPagesMutations2(fetcher) {
2148
+ const { gqlMutate } = fetcher;
2149
+ async function createPage(input, authToken) {
2150
+ const data = await gqlMutate(
2151
+ GQL_CREATE_PAGE,
2152
+ { input },
2153
+ authToken
2154
+ );
2155
+ return data.createPage.page;
2156
+ }
2157
+ async function updatePage(input, authToken) {
2158
+ const data = await gqlMutate(
2159
+ GQL_UPDATE_PAGE,
2160
+ { input },
2161
+ authToken
2162
+ );
2163
+ return data.updatePage.page;
2164
+ }
2165
+ async function deletePage(id, authToken, forceDelete = false) {
2166
+ const data = await gqlMutate(
2167
+ GQL_DELETE_PAGE,
2168
+ { input: { id, forceDelete } },
2169
+ authToken
2170
+ );
2171
+ return data.deletePage;
2172
+ }
2173
+ return { createPage, updatePage, deletePage };
2174
+ }
2175
+
2176
+ // src/integrations/wpGraphQL/core/mutations/categories/mutations.ts
2177
+ var MUTATED_CATEGORY_FIELDS = `
2178
+ id
2179
+ databaseId
2180
+ name
2181
+ slug
2182
+ `;
2183
+ var GQL_CREATE_CATEGORY = `
2184
+ mutation CreateCategory($input: CreateCategoryInput!) {
2185
+ createCategory(input: $input) {
2186
+ category { ${MUTATED_CATEGORY_FIELDS} }
2187
+ }
2188
+ }
2189
+ `;
2190
+ var GQL_UPDATE_CATEGORY = `
2191
+ mutation UpdateCategory($input: UpdateCategoryInput!) {
2192
+ updateCategory(input: $input) {
2193
+ category { ${MUTATED_CATEGORY_FIELDS} }
2194
+ }
2195
+ }
2196
+ `;
2197
+ var GQL_DELETE_CATEGORY = `
2198
+ mutation DeleteCategory($input: DeleteCategoryInput!) {
2199
+ deleteCategory(input: $input) {
2200
+ deletedId
2201
+ category { ${MUTATED_CATEGORY_FIELDS} }
2202
+ }
2203
+ }
2204
+ `;
2205
+ function createCategoriesMutations3(fetcher) {
2206
+ const { gqlMutate } = fetcher;
2207
+ async function createCategory(input, authToken) {
2208
+ const data = await gqlMutate(
2209
+ GQL_CREATE_CATEGORY,
2210
+ { input },
2211
+ authToken
2212
+ );
2213
+ return data.createCategory.category;
2214
+ }
2215
+ async function updateCategory(input, authToken) {
2216
+ const data = await gqlMutate(
2217
+ GQL_UPDATE_CATEGORY,
2218
+ { input },
2219
+ authToken
2220
+ );
2221
+ return data.updateCategory.category;
2222
+ }
2223
+ async function deleteCategory(id, authToken) {
2224
+ const data = await gqlMutate(
2225
+ GQL_DELETE_CATEGORY,
2226
+ { input: { id } },
2227
+ authToken
2228
+ );
2229
+ return data.deleteCategory;
2230
+ }
2231
+ return { createCategory, updateCategory, deleteCategory };
2232
+ }
2233
+
2234
+ // src/integrations/wpGraphQL/core/mutations/tags/mutations.ts
2235
+ var MUTATED_TAG_FIELDS = `
2236
+ id
2237
+ databaseId
2238
+ name
2239
+ slug
2240
+ `;
2241
+ var GQL_CREATE_TAG = `
2242
+ mutation CreateTag($input: CreateTagInput!) {
2243
+ createTag(input: $input) {
2244
+ tag { ${MUTATED_TAG_FIELDS} }
2245
+ }
2246
+ }
2247
+ `;
2248
+ var GQL_UPDATE_TAG = `
2249
+ mutation UpdateTag($input: UpdateTagInput!) {
2250
+ updateTag(input: $input) {
2251
+ tag { ${MUTATED_TAG_FIELDS} }
2252
+ }
2253
+ }
2254
+ `;
2255
+ var GQL_DELETE_TAG = `
2256
+ mutation DeleteTag($input: DeleteTagInput!) {
2257
+ deleteTag(input: $input) {
2258
+ deletedId
2259
+ tag { ${MUTATED_TAG_FIELDS} }
2260
+ }
2261
+ }
2262
+ `;
2263
+ function createTagsMutations3(fetcher) {
2264
+ const { gqlMutate } = fetcher;
2265
+ async function createTag(input, authToken) {
2266
+ const data = await gqlMutate(
2267
+ GQL_CREATE_TAG,
2268
+ { input },
2269
+ authToken
2270
+ );
2271
+ return data.createTag.tag;
2272
+ }
2273
+ async function updateTag(input, authToken) {
2274
+ const data = await gqlMutate(
2275
+ GQL_UPDATE_TAG,
2276
+ { input },
2277
+ authToken
2278
+ );
2279
+ return data.updateTag.tag;
2280
+ }
2281
+ async function deleteTag(id, authToken) {
2282
+ const data = await gqlMutate(
2283
+ GQL_DELETE_TAG,
2284
+ { input: { id } },
2285
+ authToken
2286
+ );
2287
+ return data.deleteTag;
2288
+ }
2289
+ return { createTag, updateTag, deleteTag };
2290
+ }
2291
+
2292
+ // src/integrations/wpGraphQL/core/mutations/authors/mutations.ts
2293
+ var MUTATED_USER_FIELDS = `
2294
+ id
2295
+ databaseId
2296
+ name
2297
+ slug
2298
+ email
2299
+ `;
2300
+ var GQL_REGISTER_USER = `
2301
+ mutation RegisterUser($input: RegisterUserInput!) {
2302
+ registerUser(input: $input) {
2303
+ user { ${MUTATED_USER_FIELDS} }
2304
+ }
2305
+ }
2306
+ `;
2307
+ var GQL_UPDATE_USER = `
2308
+ mutation UpdateUser($input: UpdateUserInput!) {
2309
+ updateUser(input: $input) {
2310
+ user { ${MUTATED_USER_FIELDS} }
2311
+ }
2312
+ }
2313
+ `;
2314
+ var GQL_DELETE_USER = `
2315
+ mutation DeleteUser($input: DeleteUserInput!) {
2316
+ deleteUser(input: $input) {
2317
+ deletedId
2318
+ user { ${MUTATED_USER_FIELDS} }
2319
+ }
2320
+ }
2321
+ `;
2322
+ function createAuthorsMutations2(fetcher) {
2323
+ const { gqlMutate } = fetcher;
2324
+ async function registerUser(input, authToken) {
2325
+ const data = await gqlMutate(
2326
+ GQL_REGISTER_USER,
2327
+ { input },
2328
+ authToken
2329
+ );
2330
+ return data.registerUser.user;
2331
+ }
2332
+ async function updateUser(input, authToken) {
2333
+ const data = await gqlMutate(
2334
+ GQL_UPDATE_USER,
2335
+ { input },
2336
+ authToken
2337
+ );
2338
+ return data.updateUser.user;
2339
+ }
2340
+ async function deleteUser(id, authToken, reassignPosts) {
2341
+ const input = { id };
2342
+ if (reassignPosts) input["reassignId"] = reassignPosts;
2343
+ const data = await gqlMutate(
2344
+ GQL_DELETE_USER,
2345
+ { input },
2346
+ authToken
2347
+ );
2348
+ return data.deleteUser;
2349
+ }
2350
+ return { registerUser, updateUser, deleteUser };
2351
+ }
2352
+
2353
+ // src/integrations/wpGraphQL/core/mutations/media/mutations.ts
2354
+ var MUTATED_MEDIA_FIELDS = `
2355
+ id
2356
+ databaseId
2357
+ slug
2358
+ title
2359
+ sourceUrl
2360
+ altText
2361
+ `;
2362
+ var GQL_CREATE_MEDIA_ITEM = `
2363
+ mutation CreateMediaItem($input: CreateMediaItemInput!) {
2364
+ createMediaItem(input: $input) {
2365
+ mediaItem { ${MUTATED_MEDIA_FIELDS} }
2366
+ }
2367
+ }
2368
+ `;
2369
+ var GQL_UPDATE_MEDIA_ITEM = `
2370
+ mutation UpdateMediaItem($input: UpdateMediaItemInput!) {
2371
+ updateMediaItem(input: $input) {
2372
+ mediaItem { ${MUTATED_MEDIA_FIELDS} }
2373
+ }
2374
+ }
2375
+ `;
2376
+ var GQL_DELETE_MEDIA_ITEM = `
2377
+ mutation DeleteMediaItem($input: DeleteMediaItemInput!) {
2378
+ deleteMediaItem(input: $input) {
2379
+ deletedId
2380
+ mediaItem { ${MUTATED_MEDIA_FIELDS} }
2381
+ }
2382
+ }
2383
+ `;
2384
+ function createMediaMutations2(fetcher) {
2385
+ const { gqlMutate } = fetcher;
2386
+ async function createMediaItem(input, authToken) {
2387
+ const data = await gqlMutate(
2388
+ GQL_CREATE_MEDIA_ITEM,
2389
+ { input },
2390
+ authToken
2391
+ );
2392
+ return data.createMediaItem.mediaItem;
2393
+ }
2394
+ async function updateMediaItem(input, authToken) {
2395
+ const data = await gqlMutate(
2396
+ GQL_UPDATE_MEDIA_ITEM,
2397
+ { input },
2398
+ authToken
2399
+ );
2400
+ return data.updateMediaItem.mediaItem;
2401
+ }
2402
+ async function deleteMediaItem(id, authToken, forceDelete = true) {
2403
+ const data = await gqlMutate(
2404
+ GQL_DELETE_MEDIA_ITEM,
2405
+ { input: { id, forceDelete } },
2406
+ authToken
2407
+ );
2408
+ return data.deleteMediaItem;
2409
+ }
2410
+ return { createMediaItem, updateMediaItem, deleteMediaItem };
2411
+ }
2412
+
2413
+ // src/integrations/wpGraphQL/core/mutations/index.ts
2414
+ function createWPGraphQLMutationsClient(config) {
2415
+ const fetcher = createWPGraphQLFetcher(config);
2416
+ return {
2417
+ ...createPostsMutations2(fetcher),
2418
+ ...createCommentsMutations2(fetcher),
2419
+ ...createPagesMutations2(fetcher),
2420
+ ...createCategoriesMutations3(fetcher),
2421
+ ...createTagsMutations3(fetcher),
2422
+ ...createAuthorsMutations2(fetcher),
2423
+ ...createMediaMutations2(fetcher)
2424
+ };
2425
+ }
2426
+
1549
2427
  // src/integrations/wpGraphQL/core/index.ts
1550
2428
  function createWPGraphQLCoreClient(config) {
1551
2429
  const fetcher = createWPGraphQLFetcher(config);
@@ -1556,7 +2434,8 @@ function createWPGraphQLCoreClient(config) {
1556
2434
  ...createTagsQueries3(fetcher),
1557
2435
  ...createAuthorsQueries2(fetcher),
1558
2436
  ...createMenusQueries2(fetcher),
1559
- ...createCommentsQueries2(fetcher)
2437
+ ...createCommentsQueries2(fetcher),
2438
+ ...createMediaQueries2(fetcher)
1560
2439
  };
1561
2440
  }
1562
2441
 
@@ -1725,7 +2604,7 @@ function buildPostsWithACFQuery(fieldGroupName, fields) {
1725
2604
  }
1726
2605
 
1727
2606
  // src/integrations/wpGraphQL/woocommerce/products/queries.ts
1728
- var DEFAULT_FIRST6 = 10;
2607
+ var DEFAULT_FIRST7 = 10;
1729
2608
  var BATCH_FIRST3 = 100;
1730
2609
  var PRODUCT_FIELDS = `
1731
2610
  id
@@ -1803,7 +2682,7 @@ var GQL_GET_ALL_PRODUCT_SLUGS = `
1803
2682
  `;
1804
2683
  function createProductsQueries2(fetcher) {
1805
2684
  const { gqlFetch, gqlFetchGraceful } = fetcher;
1806
- async function getProducts(first = DEFAULT_FIRST6, after, filter) {
2685
+ async function getProducts(first = DEFAULT_FIRST7, after, filter) {
1807
2686
  const where = {};
1808
2687
  if (filter?.search) where["search"] = filter.search;
1809
2688
  if (filter?.onSale !== void 0) where["onSale"] = filter.onSale;
@@ -1839,11 +2718,11 @@ function createProductsQueries2(fetcher) {
1839
2718
  );
1840
2719
  return data.product;
1841
2720
  }
1842
- async function getFeaturedProducts(first = DEFAULT_FIRST6) {
2721
+ async function getFeaturedProducts(first = DEFAULT_FIRST7) {
1843
2722
  const connection = await getProducts(first, void 0, { featured: true });
1844
2723
  return connection.nodes;
1845
2724
  }
1846
- async function getOnSaleProducts(first = DEFAULT_FIRST6) {
2725
+ async function getOnSaleProducts(first = DEFAULT_FIRST7) {
1847
2726
  const connection = await getProducts(first, void 0, { onSale: true });
1848
2727
  return connection.nodes;
1849
2728
  }
@@ -1875,7 +2754,7 @@ function createProductsQueries2(fetcher) {
1875
2754
  }
1876
2755
 
1877
2756
  // src/integrations/wpGraphQL/woocommerce/orders/queries.ts
1878
- var DEFAULT_FIRST7 = 10;
2757
+ var DEFAULT_FIRST8 = 10;
1879
2758
  var ADDRESS_FIELDS = `
1880
2759
  firstName lastName address1 address2 city postcode country email phone
1881
2760
  `;
@@ -1928,7 +2807,7 @@ function createOrdersQueries2(fetcher) {
1928
2807
  );
1929
2808
  return data.order;
1930
2809
  }
1931
- async function getMyOrders(first = DEFAULT_FIRST7, after) {
2810
+ async function getMyOrders(first = DEFAULT_FIRST8, after) {
1932
2811
  const data = await gqlFetchGraceful(
1933
2812
  GQL_GET_MY_ORDERS,
1934
2813
  { orders: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
@@ -1987,18 +2866,211 @@ function createCustomersQueries2(fetcher) {
1987
2866
  return { getCustomer, getCustomerById };
1988
2867
  }
1989
2868
 
2869
+ // src/integrations/wpGraphQL/woocommerce/categories/queries.ts
2870
+ var DEFAULT_FIRST9 = 100;
2871
+ var CATEGORY_FIELDS2 = `
2872
+ id
2873
+ databaseId
2874
+ name
2875
+ slug
2876
+ description
2877
+ count
2878
+ parent { node { id databaseId name slug } }
2879
+ image { sourceUrl altText }
2880
+ `;
2881
+ var GQL_GET_PRODUCT_CATEGORIES = `
2882
+ query GetProductCategories($first: Int, $after: String) {
2883
+ productCategories(first: $first, after: $after) {
2884
+ nodes { ${CATEGORY_FIELDS2} }
2885
+ pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
2886
+ }
2887
+ }
2888
+ `;
2889
+ var GQL_GET_PRODUCT_CATEGORY_BY_SLUG = `
2890
+ query GetProductCategoryBySlug($id: ID!) {
2891
+ productCategory(id: $id, idType: SLUG) { ${CATEGORY_FIELDS2} }
2892
+ }
2893
+ `;
2894
+ var GQL_GET_PRODUCT_CATEGORY_BY_ID = `
2895
+ query GetProductCategoryById($id: ID!) {
2896
+ productCategory(id: $id, idType: DATABASE_ID) { ${CATEGORY_FIELDS2} }
2897
+ }
2898
+ `;
2899
+ function createCategoriesQueries4(fetcher) {
2900
+ const { gqlFetchGraceful } = fetcher;
2901
+ async function getProductCategories(first = DEFAULT_FIRST9, after) {
2902
+ const data = await gqlFetchGraceful(
2903
+ GQL_GET_PRODUCT_CATEGORIES,
2904
+ { productCategories: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
2905
+ { first, after },
2906
+ ["wpgraphql", "gql-product-categories"]
2907
+ );
2908
+ return data.productCategories;
2909
+ }
2910
+ async function getProductCategoryBySlug(slug) {
2911
+ const data = await gqlFetchGraceful(
2912
+ GQL_GET_PRODUCT_CATEGORY_BY_SLUG,
2913
+ { productCategory: null },
2914
+ { id: slug },
2915
+ ["wpgraphql", "gql-product-categories", `gql-product-category-${slug}`]
2916
+ );
2917
+ return data.productCategory;
2918
+ }
2919
+ async function getProductCategoryById(id) {
2920
+ const data = await gqlFetchGraceful(
2921
+ GQL_GET_PRODUCT_CATEGORY_BY_ID,
2922
+ { productCategory: null },
2923
+ { id: String(id) },
2924
+ ["wpgraphql", "gql-product-categories", `gql-product-category-${id}`]
2925
+ );
2926
+ return data.productCategory;
2927
+ }
2928
+ return { getProductCategories, getProductCategoryBySlug, getProductCategoryById };
2929
+ }
2930
+
2931
+ // src/integrations/wpGraphQL/woocommerce/tags/queries.ts
2932
+ var DEFAULT_FIRST10 = 100;
2933
+ var TAG_FIELDS2 = `
2934
+ id
2935
+ databaseId
2936
+ name
2937
+ slug
2938
+ description
2939
+ count
2940
+ `;
2941
+ var GQL_GET_PRODUCT_TAGS = `
2942
+ query GetProductTags($first: Int, $after: String) {
2943
+ productTags(first: $first, after: $after) {
2944
+ nodes { ${TAG_FIELDS2} }
2945
+ pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
2946
+ }
2947
+ }
2948
+ `;
2949
+ var GQL_GET_PRODUCT_TAG_BY_SLUG = `
2950
+ query GetProductTagBySlug($id: ID!) {
2951
+ productTag(id: $id, idType: SLUG) { ${TAG_FIELDS2} }
2952
+ }
2953
+ `;
2954
+ var GQL_GET_PRODUCT_TAG_BY_ID = `
2955
+ query GetProductTagById($id: ID!) {
2956
+ productTag(id: $id, idType: DATABASE_ID) { ${TAG_FIELDS2} }
2957
+ }
2958
+ `;
2959
+ function createTagsQueries4(fetcher) {
2960
+ const { gqlFetchGraceful } = fetcher;
2961
+ async function getProductTags(first = DEFAULT_FIRST10, after) {
2962
+ const data = await gqlFetchGraceful(
2963
+ GQL_GET_PRODUCT_TAGS,
2964
+ { productTags: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
2965
+ { first, after },
2966
+ ["wpgraphql", "gql-product-tags"]
2967
+ );
2968
+ return data.productTags;
2969
+ }
2970
+ async function getProductTagBySlug(slug) {
2971
+ const data = await gqlFetchGraceful(
2972
+ GQL_GET_PRODUCT_TAG_BY_SLUG,
2973
+ { productTag: null },
2974
+ { id: slug },
2975
+ ["wpgraphql", "gql-product-tags", `gql-product-tag-${slug}`]
2976
+ );
2977
+ return data.productTag;
2978
+ }
2979
+ async function getProductTagById(id) {
2980
+ const data = await gqlFetchGraceful(
2981
+ GQL_GET_PRODUCT_TAG_BY_ID,
2982
+ { productTag: null },
2983
+ { id: String(id) },
2984
+ ["wpgraphql", "gql-product-tags", `gql-product-tag-${id}`]
2985
+ );
2986
+ return data.productTag;
2987
+ }
2988
+ return { getProductTags, getProductTagBySlug, getProductTagById };
2989
+ }
2990
+
2991
+ // src/integrations/wpGraphQL/woocommerce/coupons/queries.ts
2992
+ var DEFAULT_FIRST11 = 100;
2993
+ var COUPON_FIELDS = `
2994
+ id
2995
+ databaseId
2996
+ code
2997
+ discountType
2998
+ amount
2999
+ dateExpiry
3000
+ usageCount
3001
+ usageLimit
3002
+ usageLimitPerUser
3003
+ individualUse
3004
+ freeShipping
3005
+ minimumAmount
3006
+ maximumAmount
3007
+ description
3008
+ `;
3009
+ var GQL_GET_COUPONS = `
3010
+ query GetCoupons($first: Int, $after: String) {
3011
+ coupons(first: $first, after: $after) {
3012
+ nodes { ${COUPON_FIELDS} }
3013
+ pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
3014
+ }
3015
+ }
3016
+ `;
3017
+ var GQL_GET_COUPON_BY_CODE = `
3018
+ query GetCouponByCode($id: ID!) {
3019
+ coupon(id: $id, idType: CODE) { ${COUPON_FIELDS} }
3020
+ }
3021
+ `;
3022
+ var GQL_GET_COUPON_BY_ID = `
3023
+ query GetCouponById($id: ID!) {
3024
+ coupon(id: $id, idType: DATABASE_ID) { ${COUPON_FIELDS} }
3025
+ }
3026
+ `;
3027
+ function createCouponsQueries2(fetcher) {
3028
+ const { gqlFetchGraceful } = fetcher;
3029
+ async function getCoupons(first = DEFAULT_FIRST11, after) {
3030
+ const data = await gqlFetchGraceful(
3031
+ GQL_GET_COUPONS,
3032
+ { coupons: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
3033
+ { first, after },
3034
+ ["wpgraphql", "gql-coupons"]
3035
+ );
3036
+ return data.coupons;
3037
+ }
3038
+ async function getCouponByCode(code) {
3039
+ const data = await gqlFetchGraceful(
3040
+ GQL_GET_COUPON_BY_CODE,
3041
+ { coupon: null },
3042
+ { id: code },
3043
+ ["wpgraphql", "gql-coupons", `gql-coupon-${code}`]
3044
+ );
3045
+ return data.coupon;
3046
+ }
3047
+ async function getCouponById(id) {
3048
+ const data = await gqlFetchGraceful(
3049
+ GQL_GET_COUPON_BY_ID,
3050
+ { coupon: null },
3051
+ { id: String(id) },
3052
+ ["wpgraphql", "gql-coupons", `gql-coupon-${id}`]
3053
+ );
3054
+ return data.coupon;
3055
+ }
3056
+ return { getCoupons, getCouponByCode, getCouponById };
3057
+ }
3058
+
1990
3059
  // src/integrations/wpGraphQL/woocommerce/index.ts
1991
3060
  function createWPGraphQLWooCommerceClient(config) {
1992
3061
  const fetcher = createWPGraphQLFetcher(config);
1993
3062
  return {
1994
3063
  ...createProductsQueries2(fetcher),
1995
3064
  ...createOrdersQueries2(fetcher),
1996
- ...createCustomersQueries2(fetcher)
3065
+ ...createCustomersQueries2(fetcher),
3066
+ ...createCategoriesQueries4(fetcher),
3067
+ ...createTagsQueries4(fetcher),
3068
+ ...createCouponsQueries2(fetcher)
1997
3069
  };
1998
3070
  }
1999
3071
 
2000
3072
  // src/integrations/wpGraphQL/cpt/queries.ts
2001
- var DEFAULT_FIRST8 = 10;
3073
+ var DEFAULT_FIRST12 = 10;
2002
3074
  var BATCH_FIRST4 = 100;
2003
3075
  var BASE_CPT_FIELDS = `
2004
3076
  id databaseId slug title date modified status uri
@@ -2027,7 +3099,7 @@ function createCPTQueries(fetcher, typeName, singularTypeName, extraFields) {
2027
3099
  }
2028
3100
  }
2029
3101
  `;
2030
- async function getItems(first = DEFAULT_FIRST8, after) {
3102
+ async function getItems(first = DEFAULT_FIRST12, after) {
2031
3103
  const data = await gqlFetchGraceful(
2032
3104
  GQL_GET_ITEMS,
2033
3105
  { [typeName]: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
@@ -2067,22 +3139,130 @@ function createCPTQueries(fetcher, typeName, singularTypeName, extraFields) {
2067
3139
  return { getItems, getItemBySlug, getAllSlugs };
2068
3140
  }
2069
3141
 
3142
+ // src/nextjs/revalidation.ts
3143
+ var ACTION_TAG_MAP = {
3144
+ save_post: ["wordpress", "posts"],
3145
+ save_post_post: ["wordpress", "posts"],
3146
+ save_post_page: ["wordpress", "pages"],
3147
+ delete_post: ["wordpress", "posts", "pages"],
3148
+ created_term: ["wordpress", "categories", "tags"],
3149
+ edited_term: ["wordpress", "categories", "tags"],
3150
+ delete_term: ["wordpress", "categories", "tags"],
3151
+ wp_update_nav_menu: ["wordpress", "menus"],
3152
+ woocommerce_product_updated: ["woocommerce", "products"],
3153
+ woocommerce_new_product: ["woocommerce", "products"],
3154
+ woocommerce_delete_product: ["woocommerce", "products"],
3155
+ woocommerce_new_order: ["woocommerce", "orders"],
3156
+ woocommerce_order_status_changed: ["woocommerce", "orders"],
3157
+ woocommerce_update_order: ["woocommerce", "orders"],
3158
+ woocommerce_product_category_updated: ["woocommerce", "categories"],
3159
+ woocommerce_product_tag_updated: ["woocommerce", "tags"]
3160
+ };
3161
+ function extractSecret(request) {
3162
+ const auth = request.headers.get("Authorization");
3163
+ if (auth?.startsWith("Bearer ")) return auth.slice(7);
3164
+ return new URL(request.url).searchParams.get("secret");
3165
+ }
3166
+ function createRevalidationHandler(config, revalidateTag) {
3167
+ return async function handler(request) {
3168
+ if (extractSecret(request) !== config.secret) {
3169
+ return Response.json({ revalidated: false, tags: [], message: "Unauthorized" }, { status: 401 });
3170
+ }
3171
+ let payload;
3172
+ try {
3173
+ payload = await request.json();
3174
+ } catch {
3175
+ return Response.json({ revalidated: false, tags: [], message: "Invalid JSON body" }, { status: 400 });
3176
+ }
3177
+ const { action } = payload;
3178
+ const matched = ACTION_TAG_MAP[action];
3179
+ if (!matched) {
3180
+ return Response.json(
3181
+ { revalidated: false, tags: [], message: `Unknown action: ${action}` },
3182
+ { status: 400 }
3183
+ );
3184
+ }
3185
+ const tags = [...new Set(matched)];
3186
+ for (const tag of tags) {
3187
+ revalidateTag(tag);
3188
+ }
3189
+ return Response.json({ revalidated: true, tags });
3190
+ };
3191
+ }
3192
+
3193
+ // src/auth/applicationPassword.ts
3194
+ function createApplicationPasswordToken(username, appPassword) {
3195
+ const encoded = Buffer.from(`${username}:${appPassword}`).toString("base64");
3196
+ return `Basic ${encoded}`;
3197
+ }
3198
+
3199
+ // src/auth/types.ts
3200
+ var AuthenticationError = class extends Error {
3201
+ constructor(message, status) {
3202
+ super(message);
3203
+ __publicField(this, "status", status);
3204
+ this.name = "AuthenticationError";
3205
+ }
3206
+ };
3207
+
3208
+ // src/auth/jwt.ts
3209
+ async function authenticateJwt(config, credentials) {
3210
+ const url = `${resolveBaseUrl(config)}/wp-json/jwt-auth/v1/token`;
3211
+ const response = await fetch(url, {
3212
+ method: "POST",
3213
+ headers: { "Content-Type": "application/json" },
3214
+ body: JSON.stringify(credentials),
3215
+ cache: "no-store"
3216
+ });
3217
+ if (!response.ok) {
3218
+ throw new AuthenticationError(
3219
+ `JWT authentication failed: ${response.statusText}`,
3220
+ response.status
3221
+ );
3222
+ }
3223
+ return response.json();
3224
+ }
3225
+ async function validateJwtToken(config, token) {
3226
+ const url = `${resolveBaseUrl(config)}/wp-json/jwt-auth/v1/token/validate`;
3227
+ const response = await fetch(url, {
3228
+ method: "POST",
3229
+ headers: { Authorization: `Bearer ${token}` },
3230
+ cache: "no-store"
3231
+ });
3232
+ return response.ok;
3233
+ }
3234
+
3235
+ exports.AuthenticationError = AuthenticationError;
2070
3236
  exports.WPGraphQLError = WPGraphQLError;
3237
+ exports.authenticateJwt = authenticateJwt;
2071
3238
  exports.buildACFFragment = buildACFFragment;
2072
3239
  exports.buildPageWithACFQuery = buildPageWithACFQuery;
2073
3240
  exports.buildPostWithACFQuery = buildPostWithACFQuery;
2074
3241
  exports.buildPostsWithACFQuery = buildPostsWithACFQuery;
3242
+ exports.createApplicationPasswordToken = createApplicationPasswordToken;
3243
+ exports.createAuthorsMutations = createAuthorsMutations;
2075
3244
  exports.createCPTQueries = createCPTQueries;
3245
+ exports.createCategoriesMutations = createCategoriesMutations;
3246
+ exports.createCommentsMutations = createCommentsMutations;
3247
+ exports.createMediaMutations = createMediaMutations;
3248
+ exports.createMenusMutations = createMenusMutations;
3249
+ exports.createPagesMutations = createPagesMutations;
3250
+ exports.createPostsMutations = createPostsMutations;
3251
+ exports.createRevalidationHandler = createRevalidationHandler;
3252
+ exports.createTagsMutations = createTagsMutations;
2076
3253
  exports.createWPGraphQLClient = createWPGraphQLCoreClient;
2077
3254
  exports.createWPGraphQLCoreClient = createWPGraphQLCoreClient;
2078
3255
  exports.createWPGraphQLFetcher = createWPGraphQLFetcher;
3256
+ exports.createWPGraphQLMutationsClient = createWPGraphQLMutationsClient;
2079
3257
  exports.createWPGraphQLWooCommerceClient = createWPGraphQLWooCommerceClient;
2080
3258
  exports.createWooCommerceClient = createWooCommerceClient;
2081
3259
  exports.createWooCommerceFetcher = createWooCommerceFetcher;
2082
3260
  exports.createWordPressClient = createWordPressClient;
3261
+ exports.createWordPressMutationsClient = createWordPressMutationsClient;
2083
3262
  exports.createYoastQueries = createYoastQueries;
2084
3263
  exports.extractOmnibusData = extractOmnibusData;
2085
3264
  exports.resolveBaseUrl = resolveBaseUrl;
3265
+ exports.validateJwtToken = validateJwtToken;
2086
3266
  exports.withOmnibus = withOmnibus;
2087
3267
  exports.withOmnibusVariation = withOmnibusVariation;
2088
3268
  //# sourceMappingURL=index.cjs.map