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