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