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