@szymonpiatek/nextwordpress 0.0.3 → 0.0.5

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
@@ -85,20 +85,261 @@ function createFetcher(config) {
85
85
  return empty;
86
86
  }
87
87
  }
88
- async function wpMutate(path, body, method = "POST") {
88
+ async function wpMutate(path, body, method = "POST", authToken) {
89
89
  const url = buildUrl(config, path);
90
+ const headers = {
91
+ "Content-Type": "application/json",
92
+ "User-Agent": USER_AGENT
93
+ };
94
+ if (authToken) {
95
+ headers["Authorization"] = authToken;
96
+ }
90
97
  const res = await doFetch(url, {
91
98
  method,
99
+ headers,
100
+ body: JSON.stringify(body),
101
+ cache: "no-store"
102
+ });
103
+ return await res.json();
104
+ }
105
+ async function wpUpload(path, file, filename, mimeType, authToken) {
106
+ const url = buildUrl(config, path);
107
+ const res = await doFetch(url, {
108
+ method: "POST",
92
109
  headers: {
93
- "Content-Type": "application/json",
94
- "User-Agent": USER_AGENT
110
+ "Content-Disposition": `attachment; filename="${filename}"`,
111
+ "Content-Type": mimeType,
112
+ "User-Agent": USER_AGENT,
113
+ "Authorization": authToken
95
114
  },
96
- body: JSON.stringify(body),
115
+ body: file,
97
116
  cache: "no-store"
98
117
  });
99
118
  return await res.json();
100
119
  }
101
- return { wpFetch, wpFetchGraceful, wpFetchPaginated, wpFetchPaginatedGraceful, wpMutate };
120
+ return { wpFetch, wpFetchGraceful, wpFetchPaginated, wpFetchPaginatedGraceful, wpMutate, wpUpload };
121
+ }
122
+
123
+ // src/integrations/restApi/core/contactForm7/queries.ts
124
+ function createCF7Queries(config) {
125
+ async function submitForm(formId, data) {
126
+ const url = buildUrl(config, `/wp-json/contact-form-7/v1/contact-forms/${formId}/feedback`);
127
+ const body = new FormData();
128
+ for (const [key, value] of Object.entries(data)) {
129
+ body.append(key, value);
130
+ }
131
+ const res = await fetch(url, { method: "POST", body, cache: "no-store" });
132
+ return res.json();
133
+ }
134
+ return { submitForm };
135
+ }
136
+
137
+ // src/integrations/restApi/core/mutations/posts/mutations.ts
138
+ function createPostsMutations(fetcher) {
139
+ const { wpMutate } = fetcher;
140
+ async function createPost(input, authToken) {
141
+ return wpMutate("/wp/v2/posts", input, "POST", authToken);
142
+ }
143
+ async function updatePost(id, input, authToken) {
144
+ return wpMutate(`/wp/v2/posts/${id}`, input, "PATCH", authToken);
145
+ }
146
+ async function deletePost(id, authToken, force = false) {
147
+ return wpMutate(
148
+ `/wp/v2/posts/${id}`,
149
+ { force },
150
+ "DELETE",
151
+ authToken
152
+ );
153
+ }
154
+ return { createPost, updatePost, deletePost };
155
+ }
156
+
157
+ // src/integrations/restApi/core/mutations/comments/mutations.ts
158
+ function createCommentsMutations(fetcher) {
159
+ const { wpMutate } = fetcher;
160
+ async function createComment(input, authToken) {
161
+ return wpMutate("/wp/v2/comments", input, "POST", authToken);
162
+ }
163
+ async function updateComment(id, input, authToken) {
164
+ return wpMutate(`/wp/v2/comments/${id}`, input, "PATCH", authToken);
165
+ }
166
+ async function deleteComment(id, authToken, force = false) {
167
+ return wpMutate(
168
+ `/wp/v2/comments/${id}`,
169
+ { force },
170
+ "DELETE",
171
+ authToken
172
+ );
173
+ }
174
+ return { createComment, updateComment, deleteComment };
175
+ }
176
+
177
+ // src/integrations/restApi/core/mutations/pages/mutations.ts
178
+ function createPagesMutations(fetcher) {
179
+ const { wpMutate } = fetcher;
180
+ async function createPage(input, authToken) {
181
+ return wpMutate("/wp/v2/pages", input, "POST", authToken);
182
+ }
183
+ async function updatePage(id, input, authToken) {
184
+ return wpMutate(`/wp/v2/pages/${id}`, input, "PATCH", authToken);
185
+ }
186
+ async function deletePage(id, authToken, force = false) {
187
+ return wpMutate(
188
+ `/wp/v2/pages/${id}`,
189
+ { force },
190
+ "DELETE",
191
+ authToken
192
+ );
193
+ }
194
+ return { createPage, updatePage, deletePage };
195
+ }
196
+
197
+ // src/integrations/restApi/core/mutations/categories/mutations.ts
198
+ function createCategoriesMutations(fetcher) {
199
+ const { wpMutate } = fetcher;
200
+ async function createCategory(input, authToken) {
201
+ return wpMutate("/wp/v2/categories", input, "POST", authToken);
202
+ }
203
+ async function updateCategory(id, input, authToken) {
204
+ return wpMutate(`/wp/v2/categories/${id}`, input, "PATCH", authToken);
205
+ }
206
+ async function deleteCategory(id, authToken, force = false) {
207
+ return wpMutate(
208
+ `/wp/v2/categories/${id}`,
209
+ { force },
210
+ "DELETE",
211
+ authToken
212
+ );
213
+ }
214
+ return { createCategory, updateCategory, deleteCategory };
215
+ }
216
+
217
+ // src/integrations/restApi/core/mutations/tags/mutations.ts
218
+ function createTagsMutations(fetcher) {
219
+ const { wpMutate } = fetcher;
220
+ async function createTag(input, authToken) {
221
+ return wpMutate("/wp/v2/tags", input, "POST", authToken);
222
+ }
223
+ async function updateTag(id, input, authToken) {
224
+ return wpMutate(`/wp/v2/tags/${id}`, input, "PATCH", authToken);
225
+ }
226
+ async function deleteTag(id, authToken, force = false) {
227
+ return wpMutate(
228
+ `/wp/v2/tags/${id}`,
229
+ { force },
230
+ "DELETE",
231
+ authToken
232
+ );
233
+ }
234
+ return { createTag, updateTag, deleteTag };
235
+ }
236
+
237
+ // src/integrations/restApi/core/mutations/authors/mutations.ts
238
+ function createAuthorsMutations(fetcher) {
239
+ const { wpMutate } = fetcher;
240
+ async function createAuthor(input, authToken) {
241
+ return wpMutate("/wp/v2/users", input, "POST", authToken);
242
+ }
243
+ async function updateAuthor(id, input, authToken) {
244
+ return wpMutate(`/wp/v2/users/${id}`, input, "PATCH", authToken);
245
+ }
246
+ async function deleteAuthor(id, authToken, reassign) {
247
+ return wpMutate(
248
+ `/wp/v2/users/${id}`,
249
+ { force: true, reassign },
250
+ "DELETE",
251
+ authToken
252
+ );
253
+ }
254
+ return { createAuthor, updateAuthor, deleteAuthor };
255
+ }
256
+
257
+ // src/integrations/restApi/core/mutations/menus/mutations.ts
258
+ function createMenusMutations(fetcher) {
259
+ const { wpMutate } = fetcher;
260
+ async function createMenu(input, authToken) {
261
+ return wpMutate("/wp/v2/menus", input, "POST", authToken);
262
+ }
263
+ async function updateMenu(id, input, authToken) {
264
+ return wpMutate(`/wp/v2/menus/${id}`, input, "PATCH", authToken);
265
+ }
266
+ async function deleteMenu(id, authToken) {
267
+ return wpMutate(
268
+ `/wp/v2/menus/${id}`,
269
+ {},
270
+ "DELETE",
271
+ authToken
272
+ );
273
+ }
274
+ async function createMenuItem(input, authToken) {
275
+ return wpMutate("/wp/v2/menu-items", input, "POST", authToken);
276
+ }
277
+ async function updateMenuItem(id, input, authToken) {
278
+ return wpMutate(`/wp/v2/menu-items/${id}`, input, "PATCH", authToken);
279
+ }
280
+ async function deleteMenuItem(id, authToken, force = false) {
281
+ return wpMutate(
282
+ `/wp/v2/menu-items/${id}`,
283
+ { force },
284
+ "DELETE",
285
+ authToken
286
+ );
287
+ }
288
+ return { createMenu, updateMenu, deleteMenu, createMenuItem, updateMenuItem, deleteMenuItem };
289
+ }
290
+
291
+ // src/integrations/restApi/core/mutations/media/mutations.ts
292
+ function createMediaMutations(fetcher) {
293
+ const { wpMutate, wpUpload } = fetcher;
294
+ async function uploadMedia(input, authToken) {
295
+ const media = await wpUpload(
296
+ "/wp/v2/media",
297
+ input.file,
298
+ input.filename,
299
+ input.mimeType,
300
+ authToken
301
+ );
302
+ if (input.title || input.caption || input.alt_text) {
303
+ return wpMutate(
304
+ `/wp/v2/media/${media.id}`,
305
+ {
306
+ ...input.title && { title: input.title },
307
+ ...input.caption && { caption: input.caption },
308
+ ...input.alt_text && { alt_text: input.alt_text }
309
+ },
310
+ "PATCH",
311
+ authToken
312
+ );
313
+ }
314
+ return media;
315
+ }
316
+ async function updateMedia(id, input, authToken) {
317
+ return wpMutate(`/wp/v2/media/${id}`, input, "PATCH", authToken);
318
+ }
319
+ async function deleteMedia(id, authToken, force = true) {
320
+ return wpMutate(
321
+ `/wp/v2/media/${id}`,
322
+ { force },
323
+ "DELETE",
324
+ authToken
325
+ );
326
+ }
327
+ return { uploadMedia, updateMedia, deleteMedia };
328
+ }
329
+
330
+ // src/integrations/restApi/core/mutations/index.ts
331
+ function createWordPressMutationsClient(config) {
332
+ const fetcher = createFetcher(config);
333
+ return {
334
+ ...createPostsMutations(fetcher),
335
+ ...createCommentsMutations(fetcher),
336
+ ...createPagesMutations(fetcher),
337
+ ...createCategoriesMutations(fetcher),
338
+ ...createTagsMutations(fetcher),
339
+ ...createAuthorsMutations(fetcher),
340
+ ...createMenusMutations(fetcher),
341
+ ...createMediaMutations(fetcher)
342
+ };
102
343
  }
103
344
 
104
345
  // src/integrations/restApi/core/posts/queries.ts
@@ -676,6 +917,25 @@ function createProductsQueries(fetcher) {
676
917
  };
677
918
  }
678
919
 
920
+ // src/integrations/restApi/woocommerce/products/mutations.ts
921
+ function createProductsMutations(fetcher) {
922
+ const { wcMutate } = fetcher;
923
+ async function createProduct(input) {
924
+ return wcMutate("/wp-json/wc/v3/products", input, "POST");
925
+ }
926
+ async function updateProduct(id, input) {
927
+ return wcMutate(`/wp-json/wc/v3/products/${id}`, input, "PUT");
928
+ }
929
+ async function deleteProduct(id, force = true) {
930
+ return wcMutate(
931
+ `/wp-json/wc/v3/products/${id}`,
932
+ { force },
933
+ "DELETE"
934
+ );
935
+ }
936
+ return { createProduct, updateProduct, deleteProduct };
937
+ }
938
+
679
939
  // src/integrations/restApi/woocommerce/categories/queries.ts
680
940
  function createCategoriesQueries2(fetcher) {
681
941
  const { wcFetch, wcFetchGraceful } = fetcher;
@@ -725,6 +985,29 @@ function createCategoriesQueries2(fetcher) {
725
985
  };
726
986
  }
727
987
 
988
+ // src/integrations/restApi/woocommerce/categories/mutations.ts
989
+ function createCategoriesMutations2(fetcher) {
990
+ const { wcMutate } = fetcher;
991
+ async function createProductCategory(input) {
992
+ return wcMutate("/wp-json/wc/v3/products/categories", input, "POST");
993
+ }
994
+ async function updateProductCategory(id, input) {
995
+ return wcMutate(
996
+ `/wp-json/wc/v3/products/categories/${id}`,
997
+ input,
998
+ "PUT"
999
+ );
1000
+ }
1001
+ async function deleteProductCategory(id, force = true) {
1002
+ return wcMutate(
1003
+ `/wp-json/wc/v3/products/categories/${id}`,
1004
+ { force },
1005
+ "DELETE"
1006
+ );
1007
+ }
1008
+ return { createProductCategory, updateProductCategory, deleteProductCategory };
1009
+ }
1010
+
728
1011
  // src/integrations/restApi/woocommerce/tags/queries.ts
729
1012
  function createTagsQueries2(fetcher) {
730
1013
  const { wcFetch, wcFetchGraceful } = fetcher;
@@ -758,6 +1041,25 @@ function createTagsQueries2(fetcher) {
758
1041
  };
759
1042
  }
760
1043
 
1044
+ // src/integrations/restApi/woocommerce/tags/mutations.ts
1045
+ function createTagsMutations2(fetcher) {
1046
+ const { wcMutate } = fetcher;
1047
+ async function createProductTag(input) {
1048
+ return wcMutate("/wp-json/wc/v3/products/tags", input, "POST");
1049
+ }
1050
+ async function updateProductTag(id, input) {
1051
+ return wcMutate(`/wp-json/wc/v3/products/tags/${id}`, input, "PUT");
1052
+ }
1053
+ async function deleteProductTag(id, force = true) {
1054
+ return wcMutate(
1055
+ `/wp-json/wc/v3/products/tags/${id}`,
1056
+ { force },
1057
+ "DELETE"
1058
+ );
1059
+ }
1060
+ return { createProductTag, updateProductTag, deleteProductTag };
1061
+ }
1062
+
761
1063
  // src/integrations/restApi/woocommerce/orders/queries.ts
762
1064
  function createOrdersQueries(fetcher) {
763
1065
  const { wcFetch, wcFetchGraceful, wcMutate } = fetcher;
@@ -782,11 +1084,19 @@ function createOrdersQueries(fetcher) {
782
1084
  ["woocommerce", "orders", `orders-customer-${customerId}`]
783
1085
  );
784
1086
  }
1087
+ async function deleteOrder(id, force = true) {
1088
+ return wcMutate(
1089
+ `/wp-json/wc/v3/orders/${id}`,
1090
+ { force },
1091
+ "DELETE"
1092
+ );
1093
+ }
785
1094
  return {
786
1095
  createOrder,
787
1096
  getOrderById,
788
1097
  updateOrder,
789
- getOrdersByCustomer
1098
+ getOrdersByCustomer,
1099
+ deleteOrder
790
1100
  };
791
1101
  }
792
1102
 
@@ -820,9 +1130,28 @@ function createCouponsQueries(fetcher) {
820
1130
  };
821
1131
  }
822
1132
 
1133
+ // src/integrations/restApi/woocommerce/coupons/mutations.ts
1134
+ function createCouponsMutations(fetcher) {
1135
+ const { wcMutate } = fetcher;
1136
+ async function createCoupon(input) {
1137
+ return wcMutate("/wp-json/wc/v3/coupons", input, "POST");
1138
+ }
1139
+ async function updateCoupon(id, input) {
1140
+ return wcMutate(`/wp-json/wc/v3/coupons/${id}`, input, "PUT");
1141
+ }
1142
+ async function deleteCoupon(id, force = true) {
1143
+ return wcMutate(
1144
+ `/wp-json/wc/v3/coupons/${id}`,
1145
+ { force },
1146
+ "DELETE"
1147
+ );
1148
+ }
1149
+ return { createCoupon, updateCoupon, deleteCoupon };
1150
+ }
1151
+
823
1152
  // src/integrations/restApi/woocommerce/customers/queries.ts
824
1153
  function createCustomersQueries(fetcher) {
825
- const { wcFetch, wcFetchGraceful } = fetcher;
1154
+ const { wcFetch, wcFetchGraceful, wcMutate } = fetcher;
826
1155
  async function getCustomerById(id) {
827
1156
  return wcFetch(`/wp-json/wc/v3/customers/${id}`, void 0, [
828
1157
  "woocommerce",
@@ -860,11 +1189,23 @@ function createCustomersQueries(fetcher) {
860
1189
  { method: "POST", body: JSON.stringify(data) }
861
1190
  );
862
1191
  }
1192
+ async function updateCustomer(id, data) {
1193
+ return wcMutate(`/wp-json/wc/v3/customers/${id}`, data, "PUT");
1194
+ }
1195
+ async function deleteCustomer(id, reassign) {
1196
+ return wcMutate(
1197
+ `/wp-json/wc/v3/customers/${id}`,
1198
+ { force: true, ...reassign !== void 0 && { reassign } },
1199
+ "DELETE"
1200
+ );
1201
+ }
863
1202
  return {
864
1203
  getCustomerById,
865
1204
  getCustomerByEmail,
866
1205
  getCustomerByEmailNoCache,
867
- createCustomer
1206
+ createCustomer,
1207
+ updateCustomer,
1208
+ deleteCustomer
868
1209
  };
869
1210
  }
870
1211
 
@@ -873,10 +1214,14 @@ function createWooCommerceClient(config) {
873
1214
  const fetcher = createWooCommerceFetcher(config);
874
1215
  return {
875
1216
  ...createProductsQueries(fetcher),
1217
+ ...createProductsMutations(fetcher),
876
1218
  ...createCategoriesQueries2(fetcher),
1219
+ ...createCategoriesMutations2(fetcher),
877
1220
  ...createTagsQueries2(fetcher),
1221
+ ...createTagsMutations2(fetcher),
878
1222
  ...createOrdersQueries(fetcher),
879
1223
  ...createCouponsQueries(fetcher),
1224
+ ...createCouponsMutations(fetcher),
880
1225
  ...createCustomersQueries(fetcher)
881
1226
  };
882
1227
  }
@@ -936,7 +1281,42 @@ function createWPGraphQLFetcher(config) {
936
1281
  return fallback;
937
1282
  }
938
1283
  }
939
- return { gqlFetch, gqlFetchGraceful };
1284
+ async function gqlMutate(document, variables, authToken) {
1285
+ const headers = {
1286
+ "Content-Type": "application/json",
1287
+ "User-Agent": USER_AGENT3
1288
+ };
1289
+ if (authToken) {
1290
+ headers["Authorization"] = authToken;
1291
+ }
1292
+ const response = await fetch(url, {
1293
+ method: "POST",
1294
+ headers,
1295
+ body: JSON.stringify({ query: document, variables }),
1296
+ cache: "no-store"
1297
+ });
1298
+ if (!response.ok) {
1299
+ throw new WPGraphQLError(
1300
+ `WPGraphQL mutation failed: ${response.statusText}`,
1301
+ response.status,
1302
+ url
1303
+ );
1304
+ }
1305
+ const parsed = await response.json();
1306
+ if (parsed.errors && parsed.errors.length > 0) {
1307
+ throw new WPGraphQLError(
1308
+ parsed.errors[0].message,
1309
+ 200,
1310
+ url,
1311
+ parsed.errors
1312
+ );
1313
+ }
1314
+ if (parsed.data === void 0) {
1315
+ throw new WPGraphQLError("No data returned from WPGraphQL mutation", 200, url);
1316
+ }
1317
+ return parsed.data;
1318
+ }
1319
+ return { gqlFetch, gqlFetchGraceful, gqlMutate };
940
1320
  }
941
1321
 
942
1322
  // src/integrations/wpGraphQL/core/posts/queries.ts
@@ -1544,6 +1924,518 @@ function createCommentsQueries2(fetcher) {
1544
1924
  };
1545
1925
  }
1546
1926
 
1927
+ // src/integrations/wpGraphQL/core/media/queries.ts
1928
+ var DEFAULT_FIRST6 = 10;
1929
+ var MEDIA_FIELDS = `
1930
+ id
1931
+ databaseId
1932
+ slug
1933
+ title
1934
+ date
1935
+ sourceUrl
1936
+ altText
1937
+ caption
1938
+ description
1939
+ mediaType
1940
+ mimeType
1941
+ uri
1942
+ mediaDetails {
1943
+ width
1944
+ height
1945
+ file
1946
+ sizes { name width height mimeType sourceUrl }
1947
+ }
1948
+ `;
1949
+ var GQL_GET_MEDIA_ITEMS = `
1950
+ query GetMediaItems($first: Int, $after: String) {
1951
+ mediaItems(first: $first, after: $after) {
1952
+ nodes { ${MEDIA_FIELDS} }
1953
+ pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
1954
+ }
1955
+ }
1956
+ `;
1957
+ var GQL_GET_MEDIA_ITEM_BY_ID = `
1958
+ query GetMediaItemById($id: ID!) {
1959
+ mediaItem(id: $id, idType: DATABASE_ID) { ${MEDIA_FIELDS} }
1960
+ }
1961
+ `;
1962
+ var GQL_GET_MEDIA_ITEM_BY_SLUG = `
1963
+ query GetMediaItemBySlug($id: ID!) {
1964
+ mediaItem(id: $id, idType: SLUG) { ${MEDIA_FIELDS} }
1965
+ }
1966
+ `;
1967
+ function createMediaQueries2(fetcher) {
1968
+ const { gqlFetchGraceful } = fetcher;
1969
+ async function getMediaItems(first = DEFAULT_FIRST6, after) {
1970
+ const data = await gqlFetchGraceful(
1971
+ GQL_GET_MEDIA_ITEMS,
1972
+ { mediaItems: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
1973
+ { first, after },
1974
+ ["wpgraphql", "gql-media"]
1975
+ );
1976
+ return data.mediaItems;
1977
+ }
1978
+ async function getMediaItemById(id) {
1979
+ const data = await gqlFetchGraceful(
1980
+ GQL_GET_MEDIA_ITEM_BY_ID,
1981
+ { mediaItem: null },
1982
+ { id: String(id) },
1983
+ ["wpgraphql", "gql-media", `gql-media-${id}`]
1984
+ );
1985
+ return data.mediaItem;
1986
+ }
1987
+ async function getMediaItemBySlug(slug) {
1988
+ const data = await gqlFetchGraceful(
1989
+ GQL_GET_MEDIA_ITEM_BY_SLUG,
1990
+ { mediaItem: null },
1991
+ { id: slug },
1992
+ ["wpgraphql", "gql-media", `gql-media-${slug}`]
1993
+ );
1994
+ return data.mediaItem;
1995
+ }
1996
+ return { getMediaItems, getMediaItemById, getMediaItemBySlug };
1997
+ }
1998
+
1999
+ // src/integrations/wpGraphQL/core/mutations/posts/mutations.ts
2000
+ var MUTATED_POST_FIELDS = `
2001
+ id
2002
+ databaseId
2003
+ slug
2004
+ title
2005
+ status
2006
+ `;
2007
+ var GQL_CREATE_POST = `
2008
+ mutation CreatePost($input: CreatePostInput!) {
2009
+ createPost(input: $input) {
2010
+ post { ${MUTATED_POST_FIELDS} }
2011
+ }
2012
+ }
2013
+ `;
2014
+ var GQL_UPDATE_POST = `
2015
+ mutation UpdatePost($input: UpdatePostInput!) {
2016
+ updatePost(input: $input) {
2017
+ post { ${MUTATED_POST_FIELDS} }
2018
+ }
2019
+ }
2020
+ `;
2021
+ var GQL_DELETE_POST = `
2022
+ mutation DeletePost($input: DeletePostInput!) {
2023
+ deletePost(input: $input) {
2024
+ deletedId
2025
+ post { ${MUTATED_POST_FIELDS} }
2026
+ }
2027
+ }
2028
+ `;
2029
+ function createPostsMutations2(fetcher) {
2030
+ const { gqlMutate } = fetcher;
2031
+ async function createPost(input, authToken) {
2032
+ const data = await gqlMutate(
2033
+ GQL_CREATE_POST,
2034
+ { input },
2035
+ authToken
2036
+ );
2037
+ return data.createPost.post;
2038
+ }
2039
+ async function updatePost(input, authToken) {
2040
+ const data = await gqlMutate(
2041
+ GQL_UPDATE_POST,
2042
+ { input },
2043
+ authToken
2044
+ );
2045
+ return data.updatePost.post;
2046
+ }
2047
+ async function deletePost(id, authToken, forceDelete = false) {
2048
+ const data = await gqlMutate(
2049
+ GQL_DELETE_POST,
2050
+ { input: { id, forceDelete } },
2051
+ authToken
2052
+ );
2053
+ return data.deletePost;
2054
+ }
2055
+ return { createPost, updatePost, deletePost };
2056
+ }
2057
+
2058
+ // src/integrations/wpGraphQL/core/mutations/comments/mutations.ts
2059
+ var MUTATED_COMMENT_FIELDS = `
2060
+ id
2061
+ databaseId
2062
+ content(format: RENDERED)
2063
+ date
2064
+ status
2065
+ parentId
2066
+ author { node { name url } }
2067
+ `;
2068
+ var GQL_CREATE_COMMENT = `
2069
+ mutation CreateComment($input: CreateCommentInput!) {
2070
+ createComment(input: $input) {
2071
+ success
2072
+ comment { ${MUTATED_COMMENT_FIELDS} }
2073
+ }
2074
+ }
2075
+ `;
2076
+ var GQL_UPDATE_COMMENT = `
2077
+ mutation UpdateComment($input: UpdateCommentInput!) {
2078
+ updateComment(input: $input) {
2079
+ comment { ${MUTATED_COMMENT_FIELDS} }
2080
+ }
2081
+ }
2082
+ `;
2083
+ var GQL_DELETE_COMMENT = `
2084
+ mutation DeleteComment($input: DeleteCommentInput!) {
2085
+ deleteComment(input: $input) {
2086
+ deletedId
2087
+ comment { ${MUTATED_COMMENT_FIELDS} }
2088
+ }
2089
+ }
2090
+ `;
2091
+ function createCommentsMutations2(fetcher) {
2092
+ const { gqlMutate } = fetcher;
2093
+ async function createComment(input, authToken) {
2094
+ const gqlInput = {
2095
+ commentOn: input.postId,
2096
+ content: input.content
2097
+ };
2098
+ if (input.authorName) gqlInput["author"] = input.authorName;
2099
+ if (input.authorEmail) gqlInput["authorEmail"] = input.authorEmail;
2100
+ if (input.authorUrl) gqlInput["authorUrl"] = input.authorUrl;
2101
+ if (input.parentId) gqlInput["parent"] = input.parentId;
2102
+ const data = await gqlMutate(
2103
+ GQL_CREATE_COMMENT,
2104
+ { input: gqlInput },
2105
+ authToken
2106
+ );
2107
+ return data.createComment;
2108
+ }
2109
+ async function updateComment(input, authToken) {
2110
+ const data = await gqlMutate(
2111
+ GQL_UPDATE_COMMENT,
2112
+ { input },
2113
+ authToken
2114
+ );
2115
+ return data.updateComment.comment;
2116
+ }
2117
+ async function deleteComment(id, authToken, forceDelete = false) {
2118
+ const data = await gqlMutate(
2119
+ GQL_DELETE_COMMENT,
2120
+ { input: { id, forceDelete } },
2121
+ authToken
2122
+ );
2123
+ return data.deleteComment;
2124
+ }
2125
+ return { createComment, updateComment, deleteComment };
2126
+ }
2127
+
2128
+ // src/integrations/wpGraphQL/core/mutations/pages/mutations.ts
2129
+ var MUTATED_PAGE_FIELDS = `
2130
+ id
2131
+ databaseId
2132
+ slug
2133
+ title
2134
+ status
2135
+ uri
2136
+ `;
2137
+ var GQL_CREATE_PAGE = `
2138
+ mutation CreatePage($input: CreatePageInput!) {
2139
+ createPage(input: $input) {
2140
+ page { ${MUTATED_PAGE_FIELDS} }
2141
+ }
2142
+ }
2143
+ `;
2144
+ var GQL_UPDATE_PAGE = `
2145
+ mutation UpdatePage($input: UpdatePageInput!) {
2146
+ updatePage(input: $input) {
2147
+ page { ${MUTATED_PAGE_FIELDS} }
2148
+ }
2149
+ }
2150
+ `;
2151
+ var GQL_DELETE_PAGE = `
2152
+ mutation DeletePage($input: DeletePageInput!) {
2153
+ deletePage(input: $input) {
2154
+ deletedId
2155
+ page { ${MUTATED_PAGE_FIELDS} }
2156
+ }
2157
+ }
2158
+ `;
2159
+ function createPagesMutations2(fetcher) {
2160
+ const { gqlMutate } = fetcher;
2161
+ async function createPage(input, authToken) {
2162
+ const data = await gqlMutate(
2163
+ GQL_CREATE_PAGE,
2164
+ { input },
2165
+ authToken
2166
+ );
2167
+ return data.createPage.page;
2168
+ }
2169
+ async function updatePage(input, authToken) {
2170
+ const data = await gqlMutate(
2171
+ GQL_UPDATE_PAGE,
2172
+ { input },
2173
+ authToken
2174
+ );
2175
+ return data.updatePage.page;
2176
+ }
2177
+ async function deletePage(id, authToken, forceDelete = false) {
2178
+ const data = await gqlMutate(
2179
+ GQL_DELETE_PAGE,
2180
+ { input: { id, forceDelete } },
2181
+ authToken
2182
+ );
2183
+ return data.deletePage;
2184
+ }
2185
+ return { createPage, updatePage, deletePage };
2186
+ }
2187
+
2188
+ // src/integrations/wpGraphQL/core/mutations/categories/mutations.ts
2189
+ var MUTATED_CATEGORY_FIELDS = `
2190
+ id
2191
+ databaseId
2192
+ name
2193
+ slug
2194
+ `;
2195
+ var GQL_CREATE_CATEGORY = `
2196
+ mutation CreateCategory($input: CreateCategoryInput!) {
2197
+ createCategory(input: $input) {
2198
+ category { ${MUTATED_CATEGORY_FIELDS} }
2199
+ }
2200
+ }
2201
+ `;
2202
+ var GQL_UPDATE_CATEGORY = `
2203
+ mutation UpdateCategory($input: UpdateCategoryInput!) {
2204
+ updateCategory(input: $input) {
2205
+ category { ${MUTATED_CATEGORY_FIELDS} }
2206
+ }
2207
+ }
2208
+ `;
2209
+ var GQL_DELETE_CATEGORY = `
2210
+ mutation DeleteCategory($input: DeleteCategoryInput!) {
2211
+ deleteCategory(input: $input) {
2212
+ deletedId
2213
+ category { ${MUTATED_CATEGORY_FIELDS} }
2214
+ }
2215
+ }
2216
+ `;
2217
+ function createCategoriesMutations3(fetcher) {
2218
+ const { gqlMutate } = fetcher;
2219
+ async function createCategory(input, authToken) {
2220
+ const data = await gqlMutate(
2221
+ GQL_CREATE_CATEGORY,
2222
+ { input },
2223
+ authToken
2224
+ );
2225
+ return data.createCategory.category;
2226
+ }
2227
+ async function updateCategory(input, authToken) {
2228
+ const data = await gqlMutate(
2229
+ GQL_UPDATE_CATEGORY,
2230
+ { input },
2231
+ authToken
2232
+ );
2233
+ return data.updateCategory.category;
2234
+ }
2235
+ async function deleteCategory(id, authToken) {
2236
+ const data = await gqlMutate(
2237
+ GQL_DELETE_CATEGORY,
2238
+ { input: { id } },
2239
+ authToken
2240
+ );
2241
+ return data.deleteCategory;
2242
+ }
2243
+ return { createCategory, updateCategory, deleteCategory };
2244
+ }
2245
+
2246
+ // src/integrations/wpGraphQL/core/mutations/tags/mutations.ts
2247
+ var MUTATED_TAG_FIELDS = `
2248
+ id
2249
+ databaseId
2250
+ name
2251
+ slug
2252
+ `;
2253
+ var GQL_CREATE_TAG = `
2254
+ mutation CreateTag($input: CreateTagInput!) {
2255
+ createTag(input: $input) {
2256
+ tag { ${MUTATED_TAG_FIELDS} }
2257
+ }
2258
+ }
2259
+ `;
2260
+ var GQL_UPDATE_TAG = `
2261
+ mutation UpdateTag($input: UpdateTagInput!) {
2262
+ updateTag(input: $input) {
2263
+ tag { ${MUTATED_TAG_FIELDS} }
2264
+ }
2265
+ }
2266
+ `;
2267
+ var GQL_DELETE_TAG = `
2268
+ mutation DeleteTag($input: DeleteTagInput!) {
2269
+ deleteTag(input: $input) {
2270
+ deletedId
2271
+ tag { ${MUTATED_TAG_FIELDS} }
2272
+ }
2273
+ }
2274
+ `;
2275
+ function createTagsMutations3(fetcher) {
2276
+ const { gqlMutate } = fetcher;
2277
+ async function createTag(input, authToken) {
2278
+ const data = await gqlMutate(
2279
+ GQL_CREATE_TAG,
2280
+ { input },
2281
+ authToken
2282
+ );
2283
+ return data.createTag.tag;
2284
+ }
2285
+ async function updateTag(input, authToken) {
2286
+ const data = await gqlMutate(
2287
+ GQL_UPDATE_TAG,
2288
+ { input },
2289
+ authToken
2290
+ );
2291
+ return data.updateTag.tag;
2292
+ }
2293
+ async function deleteTag(id, authToken) {
2294
+ const data = await gqlMutate(
2295
+ GQL_DELETE_TAG,
2296
+ { input: { id } },
2297
+ authToken
2298
+ );
2299
+ return data.deleteTag;
2300
+ }
2301
+ return { createTag, updateTag, deleteTag };
2302
+ }
2303
+
2304
+ // src/integrations/wpGraphQL/core/mutations/authors/mutations.ts
2305
+ var MUTATED_USER_FIELDS = `
2306
+ id
2307
+ databaseId
2308
+ name
2309
+ slug
2310
+ email
2311
+ `;
2312
+ var GQL_REGISTER_USER = `
2313
+ mutation RegisterUser($input: RegisterUserInput!) {
2314
+ registerUser(input: $input) {
2315
+ user { ${MUTATED_USER_FIELDS} }
2316
+ }
2317
+ }
2318
+ `;
2319
+ var GQL_UPDATE_USER = `
2320
+ mutation UpdateUser($input: UpdateUserInput!) {
2321
+ updateUser(input: $input) {
2322
+ user { ${MUTATED_USER_FIELDS} }
2323
+ }
2324
+ }
2325
+ `;
2326
+ var GQL_DELETE_USER = `
2327
+ mutation DeleteUser($input: DeleteUserInput!) {
2328
+ deleteUser(input: $input) {
2329
+ deletedId
2330
+ user { ${MUTATED_USER_FIELDS} }
2331
+ }
2332
+ }
2333
+ `;
2334
+ function createAuthorsMutations2(fetcher) {
2335
+ const { gqlMutate } = fetcher;
2336
+ async function registerUser(input, authToken) {
2337
+ const data = await gqlMutate(
2338
+ GQL_REGISTER_USER,
2339
+ { input },
2340
+ authToken
2341
+ );
2342
+ return data.registerUser.user;
2343
+ }
2344
+ async function updateUser(input, authToken) {
2345
+ const data = await gqlMutate(
2346
+ GQL_UPDATE_USER,
2347
+ { input },
2348
+ authToken
2349
+ );
2350
+ return data.updateUser.user;
2351
+ }
2352
+ async function deleteUser(id, authToken, reassignPosts) {
2353
+ const input = { id };
2354
+ if (reassignPosts) input["reassignId"] = reassignPosts;
2355
+ const data = await gqlMutate(
2356
+ GQL_DELETE_USER,
2357
+ { input },
2358
+ authToken
2359
+ );
2360
+ return data.deleteUser;
2361
+ }
2362
+ return { registerUser, updateUser, deleteUser };
2363
+ }
2364
+
2365
+ // src/integrations/wpGraphQL/core/mutations/media/mutations.ts
2366
+ var MUTATED_MEDIA_FIELDS = `
2367
+ id
2368
+ databaseId
2369
+ slug
2370
+ title
2371
+ sourceUrl
2372
+ altText
2373
+ `;
2374
+ var GQL_CREATE_MEDIA_ITEM = `
2375
+ mutation CreateMediaItem($input: CreateMediaItemInput!) {
2376
+ createMediaItem(input: $input) {
2377
+ mediaItem { ${MUTATED_MEDIA_FIELDS} }
2378
+ }
2379
+ }
2380
+ `;
2381
+ var GQL_UPDATE_MEDIA_ITEM = `
2382
+ mutation UpdateMediaItem($input: UpdateMediaItemInput!) {
2383
+ updateMediaItem(input: $input) {
2384
+ mediaItem { ${MUTATED_MEDIA_FIELDS} }
2385
+ }
2386
+ }
2387
+ `;
2388
+ var GQL_DELETE_MEDIA_ITEM = `
2389
+ mutation DeleteMediaItem($input: DeleteMediaItemInput!) {
2390
+ deleteMediaItem(input: $input) {
2391
+ deletedId
2392
+ mediaItem { ${MUTATED_MEDIA_FIELDS} }
2393
+ }
2394
+ }
2395
+ `;
2396
+ function createMediaMutations2(fetcher) {
2397
+ const { gqlMutate } = fetcher;
2398
+ async function createMediaItem(input, authToken) {
2399
+ const data = await gqlMutate(
2400
+ GQL_CREATE_MEDIA_ITEM,
2401
+ { input },
2402
+ authToken
2403
+ );
2404
+ return data.createMediaItem.mediaItem;
2405
+ }
2406
+ async function updateMediaItem(input, authToken) {
2407
+ const data = await gqlMutate(
2408
+ GQL_UPDATE_MEDIA_ITEM,
2409
+ { input },
2410
+ authToken
2411
+ );
2412
+ return data.updateMediaItem.mediaItem;
2413
+ }
2414
+ async function deleteMediaItem(id, authToken, forceDelete = true) {
2415
+ const data = await gqlMutate(
2416
+ GQL_DELETE_MEDIA_ITEM,
2417
+ { input: { id, forceDelete } },
2418
+ authToken
2419
+ );
2420
+ return data.deleteMediaItem;
2421
+ }
2422
+ return { createMediaItem, updateMediaItem, deleteMediaItem };
2423
+ }
2424
+
2425
+ // src/integrations/wpGraphQL/core/mutations/index.ts
2426
+ function createWPGraphQLMutationsClient(config) {
2427
+ const fetcher = createWPGraphQLFetcher(config);
2428
+ return {
2429
+ ...createPostsMutations2(fetcher),
2430
+ ...createCommentsMutations2(fetcher),
2431
+ ...createPagesMutations2(fetcher),
2432
+ ...createCategoriesMutations3(fetcher),
2433
+ ...createTagsMutations3(fetcher),
2434
+ ...createAuthorsMutations2(fetcher),
2435
+ ...createMediaMutations2(fetcher)
2436
+ };
2437
+ }
2438
+
1547
2439
  // src/integrations/wpGraphQL/core/index.ts
1548
2440
  function createWPGraphQLCoreClient(config) {
1549
2441
  const fetcher = createWPGraphQLFetcher(config);
@@ -1554,7 +2446,8 @@ function createWPGraphQLCoreClient(config) {
1554
2446
  ...createTagsQueries3(fetcher),
1555
2447
  ...createAuthorsQueries2(fetcher),
1556
2448
  ...createMenusQueries2(fetcher),
1557
- ...createCommentsQueries2(fetcher)
2449
+ ...createCommentsQueries2(fetcher),
2450
+ ...createMediaQueries2(fetcher)
1558
2451
  };
1559
2452
  }
1560
2453
 
@@ -1723,7 +2616,7 @@ function buildPostsWithACFQuery(fieldGroupName, fields) {
1723
2616
  }
1724
2617
 
1725
2618
  // src/integrations/wpGraphQL/woocommerce/products/queries.ts
1726
- var DEFAULT_FIRST6 = 10;
2619
+ var DEFAULT_FIRST7 = 10;
1727
2620
  var BATCH_FIRST3 = 100;
1728
2621
  var PRODUCT_FIELDS = `
1729
2622
  id
@@ -1801,7 +2694,7 @@ var GQL_GET_ALL_PRODUCT_SLUGS = `
1801
2694
  `;
1802
2695
  function createProductsQueries2(fetcher) {
1803
2696
  const { gqlFetch, gqlFetchGraceful } = fetcher;
1804
- async function getProducts(first = DEFAULT_FIRST6, after, filter) {
2697
+ async function getProducts(first = DEFAULT_FIRST7, after, filter) {
1805
2698
  const where = {};
1806
2699
  if (filter?.search) where["search"] = filter.search;
1807
2700
  if (filter?.onSale !== void 0) where["onSale"] = filter.onSale;
@@ -1837,11 +2730,11 @@ function createProductsQueries2(fetcher) {
1837
2730
  );
1838
2731
  return data.product;
1839
2732
  }
1840
- async function getFeaturedProducts(first = DEFAULT_FIRST6) {
2733
+ async function getFeaturedProducts(first = DEFAULT_FIRST7) {
1841
2734
  const connection = await getProducts(first, void 0, { featured: true });
1842
2735
  return connection.nodes;
1843
2736
  }
1844
- async function getOnSaleProducts(first = DEFAULT_FIRST6) {
2737
+ async function getOnSaleProducts(first = DEFAULT_FIRST7) {
1845
2738
  const connection = await getProducts(first, void 0, { onSale: true });
1846
2739
  return connection.nodes;
1847
2740
  }
@@ -1873,7 +2766,7 @@ function createProductsQueries2(fetcher) {
1873
2766
  }
1874
2767
 
1875
2768
  // src/integrations/wpGraphQL/woocommerce/orders/queries.ts
1876
- var DEFAULT_FIRST7 = 10;
2769
+ var DEFAULT_FIRST8 = 10;
1877
2770
  var ADDRESS_FIELDS = `
1878
2771
  firstName lastName address1 address2 city postcode country email phone
1879
2772
  `;
@@ -1926,7 +2819,7 @@ function createOrdersQueries2(fetcher) {
1926
2819
  );
1927
2820
  return data.order;
1928
2821
  }
1929
- async function getMyOrders(first = DEFAULT_FIRST7, after) {
2822
+ async function getMyOrders(first = DEFAULT_FIRST8, after) {
1930
2823
  const data = await gqlFetchGraceful(
1931
2824
  GQL_GET_MY_ORDERS,
1932
2825
  { orders: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
@@ -1985,18 +2878,211 @@ function createCustomersQueries2(fetcher) {
1985
2878
  return { getCustomer, getCustomerById };
1986
2879
  }
1987
2880
 
2881
+ // src/integrations/wpGraphQL/woocommerce/categories/queries.ts
2882
+ var DEFAULT_FIRST9 = 100;
2883
+ var CATEGORY_FIELDS2 = `
2884
+ id
2885
+ databaseId
2886
+ name
2887
+ slug
2888
+ description
2889
+ count
2890
+ parent { node { id databaseId name slug } }
2891
+ image { sourceUrl altText }
2892
+ `;
2893
+ var GQL_GET_PRODUCT_CATEGORIES = `
2894
+ query GetProductCategories($first: Int, $after: String) {
2895
+ productCategories(first: $first, after: $after) {
2896
+ nodes { ${CATEGORY_FIELDS2} }
2897
+ pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
2898
+ }
2899
+ }
2900
+ `;
2901
+ var GQL_GET_PRODUCT_CATEGORY_BY_SLUG = `
2902
+ query GetProductCategoryBySlug($id: ID!) {
2903
+ productCategory(id: $id, idType: SLUG) { ${CATEGORY_FIELDS2} }
2904
+ }
2905
+ `;
2906
+ var GQL_GET_PRODUCT_CATEGORY_BY_ID = `
2907
+ query GetProductCategoryById($id: ID!) {
2908
+ productCategory(id: $id, idType: DATABASE_ID) { ${CATEGORY_FIELDS2} }
2909
+ }
2910
+ `;
2911
+ function createCategoriesQueries4(fetcher) {
2912
+ const { gqlFetchGraceful } = fetcher;
2913
+ async function getProductCategories(first = DEFAULT_FIRST9, after) {
2914
+ const data = await gqlFetchGraceful(
2915
+ GQL_GET_PRODUCT_CATEGORIES,
2916
+ { productCategories: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
2917
+ { first, after },
2918
+ ["wpgraphql", "gql-product-categories"]
2919
+ );
2920
+ return data.productCategories;
2921
+ }
2922
+ async function getProductCategoryBySlug(slug) {
2923
+ const data = await gqlFetchGraceful(
2924
+ GQL_GET_PRODUCT_CATEGORY_BY_SLUG,
2925
+ { productCategory: null },
2926
+ { id: slug },
2927
+ ["wpgraphql", "gql-product-categories", `gql-product-category-${slug}`]
2928
+ );
2929
+ return data.productCategory;
2930
+ }
2931
+ async function getProductCategoryById(id) {
2932
+ const data = await gqlFetchGraceful(
2933
+ GQL_GET_PRODUCT_CATEGORY_BY_ID,
2934
+ { productCategory: null },
2935
+ { id: String(id) },
2936
+ ["wpgraphql", "gql-product-categories", `gql-product-category-${id}`]
2937
+ );
2938
+ return data.productCategory;
2939
+ }
2940
+ return { getProductCategories, getProductCategoryBySlug, getProductCategoryById };
2941
+ }
2942
+
2943
+ // src/integrations/wpGraphQL/woocommerce/tags/queries.ts
2944
+ var DEFAULT_FIRST10 = 100;
2945
+ var TAG_FIELDS2 = `
2946
+ id
2947
+ databaseId
2948
+ name
2949
+ slug
2950
+ description
2951
+ count
2952
+ `;
2953
+ var GQL_GET_PRODUCT_TAGS = `
2954
+ query GetProductTags($first: Int, $after: String) {
2955
+ productTags(first: $first, after: $after) {
2956
+ nodes { ${TAG_FIELDS2} }
2957
+ pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
2958
+ }
2959
+ }
2960
+ `;
2961
+ var GQL_GET_PRODUCT_TAG_BY_SLUG = `
2962
+ query GetProductTagBySlug($id: ID!) {
2963
+ productTag(id: $id, idType: SLUG) { ${TAG_FIELDS2} }
2964
+ }
2965
+ `;
2966
+ var GQL_GET_PRODUCT_TAG_BY_ID = `
2967
+ query GetProductTagById($id: ID!) {
2968
+ productTag(id: $id, idType: DATABASE_ID) { ${TAG_FIELDS2} }
2969
+ }
2970
+ `;
2971
+ function createTagsQueries4(fetcher) {
2972
+ const { gqlFetchGraceful } = fetcher;
2973
+ async function getProductTags(first = DEFAULT_FIRST10, after) {
2974
+ const data = await gqlFetchGraceful(
2975
+ GQL_GET_PRODUCT_TAGS,
2976
+ { productTags: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
2977
+ { first, after },
2978
+ ["wpgraphql", "gql-product-tags"]
2979
+ );
2980
+ return data.productTags;
2981
+ }
2982
+ async function getProductTagBySlug(slug) {
2983
+ const data = await gqlFetchGraceful(
2984
+ GQL_GET_PRODUCT_TAG_BY_SLUG,
2985
+ { productTag: null },
2986
+ { id: slug },
2987
+ ["wpgraphql", "gql-product-tags", `gql-product-tag-${slug}`]
2988
+ );
2989
+ return data.productTag;
2990
+ }
2991
+ async function getProductTagById(id) {
2992
+ const data = await gqlFetchGraceful(
2993
+ GQL_GET_PRODUCT_TAG_BY_ID,
2994
+ { productTag: null },
2995
+ { id: String(id) },
2996
+ ["wpgraphql", "gql-product-tags", `gql-product-tag-${id}`]
2997
+ );
2998
+ return data.productTag;
2999
+ }
3000
+ return { getProductTags, getProductTagBySlug, getProductTagById };
3001
+ }
3002
+
3003
+ // src/integrations/wpGraphQL/woocommerce/coupons/queries.ts
3004
+ var DEFAULT_FIRST11 = 100;
3005
+ var COUPON_FIELDS = `
3006
+ id
3007
+ databaseId
3008
+ code
3009
+ discountType
3010
+ amount
3011
+ dateExpiry
3012
+ usageCount
3013
+ usageLimit
3014
+ usageLimitPerUser
3015
+ individualUse
3016
+ freeShipping
3017
+ minimumAmount
3018
+ maximumAmount
3019
+ description
3020
+ `;
3021
+ var GQL_GET_COUPONS = `
3022
+ query GetCoupons($first: Int, $after: String) {
3023
+ coupons(first: $first, after: $after) {
3024
+ nodes { ${COUPON_FIELDS} }
3025
+ pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
3026
+ }
3027
+ }
3028
+ `;
3029
+ var GQL_GET_COUPON_BY_CODE = `
3030
+ query GetCouponByCode($id: ID!) {
3031
+ coupon(id: $id, idType: CODE) { ${COUPON_FIELDS} }
3032
+ }
3033
+ `;
3034
+ var GQL_GET_COUPON_BY_ID = `
3035
+ query GetCouponById($id: ID!) {
3036
+ coupon(id: $id, idType: DATABASE_ID) { ${COUPON_FIELDS} }
3037
+ }
3038
+ `;
3039
+ function createCouponsQueries2(fetcher) {
3040
+ const { gqlFetchGraceful } = fetcher;
3041
+ async function getCoupons(first = DEFAULT_FIRST11, after) {
3042
+ const data = await gqlFetchGraceful(
3043
+ GQL_GET_COUPONS,
3044
+ { coupons: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
3045
+ { first, after },
3046
+ ["wpgraphql", "gql-coupons"]
3047
+ );
3048
+ return data.coupons;
3049
+ }
3050
+ async function getCouponByCode(code) {
3051
+ const data = await gqlFetchGraceful(
3052
+ GQL_GET_COUPON_BY_CODE,
3053
+ { coupon: null },
3054
+ { id: code },
3055
+ ["wpgraphql", "gql-coupons", `gql-coupon-${code}`]
3056
+ );
3057
+ return data.coupon;
3058
+ }
3059
+ async function getCouponById(id) {
3060
+ const data = await gqlFetchGraceful(
3061
+ GQL_GET_COUPON_BY_ID,
3062
+ { coupon: null },
3063
+ { id: String(id) },
3064
+ ["wpgraphql", "gql-coupons", `gql-coupon-${id}`]
3065
+ );
3066
+ return data.coupon;
3067
+ }
3068
+ return { getCoupons, getCouponByCode, getCouponById };
3069
+ }
3070
+
1988
3071
  // src/integrations/wpGraphQL/woocommerce/index.ts
1989
3072
  function createWPGraphQLWooCommerceClient(config) {
1990
3073
  const fetcher = createWPGraphQLFetcher(config);
1991
3074
  return {
1992
3075
  ...createProductsQueries2(fetcher),
1993
3076
  ...createOrdersQueries2(fetcher),
1994
- ...createCustomersQueries2(fetcher)
3077
+ ...createCustomersQueries2(fetcher),
3078
+ ...createCategoriesQueries4(fetcher),
3079
+ ...createTagsQueries4(fetcher),
3080
+ ...createCouponsQueries2(fetcher)
1995
3081
  };
1996
3082
  }
1997
3083
 
1998
3084
  // src/integrations/wpGraphQL/cpt/queries.ts
1999
- var DEFAULT_FIRST8 = 10;
3085
+ var DEFAULT_FIRST12 = 10;
2000
3086
  var BATCH_FIRST4 = 100;
2001
3087
  var BASE_CPT_FIELDS = `
2002
3088
  id databaseId slug title date modified status uri
@@ -2025,7 +3111,7 @@ function createCPTQueries(fetcher, typeName, singularTypeName, extraFields) {
2025
3111
  }
2026
3112
  }
2027
3113
  `;
2028
- async function getItems(first = DEFAULT_FIRST8, after) {
3114
+ async function getItems(first = DEFAULT_FIRST12, after) {
2029
3115
  const data = await gqlFetchGraceful(
2030
3116
  GQL_GET_ITEMS,
2031
3117
  { [typeName]: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
@@ -2065,6 +3151,184 @@ function createCPTQueries(fetcher, typeName, singularTypeName, extraFields) {
2065
3151
  return { getItems, getItemBySlug, getAllSlugs };
2066
3152
  }
2067
3153
 
2068
- export { WPGraphQLError, buildACFFragment, buildPageWithACFQuery, buildPostWithACFQuery, buildPostsWithACFQuery, createCPTQueries, createWPGraphQLCoreClient as createWPGraphQLClient, createWPGraphQLCoreClient, createWPGraphQLFetcher, createWPGraphQLWooCommerceClient, createWooCommerceClient, createWooCommerceFetcher, createWordPressClient, createYoastQueries, extractOmnibusData, resolveBaseUrl, withOmnibus, withOmnibusVariation };
3154
+ // src/nextjs/revalidation.ts
3155
+ var ACTION_TAG_MAP = {
3156
+ save_post: ["wordpress", "posts"],
3157
+ save_post_post: ["wordpress", "posts"],
3158
+ save_post_page: ["wordpress", "pages"],
3159
+ delete_post: ["wordpress", "posts", "pages"],
3160
+ created_term: ["wordpress", "categories", "tags"],
3161
+ edited_term: ["wordpress", "categories", "tags"],
3162
+ delete_term: ["wordpress", "categories", "tags"],
3163
+ wp_update_nav_menu: ["wordpress", "menus"],
3164
+ woocommerce_product_updated: ["woocommerce", "products"],
3165
+ woocommerce_new_product: ["woocommerce", "products"],
3166
+ woocommerce_delete_product: ["woocommerce", "products"],
3167
+ woocommerce_new_order: ["woocommerce", "orders"],
3168
+ woocommerce_order_status_changed: ["woocommerce", "orders"],
3169
+ woocommerce_update_order: ["woocommerce", "orders"],
3170
+ woocommerce_product_category_updated: ["woocommerce", "categories"],
3171
+ woocommerce_product_tag_updated: ["woocommerce", "tags"]
3172
+ };
3173
+ function extractSecret(request) {
3174
+ const auth = request.headers.get("Authorization");
3175
+ if (auth?.startsWith("Bearer ")) return auth.slice(7);
3176
+ return new URL(request.url).searchParams.get("secret");
3177
+ }
3178
+ function createRevalidationHandler(config, revalidateTag) {
3179
+ return async function handler(request) {
3180
+ if (extractSecret(request) !== config.secret) {
3181
+ return Response.json({ revalidated: false, tags: [], message: "Unauthorized" }, { status: 401 });
3182
+ }
3183
+ let payload;
3184
+ try {
3185
+ payload = await request.json();
3186
+ } catch {
3187
+ return Response.json({ revalidated: false, tags: [], message: "Invalid JSON body" }, { status: 400 });
3188
+ }
3189
+ const { action } = payload;
3190
+ const matched = ACTION_TAG_MAP[action];
3191
+ if (!matched) {
3192
+ return Response.json(
3193
+ { revalidated: false, tags: [], message: `Unknown action: ${action}` },
3194
+ { status: 400 }
3195
+ );
3196
+ }
3197
+ const tags = [...new Set(matched)];
3198
+ for (const tag of tags) {
3199
+ revalidateTag(tag);
3200
+ }
3201
+ return Response.json({ revalidated: true, tags });
3202
+ };
3203
+ }
3204
+
3205
+ // src/nextjs/faust.ts
3206
+ function createFaustAuthHandler(config) {
3207
+ const cookieName = config.cookieName ?? "faustwp-rt";
3208
+ return async function handler(request, routePath) {
3209
+ if (routePath === "auth/token") {
3210
+ const url = new URL(request.url);
3211
+ const code = url.searchParams.get("code");
3212
+ const redirectUri = url.searchParams.get("redirect_uri") ?? "/";
3213
+ const refreshToken = parseCookie(request, cookieName);
3214
+ if (!code && !refreshToken) {
3215
+ return Response.json({ error: "Unauthorized" }, { status: 401 });
3216
+ }
3217
+ const wpRes = await fetch(`${config.wpUrl}/?rest_route=/faustwp/v1/authorize`, {
3218
+ method: "POST",
3219
+ headers: {
3220
+ "Content-Type": "application/json",
3221
+ "x-faustwp-secret": config.secretKey
3222
+ },
3223
+ body: JSON.stringify({ code, refreshToken })
3224
+ });
3225
+ if (!wpRes.ok) {
3226
+ const body = await wpRes.text();
3227
+ return new Response(body, { status: wpRes.status });
3228
+ }
3229
+ const data = await wpRes.json();
3230
+ return new Response(null, {
3231
+ status: 302,
3232
+ headers: {
3233
+ Location: new URL(redirectUri, request.url).toString(),
3234
+ "Set-Cookie": buildSetCookie(cookieName, data.refreshToken, 2592e3)
3235
+ }
3236
+ });
3237
+ }
3238
+ if (routePath === "auth/logout") {
3239
+ return new Response(JSON.stringify({}), {
3240
+ status: 200,
3241
+ headers: {
3242
+ "Content-Type": "application/json",
3243
+ "Set-Cookie": `${cookieName}=; Max-Age=0; Path=/; HttpOnly`
3244
+ }
3245
+ });
3246
+ }
3247
+ return Response.json({ error: "Not Found" }, { status: 404 });
3248
+ };
3249
+ }
3250
+ function createPreviewHandler(config, deps) {
3251
+ const previewPath = config.previewPath ?? "posts";
3252
+ return async function handler(request) {
3253
+ const url = new URL(request.url);
3254
+ const postId = url.searchParams.get("postId");
3255
+ const previewPathname = url.searchParams.get("previewPathname");
3256
+ if (!postId) {
3257
+ return new Response("Missing postId", { status: 400 });
3258
+ }
3259
+ const slug = await resolvePreviewSlug(config, postId, previewPathname);
3260
+ if (!slug) {
3261
+ return new Response("Post not found", { status: 404 });
3262
+ }
3263
+ await deps.enableDraftMode();
3264
+ deps.redirect(`/${previewPath}/${slug}?postId=${postId}`);
3265
+ };
3266
+ }
3267
+ function parseCookie(request, name) {
3268
+ const header = request.headers.get("cookie") ?? "";
3269
+ const match = header.match(new RegExp(`(?:^|;\\s*)${name}=([^;]*)`));
3270
+ return match?.[1];
3271
+ }
3272
+ function buildSetCookie(name, value, maxAge) {
3273
+ const secure = process.env.NODE_ENV === "production" ? "; Secure" : "";
3274
+ return `${name}=${value}; HttpOnly; Path=/; SameSite=Strict; Max-Age=${maxAge}${secure}`;
3275
+ }
3276
+ async function resolvePreviewSlug(config, postId, previewPathname) {
3277
+ if (previewPathname && !previewPathname.includes("p=")) {
3278
+ const slug = previewPathname.replace(/\/$/, "").split("/").pop();
3279
+ if (slug) return slug;
3280
+ }
3281
+ const res = await fetch(`${config.wpUrl}/wp-json/wp/v2/posts/${postId}?_fields=slug`, {
3282
+ headers: { "x-faustwp-secret": config.secretKey },
3283
+ cache: "no-store"
3284
+ });
3285
+ if (!res.ok) return null;
3286
+ const data = await res.json();
3287
+ return data.slug ?? `preview-${postId}`;
3288
+ }
3289
+
3290
+ // src/auth/applicationPassword.ts
3291
+ function createApplicationPasswordToken(username, appPassword) {
3292
+ const encoded = Buffer.from(`${username}:${appPassword}`).toString("base64");
3293
+ return `Basic ${encoded}`;
3294
+ }
3295
+
3296
+ // src/auth/types.ts
3297
+ var AuthenticationError = class extends Error {
3298
+ constructor(message, status) {
3299
+ super(message);
3300
+ __publicField(this, "status", status);
3301
+ this.name = "AuthenticationError";
3302
+ }
3303
+ };
3304
+
3305
+ // src/auth/jwt.ts
3306
+ async function authenticateJwt(config, credentials) {
3307
+ const url = `${resolveBaseUrl(config)}/wp-json/jwt-auth/v1/token`;
3308
+ const response = await fetch(url, {
3309
+ method: "POST",
3310
+ headers: { "Content-Type": "application/json" },
3311
+ body: JSON.stringify(credentials),
3312
+ cache: "no-store"
3313
+ });
3314
+ if (!response.ok) {
3315
+ throw new AuthenticationError(
3316
+ `JWT authentication failed: ${response.statusText}`,
3317
+ response.status
3318
+ );
3319
+ }
3320
+ return response.json();
3321
+ }
3322
+ async function validateJwtToken(config, token) {
3323
+ const url = `${resolveBaseUrl(config)}/wp-json/jwt-auth/v1/token/validate`;
3324
+ const response = await fetch(url, {
3325
+ method: "POST",
3326
+ headers: { Authorization: `Bearer ${token}` },
3327
+ cache: "no-store"
3328
+ });
3329
+ return response.ok;
3330
+ }
3331
+
3332
+ export { AuthenticationError, WPGraphQLError, authenticateJwt, buildACFFragment, buildPageWithACFQuery, buildPostWithACFQuery, buildPostsWithACFQuery, createApplicationPasswordToken, createAuthorsMutations, createCF7Queries, createCPTQueries, createCategoriesMutations, createCommentsMutations, createFaustAuthHandler, createMediaMutations, createMenusMutations, createPagesMutations, createPostsMutations, createPreviewHandler, createRevalidationHandler, createTagsMutations, createWPGraphQLCoreClient as createWPGraphQLClient, createWPGraphQLCoreClient, createWPGraphQLFetcher, createWPGraphQLMutationsClient, createWPGraphQLWooCommerceClient, createWooCommerceClient, createWooCommerceFetcher, createWordPressClient, createWordPressMutationsClient, createYoastQueries, extractOmnibusData, resolveBaseUrl, validateJwtToken, withOmnibus, withOmnibusVariation };
2069
3333
  //# sourceMappingURL=index.js.map
2070
3334
  //# sourceMappingURL=index.js.map