@szymonpiatek/nextwordpress 0.0.10 → 0.0.11
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/client/index.cjs +1372 -0
- package/dist/client/index.cjs.map +1 -0
- package/dist/client/index.d.cts +4 -0
- package/dist/client/index.d.ts +4 -0
- package/dist/client/index.js +1348 -0
- package/dist/client/index.js.map +1 -0
- package/dist/server/index.cjs +4274 -0
- package/dist/server/index.cjs.map +1 -0
- package/dist/server/index.d.cts +2 -0
- package/dist/server/index.d.ts +2 -0
- package/dist/server/index.js +4231 -0
- package/dist/server/index.js.map +1 -0
- package/package.json +11 -1
|
@@ -0,0 +1,4274 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
5
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
6
|
+
|
|
7
|
+
// src/shared/url.ts
|
|
8
|
+
function resolveBaseUrl(config) {
|
|
9
|
+
return typeof window === "undefined" ? config.serverURL : config.clientURL;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// src/shared/errors/codes.ts
|
|
13
|
+
var ErrorCode = {
|
|
14
|
+
// WordPress REST API
|
|
15
|
+
WP_REQUEST_FAILED: "WP_REQUEST_FAILED",
|
|
16
|
+
WP_NOT_FOUND: "WP_NOT_FOUND",
|
|
17
|
+
WP_UNAUTHORIZED: "WP_UNAUTHORIZED",
|
|
18
|
+
WP_FORBIDDEN: "WP_FORBIDDEN",
|
|
19
|
+
// WPGraphQL
|
|
20
|
+
GQL_REQUEST_FAILED: "GQL_REQUEST_FAILED",
|
|
21
|
+
GQL_NO_DATA: "GQL_NO_DATA",
|
|
22
|
+
GQL_ERRORS_IN_RESPONSE: "GQL_ERRORS_IN_RESPONSE",
|
|
23
|
+
// WooCommerce — generic
|
|
24
|
+
WOO_REQUEST_FAILED: "WOO_REQUEST_FAILED",
|
|
25
|
+
WOO_NOT_FOUND: "WOO_NOT_FOUND",
|
|
26
|
+
WOO_UNAUTHORIZED: "WOO_UNAUTHORIZED",
|
|
27
|
+
WOO_FORBIDDEN: "WOO_FORBIDDEN",
|
|
28
|
+
// WooCommerce — resource-specific
|
|
29
|
+
WOO_COUPON_NOT_FOUND: "WOO_COUPON_NOT_FOUND",
|
|
30
|
+
WOO_PRODUCT_NOT_FOUND: "WOO_PRODUCT_NOT_FOUND",
|
|
31
|
+
WOO_ORDER_NOT_FOUND: "WOO_ORDER_NOT_FOUND",
|
|
32
|
+
WOO_CUSTOMER_NOT_FOUND: "WOO_CUSTOMER_NOT_FOUND",
|
|
33
|
+
WOO_CATEGORY_NOT_FOUND: "WOO_CATEGORY_NOT_FOUND",
|
|
34
|
+
WOO_TAG_NOT_FOUND: "WOO_TAG_NOT_FOUND",
|
|
35
|
+
WOO_REVIEW_NOT_FOUND: "WOO_REVIEW_NOT_FOUND",
|
|
36
|
+
WOO_WEBHOOK_NOT_FOUND: "WOO_WEBHOOK_NOT_FOUND",
|
|
37
|
+
WOO_SHIPPING_ZONE_NOT_FOUND: "WOO_SHIPPING_ZONE_NOT_FOUND",
|
|
38
|
+
// Auth
|
|
39
|
+
AUTH_JWT_FAILED: "AUTH_JWT_FAILED",
|
|
40
|
+
AUTH_CREDENTIALS_INVALID: "AUTH_CREDENTIALS_INVALID",
|
|
41
|
+
AUTH_TOKEN_INVALID: "AUTH_TOKEN_INVALID"
|
|
42
|
+
};
|
|
43
|
+
var defaultMessages = {
|
|
44
|
+
WP_REQUEST_FAILED: "WordPress API request failed",
|
|
45
|
+
WP_NOT_FOUND: "WordPress resource not found",
|
|
46
|
+
WP_UNAUTHORIZED: "WordPress authentication required",
|
|
47
|
+
WP_FORBIDDEN: "WordPress access denied",
|
|
48
|
+
GQL_REQUEST_FAILED: "WPGraphQL request failed",
|
|
49
|
+
GQL_NO_DATA: "No data returned from WPGraphQL",
|
|
50
|
+
GQL_ERRORS_IN_RESPONSE: "WPGraphQL returned errors",
|
|
51
|
+
WOO_REQUEST_FAILED: "WooCommerce API request failed",
|
|
52
|
+
WOO_NOT_FOUND: "WooCommerce resource not found",
|
|
53
|
+
WOO_UNAUTHORIZED: "WooCommerce authentication required",
|
|
54
|
+
WOO_FORBIDDEN: "WooCommerce access denied",
|
|
55
|
+
WOO_COUPON_NOT_FOUND: "Coupon not found",
|
|
56
|
+
WOO_PRODUCT_NOT_FOUND: "Product not found",
|
|
57
|
+
WOO_ORDER_NOT_FOUND: "Order not found",
|
|
58
|
+
WOO_CUSTOMER_NOT_FOUND: "Customer not found",
|
|
59
|
+
WOO_CATEGORY_NOT_FOUND: "Category not found",
|
|
60
|
+
WOO_TAG_NOT_FOUND: "Tag not found",
|
|
61
|
+
WOO_REVIEW_NOT_FOUND: "Product review not found",
|
|
62
|
+
WOO_WEBHOOK_NOT_FOUND: "Webhook not found",
|
|
63
|
+
WOO_SHIPPING_ZONE_NOT_FOUND: "Shipping zone not found",
|
|
64
|
+
AUTH_JWT_FAILED: "JWT authentication failed",
|
|
65
|
+
AUTH_CREDENTIALS_INVALID: "Invalid credentials",
|
|
66
|
+
AUTH_TOKEN_INVALID: "JWT token is invalid or expired"
|
|
67
|
+
};
|
|
68
|
+
var defaultMessagesPl = {
|
|
69
|
+
WP_REQUEST_FAILED: "B\u0142\u0105d \u017C\u0105dania do WordPress API",
|
|
70
|
+
WP_NOT_FOUND: "Zas\xF3b WordPress nie istnieje",
|
|
71
|
+
WP_UNAUTHORIZED: "Wymagane uwierzytelnienie WordPress",
|
|
72
|
+
WP_FORBIDDEN: "Brak dost\u0119pu do zasobu WordPress",
|
|
73
|
+
GQL_REQUEST_FAILED: "B\u0142\u0105d \u017C\u0105dania WPGraphQL",
|
|
74
|
+
GQL_NO_DATA: "WPGraphQL nie zwr\xF3ci\u0142o danych",
|
|
75
|
+
GQL_ERRORS_IN_RESPONSE: "WPGraphQL zwr\xF3ci\u0142o b\u0142\u0119dy",
|
|
76
|
+
WOO_REQUEST_FAILED: "B\u0142\u0105d \u017C\u0105dania do WooCommerce API",
|
|
77
|
+
WOO_NOT_FOUND: "Zas\xF3b WooCommerce nie istnieje",
|
|
78
|
+
WOO_UNAUTHORIZED: "Wymagane uwierzytelnienie WooCommerce",
|
|
79
|
+
WOO_FORBIDDEN: "Brak dost\u0119pu do zasobu WooCommerce",
|
|
80
|
+
WOO_COUPON_NOT_FOUND: "Kupon nie istnieje",
|
|
81
|
+
WOO_PRODUCT_NOT_FOUND: "Produkt nie istnieje",
|
|
82
|
+
WOO_ORDER_NOT_FOUND: "Zam\xF3wienie nie istnieje",
|
|
83
|
+
WOO_CUSTOMER_NOT_FOUND: "Klient nie istnieje",
|
|
84
|
+
WOO_CATEGORY_NOT_FOUND: "Kategoria produkt\xF3w nie istnieje",
|
|
85
|
+
WOO_TAG_NOT_FOUND: "Tag produkt\xF3w nie istnieje",
|
|
86
|
+
WOO_REVIEW_NOT_FOUND: "Opinia o produkcie nie istnieje",
|
|
87
|
+
WOO_WEBHOOK_NOT_FOUND: "Webhook nie istnieje",
|
|
88
|
+
WOO_SHIPPING_ZONE_NOT_FOUND: "Strefa wysy\u0142ki nie istnieje",
|
|
89
|
+
AUTH_JWT_FAILED: "B\u0142\u0105d uwierzytelnienia JWT",
|
|
90
|
+
AUTH_CREDENTIALS_INVALID: "Nieprawid\u0142owe dane logowania",
|
|
91
|
+
AUTH_TOKEN_INVALID: "Token JWT jest nieprawid\u0142owy lub wygas\u0142"
|
|
92
|
+
};
|
|
93
|
+
function resolveMessage(code, overrides) {
|
|
94
|
+
return overrides?.[code] ?? defaultMessages[code];
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// src/integrations/restApi/core/client/types.ts
|
|
98
|
+
var WordPressAPIError = class extends Error {
|
|
99
|
+
constructor(code, status, endpoint, message, detail) {
|
|
100
|
+
super(detail ? `${message}: ${detail}` : message);
|
|
101
|
+
__publicField(this, "code", code);
|
|
102
|
+
__publicField(this, "status", status);
|
|
103
|
+
__publicField(this, "endpoint", endpoint);
|
|
104
|
+
this.name = "WordPressAPIError";
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
// src/integrations/restApi/core/client/url.ts
|
|
109
|
+
function buildUrl(config, path, query) {
|
|
110
|
+
const base = resolveBaseUrl(config);
|
|
111
|
+
if (!query) return `${base}${path}`;
|
|
112
|
+
const params = new URLSearchParams();
|
|
113
|
+
for (const [key, value] of Object.entries(query)) {
|
|
114
|
+
if (value !== void 0 && value !== null) {
|
|
115
|
+
params.set(key, String(value));
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
const qs = params.toString();
|
|
119
|
+
return qs ? `${base}${path}?${qs}` : `${base}${path}`;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// src/integrations/restApi/core/client/fetcher.ts
|
|
123
|
+
var USER_AGENT = "NextWordpress Client";
|
|
124
|
+
function resolveWpErrorCode(status) {
|
|
125
|
+
if (status === 401) return ErrorCode.WP_UNAUTHORIZED;
|
|
126
|
+
if (status === 403) return ErrorCode.WP_FORBIDDEN;
|
|
127
|
+
if (status === 404) return ErrorCode.WP_NOT_FOUND;
|
|
128
|
+
return ErrorCode.WP_REQUEST_FAILED;
|
|
129
|
+
}
|
|
130
|
+
function createFetcher(config) {
|
|
131
|
+
const cacheTtl = config.cacheTTL ?? 300;
|
|
132
|
+
async function doFetch(url, init = {}) {
|
|
133
|
+
const response = await fetch(url, init);
|
|
134
|
+
if (!response.ok) {
|
|
135
|
+
const code = resolveWpErrorCode(response.status);
|
|
136
|
+
throw new WordPressAPIError(
|
|
137
|
+
code,
|
|
138
|
+
response.status,
|
|
139
|
+
url,
|
|
140
|
+
resolveMessage(code, config.errorMessages),
|
|
141
|
+
response.statusText
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
return response;
|
|
145
|
+
}
|
|
146
|
+
async function wpFetch(path, query, tags = ["wordpress"]) {
|
|
147
|
+
const url = buildUrl(config, path, query);
|
|
148
|
+
const res = await doFetch(url, {
|
|
149
|
+
headers: { "User-Agent": USER_AGENT },
|
|
150
|
+
next: { tags, revalidate: cacheTtl }
|
|
151
|
+
});
|
|
152
|
+
return await res.json();
|
|
153
|
+
}
|
|
154
|
+
async function wpFetchGraceful(path, fallback, query, tags = ["wordpress"]) {
|
|
155
|
+
try {
|
|
156
|
+
return await wpFetch(path, query, tags);
|
|
157
|
+
} catch {
|
|
158
|
+
console.warn(`WordPress fetch failed for ${path}`);
|
|
159
|
+
return fallback;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
async function wpFetchPaginated(path, query, tags = ["wordpress"]) {
|
|
163
|
+
const url = buildUrl(config, path, query);
|
|
164
|
+
const res = await doFetch(url, {
|
|
165
|
+
headers: { "User-Agent": USER_AGENT },
|
|
166
|
+
next: { tags, revalidate: cacheTtl }
|
|
167
|
+
});
|
|
168
|
+
return {
|
|
169
|
+
data: await res.json(),
|
|
170
|
+
headers: {
|
|
171
|
+
total: parseInt(res.headers.get("X-WP-Total") ?? "0", 10),
|
|
172
|
+
totalPages: parseInt(res.headers.get("X-WP-TotalPages") ?? "0", 10)
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
async function wpFetchPaginatedGraceful(path, query, tags = ["wordpress"]) {
|
|
177
|
+
const empty = { data: [], headers: { total: 0, totalPages: 0 } };
|
|
178
|
+
try {
|
|
179
|
+
return await wpFetchPaginated(path, query, tags);
|
|
180
|
+
} catch {
|
|
181
|
+
console.warn(`WordPress paginated fetch failed for ${path}`);
|
|
182
|
+
return empty;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
async function wpMutate(path, body, method = "POST", authToken) {
|
|
186
|
+
const url = buildUrl(config, path);
|
|
187
|
+
const headers = {
|
|
188
|
+
"Content-Type": "application/json",
|
|
189
|
+
"User-Agent": USER_AGENT
|
|
190
|
+
};
|
|
191
|
+
if (authToken) {
|
|
192
|
+
headers["Authorization"] = authToken.startsWith("Basic ") || authToken.startsWith("Bearer ") ? authToken : `Bearer ${authToken}`;
|
|
193
|
+
}
|
|
194
|
+
const res = await doFetch(url, {
|
|
195
|
+
method,
|
|
196
|
+
headers,
|
|
197
|
+
body: JSON.stringify(body),
|
|
198
|
+
cache: "no-store"
|
|
199
|
+
});
|
|
200
|
+
return await res.json();
|
|
201
|
+
}
|
|
202
|
+
async function wpUpload(path, file, filename, mimeType, authToken) {
|
|
203
|
+
const url = buildUrl(config, path);
|
|
204
|
+
const res = await doFetch(url, {
|
|
205
|
+
method: "POST",
|
|
206
|
+
headers: {
|
|
207
|
+
"Content-Disposition": `attachment; filename="${filename}"`,
|
|
208
|
+
"Content-Type": mimeType,
|
|
209
|
+
"User-Agent": USER_AGENT,
|
|
210
|
+
"Authorization": authToken.startsWith("Basic ") || authToken.startsWith("Bearer ") ? authToken : `Bearer ${authToken}`
|
|
211
|
+
},
|
|
212
|
+
body: file,
|
|
213
|
+
cache: "no-store"
|
|
214
|
+
});
|
|
215
|
+
return await res.json();
|
|
216
|
+
}
|
|
217
|
+
return { wpFetch, wpFetchGraceful, wpFetchPaginated, wpFetchPaginatedGraceful, wpMutate, wpUpload };
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// src/integrations/restApi/core/contactForm7/queries.ts
|
|
221
|
+
function createCF7Queries(config) {
|
|
222
|
+
async function submitForm(formId, data) {
|
|
223
|
+
const url = buildUrl(config, `/wp-json/contact-form-7/v1/contact-forms/${formId}/feedback`);
|
|
224
|
+
const body = new FormData();
|
|
225
|
+
for (const [key, value] of Object.entries(data)) {
|
|
226
|
+
body.append(key, value);
|
|
227
|
+
}
|
|
228
|
+
const res = await fetch(url, { method: "POST", body, cache: "no-store" });
|
|
229
|
+
return res.json();
|
|
230
|
+
}
|
|
231
|
+
return { submitForm };
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// src/integrations/restApi/core/mutations/posts/mutations.ts
|
|
235
|
+
function createPostsMutations(fetcher) {
|
|
236
|
+
const { wpMutate } = fetcher;
|
|
237
|
+
async function createPost(input, authToken) {
|
|
238
|
+
return wpMutate("/wp-json/wp/v2/posts", input, "POST", authToken);
|
|
239
|
+
}
|
|
240
|
+
async function updatePost(id, input, authToken) {
|
|
241
|
+
return wpMutate(`/wp-json/wp/v2/posts/${id}`, input, "PATCH", authToken);
|
|
242
|
+
}
|
|
243
|
+
async function deletePost(id, authToken, force = false) {
|
|
244
|
+
return wpMutate(
|
|
245
|
+
`/wp-json/wp/v2/posts/${id}`,
|
|
246
|
+
{ force },
|
|
247
|
+
"DELETE",
|
|
248
|
+
authToken
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
return { createPost, updatePost, deletePost };
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// src/integrations/restApi/core/mutations/comments/mutations.ts
|
|
255
|
+
function createCommentsMutations(fetcher) {
|
|
256
|
+
const { wpMutate } = fetcher;
|
|
257
|
+
async function createComment(input, authToken) {
|
|
258
|
+
return wpMutate("/wp-json/wp/v2/comments", input, "POST", authToken);
|
|
259
|
+
}
|
|
260
|
+
async function updateComment(id, input, authToken) {
|
|
261
|
+
return wpMutate(`/wp-json/wp/v2/comments/${id}`, input, "PATCH", authToken);
|
|
262
|
+
}
|
|
263
|
+
async function deleteComment(id, authToken, force = false) {
|
|
264
|
+
return wpMutate(
|
|
265
|
+
`/wp-json/wp/v2/comments/${id}`,
|
|
266
|
+
{ force },
|
|
267
|
+
"DELETE",
|
|
268
|
+
authToken
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
return { createComment, updateComment, deleteComment };
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// src/integrations/restApi/core/mutations/pages/mutations.ts
|
|
275
|
+
function createPagesMutations(fetcher) {
|
|
276
|
+
const { wpMutate } = fetcher;
|
|
277
|
+
async function createPage(input, authToken) {
|
|
278
|
+
return wpMutate("/wp-json/wp/v2/pages", input, "POST", authToken);
|
|
279
|
+
}
|
|
280
|
+
async function updatePage(id, input, authToken) {
|
|
281
|
+
return wpMutate(`/wp-json/wp/v2/pages/${id}`, input, "PATCH", authToken);
|
|
282
|
+
}
|
|
283
|
+
async function deletePage(id, authToken, force = false) {
|
|
284
|
+
return wpMutate(
|
|
285
|
+
`/wp-json/wp/v2/pages/${id}`,
|
|
286
|
+
{ force },
|
|
287
|
+
"DELETE",
|
|
288
|
+
authToken
|
|
289
|
+
);
|
|
290
|
+
}
|
|
291
|
+
return { createPage, updatePage, deletePage };
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// src/integrations/restApi/core/mutations/categories/mutations.ts
|
|
295
|
+
function createCategoriesMutations(fetcher) {
|
|
296
|
+
const { wpMutate } = fetcher;
|
|
297
|
+
async function createCategory(input, authToken) {
|
|
298
|
+
return wpMutate("/wp-json/wp/v2/categories", input, "POST", authToken);
|
|
299
|
+
}
|
|
300
|
+
async function updateCategory(id, input, authToken) {
|
|
301
|
+
return wpMutate(`/wp-json/wp/v2/categories/${id}`, input, "PATCH", authToken);
|
|
302
|
+
}
|
|
303
|
+
async function deleteCategory(id, authToken, force = false) {
|
|
304
|
+
return wpMutate(
|
|
305
|
+
`/wp-json/wp/v2/categories/${id}`,
|
|
306
|
+
{ force },
|
|
307
|
+
"DELETE",
|
|
308
|
+
authToken
|
|
309
|
+
);
|
|
310
|
+
}
|
|
311
|
+
return { createCategory, updateCategory, deleteCategory };
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// src/integrations/restApi/core/mutations/tags/mutations.ts
|
|
315
|
+
function createTagsMutations(fetcher) {
|
|
316
|
+
const { wpMutate } = fetcher;
|
|
317
|
+
async function createTag(input, authToken) {
|
|
318
|
+
return wpMutate("/wp-json/wp/v2/tags", input, "POST", authToken);
|
|
319
|
+
}
|
|
320
|
+
async function updateTag(id, input, authToken) {
|
|
321
|
+
return wpMutate(`/wp-json/wp/v2/tags/${id}`, input, "PATCH", authToken);
|
|
322
|
+
}
|
|
323
|
+
async function deleteTag(id, authToken, force = false) {
|
|
324
|
+
return wpMutate(
|
|
325
|
+
`/wp-json/wp/v2/tags/${id}`,
|
|
326
|
+
{ force },
|
|
327
|
+
"DELETE",
|
|
328
|
+
authToken
|
|
329
|
+
);
|
|
330
|
+
}
|
|
331
|
+
return { createTag, updateTag, deleteTag };
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
// src/integrations/restApi/core/mutations/authors/mutations.ts
|
|
335
|
+
function createAuthorsMutations(fetcher) {
|
|
336
|
+
const { wpMutate } = fetcher;
|
|
337
|
+
async function createAuthor(input, authToken) {
|
|
338
|
+
return wpMutate("/wp-json/wp/v2/users", input, "POST", authToken);
|
|
339
|
+
}
|
|
340
|
+
async function updateAuthor(id, input, authToken) {
|
|
341
|
+
return wpMutate(`/wp-json/wp/v2/users/${id}`, input, "PATCH", authToken);
|
|
342
|
+
}
|
|
343
|
+
async function deleteAuthor(id, authToken, reassign) {
|
|
344
|
+
return wpMutate(
|
|
345
|
+
`/wp-json/wp/v2/users/${id}`,
|
|
346
|
+
{ force: true, reassign },
|
|
347
|
+
"DELETE",
|
|
348
|
+
authToken
|
|
349
|
+
);
|
|
350
|
+
}
|
|
351
|
+
return { createAuthor, updateAuthor, deleteAuthor };
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
// src/integrations/restApi/core/mutations/menus/mutations.ts
|
|
355
|
+
function createMenusMutations(fetcher) {
|
|
356
|
+
const { wpMutate } = fetcher;
|
|
357
|
+
async function createMenu(input, authToken) {
|
|
358
|
+
return wpMutate("/wp-json/wp/v2/menus", input, "POST", authToken);
|
|
359
|
+
}
|
|
360
|
+
async function updateMenu(id, input, authToken) {
|
|
361
|
+
return wpMutate(`/wp-json/wp/v2/menus/${id}`, input, "PATCH", authToken);
|
|
362
|
+
}
|
|
363
|
+
async function deleteMenu(id, authToken) {
|
|
364
|
+
return wpMutate(
|
|
365
|
+
`/wp-json/wp/v2/menus/${id}`,
|
|
366
|
+
{},
|
|
367
|
+
"DELETE",
|
|
368
|
+
authToken
|
|
369
|
+
);
|
|
370
|
+
}
|
|
371
|
+
async function createMenuItem(input, authToken) {
|
|
372
|
+
return wpMutate("/wp-json/wp/v2/menu-items", input, "POST", authToken);
|
|
373
|
+
}
|
|
374
|
+
async function updateMenuItem(id, input, authToken) {
|
|
375
|
+
return wpMutate(`/wp-json/wp/v2/menu-items/${id}`, input, "PATCH", authToken);
|
|
376
|
+
}
|
|
377
|
+
async function deleteMenuItem(id, authToken, force = false) {
|
|
378
|
+
return wpMutate(
|
|
379
|
+
`/wp-json/wp/v2/menu-items/${id}`,
|
|
380
|
+
{ force },
|
|
381
|
+
"DELETE",
|
|
382
|
+
authToken
|
|
383
|
+
);
|
|
384
|
+
}
|
|
385
|
+
return { createMenu, updateMenu, deleteMenu, createMenuItem, updateMenuItem, deleteMenuItem };
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
// src/integrations/restApi/core/mutations/media/mutations.ts
|
|
389
|
+
function createMediaMutations(fetcher) {
|
|
390
|
+
const { wpMutate, wpUpload } = fetcher;
|
|
391
|
+
async function uploadMedia(input, authToken) {
|
|
392
|
+
const media = await wpUpload(
|
|
393
|
+
"/wp-json/wp/v2/media",
|
|
394
|
+
input.file,
|
|
395
|
+
input.filename,
|
|
396
|
+
input.mimeType,
|
|
397
|
+
authToken
|
|
398
|
+
);
|
|
399
|
+
if (input.title || input.caption || input.alt_text) {
|
|
400
|
+
return wpMutate(
|
|
401
|
+
`/wp-json/wp/v2/media/${media.id}`,
|
|
402
|
+
{
|
|
403
|
+
...input.title && { title: input.title },
|
|
404
|
+
...input.caption && { caption: input.caption },
|
|
405
|
+
...input.alt_text && { alt_text: input.alt_text }
|
|
406
|
+
},
|
|
407
|
+
"PATCH",
|
|
408
|
+
authToken
|
|
409
|
+
);
|
|
410
|
+
}
|
|
411
|
+
return media;
|
|
412
|
+
}
|
|
413
|
+
async function updateMedia(id, input, authToken) {
|
|
414
|
+
return wpMutate(`/wp-json/wp/v2/media/${id}`, input, "PATCH", authToken);
|
|
415
|
+
}
|
|
416
|
+
async function deleteMedia(id, authToken, force = true) {
|
|
417
|
+
return wpMutate(
|
|
418
|
+
`/wp-json/wp/v2/media/${id}`,
|
|
419
|
+
{ force },
|
|
420
|
+
"DELETE",
|
|
421
|
+
authToken
|
|
422
|
+
);
|
|
423
|
+
}
|
|
424
|
+
return { uploadMedia, updateMedia, deleteMedia };
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
// src/integrations/restApi/core/mutations/index.ts
|
|
428
|
+
function createWordPressMutationsClient(config) {
|
|
429
|
+
const fetcher = createFetcher(config);
|
|
430
|
+
return {
|
|
431
|
+
...createPostsMutations(fetcher),
|
|
432
|
+
...createCommentsMutations(fetcher),
|
|
433
|
+
...createPagesMutations(fetcher),
|
|
434
|
+
...createCategoriesMutations(fetcher),
|
|
435
|
+
...createTagsMutations(fetcher),
|
|
436
|
+
...createAuthorsMutations(fetcher),
|
|
437
|
+
...createMenusMutations(fetcher),
|
|
438
|
+
...createMediaMutations(fetcher)
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
// src/integrations/restApi/core/posts/queries.ts
|
|
443
|
+
function createPostsQueries(fetcher) {
|
|
444
|
+
const { wpFetch, wpFetchGraceful, wpFetchPaginated, wpFetchPaginatedGraceful } = fetcher;
|
|
445
|
+
async function getPostsPaginated(page = 1, perPage = 9, filterParams) {
|
|
446
|
+
const query = { _embed: true, per_page: perPage, page };
|
|
447
|
+
const cacheTags = ["wordpress", "posts", `posts-page-${page}`];
|
|
448
|
+
if (filterParams?.search) {
|
|
449
|
+
query.search = filterParams.search;
|
|
450
|
+
cacheTags.push("posts-search");
|
|
451
|
+
}
|
|
452
|
+
if (filterParams?.author) {
|
|
453
|
+
query.author = filterParams.author;
|
|
454
|
+
cacheTags.push(`posts-author-${filterParams.author}`);
|
|
455
|
+
}
|
|
456
|
+
if (filterParams?.tag) {
|
|
457
|
+
query.tags = filterParams.tag;
|
|
458
|
+
cacheTags.push(`posts-tag-${filterParams.tag}`);
|
|
459
|
+
}
|
|
460
|
+
if (filterParams?.category) {
|
|
461
|
+
query.categories = filterParams.category;
|
|
462
|
+
cacheTags.push(`posts-category-${filterParams.category}`);
|
|
463
|
+
}
|
|
464
|
+
return wpFetchPaginatedGraceful("/wp-json/wp/v2/posts", query, cacheTags);
|
|
465
|
+
}
|
|
466
|
+
async function getRecentPosts(filterParams) {
|
|
467
|
+
const query = { _embed: true, per_page: 100 };
|
|
468
|
+
if (filterParams?.search) query.search = filterParams.search;
|
|
469
|
+
if (filterParams?.author) query.author = filterParams.author;
|
|
470
|
+
if (filterParams?.tag) query.tags = filterParams.tag;
|
|
471
|
+
if (filterParams?.category) query.categories = filterParams.category;
|
|
472
|
+
return wpFetchGraceful("/wp-json/wp/v2/posts", [], query, ["wordpress", "posts"]);
|
|
473
|
+
}
|
|
474
|
+
async function getPostById(id) {
|
|
475
|
+
return wpFetch(`/wp-json/wp/v2/posts/${id}`);
|
|
476
|
+
}
|
|
477
|
+
async function getPostBySlug(slug) {
|
|
478
|
+
const posts = await wpFetchGraceful("/wp-json/wp/v2/posts", [], { slug, _embed: true });
|
|
479
|
+
return posts[0];
|
|
480
|
+
}
|
|
481
|
+
async function getPostsByCategory(categoryId) {
|
|
482
|
+
return wpFetch("/wp-json/wp/v2/posts", { categories: categoryId });
|
|
483
|
+
}
|
|
484
|
+
async function getPostsByTag(tagId) {
|
|
485
|
+
return wpFetch("/wp-json/wp/v2/posts", { tags: tagId });
|
|
486
|
+
}
|
|
487
|
+
async function getPostsByAuthor(authorId) {
|
|
488
|
+
return wpFetch("/wp-json/wp/v2/posts", { author: authorId });
|
|
489
|
+
}
|
|
490
|
+
async function getPostsByCategoryPaginated(categoryId, page = 1, perPage = 9) {
|
|
491
|
+
return wpFetchPaginatedGraceful("/wp-json/wp/v2/posts", {
|
|
492
|
+
_embed: true,
|
|
493
|
+
per_page: perPage,
|
|
494
|
+
page,
|
|
495
|
+
categories: categoryId
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
async function getPostsByTagPaginated(tagId, page = 1, perPage = 9) {
|
|
499
|
+
return wpFetchPaginatedGraceful("/wp-json/wp/v2/posts", {
|
|
500
|
+
_embed: true,
|
|
501
|
+
per_page: perPage,
|
|
502
|
+
page,
|
|
503
|
+
tags: tagId
|
|
504
|
+
});
|
|
505
|
+
}
|
|
506
|
+
async function getPostsByAuthorPaginated(authorId, page = 1, perPage = 9) {
|
|
507
|
+
return wpFetchPaginatedGraceful("/wp-json/wp/v2/posts", {
|
|
508
|
+
_embed: true,
|
|
509
|
+
per_page: perPage,
|
|
510
|
+
page,
|
|
511
|
+
author: authorId
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
async function getAllPostSlugs() {
|
|
515
|
+
try {
|
|
516
|
+
const allSlugs = [];
|
|
517
|
+
let page = 1;
|
|
518
|
+
let hasMore = true;
|
|
519
|
+
while (hasMore) {
|
|
520
|
+
const response = await wpFetchPaginated(
|
|
521
|
+
"/wp-json/wp/v2/posts",
|
|
522
|
+
{ per_page: 100, page, _fields: "slug" }
|
|
523
|
+
);
|
|
524
|
+
allSlugs.push(...response.data.map((post) => ({ slug: post.slug })));
|
|
525
|
+
hasMore = page < response.headers.totalPages;
|
|
526
|
+
page++;
|
|
527
|
+
}
|
|
528
|
+
return allSlugs;
|
|
529
|
+
} catch {
|
|
530
|
+
console.warn("WordPress unavailable, skipping static generation for posts");
|
|
531
|
+
return [];
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
async function getAllPostsForSitemap() {
|
|
535
|
+
try {
|
|
536
|
+
const allPosts = [];
|
|
537
|
+
let page = 1;
|
|
538
|
+
let hasMore = true;
|
|
539
|
+
while (hasMore) {
|
|
540
|
+
const response = await wpFetchPaginated(
|
|
541
|
+
"/wp-json/wp/v2/posts",
|
|
542
|
+
{ per_page: 100, page, _fields: "slug,modified" }
|
|
543
|
+
);
|
|
544
|
+
allPosts.push(...response.data.map((post) => ({ slug: post.slug, modified: post.modified })));
|
|
545
|
+
hasMore = page < response.headers.totalPages;
|
|
546
|
+
page++;
|
|
547
|
+
}
|
|
548
|
+
return allPosts;
|
|
549
|
+
} catch {
|
|
550
|
+
console.warn("WordPress unavailable, skipping sitemap generation");
|
|
551
|
+
return [];
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
return {
|
|
555
|
+
getPostsPaginated,
|
|
556
|
+
getRecentPosts,
|
|
557
|
+
getPostById,
|
|
558
|
+
getPostBySlug,
|
|
559
|
+
getPostsByCategory,
|
|
560
|
+
getPostsByTag,
|
|
561
|
+
getPostsByAuthor,
|
|
562
|
+
getPostsByCategoryPaginated,
|
|
563
|
+
getPostsByTagPaginated,
|
|
564
|
+
getPostsByAuthorPaginated,
|
|
565
|
+
getAllPostSlugs,
|
|
566
|
+
getAllPostsForSitemap
|
|
567
|
+
};
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
// src/integrations/restApi/core/categories/queries.ts
|
|
571
|
+
function createCategoriesQueries(fetcher) {
|
|
572
|
+
const { wpFetch, wpFetchGraceful } = fetcher;
|
|
573
|
+
async function getAllCategories() {
|
|
574
|
+
return wpFetchGraceful("/wp-json/wp/v2/categories", [], { per_page: 100 }, [
|
|
575
|
+
"wordpress",
|
|
576
|
+
"categories"
|
|
577
|
+
]);
|
|
578
|
+
}
|
|
579
|
+
async function getCategoryById(id) {
|
|
580
|
+
return wpFetch(`/wp-json/wp/v2/categories/${id}`);
|
|
581
|
+
}
|
|
582
|
+
async function getCategoryBySlug(slug) {
|
|
583
|
+
const categories = await wpFetch("/wp-json/wp/v2/categories", { slug });
|
|
584
|
+
return categories[0];
|
|
585
|
+
}
|
|
586
|
+
async function searchCategories(query) {
|
|
587
|
+
return wpFetchGraceful("/wp-json/wp/v2/categories", [], {
|
|
588
|
+
search: query,
|
|
589
|
+
per_page: 100
|
|
590
|
+
});
|
|
591
|
+
}
|
|
592
|
+
return { getAllCategories, getCategoryById, getCategoryBySlug, searchCategories };
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
// src/integrations/restApi/core/tags/queries.ts
|
|
596
|
+
function createTagsQueries(fetcher) {
|
|
597
|
+
const { wpFetch, wpFetchGraceful } = fetcher;
|
|
598
|
+
async function getAllTags() {
|
|
599
|
+
return wpFetchGraceful("/wp-json/wp/v2/tags", [], { per_page: 100 }, [
|
|
600
|
+
"wordpress",
|
|
601
|
+
"tags"
|
|
602
|
+
]);
|
|
603
|
+
}
|
|
604
|
+
async function getTagById(id) {
|
|
605
|
+
return wpFetch(`/wp-json/wp/v2/tags/${id}`);
|
|
606
|
+
}
|
|
607
|
+
async function getTagBySlug(slug) {
|
|
608
|
+
const tags = await wpFetch("/wp-json/wp/v2/tags", { slug });
|
|
609
|
+
return tags[0];
|
|
610
|
+
}
|
|
611
|
+
async function getTagsByPost(postId) {
|
|
612
|
+
return wpFetch("/wp-json/wp/v2/tags", { post: postId });
|
|
613
|
+
}
|
|
614
|
+
async function searchTags(query) {
|
|
615
|
+
return wpFetchGraceful("/wp-json/wp/v2/tags", [], { search: query, per_page: 100 });
|
|
616
|
+
}
|
|
617
|
+
return { getAllTags, getTagById, getTagBySlug, getTagsByPost, searchTags };
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
// src/integrations/restApi/core/authors/queries.ts
|
|
621
|
+
function createAuthorsQueries(fetcher) {
|
|
622
|
+
const { wpFetch, wpFetchGraceful } = fetcher;
|
|
623
|
+
async function getAllAuthors() {
|
|
624
|
+
return wpFetchGraceful("/wp-json/wp/v2/users", [], { per_page: 100 }, [
|
|
625
|
+
"wordpress",
|
|
626
|
+
"authors"
|
|
627
|
+
]);
|
|
628
|
+
}
|
|
629
|
+
async function getAuthorById(id) {
|
|
630
|
+
return wpFetch(`/wp-json/wp/v2/users/${id}`);
|
|
631
|
+
}
|
|
632
|
+
async function getAuthorBySlug(slug) {
|
|
633
|
+
const users = await wpFetch("/wp-json/wp/v2/users", { slug });
|
|
634
|
+
return users[0];
|
|
635
|
+
}
|
|
636
|
+
async function searchAuthors(query) {
|
|
637
|
+
return wpFetchGraceful("/wp-json/wp/v2/users", [], { search: query, per_page: 100 });
|
|
638
|
+
}
|
|
639
|
+
return { getAllAuthors, getAuthorById, getAuthorBySlug, searchAuthors };
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
// src/integrations/restApi/core/media/queries.ts
|
|
643
|
+
function createMediaQueries(fetcher) {
|
|
644
|
+
const { wpFetch } = fetcher;
|
|
645
|
+
async function getFeaturedMediaById(id) {
|
|
646
|
+
return wpFetch(`/wp-json/wp/v2/media/${id}`);
|
|
647
|
+
}
|
|
648
|
+
return { getFeaturedMediaById };
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
// src/integrations/restApi/core/pages/queries.ts
|
|
652
|
+
function createPagesQueries(fetcher) {
|
|
653
|
+
const { wpFetch, wpFetchGraceful } = fetcher;
|
|
654
|
+
async function getAllPages() {
|
|
655
|
+
return wpFetchGraceful("/wp-json/wp/v2/pages", [], { per_page: 100 }, [
|
|
656
|
+
"wordpress",
|
|
657
|
+
"pages"
|
|
658
|
+
]);
|
|
659
|
+
}
|
|
660
|
+
async function getPageById(id) {
|
|
661
|
+
return wpFetch(`/wp-json/wp/v2/pages/${id}`);
|
|
662
|
+
}
|
|
663
|
+
async function getPageBySlug(slug) {
|
|
664
|
+
const pages = await wpFetchGraceful("/wp-json/wp/v2/pages", [], { slug });
|
|
665
|
+
return pages[0];
|
|
666
|
+
}
|
|
667
|
+
return { getAllPages, getPageById, getPageBySlug };
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
// src/integrations/restApi/core/menus/queries.ts
|
|
671
|
+
function createMenusQueries(fetcher) {
|
|
672
|
+
const { wpFetch, wpFetchGraceful } = fetcher;
|
|
673
|
+
async function getMenus() {
|
|
674
|
+
return wpFetchGraceful("/wp-json/wp/v2/menus", [], void 0, ["wordpress", "menus"]);
|
|
675
|
+
}
|
|
676
|
+
async function getMenuById(id) {
|
|
677
|
+
return wpFetch(`/wp-json/wp/v2/menus/${id}`, void 0, ["wordpress", "menus", `menu-${id}`]);
|
|
678
|
+
}
|
|
679
|
+
async function getMenuBySlug(slug) {
|
|
680
|
+
const menus = await wpFetchGraceful("/wp-json/wp/v2/menus", [], { slug }, ["wordpress", "menus"]);
|
|
681
|
+
return menus[0];
|
|
682
|
+
}
|
|
683
|
+
async function getMenuItemsByMenuId(menuId) {
|
|
684
|
+
return wpFetchGraceful(
|
|
685
|
+
"/wp-json/wp/v2/menu-items",
|
|
686
|
+
[],
|
|
687
|
+
{ menus: menuId, per_page: 100, orderby: "menu_order", order: "asc" },
|
|
688
|
+
["wordpress", "menus", `menu-items-${menuId}`]
|
|
689
|
+
);
|
|
690
|
+
}
|
|
691
|
+
async function getMenuLocations() {
|
|
692
|
+
return wpFetchGraceful(
|
|
693
|
+
"/wp-json/wp/v2/menu-locations",
|
|
694
|
+
{},
|
|
695
|
+
void 0,
|
|
696
|
+
["wordpress", "menus", "menu-locations"]
|
|
697
|
+
);
|
|
698
|
+
}
|
|
699
|
+
async function getMenuByLocation(location) {
|
|
700
|
+
const locations = await getMenuLocations();
|
|
701
|
+
const loc = locations[location];
|
|
702
|
+
if (!loc || !loc.menu) return void 0;
|
|
703
|
+
const [menu, items] = await Promise.all([
|
|
704
|
+
getMenuById(loc.menu),
|
|
705
|
+
getMenuItemsByMenuId(loc.menu)
|
|
706
|
+
]);
|
|
707
|
+
return { menu, items };
|
|
708
|
+
}
|
|
709
|
+
return {
|
|
710
|
+
getMenus,
|
|
711
|
+
getMenuById,
|
|
712
|
+
getMenuBySlug,
|
|
713
|
+
getMenuItemsByMenuId,
|
|
714
|
+
getMenuLocations,
|
|
715
|
+
getMenuByLocation
|
|
716
|
+
};
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
// src/integrations/restApi/core/comments/queries.ts
|
|
720
|
+
function createCommentsQueries(fetcher) {
|
|
721
|
+
const { wpFetch, wpFetchGraceful, wpFetchPaginatedGraceful, wpMutate } = fetcher;
|
|
722
|
+
async function getCommentsByPostId(postId, page = 1, perPage = 10) {
|
|
723
|
+
return wpFetchPaginatedGraceful(
|
|
724
|
+
"/wp-json/wp/v2/comments",
|
|
725
|
+
{ post: postId, per_page: perPage, page, status: "approve" },
|
|
726
|
+
["wordpress", "comments", `comments-post-${postId}`]
|
|
727
|
+
);
|
|
728
|
+
}
|
|
729
|
+
async function getAllCommentsByPostId(postId) {
|
|
730
|
+
return wpFetchGraceful(
|
|
731
|
+
"/wp-json/wp/v2/comments",
|
|
732
|
+
[],
|
|
733
|
+
{ post: postId, per_page: 100, status: "approve" },
|
|
734
|
+
["wordpress", "comments", `comments-post-${postId}`]
|
|
735
|
+
);
|
|
736
|
+
}
|
|
737
|
+
async function getCommentById(id) {
|
|
738
|
+
return wpFetch(`/wp-json/wp/v2/comments/${id}`, void 0, [
|
|
739
|
+
"wordpress",
|
|
740
|
+
"comments",
|
|
741
|
+
`comment-${id}`
|
|
742
|
+
]);
|
|
743
|
+
}
|
|
744
|
+
async function getCommentReplies(parentId) {
|
|
745
|
+
return wpFetchGraceful(
|
|
746
|
+
"/wp-json/wp/v2/comments",
|
|
747
|
+
[],
|
|
748
|
+
{ parent: parentId, per_page: 100, status: "approve" },
|
|
749
|
+
["wordpress", "comments", `comments-parent-${parentId}`]
|
|
750
|
+
);
|
|
751
|
+
}
|
|
752
|
+
async function createComment(input) {
|
|
753
|
+
return wpMutate("/wp-json/wp/v2/comments", input, "POST");
|
|
754
|
+
}
|
|
755
|
+
return {
|
|
756
|
+
getCommentsByPostId,
|
|
757
|
+
getAllCommentsByPostId,
|
|
758
|
+
getCommentById,
|
|
759
|
+
getCommentReplies,
|
|
760
|
+
createComment
|
|
761
|
+
};
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
// src/integrations/restApi/core/index.ts
|
|
765
|
+
function createWordPressClient(config) {
|
|
766
|
+
const fetcher = createFetcher(config);
|
|
767
|
+
return {
|
|
768
|
+
...createPostsQueries(fetcher),
|
|
769
|
+
...createCategoriesQueries(fetcher),
|
|
770
|
+
...createTagsQueries(fetcher),
|
|
771
|
+
...createAuthorsQueries(fetcher),
|
|
772
|
+
...createMediaQueries(fetcher),
|
|
773
|
+
...createPagesQueries(fetcher),
|
|
774
|
+
...createMenusQueries(fetcher),
|
|
775
|
+
...createCommentsQueries(fetcher)
|
|
776
|
+
};
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
// src/integrations/restApi/woocommerce/omnibus/queries.ts
|
|
780
|
+
var META_KEY_LOWEST_PRICE = "wpo_lowest_price";
|
|
781
|
+
var META_KEY_PRICE_HISTORY = "_alg_wc_price_history";
|
|
782
|
+
function extractMetaValue(meta_data, key) {
|
|
783
|
+
return meta_data.find((m) => m.key === key)?.value;
|
|
784
|
+
}
|
|
785
|
+
function parseHistory(raw) {
|
|
786
|
+
if (!raw || typeof raw !== "object") return [];
|
|
787
|
+
if (Array.isArray(raw)) {
|
|
788
|
+
return raw.filter((e) => e && typeof e.price === "string" && typeof e.date === "string").map((e) => ({ price: e.price, date: e.date }));
|
|
789
|
+
}
|
|
790
|
+
return Object.entries(raw).map(([date, price]) => ({ date, price })).sort((a, b) => a.date.localeCompare(b.date));
|
|
791
|
+
}
|
|
792
|
+
function extractOmnibusData(meta_data) {
|
|
793
|
+
const lowestPrice = extractMetaValue(meta_data, META_KEY_LOWEST_PRICE) ?? null;
|
|
794
|
+
const rawHistory = extractMetaValue(meta_data, META_KEY_PRICE_HISTORY);
|
|
795
|
+
const priceHistory = parseHistory(rawHistory);
|
|
796
|
+
return { lowestPrice, priceHistory };
|
|
797
|
+
}
|
|
798
|
+
function withOmnibus(product) {
|
|
799
|
+
return { ...product, omnibus: extractOmnibusData(product.meta_data) };
|
|
800
|
+
}
|
|
801
|
+
function withOmnibusVariation(variation) {
|
|
802
|
+
return {
|
|
803
|
+
...variation,
|
|
804
|
+
omnibus: extractOmnibusData(variation.meta_data ?? [])
|
|
805
|
+
};
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
// src/integrations/restApi/woocommerce/client/types.ts
|
|
809
|
+
var WooCommerceError = class extends Error {
|
|
810
|
+
constructor(code, status, endpoint, message, upstreamCode, detail) {
|
|
811
|
+
super(detail ? `${message}: ${detail}` : message);
|
|
812
|
+
__publicField(this, "code", code);
|
|
813
|
+
__publicField(this, "status", status);
|
|
814
|
+
__publicField(this, "endpoint", endpoint);
|
|
815
|
+
__publicField(this, "upstreamCode", upstreamCode);
|
|
816
|
+
this.name = "WooCommerceError";
|
|
817
|
+
}
|
|
818
|
+
};
|
|
819
|
+
|
|
820
|
+
// src/integrations/restApi/woocommerce/client/errorMap.ts
|
|
821
|
+
var upstreamToErrorCode = {
|
|
822
|
+
woocommerce_rest_coupon_invalid_id: ErrorCode.WOO_COUPON_NOT_FOUND,
|
|
823
|
+
woocommerce_rest_product_invalid_id: ErrorCode.WOO_PRODUCT_NOT_FOUND,
|
|
824
|
+
woocommerce_rest_order_invalid_id: ErrorCode.WOO_ORDER_NOT_FOUND,
|
|
825
|
+
woocommerce_rest_customer_invalid_id: ErrorCode.WOO_CUSTOMER_NOT_FOUND,
|
|
826
|
+
woocommerce_rest_term_invalid: ErrorCode.WOO_CATEGORY_NOT_FOUND,
|
|
827
|
+
woocommerce_rest_review_invalid_id: ErrorCode.WOO_REVIEW_NOT_FOUND,
|
|
828
|
+
woocommerce_rest_webhook_invalid_id: ErrorCode.WOO_WEBHOOK_NOT_FOUND,
|
|
829
|
+
woocommerce_rest_shipping_zone_invalid_id: ErrorCode.WOO_SHIPPING_ZONE_NOT_FOUND
|
|
830
|
+
};
|
|
831
|
+
function resolveWooErrorCode(status, upstreamCode) {
|
|
832
|
+
if (status === 401) return ErrorCode.WOO_UNAUTHORIZED;
|
|
833
|
+
if (status === 403) return ErrorCode.WOO_FORBIDDEN;
|
|
834
|
+
if (status === 404) {
|
|
835
|
+
if (upstreamCode) {
|
|
836
|
+
const mapped = upstreamToErrorCode[upstreamCode];
|
|
837
|
+
if (mapped) return mapped;
|
|
838
|
+
}
|
|
839
|
+
return ErrorCode.WOO_NOT_FOUND;
|
|
840
|
+
}
|
|
841
|
+
return ErrorCode.WOO_REQUEST_FAILED;
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
// src/integrations/restApi/woocommerce/client/fetcher.ts
|
|
845
|
+
var USER_AGENT2 = "NextWordpress WooCommerce Client";
|
|
846
|
+
var DEFAULT_CACHE_TTL = 3600;
|
|
847
|
+
function toQueryString(params) {
|
|
848
|
+
const pairs = [];
|
|
849
|
+
for (const [key, value] of Object.entries(params)) {
|
|
850
|
+
if (value === void 0 || value === null) continue;
|
|
851
|
+
pairs.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`);
|
|
852
|
+
}
|
|
853
|
+
return pairs.join("&");
|
|
854
|
+
}
|
|
855
|
+
function createWooCommerceFetcher(config) {
|
|
856
|
+
const cacheTTL = config.cacheTTL ?? DEFAULT_CACHE_TTL;
|
|
857
|
+
function withAuth(query) {
|
|
858
|
+
return { ...query, consumer_key: config.consumerKey, consumer_secret: config.consumerSecret };
|
|
859
|
+
}
|
|
860
|
+
function buildUrl2(path, query) {
|
|
861
|
+
const base = typeof window !== "undefined" && config.clientURL ? config.clientURL : config.serverURL;
|
|
862
|
+
return `${base}${path}?${toQueryString(withAuth(query))}`;
|
|
863
|
+
}
|
|
864
|
+
async function throwWooError(response, url) {
|
|
865
|
+
const body = await response.json().catch(() => ({}));
|
|
866
|
+
const errorCode = resolveWooErrorCode(response.status, body.code);
|
|
867
|
+
throw new WooCommerceError(
|
|
868
|
+
errorCode,
|
|
869
|
+
response.status,
|
|
870
|
+
url,
|
|
871
|
+
resolveMessage(errorCode, config.errorMessages),
|
|
872
|
+
body.code,
|
|
873
|
+
body.message
|
|
874
|
+
);
|
|
875
|
+
}
|
|
876
|
+
async function wcFetch(path, query, tags = ["woocommerce"], options) {
|
|
877
|
+
const url = buildUrl2(path, query);
|
|
878
|
+
const isMutation = options?.method && options.method !== "GET";
|
|
879
|
+
const noStore = options?.cache === "no-store";
|
|
880
|
+
const response = await fetch(url, {
|
|
881
|
+
...options,
|
|
882
|
+
headers: {
|
|
883
|
+
"User-Agent": USER_AGENT2,
|
|
884
|
+
"Content-Type": "application/json",
|
|
885
|
+
...options?.headers
|
|
886
|
+
},
|
|
887
|
+
next: isMutation || noStore ? void 0 : { tags, revalidate: cacheTTL }
|
|
888
|
+
});
|
|
889
|
+
if (!response.ok) {
|
|
890
|
+
await throwWooError(response, url);
|
|
891
|
+
}
|
|
892
|
+
return response.json();
|
|
893
|
+
}
|
|
894
|
+
async function wcFetchGraceful(path, fallback, query, tags = ["woocommerce"]) {
|
|
895
|
+
try {
|
|
896
|
+
return await wcFetch(path, query, tags);
|
|
897
|
+
} catch (err) {
|
|
898
|
+
console.warn(`WooCommerce fetch failed for ${path}`, err);
|
|
899
|
+
return fallback;
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
async function wcFetchPaginated(path, query, tags = ["woocommerce"]) {
|
|
903
|
+
const url = buildUrl2(path, query);
|
|
904
|
+
const response = await fetch(url, {
|
|
905
|
+
headers: { "User-Agent": USER_AGENT2 },
|
|
906
|
+
next: { tags, revalidate: cacheTTL }
|
|
907
|
+
});
|
|
908
|
+
if (!response.ok) {
|
|
909
|
+
await throwWooError(response, url);
|
|
910
|
+
}
|
|
911
|
+
return {
|
|
912
|
+
data: await response.json(),
|
|
913
|
+
headers: {
|
|
914
|
+
total: parseInt(response.headers.get("X-WP-Total") ?? "0", 10),
|
|
915
|
+
totalPages: parseInt(response.headers.get("X-WP-TotalPages") ?? "0", 10)
|
|
916
|
+
}
|
|
917
|
+
};
|
|
918
|
+
}
|
|
919
|
+
async function wcFetchPaginatedGraceful(path, query, tags = ["woocommerce"]) {
|
|
920
|
+
const empty = { data: [], headers: { total: 0, totalPages: 0 } };
|
|
921
|
+
try {
|
|
922
|
+
return await wcFetchPaginated(path, query, tags);
|
|
923
|
+
} catch (err) {
|
|
924
|
+
console.warn(`WooCommerce paginated fetch failed for ${path}`, err);
|
|
925
|
+
return empty;
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
async function wcMutate(path, body, method = "POST") {
|
|
929
|
+
return wcFetch(path, void 0, ["woocommerce"], {
|
|
930
|
+
method,
|
|
931
|
+
body: JSON.stringify(body)
|
|
932
|
+
});
|
|
933
|
+
}
|
|
934
|
+
return { wcFetch, wcFetchGraceful, wcFetchPaginated, wcFetchPaginatedGraceful, wcMutate };
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
// src/integrations/restApi/woocommerce/products/queries.ts
|
|
938
|
+
function buildProductQuery(base, filterParams) {
|
|
939
|
+
const query = { ...base };
|
|
940
|
+
if (!filterParams) return query;
|
|
941
|
+
if (filterParams.category !== void 0) query.category = filterParams.category;
|
|
942
|
+
if (filterParams.tag !== void 0) query.tag = filterParams.tag;
|
|
943
|
+
if (filterParams.featured !== void 0) query.featured = filterParams.featured;
|
|
944
|
+
if (filterParams.on_sale !== void 0) query.on_sale = filterParams.on_sale;
|
|
945
|
+
if (filterParams.min_price !== void 0) query.min_price = filterParams.min_price;
|
|
946
|
+
if (filterParams.max_price !== void 0) query.max_price = filterParams.max_price;
|
|
947
|
+
if (filterParams.search !== void 0) query.search = filterParams.search;
|
|
948
|
+
if (filterParams.orderby !== void 0) query.orderby = filterParams.orderby;
|
|
949
|
+
if (filterParams.order !== void 0) query.order = filterParams.order;
|
|
950
|
+
if (filterParams.stock_status !== void 0) query.stock_status = filterParams.stock_status;
|
|
951
|
+
if (filterParams.type !== void 0) query.type = filterParams.type;
|
|
952
|
+
return query;
|
|
953
|
+
}
|
|
954
|
+
function createProductsQueries(fetcher) {
|
|
955
|
+
const { wcFetch, wcFetchGraceful, wcFetchPaginated, wcFetchPaginatedGraceful } = fetcher;
|
|
956
|
+
async function getProducts(filterParams) {
|
|
957
|
+
const query = buildProductQuery({ per_page: 100, status: "publish" }, filterParams);
|
|
958
|
+
return wcFetchGraceful("/wp-json/wc/v3/products", [], query, [
|
|
959
|
+
"woocommerce",
|
|
960
|
+
"products"
|
|
961
|
+
]);
|
|
962
|
+
}
|
|
963
|
+
async function getProductsPaginated(page = 1, perPage = 12, filterParams) {
|
|
964
|
+
const query = buildProductQuery({ per_page: perPage, page, status: "publish" }, filterParams);
|
|
965
|
+
const cacheTags = ["woocommerce", "products", `products-page-${page}`];
|
|
966
|
+
if (filterParams?.category) cacheTags.push(`products-category-${filterParams.category}`);
|
|
967
|
+
if (filterParams?.tag) cacheTags.push(`products-tag-${filterParams.tag}`);
|
|
968
|
+
if (filterParams?.search) cacheTags.push("products-search");
|
|
969
|
+
return wcFetchPaginatedGraceful("/wp-json/wc/v3/products", query, cacheTags);
|
|
970
|
+
}
|
|
971
|
+
async function getProductById(id) {
|
|
972
|
+
return wcFetch(`/wp-json/wc/v3/products/${id}`, void 0, [
|
|
973
|
+
"woocommerce",
|
|
974
|
+
"products",
|
|
975
|
+
`product-${id}`
|
|
976
|
+
]);
|
|
977
|
+
}
|
|
978
|
+
async function getProductBySlug(slug) {
|
|
979
|
+
const products = await wcFetchGraceful(
|
|
980
|
+
"/wp-json/wc/v3/products",
|
|
981
|
+
[],
|
|
982
|
+
{ slug },
|
|
983
|
+
["woocommerce", "products", `product-slug-${slug}`]
|
|
984
|
+
);
|
|
985
|
+
return products[0];
|
|
986
|
+
}
|
|
987
|
+
async function getFeaturedProducts(limit = 10) {
|
|
988
|
+
return wcFetchGraceful(
|
|
989
|
+
"/wp-json/wc/v3/products",
|
|
990
|
+
[],
|
|
991
|
+
{ featured: true, per_page: limit, status: "publish" },
|
|
992
|
+
["woocommerce", "products", "featured"]
|
|
993
|
+
);
|
|
994
|
+
}
|
|
995
|
+
async function getOnSaleProducts(limit = 10) {
|
|
996
|
+
return wcFetchGraceful(
|
|
997
|
+
"/wp-json/wc/v3/products",
|
|
998
|
+
[],
|
|
999
|
+
{ on_sale: true, per_page: limit, status: "publish" },
|
|
1000
|
+
["woocommerce", "products", "on-sale"]
|
|
1001
|
+
);
|
|
1002
|
+
}
|
|
1003
|
+
async function getRelatedProducts(productId) {
|
|
1004
|
+
const product = await getProductById(productId);
|
|
1005
|
+
if (!product.related_ids.length) return [];
|
|
1006
|
+
return wcFetchGraceful(
|
|
1007
|
+
"/wp-json/wc/v3/products",
|
|
1008
|
+
[],
|
|
1009
|
+
{ include: product.related_ids.join(","), per_page: 10, status: "publish" },
|
|
1010
|
+
["woocommerce", "products", `related-${productId}`]
|
|
1011
|
+
);
|
|
1012
|
+
}
|
|
1013
|
+
async function getAllProductSlugs() {
|
|
1014
|
+
try {
|
|
1015
|
+
const allSlugs = [];
|
|
1016
|
+
let page = 1;
|
|
1017
|
+
let hasMore = true;
|
|
1018
|
+
while (hasMore) {
|
|
1019
|
+
const response = await wcFetchPaginated("/wp-json/wc/v3/products", {
|
|
1020
|
+
per_page: 100,
|
|
1021
|
+
page,
|
|
1022
|
+
status: "publish",
|
|
1023
|
+
_fields: "slug"
|
|
1024
|
+
});
|
|
1025
|
+
allSlugs.push(...response.data.map((p) => ({ slug: p.slug })));
|
|
1026
|
+
hasMore = page < response.headers.totalPages;
|
|
1027
|
+
page++;
|
|
1028
|
+
}
|
|
1029
|
+
return allSlugs;
|
|
1030
|
+
} catch {
|
|
1031
|
+
console.warn("WooCommerce unavailable, skipping static generation for products");
|
|
1032
|
+
return [];
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
async function getProductVariations(productId) {
|
|
1036
|
+
return wcFetchGraceful(
|
|
1037
|
+
`/wp-json/wc/v3/products/${productId}/variations`,
|
|
1038
|
+
[],
|
|
1039
|
+
{ per_page: 100 },
|
|
1040
|
+
["woocommerce", "products", `product-${productId}`, "variations"]
|
|
1041
|
+
);
|
|
1042
|
+
}
|
|
1043
|
+
async function getProductVariationById(productId, variationId) {
|
|
1044
|
+
return wcFetch(
|
|
1045
|
+
`/wp-json/wc/v3/products/${productId}/variations/${variationId}`,
|
|
1046
|
+
void 0,
|
|
1047
|
+
["woocommerce", "products", `product-${productId}`, `variation-${variationId}`]
|
|
1048
|
+
);
|
|
1049
|
+
}
|
|
1050
|
+
return {
|
|
1051
|
+
getProducts,
|
|
1052
|
+
getProductsPaginated,
|
|
1053
|
+
getProductById,
|
|
1054
|
+
getProductBySlug,
|
|
1055
|
+
getFeaturedProducts,
|
|
1056
|
+
getOnSaleProducts,
|
|
1057
|
+
getRelatedProducts,
|
|
1058
|
+
getAllProductSlugs,
|
|
1059
|
+
getProductVariations,
|
|
1060
|
+
getProductVariationById
|
|
1061
|
+
};
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
// src/integrations/restApi/woocommerce/products/mutations.ts
|
|
1065
|
+
function createProductsMutations(fetcher) {
|
|
1066
|
+
const { wcMutate } = fetcher;
|
|
1067
|
+
async function createProduct(input) {
|
|
1068
|
+
return wcMutate("/wp-json/wc/v3/products", input, "POST");
|
|
1069
|
+
}
|
|
1070
|
+
async function updateProduct(id, input) {
|
|
1071
|
+
return wcMutate(`/wp-json/wc/v3/products/${id}`, input, "PUT");
|
|
1072
|
+
}
|
|
1073
|
+
async function deleteProduct(id, force = true) {
|
|
1074
|
+
return wcMutate(
|
|
1075
|
+
`/wp-json/wc/v3/products/${id}`,
|
|
1076
|
+
{ force },
|
|
1077
|
+
"DELETE"
|
|
1078
|
+
);
|
|
1079
|
+
}
|
|
1080
|
+
return { createProduct, updateProduct, deleteProduct };
|
|
1081
|
+
}
|
|
1082
|
+
|
|
1083
|
+
// src/integrations/restApi/woocommerce/categories/queries.ts
|
|
1084
|
+
function createCategoriesQueries2(fetcher) {
|
|
1085
|
+
const { wcFetch, wcFetchGraceful } = fetcher;
|
|
1086
|
+
async function getAllProductCategories() {
|
|
1087
|
+
return wcFetchGraceful(
|
|
1088
|
+
"/wp-json/wc/v3/products/categories",
|
|
1089
|
+
[],
|
|
1090
|
+
{ per_page: 100, hide_empty: false },
|
|
1091
|
+
["woocommerce", "product-categories"]
|
|
1092
|
+
);
|
|
1093
|
+
}
|
|
1094
|
+
async function getProductCategoryById(id) {
|
|
1095
|
+
return wcFetch(
|
|
1096
|
+
`/wp-json/wc/v3/products/categories/${id}`,
|
|
1097
|
+
void 0,
|
|
1098
|
+
["woocommerce", "product-categories", `product-category-${id}`]
|
|
1099
|
+
);
|
|
1100
|
+
}
|
|
1101
|
+
async function getProductCategoryBySlug(slug) {
|
|
1102
|
+
const categories = await wcFetchGraceful(
|
|
1103
|
+
"/wp-json/wc/v3/products/categories",
|
|
1104
|
+
[],
|
|
1105
|
+
{ slug },
|
|
1106
|
+
["woocommerce", "product-categories", `product-category-slug-${slug}`]
|
|
1107
|
+
);
|
|
1108
|
+
return categories[0];
|
|
1109
|
+
}
|
|
1110
|
+
async function getProductsByCategory(categoryId, limit = 100) {
|
|
1111
|
+
return wcFetchGraceful(
|
|
1112
|
+
"/wp-json/wc/v3/products",
|
|
1113
|
+
[],
|
|
1114
|
+
{ category: categoryId, per_page: limit, status: "publish" },
|
|
1115
|
+
["woocommerce", "products", `products-category-${categoryId}`]
|
|
1116
|
+
);
|
|
1117
|
+
}
|
|
1118
|
+
async function getProductsByCategorySlug(categorySlug) {
|
|
1119
|
+
const category = await getProductCategoryBySlug(categorySlug);
|
|
1120
|
+
if (!category) return [];
|
|
1121
|
+
return getProductsByCategory(category.id);
|
|
1122
|
+
}
|
|
1123
|
+
return {
|
|
1124
|
+
getAllProductCategories,
|
|
1125
|
+
getProductCategoryById,
|
|
1126
|
+
getProductCategoryBySlug,
|
|
1127
|
+
getProductsByCategory,
|
|
1128
|
+
getProductsByCategorySlug
|
|
1129
|
+
};
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1132
|
+
// src/integrations/restApi/woocommerce/categories/mutations.ts
|
|
1133
|
+
function createCategoriesMutations2(fetcher) {
|
|
1134
|
+
const { wcMutate } = fetcher;
|
|
1135
|
+
async function createProductCategory(input) {
|
|
1136
|
+
return wcMutate("/wp-json/wc/v3/products/categories", input, "POST");
|
|
1137
|
+
}
|
|
1138
|
+
async function updateProductCategory(id, input) {
|
|
1139
|
+
return wcMutate(
|
|
1140
|
+
`/wp-json/wc/v3/products/categories/${id}`,
|
|
1141
|
+
input,
|
|
1142
|
+
"PUT"
|
|
1143
|
+
);
|
|
1144
|
+
}
|
|
1145
|
+
async function deleteProductCategory(id, force = true) {
|
|
1146
|
+
return wcMutate(
|
|
1147
|
+
`/wp-json/wc/v3/products/categories/${id}`,
|
|
1148
|
+
{ force },
|
|
1149
|
+
"DELETE"
|
|
1150
|
+
);
|
|
1151
|
+
}
|
|
1152
|
+
return { createProductCategory, updateProductCategory, deleteProductCategory };
|
|
1153
|
+
}
|
|
1154
|
+
|
|
1155
|
+
// src/integrations/restApi/woocommerce/tags/queries.ts
|
|
1156
|
+
function createTagsQueries2(fetcher) {
|
|
1157
|
+
const { wcFetch, wcFetchGraceful } = fetcher;
|
|
1158
|
+
async function getAllProductTags() {
|
|
1159
|
+
return wcFetchGraceful(
|
|
1160
|
+
"/wp-json/wc/v3/products/tags",
|
|
1161
|
+
[],
|
|
1162
|
+
{ per_page: 100 },
|
|
1163
|
+
["woocommerce", "product-tags"]
|
|
1164
|
+
);
|
|
1165
|
+
}
|
|
1166
|
+
async function getProductTagById(id) {
|
|
1167
|
+
return wcFetch(`/wp-json/wc/v3/products/tags/${id}`, void 0, [
|
|
1168
|
+
"woocommerce",
|
|
1169
|
+
"product-tags",
|
|
1170
|
+
`product-tag-${id}`
|
|
1171
|
+
]);
|
|
1172
|
+
}
|
|
1173
|
+
async function getProductsByTag(tagId, limit = 100) {
|
|
1174
|
+
return wcFetchGraceful(
|
|
1175
|
+
"/wp-json/wc/v3/products",
|
|
1176
|
+
[],
|
|
1177
|
+
{ tag: tagId, per_page: limit },
|
|
1178
|
+
["woocommerce", "products", `products-tag-${tagId}`]
|
|
1179
|
+
);
|
|
1180
|
+
}
|
|
1181
|
+
return {
|
|
1182
|
+
getAllProductTags,
|
|
1183
|
+
getProductTagById,
|
|
1184
|
+
getProductsByTag
|
|
1185
|
+
};
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
// src/integrations/restApi/woocommerce/tags/mutations.ts
|
|
1189
|
+
function createTagsMutations2(fetcher) {
|
|
1190
|
+
const { wcMutate } = fetcher;
|
|
1191
|
+
async function createProductTag(input) {
|
|
1192
|
+
return wcMutate("/wp-json/wc/v3/products/tags", input, "POST");
|
|
1193
|
+
}
|
|
1194
|
+
async function updateProductTag(id, input) {
|
|
1195
|
+
return wcMutate(`/wp-json/wc/v3/products/tags/${id}`, input, "PUT");
|
|
1196
|
+
}
|
|
1197
|
+
async function deleteProductTag(id, force = true) {
|
|
1198
|
+
return wcMutate(
|
|
1199
|
+
`/wp-json/wc/v3/products/tags/${id}`,
|
|
1200
|
+
{ force },
|
|
1201
|
+
"DELETE"
|
|
1202
|
+
);
|
|
1203
|
+
}
|
|
1204
|
+
return { createProductTag, updateProductTag, deleteProductTag };
|
|
1205
|
+
}
|
|
1206
|
+
|
|
1207
|
+
// src/integrations/restApi/woocommerce/orders/queries.ts
|
|
1208
|
+
function createOrdersQueries(fetcher) {
|
|
1209
|
+
const { wcFetch, wcFetchGraceful, wcMutate } = fetcher;
|
|
1210
|
+
async function createOrder(input) {
|
|
1211
|
+
return wcMutate("/wp-json/wc/v3/orders", input, "POST");
|
|
1212
|
+
}
|
|
1213
|
+
async function getOrderById(id) {
|
|
1214
|
+
return wcFetch(`/wp-json/wc/v3/orders/${id}`, void 0, [
|
|
1215
|
+
"woocommerce",
|
|
1216
|
+
"orders",
|
|
1217
|
+
`order-${id}`
|
|
1218
|
+
]);
|
|
1219
|
+
}
|
|
1220
|
+
async function updateOrder(id, data) {
|
|
1221
|
+
return wcMutate(`/wp-json/wc/v3/orders/${id}`, data, "PUT");
|
|
1222
|
+
}
|
|
1223
|
+
async function getOrdersByCustomer(customerId) {
|
|
1224
|
+
return wcFetchGraceful(
|
|
1225
|
+
"/wp-json/wc/v3/orders",
|
|
1226
|
+
[],
|
|
1227
|
+
{ customer: customerId, per_page: 100 },
|
|
1228
|
+
["woocommerce", "orders", `orders-customer-${customerId}`]
|
|
1229
|
+
);
|
|
1230
|
+
}
|
|
1231
|
+
async function deleteOrder(id, force = true) {
|
|
1232
|
+
return wcMutate(
|
|
1233
|
+
`/wp-json/wc/v3/orders/${id}`,
|
|
1234
|
+
{ force },
|
|
1235
|
+
"DELETE"
|
|
1236
|
+
);
|
|
1237
|
+
}
|
|
1238
|
+
return {
|
|
1239
|
+
createOrder,
|
|
1240
|
+
getOrderById,
|
|
1241
|
+
updateOrder,
|
|
1242
|
+
getOrdersByCustomer,
|
|
1243
|
+
deleteOrder
|
|
1244
|
+
};
|
|
1245
|
+
}
|
|
1246
|
+
|
|
1247
|
+
// src/integrations/restApi/woocommerce/coupons/queries.ts
|
|
1248
|
+
function createCouponsQueries(fetcher) {
|
|
1249
|
+
const { wcFetchGraceful } = fetcher;
|
|
1250
|
+
async function getCouponByCode(code) {
|
|
1251
|
+
const coupons = await wcFetchGraceful(
|
|
1252
|
+
"/wp-json/wc/v3/coupons",
|
|
1253
|
+
[],
|
|
1254
|
+
{ code },
|
|
1255
|
+
["woocommerce", "coupons"]
|
|
1256
|
+
);
|
|
1257
|
+
return coupons[0];
|
|
1258
|
+
}
|
|
1259
|
+
async function validateCoupon(code) {
|
|
1260
|
+
const coupon = await getCouponByCode(code);
|
|
1261
|
+
if (!coupon) return { valid: false, reason: "Coupon not found" };
|
|
1262
|
+
if (coupon.date_expires) {
|
|
1263
|
+
const expiry = new Date(coupon.date_expires);
|
|
1264
|
+
if (expiry < /* @__PURE__ */ new Date()) return { valid: false, reason: "Coupon has expired", coupon };
|
|
1265
|
+
}
|
|
1266
|
+
if (coupon.usage_limit !== null && coupon.usage_count >= coupon.usage_limit) {
|
|
1267
|
+
return { valid: false, reason: "Coupon usage limit reached", coupon };
|
|
1268
|
+
}
|
|
1269
|
+
return { valid: true, coupon };
|
|
1270
|
+
}
|
|
1271
|
+
return {
|
|
1272
|
+
getCouponByCode,
|
|
1273
|
+
validateCoupon
|
|
1274
|
+
};
|
|
1275
|
+
}
|
|
1276
|
+
|
|
1277
|
+
// src/integrations/restApi/woocommerce/coupons/mutations.ts
|
|
1278
|
+
function createCouponsMutations(fetcher) {
|
|
1279
|
+
const { wcMutate } = fetcher;
|
|
1280
|
+
async function createCoupon(input) {
|
|
1281
|
+
return wcMutate("/wp-json/wc/v3/coupons", input, "POST");
|
|
1282
|
+
}
|
|
1283
|
+
async function updateCoupon(id, input) {
|
|
1284
|
+
return wcMutate(`/wp-json/wc/v3/coupons/${id}`, input, "PUT");
|
|
1285
|
+
}
|
|
1286
|
+
async function deleteCoupon(id, force = true) {
|
|
1287
|
+
return wcMutate(
|
|
1288
|
+
`/wp-json/wc/v3/coupons/${id}`,
|
|
1289
|
+
{ force },
|
|
1290
|
+
"DELETE"
|
|
1291
|
+
);
|
|
1292
|
+
}
|
|
1293
|
+
return { createCoupon, updateCoupon, deleteCoupon };
|
|
1294
|
+
}
|
|
1295
|
+
|
|
1296
|
+
// src/integrations/restApi/woocommerce/customers/queries.ts
|
|
1297
|
+
function createCustomersQueries(fetcher) {
|
|
1298
|
+
const { wcFetch, wcFetchGraceful, wcMutate } = fetcher;
|
|
1299
|
+
async function getCustomerById(id) {
|
|
1300
|
+
return wcFetch(`/wp-json/wc/v3/customers/${id}`, void 0, [
|
|
1301
|
+
"woocommerce",
|
|
1302
|
+
"customers",
|
|
1303
|
+
`customer-${id}`
|
|
1304
|
+
]);
|
|
1305
|
+
}
|
|
1306
|
+
async function getCustomerByEmail(email) {
|
|
1307
|
+
const customers = await wcFetchGraceful(
|
|
1308
|
+
"/wp-json/wc/v3/customers",
|
|
1309
|
+
[],
|
|
1310
|
+
{ email },
|
|
1311
|
+
["woocommerce", "customers"]
|
|
1312
|
+
);
|
|
1313
|
+
return customers[0];
|
|
1314
|
+
}
|
|
1315
|
+
async function getCustomerByEmailNoCache(email) {
|
|
1316
|
+
try {
|
|
1317
|
+
const customers = await wcFetch(
|
|
1318
|
+
"/wp-json/wc/v3/customers",
|
|
1319
|
+
{ email },
|
|
1320
|
+
["woocommerce", "customers"],
|
|
1321
|
+
{ cache: "no-store" }
|
|
1322
|
+
);
|
|
1323
|
+
return customers[0];
|
|
1324
|
+
} catch {
|
|
1325
|
+
return void 0;
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
async function createCustomer(data) {
|
|
1329
|
+
return wcFetch(
|
|
1330
|
+
"/wp-json/wc/v3/customers",
|
|
1331
|
+
void 0,
|
|
1332
|
+
["woocommerce", "customers"],
|
|
1333
|
+
{ method: "POST", body: JSON.stringify(data) }
|
|
1334
|
+
);
|
|
1335
|
+
}
|
|
1336
|
+
async function updateCustomer(id, data) {
|
|
1337
|
+
return wcMutate(`/wp-json/wc/v3/customers/${id}`, data, "PUT");
|
|
1338
|
+
}
|
|
1339
|
+
async function deleteCustomer(id, reassign) {
|
|
1340
|
+
return wcMutate(
|
|
1341
|
+
`/wp-json/wc/v3/customers/${id}`,
|
|
1342
|
+
{ force: true, ...reassign !== void 0 && { reassign } },
|
|
1343
|
+
"DELETE"
|
|
1344
|
+
);
|
|
1345
|
+
}
|
|
1346
|
+
return {
|
|
1347
|
+
getCustomerById,
|
|
1348
|
+
getCustomerByEmail,
|
|
1349
|
+
getCustomerByEmailNoCache,
|
|
1350
|
+
createCustomer,
|
|
1351
|
+
updateCustomer,
|
|
1352
|
+
deleteCustomer
|
|
1353
|
+
};
|
|
1354
|
+
}
|
|
1355
|
+
|
|
1356
|
+
// src/integrations/restApi/woocommerce/payment_gateways/queries.ts
|
|
1357
|
+
function createPaymentGatewaysQueries(fetcher) {
|
|
1358
|
+
const { wcFetch, wcFetchGraceful } = fetcher;
|
|
1359
|
+
async function getPaymentGateways() {
|
|
1360
|
+
return wcFetchGraceful(
|
|
1361
|
+
"/wp-json/wc/v3/payment_gateways",
|
|
1362
|
+
[],
|
|
1363
|
+
void 0,
|
|
1364
|
+
["woocommerce", "payment_gateways"]
|
|
1365
|
+
);
|
|
1366
|
+
}
|
|
1367
|
+
async function getEnabledPaymentGateways() {
|
|
1368
|
+
const gateways = await wcFetchGraceful(
|
|
1369
|
+
"/wp-json/wc/v3/payment_gateways",
|
|
1370
|
+
[],
|
|
1371
|
+
void 0,
|
|
1372
|
+
["woocommerce", "payment_gateways"]
|
|
1373
|
+
);
|
|
1374
|
+
return gateways.filter((g) => g.enabled);
|
|
1375
|
+
}
|
|
1376
|
+
async function getPaymentGatewayById(id) {
|
|
1377
|
+
return wcFetch(
|
|
1378
|
+
`/wp-json/wc/v3/payment_gateways/${id}`,
|
|
1379
|
+
void 0,
|
|
1380
|
+
["woocommerce", "payment_gateways", `payment_gateway-${id}`]
|
|
1381
|
+
);
|
|
1382
|
+
}
|
|
1383
|
+
return {
|
|
1384
|
+
getPaymentGateways,
|
|
1385
|
+
getEnabledPaymentGateways,
|
|
1386
|
+
getPaymentGatewayById
|
|
1387
|
+
};
|
|
1388
|
+
}
|
|
1389
|
+
|
|
1390
|
+
// src/integrations/restApi/woocommerce/order_notes/queries.ts
|
|
1391
|
+
function createOrderNotesQueries(fetcher) {
|
|
1392
|
+
const { wcFetch, wcFetchGraceful, wcMutate } = fetcher;
|
|
1393
|
+
async function getNotesByOrderId(orderId) {
|
|
1394
|
+
return wcFetchGraceful(
|
|
1395
|
+
`/wp-json/wc/v3/orders/${orderId}/notes`,
|
|
1396
|
+
[],
|
|
1397
|
+
void 0,
|
|
1398
|
+
["woocommerce", "order_notes", `order-${orderId}-notes`]
|
|
1399
|
+
);
|
|
1400
|
+
}
|
|
1401
|
+
async function getOrderNoteById(orderId, noteId) {
|
|
1402
|
+
return wcFetch(
|
|
1403
|
+
`/wp-json/wc/v3/orders/${orderId}/notes/${noteId}`,
|
|
1404
|
+
void 0,
|
|
1405
|
+
["woocommerce", "order_notes", `order-${orderId}-note-${noteId}`]
|
|
1406
|
+
);
|
|
1407
|
+
}
|
|
1408
|
+
async function createOrderNote(orderId, input) {
|
|
1409
|
+
return wcMutate(
|
|
1410
|
+
`/wp-json/wc/v3/orders/${orderId}/notes`,
|
|
1411
|
+
input,
|
|
1412
|
+
"POST"
|
|
1413
|
+
);
|
|
1414
|
+
}
|
|
1415
|
+
async function deleteOrderNote(orderId, noteId, force = true) {
|
|
1416
|
+
return wcMutate(
|
|
1417
|
+
`/wp-json/wc/v3/orders/${orderId}/notes/${noteId}`,
|
|
1418
|
+
{ force },
|
|
1419
|
+
"DELETE"
|
|
1420
|
+
);
|
|
1421
|
+
}
|
|
1422
|
+
return {
|
|
1423
|
+
getNotesByOrderId,
|
|
1424
|
+
getOrderNoteById,
|
|
1425
|
+
createOrderNote,
|
|
1426
|
+
deleteOrderNote
|
|
1427
|
+
};
|
|
1428
|
+
}
|
|
1429
|
+
|
|
1430
|
+
// src/integrations/restApi/woocommerce/order_refunds/queries.ts
|
|
1431
|
+
function createOrderRefundsQueries(fetcher) {
|
|
1432
|
+
const { wcFetch, wcFetchGraceful, wcMutate } = fetcher;
|
|
1433
|
+
async function getRefundsByOrderId(orderId) {
|
|
1434
|
+
return wcFetchGraceful(
|
|
1435
|
+
`/wp-json/wc/v3/orders/${orderId}/refunds`,
|
|
1436
|
+
[],
|
|
1437
|
+
void 0,
|
|
1438
|
+
["woocommerce", "order_refunds", `order-${orderId}-refunds`]
|
|
1439
|
+
);
|
|
1440
|
+
}
|
|
1441
|
+
async function getOrderRefundById(orderId, refundId) {
|
|
1442
|
+
return wcFetch(
|
|
1443
|
+
`/wp-json/wc/v3/orders/${orderId}/refunds/${refundId}`,
|
|
1444
|
+
void 0,
|
|
1445
|
+
["woocommerce", "order_refunds", `order-${orderId}-refund-${refundId}`]
|
|
1446
|
+
);
|
|
1447
|
+
}
|
|
1448
|
+
async function createOrderRefund(orderId, input) {
|
|
1449
|
+
return wcMutate(
|
|
1450
|
+
`/wp-json/wc/v3/orders/${orderId}/refunds`,
|
|
1451
|
+
input,
|
|
1452
|
+
"POST"
|
|
1453
|
+
);
|
|
1454
|
+
}
|
|
1455
|
+
async function deleteOrderRefund(orderId, refundId, force = true) {
|
|
1456
|
+
return wcMutate(
|
|
1457
|
+
`/wp-json/wc/v3/orders/${orderId}/refunds/${refundId}`,
|
|
1458
|
+
{ force },
|
|
1459
|
+
"DELETE"
|
|
1460
|
+
);
|
|
1461
|
+
}
|
|
1462
|
+
return {
|
|
1463
|
+
getRefundsByOrderId,
|
|
1464
|
+
getOrderRefundById,
|
|
1465
|
+
createOrderRefund,
|
|
1466
|
+
deleteOrderRefund
|
|
1467
|
+
};
|
|
1468
|
+
}
|
|
1469
|
+
|
|
1470
|
+
// src/integrations/restApi/woocommerce/product_attributes/queries.ts
|
|
1471
|
+
function createProductAttributesQueries(fetcher) {
|
|
1472
|
+
const { wcFetch, wcFetchGraceful, wcMutate } = fetcher;
|
|
1473
|
+
async function getProductAttributes() {
|
|
1474
|
+
return wcFetchGraceful(
|
|
1475
|
+
"/wp-json/wc/v3/products/attributes",
|
|
1476
|
+
[],
|
|
1477
|
+
void 0,
|
|
1478
|
+
["woocommerce", "product_attributes"]
|
|
1479
|
+
);
|
|
1480
|
+
}
|
|
1481
|
+
async function getProductAttributeById(id) {
|
|
1482
|
+
return wcFetch(
|
|
1483
|
+
`/wp-json/wc/v3/products/attributes/${id}`,
|
|
1484
|
+
void 0,
|
|
1485
|
+
["woocommerce", "product_attributes", `attribute-${id}`]
|
|
1486
|
+
);
|
|
1487
|
+
}
|
|
1488
|
+
async function createProductAttribute(input) {
|
|
1489
|
+
return wcMutate("/wp-json/wc/v3/products/attributes", input, "POST");
|
|
1490
|
+
}
|
|
1491
|
+
async function updateProductAttribute(id, input) {
|
|
1492
|
+
return wcMutate(
|
|
1493
|
+
`/wp-json/wc/v3/products/attributes/${id}`,
|
|
1494
|
+
input,
|
|
1495
|
+
"PUT"
|
|
1496
|
+
);
|
|
1497
|
+
}
|
|
1498
|
+
async function deleteProductAttribute(id, force = true) {
|
|
1499
|
+
return wcMutate(
|
|
1500
|
+
`/wp-json/wc/v3/products/attributes/${id}`,
|
|
1501
|
+
{ force },
|
|
1502
|
+
"DELETE"
|
|
1503
|
+
);
|
|
1504
|
+
}
|
|
1505
|
+
async function getAttributeTerms(attributeId) {
|
|
1506
|
+
return wcFetchGraceful(
|
|
1507
|
+
`/wp-json/wc/v3/products/attributes/${attributeId}/terms`,
|
|
1508
|
+
[],
|
|
1509
|
+
void 0,
|
|
1510
|
+
["woocommerce", "attribute_terms", `attribute-${attributeId}-terms`]
|
|
1511
|
+
);
|
|
1512
|
+
}
|
|
1513
|
+
async function getAttributeTermById(attributeId, termId) {
|
|
1514
|
+
return wcFetch(
|
|
1515
|
+
`/wp-json/wc/v3/products/attributes/${attributeId}/terms/${termId}`,
|
|
1516
|
+
void 0,
|
|
1517
|
+
["woocommerce", "attribute_terms", `attribute-${attributeId}-term-${termId}`]
|
|
1518
|
+
);
|
|
1519
|
+
}
|
|
1520
|
+
async function createAttributeTerm(attributeId, input) {
|
|
1521
|
+
return wcMutate(
|
|
1522
|
+
`/wp-json/wc/v3/products/attributes/${attributeId}/terms`,
|
|
1523
|
+
input,
|
|
1524
|
+
"POST"
|
|
1525
|
+
);
|
|
1526
|
+
}
|
|
1527
|
+
async function updateAttributeTerm(attributeId, termId, input) {
|
|
1528
|
+
return wcMutate(
|
|
1529
|
+
`/wp-json/wc/v3/products/attributes/${attributeId}/terms/${termId}`,
|
|
1530
|
+
input,
|
|
1531
|
+
"PUT"
|
|
1532
|
+
);
|
|
1533
|
+
}
|
|
1534
|
+
async function deleteAttributeTerm(attributeId, termId, force = true) {
|
|
1535
|
+
return wcMutate(
|
|
1536
|
+
`/wp-json/wc/v3/products/attributes/${attributeId}/terms/${termId}`,
|
|
1537
|
+
{ force },
|
|
1538
|
+
"DELETE"
|
|
1539
|
+
);
|
|
1540
|
+
}
|
|
1541
|
+
return {
|
|
1542
|
+
getProductAttributes,
|
|
1543
|
+
getProductAttributeById,
|
|
1544
|
+
createProductAttribute,
|
|
1545
|
+
updateProductAttribute,
|
|
1546
|
+
deleteProductAttribute,
|
|
1547
|
+
getAttributeTerms,
|
|
1548
|
+
getAttributeTermById,
|
|
1549
|
+
createAttributeTerm,
|
|
1550
|
+
updateAttributeTerm,
|
|
1551
|
+
deleteAttributeTerm
|
|
1552
|
+
};
|
|
1553
|
+
}
|
|
1554
|
+
|
|
1555
|
+
// src/integrations/restApi/woocommerce/product_reviews/queries.ts
|
|
1556
|
+
function createProductReviewsQueries(fetcher) {
|
|
1557
|
+
const { wcFetch, wcFetchGraceful, wcMutate } = fetcher;
|
|
1558
|
+
async function getProductReviews(params) {
|
|
1559
|
+
return wcFetchGraceful(
|
|
1560
|
+
"/wp-json/wc/v3/products/reviews",
|
|
1561
|
+
[],
|
|
1562
|
+
params,
|
|
1563
|
+
["woocommerce", "product_reviews"]
|
|
1564
|
+
);
|
|
1565
|
+
}
|
|
1566
|
+
async function getProductReviewsByProductId(productId) {
|
|
1567
|
+
return wcFetchGraceful(
|
|
1568
|
+
"/wp-json/wc/v3/products/reviews",
|
|
1569
|
+
[],
|
|
1570
|
+
{ product: [productId] },
|
|
1571
|
+
["woocommerce", "product_reviews", `reviews-product-${productId}`]
|
|
1572
|
+
);
|
|
1573
|
+
}
|
|
1574
|
+
async function getProductReviewById(id) {
|
|
1575
|
+
return wcFetch(
|
|
1576
|
+
`/wp-json/wc/v3/products/reviews/${id}`,
|
|
1577
|
+
void 0,
|
|
1578
|
+
["woocommerce", "product_reviews", `review-${id}`]
|
|
1579
|
+
);
|
|
1580
|
+
}
|
|
1581
|
+
async function createProductReview(input) {
|
|
1582
|
+
return wcMutate("/wp-json/wc/v3/products/reviews", input, "POST");
|
|
1583
|
+
}
|
|
1584
|
+
async function updateProductReview(id, input) {
|
|
1585
|
+
return wcMutate(`/wp-json/wc/v3/products/reviews/${id}`, input, "PUT");
|
|
1586
|
+
}
|
|
1587
|
+
async function deleteProductReview(id, force = true) {
|
|
1588
|
+
return wcMutate(
|
|
1589
|
+
`/wp-json/wc/v3/products/reviews/${id}`,
|
|
1590
|
+
{ force },
|
|
1591
|
+
"DELETE"
|
|
1592
|
+
);
|
|
1593
|
+
}
|
|
1594
|
+
return {
|
|
1595
|
+
getProductReviews,
|
|
1596
|
+
getProductReviewsByProductId,
|
|
1597
|
+
getProductReviewById,
|
|
1598
|
+
createProductReview,
|
|
1599
|
+
updateProductReview,
|
|
1600
|
+
deleteProductReview
|
|
1601
|
+
};
|
|
1602
|
+
}
|
|
1603
|
+
|
|
1604
|
+
// src/integrations/restApi/woocommerce/shipping_classes/queries.ts
|
|
1605
|
+
function createShippingClassesQueries(fetcher) {
|
|
1606
|
+
const { wcFetch, wcFetchGraceful, wcMutate } = fetcher;
|
|
1607
|
+
async function getShippingClasses() {
|
|
1608
|
+
return wcFetchGraceful(
|
|
1609
|
+
"/wp-json/wc/v3/products/shipping_classes",
|
|
1610
|
+
[],
|
|
1611
|
+
void 0,
|
|
1612
|
+
["woocommerce", "shipping_classes"]
|
|
1613
|
+
);
|
|
1614
|
+
}
|
|
1615
|
+
async function getShippingClassById(id) {
|
|
1616
|
+
return wcFetch(
|
|
1617
|
+
`/wp-json/wc/v3/products/shipping_classes/${id}`,
|
|
1618
|
+
void 0,
|
|
1619
|
+
["woocommerce", "shipping_classes", `shipping-class-${id}`]
|
|
1620
|
+
);
|
|
1621
|
+
}
|
|
1622
|
+
async function createShippingClass(input) {
|
|
1623
|
+
return wcMutate("/wp-json/wc/v3/products/shipping_classes", input, "POST");
|
|
1624
|
+
}
|
|
1625
|
+
async function updateShippingClass(id, input) {
|
|
1626
|
+
return wcMutate(
|
|
1627
|
+
`/wp-json/wc/v3/products/shipping_classes/${id}`,
|
|
1628
|
+
input,
|
|
1629
|
+
"PUT"
|
|
1630
|
+
);
|
|
1631
|
+
}
|
|
1632
|
+
async function deleteShippingClass(id, force = true) {
|
|
1633
|
+
return wcMutate(
|
|
1634
|
+
`/wp-json/wc/v3/products/shipping_classes/${id}`,
|
|
1635
|
+
{ force },
|
|
1636
|
+
"DELETE"
|
|
1637
|
+
);
|
|
1638
|
+
}
|
|
1639
|
+
return {
|
|
1640
|
+
getShippingClasses,
|
|
1641
|
+
getShippingClassById,
|
|
1642
|
+
createShippingClass,
|
|
1643
|
+
updateShippingClass,
|
|
1644
|
+
deleteShippingClass
|
|
1645
|
+
};
|
|
1646
|
+
}
|
|
1647
|
+
|
|
1648
|
+
// src/integrations/restApi/woocommerce/taxes/queries.ts
|
|
1649
|
+
function createTaxesQueries(fetcher) {
|
|
1650
|
+
const { wcFetch, wcFetchGraceful, wcMutate } = fetcher;
|
|
1651
|
+
async function getTaxRates(params) {
|
|
1652
|
+
return wcFetchGraceful(
|
|
1653
|
+
"/wp-json/wc/v3/taxes",
|
|
1654
|
+
[],
|
|
1655
|
+
params,
|
|
1656
|
+
["woocommerce", "tax_rates"]
|
|
1657
|
+
);
|
|
1658
|
+
}
|
|
1659
|
+
async function getTaxRateById(id) {
|
|
1660
|
+
return wcFetch(
|
|
1661
|
+
`/wp-json/wc/v3/taxes/${id}`,
|
|
1662
|
+
void 0,
|
|
1663
|
+
["woocommerce", "tax_rates", `tax-rate-${id}`]
|
|
1664
|
+
);
|
|
1665
|
+
}
|
|
1666
|
+
async function createTaxRate(input) {
|
|
1667
|
+
return wcMutate("/wp-json/wc/v3/taxes", input, "POST");
|
|
1668
|
+
}
|
|
1669
|
+
async function updateTaxRate(id, input) {
|
|
1670
|
+
return wcMutate(`/wp-json/wc/v3/taxes/${id}`, input, "PUT");
|
|
1671
|
+
}
|
|
1672
|
+
async function deleteTaxRate(id, force = true) {
|
|
1673
|
+
return wcMutate(
|
|
1674
|
+
`/wp-json/wc/v3/taxes/${id}`,
|
|
1675
|
+
{ force },
|
|
1676
|
+
"DELETE"
|
|
1677
|
+
);
|
|
1678
|
+
}
|
|
1679
|
+
async function getTaxClasses() {
|
|
1680
|
+
return wcFetchGraceful(
|
|
1681
|
+
"/wp-json/wc/v3/taxes/classes",
|
|
1682
|
+
[],
|
|
1683
|
+
void 0,
|
|
1684
|
+
["woocommerce", "tax_classes"]
|
|
1685
|
+
);
|
|
1686
|
+
}
|
|
1687
|
+
async function createTaxClass(input) {
|
|
1688
|
+
return wcMutate("/wp-json/wc/v3/taxes/classes", input, "POST");
|
|
1689
|
+
}
|
|
1690
|
+
async function deleteTaxClass(slug, force = true) {
|
|
1691
|
+
return wcMutate(
|
|
1692
|
+
`/wp-json/wc/v3/taxes/classes/${slug}`,
|
|
1693
|
+
{ force },
|
|
1694
|
+
"DELETE"
|
|
1695
|
+
);
|
|
1696
|
+
}
|
|
1697
|
+
return {
|
|
1698
|
+
getTaxRates,
|
|
1699
|
+
getTaxRateById,
|
|
1700
|
+
createTaxRate,
|
|
1701
|
+
updateTaxRate,
|
|
1702
|
+
deleteTaxRate,
|
|
1703
|
+
getTaxClasses,
|
|
1704
|
+
createTaxClass,
|
|
1705
|
+
deleteTaxClass
|
|
1706
|
+
};
|
|
1707
|
+
}
|
|
1708
|
+
|
|
1709
|
+
// src/integrations/restApi/woocommerce/shipping/queries.ts
|
|
1710
|
+
function createShippingQueries(fetcher) {
|
|
1711
|
+
const { wcFetch, wcFetchGraceful, wcMutate } = fetcher;
|
|
1712
|
+
async function getShippingZones() {
|
|
1713
|
+
return wcFetchGraceful(
|
|
1714
|
+
"/wp-json/wc/v3/shipping/zones",
|
|
1715
|
+
[],
|
|
1716
|
+
void 0,
|
|
1717
|
+
["woocommerce", "shipping_zones"]
|
|
1718
|
+
);
|
|
1719
|
+
}
|
|
1720
|
+
async function getShippingZoneById(id) {
|
|
1721
|
+
return wcFetch(
|
|
1722
|
+
`/wp-json/wc/v3/shipping/zones/${id}`,
|
|
1723
|
+
void 0,
|
|
1724
|
+
["woocommerce", "shipping_zones", `zone-${id}`]
|
|
1725
|
+
);
|
|
1726
|
+
}
|
|
1727
|
+
async function createShippingZone(input) {
|
|
1728
|
+
return wcMutate("/wp-json/wc/v3/shipping/zones", input, "POST");
|
|
1729
|
+
}
|
|
1730
|
+
async function updateShippingZone(id, input) {
|
|
1731
|
+
return wcMutate(`/wp-json/wc/v3/shipping/zones/${id}`, input, "PUT");
|
|
1732
|
+
}
|
|
1733
|
+
async function deleteShippingZone(id, force = true) {
|
|
1734
|
+
return wcMutate(
|
|
1735
|
+
`/wp-json/wc/v3/shipping/zones/${id}`,
|
|
1736
|
+
{ force },
|
|
1737
|
+
"DELETE"
|
|
1738
|
+
);
|
|
1739
|
+
}
|
|
1740
|
+
async function getShippingZoneLocations(zoneId) {
|
|
1741
|
+
return wcFetchGraceful(
|
|
1742
|
+
`/wp-json/wc/v3/shipping/zones/${zoneId}/locations`,
|
|
1743
|
+
[],
|
|
1744
|
+
void 0,
|
|
1745
|
+
["woocommerce", "shipping_zone_locations", `zone-${zoneId}-locations`]
|
|
1746
|
+
);
|
|
1747
|
+
}
|
|
1748
|
+
async function updateShippingZoneLocations(zoneId, locations) {
|
|
1749
|
+
return wcMutate(
|
|
1750
|
+
`/wp-json/wc/v3/shipping/zones/${zoneId}/locations`,
|
|
1751
|
+
locations,
|
|
1752
|
+
"PUT"
|
|
1753
|
+
);
|
|
1754
|
+
}
|
|
1755
|
+
async function getShippingZoneMethods(zoneId) {
|
|
1756
|
+
return wcFetchGraceful(
|
|
1757
|
+
`/wp-json/wc/v3/shipping/zones/${zoneId}/methods`,
|
|
1758
|
+
[],
|
|
1759
|
+
void 0,
|
|
1760
|
+
["woocommerce", "shipping_zone_methods", `zone-${zoneId}-methods`]
|
|
1761
|
+
);
|
|
1762
|
+
}
|
|
1763
|
+
async function getShippingZoneMethodById(zoneId, instanceId) {
|
|
1764
|
+
return wcFetch(
|
|
1765
|
+
`/wp-json/wc/v3/shipping/zones/${zoneId}/methods/${instanceId}`,
|
|
1766
|
+
void 0,
|
|
1767
|
+
["woocommerce", "shipping_zone_methods", `zone-${zoneId}-method-${instanceId}`]
|
|
1768
|
+
);
|
|
1769
|
+
}
|
|
1770
|
+
async function createShippingZoneMethod(zoneId, input) {
|
|
1771
|
+
return wcMutate(
|
|
1772
|
+
`/wp-json/wc/v3/shipping/zones/${zoneId}/methods`,
|
|
1773
|
+
input,
|
|
1774
|
+
"POST"
|
|
1775
|
+
);
|
|
1776
|
+
}
|
|
1777
|
+
async function updateShippingZoneMethod(zoneId, instanceId, input) {
|
|
1778
|
+
return wcMutate(
|
|
1779
|
+
`/wp-json/wc/v3/shipping/zones/${zoneId}/methods/${instanceId}`,
|
|
1780
|
+
input,
|
|
1781
|
+
"PUT"
|
|
1782
|
+
);
|
|
1783
|
+
}
|
|
1784
|
+
async function deleteShippingZoneMethod(zoneId, instanceId, force = true) {
|
|
1785
|
+
return wcMutate(
|
|
1786
|
+
`/wp-json/wc/v3/shipping/zones/${zoneId}/methods/${instanceId}`,
|
|
1787
|
+
{ force },
|
|
1788
|
+
"DELETE"
|
|
1789
|
+
);
|
|
1790
|
+
}
|
|
1791
|
+
async function getShippingMethods() {
|
|
1792
|
+
return wcFetchGraceful(
|
|
1793
|
+
"/wp-json/wc/v3/shipping_methods",
|
|
1794
|
+
[],
|
|
1795
|
+
void 0,
|
|
1796
|
+
["woocommerce", "shipping_methods"]
|
|
1797
|
+
);
|
|
1798
|
+
}
|
|
1799
|
+
async function getShippingMethodById(id) {
|
|
1800
|
+
return wcFetch(
|
|
1801
|
+
`/wp-json/wc/v3/shipping_methods/${id}`,
|
|
1802
|
+
void 0,
|
|
1803
|
+
["woocommerce", "shipping_methods", `shipping-method-${id}`]
|
|
1804
|
+
);
|
|
1805
|
+
}
|
|
1806
|
+
return {
|
|
1807
|
+
getShippingZones,
|
|
1808
|
+
getShippingZoneById,
|
|
1809
|
+
createShippingZone,
|
|
1810
|
+
updateShippingZone,
|
|
1811
|
+
deleteShippingZone,
|
|
1812
|
+
getShippingZoneLocations,
|
|
1813
|
+
updateShippingZoneLocations,
|
|
1814
|
+
getShippingZoneMethods,
|
|
1815
|
+
getShippingZoneMethodById,
|
|
1816
|
+
createShippingZoneMethod,
|
|
1817
|
+
updateShippingZoneMethod,
|
|
1818
|
+
deleteShippingZoneMethod,
|
|
1819
|
+
getShippingMethods,
|
|
1820
|
+
getShippingMethodById
|
|
1821
|
+
};
|
|
1822
|
+
}
|
|
1823
|
+
|
|
1824
|
+
// src/integrations/restApi/woocommerce/webhooks/queries.ts
|
|
1825
|
+
function createWebhooksQueries(fetcher) {
|
|
1826
|
+
const { wcFetch, wcFetchGraceful, wcMutate } = fetcher;
|
|
1827
|
+
async function getWebhooks(params) {
|
|
1828
|
+
return wcFetchGraceful(
|
|
1829
|
+
"/wp-json/wc/v3/webhooks",
|
|
1830
|
+
[],
|
|
1831
|
+
params,
|
|
1832
|
+
["woocommerce", "webhooks"]
|
|
1833
|
+
);
|
|
1834
|
+
}
|
|
1835
|
+
async function getWebhookById(id) {
|
|
1836
|
+
return wcFetch(
|
|
1837
|
+
`/wp-json/wc/v3/webhooks/${id}`,
|
|
1838
|
+
void 0,
|
|
1839
|
+
["woocommerce", "webhooks", `webhook-${id}`]
|
|
1840
|
+
);
|
|
1841
|
+
}
|
|
1842
|
+
async function createWebhook(input) {
|
|
1843
|
+
return wcMutate("/wp-json/wc/v3/webhooks", input, "POST");
|
|
1844
|
+
}
|
|
1845
|
+
async function updateWebhook(id, input) {
|
|
1846
|
+
return wcMutate(`/wp-json/wc/v3/webhooks/${id}`, input, "PUT");
|
|
1847
|
+
}
|
|
1848
|
+
async function deleteWebhook(id, force = true) {
|
|
1849
|
+
return wcMutate(
|
|
1850
|
+
`/wp-json/wc/v3/webhooks/${id}`,
|
|
1851
|
+
{ force },
|
|
1852
|
+
"DELETE"
|
|
1853
|
+
);
|
|
1854
|
+
}
|
|
1855
|
+
return {
|
|
1856
|
+
getWebhooks,
|
|
1857
|
+
getWebhookById,
|
|
1858
|
+
createWebhook,
|
|
1859
|
+
updateWebhook,
|
|
1860
|
+
deleteWebhook
|
|
1861
|
+
};
|
|
1862
|
+
}
|
|
1863
|
+
|
|
1864
|
+
// src/integrations/restApi/woocommerce/settings/queries.ts
|
|
1865
|
+
function createSettingsQueries(fetcher) {
|
|
1866
|
+
const { wcFetch, wcFetchGraceful, wcMutate } = fetcher;
|
|
1867
|
+
async function getSettingGroups() {
|
|
1868
|
+
return wcFetchGraceful(
|
|
1869
|
+
"/wp-json/wc/v3/settings",
|
|
1870
|
+
[],
|
|
1871
|
+
void 0,
|
|
1872
|
+
["woocommerce", "settings"]
|
|
1873
|
+
);
|
|
1874
|
+
}
|
|
1875
|
+
async function getSettingOptions(groupId) {
|
|
1876
|
+
return wcFetchGraceful(
|
|
1877
|
+
`/wp-json/wc/v3/settings/${groupId}`,
|
|
1878
|
+
[],
|
|
1879
|
+
void 0,
|
|
1880
|
+
["woocommerce", "settings", `settings-${groupId}`]
|
|
1881
|
+
);
|
|
1882
|
+
}
|
|
1883
|
+
async function getSettingOption(groupId, optionId) {
|
|
1884
|
+
return wcFetch(
|
|
1885
|
+
`/wp-json/wc/v3/settings/${groupId}/${optionId}`,
|
|
1886
|
+
void 0,
|
|
1887
|
+
["woocommerce", "settings", `settings-${groupId}-${optionId}`]
|
|
1888
|
+
);
|
|
1889
|
+
}
|
|
1890
|
+
async function updateSettingOption(groupId, optionId, value) {
|
|
1891
|
+
return wcMutate(
|
|
1892
|
+
`/wp-json/wc/v3/settings/${groupId}/${optionId}`,
|
|
1893
|
+
{ value },
|
|
1894
|
+
"PUT"
|
|
1895
|
+
);
|
|
1896
|
+
}
|
|
1897
|
+
return {
|
|
1898
|
+
getSettingGroups,
|
|
1899
|
+
getSettingOptions,
|
|
1900
|
+
getSettingOption,
|
|
1901
|
+
updateSettingOption
|
|
1902
|
+
};
|
|
1903
|
+
}
|
|
1904
|
+
|
|
1905
|
+
// src/integrations/restApi/woocommerce/reports/queries.ts
|
|
1906
|
+
function createReportsQueries(fetcher) {
|
|
1907
|
+
const { wcFetchGraceful } = fetcher;
|
|
1908
|
+
async function getSalesReport(params) {
|
|
1909
|
+
return wcFetchGraceful(
|
|
1910
|
+
"/wp-json/wc/v3/reports/sales",
|
|
1911
|
+
[],
|
|
1912
|
+
params,
|
|
1913
|
+
["woocommerce", "reports", "sales"]
|
|
1914
|
+
);
|
|
1915
|
+
}
|
|
1916
|
+
async function getTopSellers(params) {
|
|
1917
|
+
return wcFetchGraceful(
|
|
1918
|
+
"/wp-json/wc/v3/reports/top_sellers",
|
|
1919
|
+
[],
|
|
1920
|
+
params,
|
|
1921
|
+
["woocommerce", "reports", "top_sellers"]
|
|
1922
|
+
);
|
|
1923
|
+
}
|
|
1924
|
+
async function getOrdersTotals() {
|
|
1925
|
+
return wcFetchGraceful(
|
|
1926
|
+
"/wp-json/wc/v3/reports/orders/totals",
|
|
1927
|
+
[],
|
|
1928
|
+
void 0,
|
|
1929
|
+
["woocommerce", "reports", "orders_totals"]
|
|
1930
|
+
);
|
|
1931
|
+
}
|
|
1932
|
+
async function getProductsTotals() {
|
|
1933
|
+
return wcFetchGraceful(
|
|
1934
|
+
"/wp-json/wc/v3/reports/products/totals",
|
|
1935
|
+
[],
|
|
1936
|
+
void 0,
|
|
1937
|
+
["woocommerce", "reports", "products_totals"]
|
|
1938
|
+
);
|
|
1939
|
+
}
|
|
1940
|
+
async function getCustomersTotals() {
|
|
1941
|
+
return wcFetchGraceful(
|
|
1942
|
+
"/wp-json/wc/v3/reports/customers/totals",
|
|
1943
|
+
[],
|
|
1944
|
+
void 0,
|
|
1945
|
+
["woocommerce", "reports", "customers_totals"]
|
|
1946
|
+
);
|
|
1947
|
+
}
|
|
1948
|
+
async function getCouponsTotals() {
|
|
1949
|
+
return wcFetchGraceful(
|
|
1950
|
+
"/wp-json/wc/v3/reports/coupons/totals",
|
|
1951
|
+
[],
|
|
1952
|
+
void 0,
|
|
1953
|
+
["woocommerce", "reports", "coupons_totals"]
|
|
1954
|
+
);
|
|
1955
|
+
}
|
|
1956
|
+
async function getReviewsTotals() {
|
|
1957
|
+
return wcFetchGraceful(
|
|
1958
|
+
"/wp-json/wc/v3/reports/reviews/totals",
|
|
1959
|
+
[],
|
|
1960
|
+
void 0,
|
|
1961
|
+
["woocommerce", "reports", "reviews_totals"]
|
|
1962
|
+
);
|
|
1963
|
+
}
|
|
1964
|
+
return {
|
|
1965
|
+
getSalesReport,
|
|
1966
|
+
getTopSellers,
|
|
1967
|
+
getOrdersTotals,
|
|
1968
|
+
getProductsTotals,
|
|
1969
|
+
getCustomersTotals,
|
|
1970
|
+
getCouponsTotals,
|
|
1971
|
+
getReviewsTotals
|
|
1972
|
+
};
|
|
1973
|
+
}
|
|
1974
|
+
|
|
1975
|
+
// src/integrations/restApi/woocommerce/data/queries.ts
|
|
1976
|
+
function createDataQueries(fetcher) {
|
|
1977
|
+
const { wcFetch, wcFetchGraceful, wcMutate } = fetcher;
|
|
1978
|
+
async function getCurrencies() {
|
|
1979
|
+
return wcFetchGraceful(
|
|
1980
|
+
"/wp-json/wc/v3/data/currencies",
|
|
1981
|
+
[],
|
|
1982
|
+
void 0,
|
|
1983
|
+
["woocommerce", "data", "currencies"]
|
|
1984
|
+
);
|
|
1985
|
+
}
|
|
1986
|
+
async function getCurrentCurrency() {
|
|
1987
|
+
return wcFetch(
|
|
1988
|
+
"/wp-json/wc/v3/data/currencies/current",
|
|
1989
|
+
void 0,
|
|
1990
|
+
["woocommerce", "data", "currency_current"]
|
|
1991
|
+
);
|
|
1992
|
+
}
|
|
1993
|
+
async function getCurrencyByCode(code) {
|
|
1994
|
+
return wcFetch(
|
|
1995
|
+
`/wp-json/wc/v3/data/currencies/${code.toUpperCase()}`,
|
|
1996
|
+
void 0,
|
|
1997
|
+
["woocommerce", "data", `currency-${code}`]
|
|
1998
|
+
);
|
|
1999
|
+
}
|
|
2000
|
+
async function getContinents() {
|
|
2001
|
+
return wcFetchGraceful(
|
|
2002
|
+
"/wp-json/wc/v3/data/continents",
|
|
2003
|
+
[],
|
|
2004
|
+
void 0,
|
|
2005
|
+
["woocommerce", "data", "continents"]
|
|
2006
|
+
);
|
|
2007
|
+
}
|
|
2008
|
+
async function getContinentByCode(code) {
|
|
2009
|
+
return wcFetch(
|
|
2010
|
+
`/wp-json/wc/v3/data/continents/${code.toUpperCase()}`,
|
|
2011
|
+
void 0,
|
|
2012
|
+
["woocommerce", "data", `continent-${code}`]
|
|
2013
|
+
);
|
|
2014
|
+
}
|
|
2015
|
+
async function getCountries() {
|
|
2016
|
+
return wcFetchGraceful(
|
|
2017
|
+
"/wp-json/wc/v3/data/countries",
|
|
2018
|
+
[],
|
|
2019
|
+
void 0,
|
|
2020
|
+
["woocommerce", "data", "countries"]
|
|
2021
|
+
);
|
|
2022
|
+
}
|
|
2023
|
+
async function getCountryByCode(code) {
|
|
2024
|
+
return wcFetch(
|
|
2025
|
+
`/wp-json/wc/v3/data/countries/${code.toUpperCase()}`,
|
|
2026
|
+
void 0,
|
|
2027
|
+
["woocommerce", "data", `country-${code}`]
|
|
2028
|
+
);
|
|
2029
|
+
}
|
|
2030
|
+
async function getTimeZones() {
|
|
2031
|
+
return wcFetchGraceful(
|
|
2032
|
+
"/wp-json/wc/v3/data/time_zones",
|
|
2033
|
+
{},
|
|
2034
|
+
void 0,
|
|
2035
|
+
["woocommerce", "data", "time_zones"]
|
|
2036
|
+
);
|
|
2037
|
+
}
|
|
2038
|
+
async function getSystemStatus() {
|
|
2039
|
+
return wcFetch(
|
|
2040
|
+
"/wp-json/wc/v3/system_status",
|
|
2041
|
+
void 0,
|
|
2042
|
+
["woocommerce", "system_status"]
|
|
2043
|
+
);
|
|
2044
|
+
}
|
|
2045
|
+
async function getSystemStatusTools() {
|
|
2046
|
+
return wcFetchGraceful(
|
|
2047
|
+
"/wp-json/wc/v3/system_status/tools",
|
|
2048
|
+
[],
|
|
2049
|
+
void 0,
|
|
2050
|
+
["woocommerce", "system_status_tools"]
|
|
2051
|
+
);
|
|
2052
|
+
}
|
|
2053
|
+
async function runSystemStatusTool(toolId) {
|
|
2054
|
+
return wcMutate(
|
|
2055
|
+
`/wp-json/wc/v3/system_status/tools/${toolId}`,
|
|
2056
|
+
{},
|
|
2057
|
+
"PUT"
|
|
2058
|
+
);
|
|
2059
|
+
}
|
|
2060
|
+
return {
|
|
2061
|
+
getCurrencies,
|
|
2062
|
+
getCurrentCurrency,
|
|
2063
|
+
getCurrencyByCode,
|
|
2064
|
+
getContinents,
|
|
2065
|
+
getContinentByCode,
|
|
2066
|
+
getCountries,
|
|
2067
|
+
getCountryByCode,
|
|
2068
|
+
getTimeZones,
|
|
2069
|
+
getSystemStatus,
|
|
2070
|
+
getSystemStatusTools,
|
|
2071
|
+
runSystemStatusTool
|
|
2072
|
+
};
|
|
2073
|
+
}
|
|
2074
|
+
|
|
2075
|
+
// src/integrations/restApi/woocommerce/index.ts
|
|
2076
|
+
function createWooCommerceClient(config) {
|
|
2077
|
+
const fetcher = createWooCommerceFetcher(config);
|
|
2078
|
+
return {
|
|
2079
|
+
...createProductsQueries(fetcher),
|
|
2080
|
+
...createProductsMutations(fetcher),
|
|
2081
|
+
...createCategoriesQueries2(fetcher),
|
|
2082
|
+
...createCategoriesMutations2(fetcher),
|
|
2083
|
+
...createTagsQueries2(fetcher),
|
|
2084
|
+
...createTagsMutations2(fetcher),
|
|
2085
|
+
...createOrdersQueries(fetcher),
|
|
2086
|
+
...createOrderNotesQueries(fetcher),
|
|
2087
|
+
...createOrderRefundsQueries(fetcher),
|
|
2088
|
+
...createProductAttributesQueries(fetcher),
|
|
2089
|
+
...createProductReviewsQueries(fetcher),
|
|
2090
|
+
...createShippingClassesQueries(fetcher),
|
|
2091
|
+
...createTaxesQueries(fetcher),
|
|
2092
|
+
...createShippingQueries(fetcher),
|
|
2093
|
+
...createWebhooksQueries(fetcher),
|
|
2094
|
+
...createSettingsQueries(fetcher),
|
|
2095
|
+
...createReportsQueries(fetcher),
|
|
2096
|
+
...createDataQueries(fetcher),
|
|
2097
|
+
...createCouponsQueries(fetcher),
|
|
2098
|
+
...createCouponsMutations(fetcher),
|
|
2099
|
+
...createCustomersQueries(fetcher),
|
|
2100
|
+
...createPaymentGatewaysQueries(fetcher)
|
|
2101
|
+
};
|
|
2102
|
+
}
|
|
2103
|
+
|
|
2104
|
+
// src/integrations/wpGraphQL/client/types.ts
|
|
2105
|
+
var WPGraphQLError = class extends Error {
|
|
2106
|
+
constructor(code, status, endpoint, message, gqlErrors) {
|
|
2107
|
+
super(message);
|
|
2108
|
+
__publicField(this, "code", code);
|
|
2109
|
+
__publicField(this, "status", status);
|
|
2110
|
+
__publicField(this, "endpoint", endpoint);
|
|
2111
|
+
__publicField(this, "gqlErrors", gqlErrors);
|
|
2112
|
+
this.name = "WPGraphQLError";
|
|
2113
|
+
}
|
|
2114
|
+
};
|
|
2115
|
+
|
|
2116
|
+
// src/integrations/wpGraphQL/client/fetcher.ts
|
|
2117
|
+
var USER_AGENT3 = "NextWordpress WPGraphQL Client";
|
|
2118
|
+
function createWPGraphQLFetcher(config) {
|
|
2119
|
+
const url = `${resolveBaseUrl(config)}/graphql`;
|
|
2120
|
+
const cacheTTL = config.cacheTTL ?? 300;
|
|
2121
|
+
async function gqlFetch(document, variables, tags = ["wpgraphql"]) {
|
|
2122
|
+
const response = await fetch(url, {
|
|
2123
|
+
method: "POST",
|
|
2124
|
+
headers: {
|
|
2125
|
+
"Content-Type": "application/json",
|
|
2126
|
+
"User-Agent": USER_AGENT3
|
|
2127
|
+
},
|
|
2128
|
+
body: JSON.stringify({ query: document, variables }),
|
|
2129
|
+
next: { tags, revalidate: cacheTTL }
|
|
2130
|
+
});
|
|
2131
|
+
if (!response.ok) {
|
|
2132
|
+
throw new WPGraphQLError(
|
|
2133
|
+
ErrorCode.GQL_REQUEST_FAILED,
|
|
2134
|
+
response.status,
|
|
2135
|
+
url,
|
|
2136
|
+
resolveMessage(ErrorCode.GQL_REQUEST_FAILED, config.errorMessages)
|
|
2137
|
+
);
|
|
2138
|
+
}
|
|
2139
|
+
const parsed = await response.json();
|
|
2140
|
+
if (parsed.errors && parsed.errors.length > 0) {
|
|
2141
|
+
throw new WPGraphQLError(
|
|
2142
|
+
ErrorCode.GQL_ERRORS_IN_RESPONSE,
|
|
2143
|
+
200,
|
|
2144
|
+
url,
|
|
2145
|
+
resolveMessage(ErrorCode.GQL_ERRORS_IN_RESPONSE, config.errorMessages),
|
|
2146
|
+
parsed.errors
|
|
2147
|
+
);
|
|
2148
|
+
}
|
|
2149
|
+
if (parsed.data === void 0) {
|
|
2150
|
+
throw new WPGraphQLError(
|
|
2151
|
+
ErrorCode.GQL_NO_DATA,
|
|
2152
|
+
200,
|
|
2153
|
+
url,
|
|
2154
|
+
resolveMessage(ErrorCode.GQL_NO_DATA, config.errorMessages)
|
|
2155
|
+
);
|
|
2156
|
+
}
|
|
2157
|
+
return parsed.data;
|
|
2158
|
+
}
|
|
2159
|
+
async function gqlFetchGraceful(document, fallback, variables, tags = ["wpgraphql"]) {
|
|
2160
|
+
try {
|
|
2161
|
+
return await gqlFetch(document, variables, tags);
|
|
2162
|
+
} catch {
|
|
2163
|
+
console.warn(`WPGraphQL fetch failed for query`);
|
|
2164
|
+
return fallback;
|
|
2165
|
+
}
|
|
2166
|
+
}
|
|
2167
|
+
async function gqlMutate(document, variables, authToken) {
|
|
2168
|
+
const headers = {
|
|
2169
|
+
"Content-Type": "application/json",
|
|
2170
|
+
"User-Agent": USER_AGENT3
|
|
2171
|
+
};
|
|
2172
|
+
if (authToken) {
|
|
2173
|
+
headers["Authorization"] = authToken;
|
|
2174
|
+
}
|
|
2175
|
+
const response = await fetch(url, {
|
|
2176
|
+
method: "POST",
|
|
2177
|
+
headers,
|
|
2178
|
+
body: JSON.stringify({ query: document, variables }),
|
|
2179
|
+
cache: "no-store"
|
|
2180
|
+
});
|
|
2181
|
+
if (!response.ok) {
|
|
2182
|
+
throw new WPGraphQLError(
|
|
2183
|
+
ErrorCode.GQL_REQUEST_FAILED,
|
|
2184
|
+
response.status,
|
|
2185
|
+
url,
|
|
2186
|
+
resolveMessage(ErrorCode.GQL_REQUEST_FAILED, config.errorMessages)
|
|
2187
|
+
);
|
|
2188
|
+
}
|
|
2189
|
+
const parsed = await response.json();
|
|
2190
|
+
if (parsed.errors && parsed.errors.length > 0) {
|
|
2191
|
+
throw new WPGraphQLError(
|
|
2192
|
+
ErrorCode.GQL_ERRORS_IN_RESPONSE,
|
|
2193
|
+
200,
|
|
2194
|
+
url,
|
|
2195
|
+
resolveMessage(ErrorCode.GQL_ERRORS_IN_RESPONSE, config.errorMessages),
|
|
2196
|
+
parsed.errors
|
|
2197
|
+
);
|
|
2198
|
+
}
|
|
2199
|
+
if (parsed.data === void 0) {
|
|
2200
|
+
throw new WPGraphQLError(
|
|
2201
|
+
ErrorCode.GQL_NO_DATA,
|
|
2202
|
+
200,
|
|
2203
|
+
url,
|
|
2204
|
+
resolveMessage(ErrorCode.GQL_NO_DATA, config.errorMessages)
|
|
2205
|
+
);
|
|
2206
|
+
}
|
|
2207
|
+
return parsed.data;
|
|
2208
|
+
}
|
|
2209
|
+
return { gqlFetch, gqlFetchGraceful, gqlMutate };
|
|
2210
|
+
}
|
|
2211
|
+
|
|
2212
|
+
// src/integrations/wpGraphQL/core/posts/queries.ts
|
|
2213
|
+
var DEFAULT_FIRST = 10;
|
|
2214
|
+
var BATCH_FIRST = 100;
|
|
2215
|
+
var POST_FIELDS = `
|
|
2216
|
+
id
|
|
2217
|
+
databaseId
|
|
2218
|
+
slug
|
|
2219
|
+
title
|
|
2220
|
+
excerpt
|
|
2221
|
+
date
|
|
2222
|
+
modified
|
|
2223
|
+
status
|
|
2224
|
+
uri
|
|
2225
|
+
author {
|
|
2226
|
+
node {
|
|
2227
|
+
databaseId
|
|
2228
|
+
name
|
|
2229
|
+
slug
|
|
2230
|
+
avatar { url }
|
|
2231
|
+
}
|
|
2232
|
+
}
|
|
2233
|
+
featuredImage {
|
|
2234
|
+
node {
|
|
2235
|
+
sourceUrl
|
|
2236
|
+
altText
|
|
2237
|
+
mediaDetails { width height }
|
|
2238
|
+
}
|
|
2239
|
+
}
|
|
2240
|
+
categories {
|
|
2241
|
+
nodes { databaseId name slug }
|
|
2242
|
+
}
|
|
2243
|
+
tags {
|
|
2244
|
+
nodes { databaseId name slug }
|
|
2245
|
+
}
|
|
2246
|
+
`;
|
|
2247
|
+
var POST_FIELDS_WITH_CONTENT = `
|
|
2248
|
+
${POST_FIELDS}
|
|
2249
|
+
content
|
|
2250
|
+
`;
|
|
2251
|
+
var GQL_GET_POSTS = `
|
|
2252
|
+
query GetPosts($first: Int, $after: String, $where: RootQueryToPostConnectionWhereArgs) {
|
|
2253
|
+
posts(first: $first, after: $after, where: $where) {
|
|
2254
|
+
nodes { ${POST_FIELDS} }
|
|
2255
|
+
pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
|
|
2256
|
+
}
|
|
2257
|
+
}
|
|
2258
|
+
`;
|
|
2259
|
+
var GQL_GET_POST_BY_SLUG = `
|
|
2260
|
+
query GetPostBySlug($slug: ID!) {
|
|
2261
|
+
post(id: $slug, idType: SLUG) { ${POST_FIELDS_WITH_CONTENT} }
|
|
2262
|
+
}
|
|
2263
|
+
`;
|
|
2264
|
+
var GQL_GET_POST_BY_DATABASE_ID = `
|
|
2265
|
+
query GetPostByDatabaseId($id: ID!) {
|
|
2266
|
+
post(id: $id, idType: DATABASE_ID) { ${POST_FIELDS_WITH_CONTENT} }
|
|
2267
|
+
}
|
|
2268
|
+
`;
|
|
2269
|
+
var GQL_GET_ALL_POST_SLUGS = `
|
|
2270
|
+
query GetAllPostSlugs($first: Int, $after: String) {
|
|
2271
|
+
posts(first: $first, after: $after) {
|
|
2272
|
+
nodes { slug }
|
|
2273
|
+
pageInfo { hasNextPage endCursor }
|
|
2274
|
+
}
|
|
2275
|
+
}
|
|
2276
|
+
`;
|
|
2277
|
+
var GQL_GET_ALL_POSTS_FOR_SITEMAP = `
|
|
2278
|
+
query GetAllPostsForSitemap($first: Int, $after: String) {
|
|
2279
|
+
posts(first: $first, after: $after) {
|
|
2280
|
+
nodes { slug modified }
|
|
2281
|
+
pageInfo { hasNextPage endCursor }
|
|
2282
|
+
}
|
|
2283
|
+
}
|
|
2284
|
+
`;
|
|
2285
|
+
function createPostsQueries2(fetcher) {
|
|
2286
|
+
const { gqlFetch, gqlFetchGraceful } = fetcher;
|
|
2287
|
+
async function getPosts(first = DEFAULT_FIRST, after, filter) {
|
|
2288
|
+
const where = {};
|
|
2289
|
+
if (filter?.authorName) where["authorName"] = filter.authorName;
|
|
2290
|
+
if (filter?.categoryName) where["categoryName"] = filter.categoryName;
|
|
2291
|
+
if (filter?.tag) where["tag"] = filter.tag;
|
|
2292
|
+
if (filter?.search) where["search"] = filter.search;
|
|
2293
|
+
if (filter?.status) where["status"] = filter.status;
|
|
2294
|
+
const data = await gqlFetchGraceful(
|
|
2295
|
+
GQL_GET_POSTS,
|
|
2296
|
+
{ posts: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
|
|
2297
|
+
{ first, after, where: Object.keys(where).length > 0 ? where : void 0 },
|
|
2298
|
+
["wpgraphql", "gql-posts"]
|
|
2299
|
+
);
|
|
2300
|
+
return data.posts;
|
|
2301
|
+
}
|
|
2302
|
+
async function getPostBySlug(slug) {
|
|
2303
|
+
const data = await gqlFetchGraceful(
|
|
2304
|
+
GQL_GET_POST_BY_SLUG,
|
|
2305
|
+
{ post: null },
|
|
2306
|
+
{ slug },
|
|
2307
|
+
["wpgraphql", "gql-posts", `gql-post-${slug}`]
|
|
2308
|
+
);
|
|
2309
|
+
return data.post;
|
|
2310
|
+
}
|
|
2311
|
+
async function getPostByDatabaseId(id) {
|
|
2312
|
+
const data = await gqlFetchGraceful(
|
|
2313
|
+
GQL_GET_POST_BY_DATABASE_ID,
|
|
2314
|
+
{ post: null },
|
|
2315
|
+
{ id: String(id) },
|
|
2316
|
+
["wpgraphql", "gql-posts", `gql-post-id-${id}`]
|
|
2317
|
+
);
|
|
2318
|
+
return data.post;
|
|
2319
|
+
}
|
|
2320
|
+
async function getRecentPosts(first = DEFAULT_FIRST) {
|
|
2321
|
+
const connection = await getPosts(first);
|
|
2322
|
+
return connection.nodes;
|
|
2323
|
+
}
|
|
2324
|
+
async function getAllPostSlugs() {
|
|
2325
|
+
try {
|
|
2326
|
+
const all = [];
|
|
2327
|
+
let after = void 0;
|
|
2328
|
+
let hasNextPage = true;
|
|
2329
|
+
while (hasNextPage) {
|
|
2330
|
+
const data = await gqlFetch(GQL_GET_ALL_POST_SLUGS, { first: BATCH_FIRST, after }, ["wpgraphql"]);
|
|
2331
|
+
all.push(...data.posts.nodes);
|
|
2332
|
+
hasNextPage = data.posts.pageInfo.hasNextPage;
|
|
2333
|
+
after = data.posts.pageInfo.endCursor;
|
|
2334
|
+
}
|
|
2335
|
+
return all;
|
|
2336
|
+
} catch {
|
|
2337
|
+
console.warn("WPGraphQL unavailable, skipping static generation for posts");
|
|
2338
|
+
return [];
|
|
2339
|
+
}
|
|
2340
|
+
}
|
|
2341
|
+
async function getAllPostsForSitemap() {
|
|
2342
|
+
try {
|
|
2343
|
+
const all = [];
|
|
2344
|
+
let after = void 0;
|
|
2345
|
+
let hasNextPage = true;
|
|
2346
|
+
while (hasNextPage) {
|
|
2347
|
+
const data = await gqlFetch(
|
|
2348
|
+
GQL_GET_ALL_POSTS_FOR_SITEMAP,
|
|
2349
|
+
{ first: BATCH_FIRST, after },
|
|
2350
|
+
["wpgraphql"]
|
|
2351
|
+
);
|
|
2352
|
+
all.push(...data.posts.nodes);
|
|
2353
|
+
hasNextPage = data.posts.pageInfo.hasNextPage;
|
|
2354
|
+
after = data.posts.pageInfo.endCursor;
|
|
2355
|
+
}
|
|
2356
|
+
return all;
|
|
2357
|
+
} catch {
|
|
2358
|
+
console.warn("WPGraphQL unavailable, skipping sitemap generation");
|
|
2359
|
+
return [];
|
|
2360
|
+
}
|
|
2361
|
+
}
|
|
2362
|
+
return {
|
|
2363
|
+
getPosts,
|
|
2364
|
+
getPostBySlug,
|
|
2365
|
+
getPostByDatabaseId,
|
|
2366
|
+
getRecentPosts,
|
|
2367
|
+
getAllPostSlugs,
|
|
2368
|
+
getAllPostsForSitemap
|
|
2369
|
+
};
|
|
2370
|
+
}
|
|
2371
|
+
|
|
2372
|
+
// src/integrations/wpGraphQL/core/pages/queries.ts
|
|
2373
|
+
var DEFAULT_FIRST2 = 10;
|
|
2374
|
+
var BATCH_FIRST2 = 100;
|
|
2375
|
+
var PAGE_FIELDS = `
|
|
2376
|
+
id
|
|
2377
|
+
databaseId
|
|
2378
|
+
slug
|
|
2379
|
+
title
|
|
2380
|
+
content
|
|
2381
|
+
date
|
|
2382
|
+
modified
|
|
2383
|
+
status
|
|
2384
|
+
uri
|
|
2385
|
+
featuredImage {
|
|
2386
|
+
node {
|
|
2387
|
+
sourceUrl
|
|
2388
|
+
altText
|
|
2389
|
+
mediaDetails { width height }
|
|
2390
|
+
}
|
|
2391
|
+
}
|
|
2392
|
+
`;
|
|
2393
|
+
var GQL_GET_PAGES = `
|
|
2394
|
+
query GetPages($first: Int, $after: String) {
|
|
2395
|
+
pages(first: $first, after: $after) {
|
|
2396
|
+
nodes { ${PAGE_FIELDS} }
|
|
2397
|
+
pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
|
|
2398
|
+
}
|
|
2399
|
+
}
|
|
2400
|
+
`;
|
|
2401
|
+
var GQL_GET_PAGE_BY_SLUG = `
|
|
2402
|
+
query GetPageBySlug($uri: ID!) {
|
|
2403
|
+
page(id: $uri, idType: URI) { ${PAGE_FIELDS} }
|
|
2404
|
+
}
|
|
2405
|
+
`;
|
|
2406
|
+
var GQL_GET_PAGE_BY_URI = `
|
|
2407
|
+
query GetPageByUri($uri: ID!) {
|
|
2408
|
+
page(id: $uri, idType: URI) { ${PAGE_FIELDS} }
|
|
2409
|
+
}
|
|
2410
|
+
`;
|
|
2411
|
+
var GQL_GET_ALL_PAGE_URIS = `
|
|
2412
|
+
query GetAllPageUris($first: Int, $after: String) {
|
|
2413
|
+
pages(first: $first, after: $after) {
|
|
2414
|
+
nodes { uri }
|
|
2415
|
+
pageInfo { hasNextPage endCursor }
|
|
2416
|
+
}
|
|
2417
|
+
}
|
|
2418
|
+
`;
|
|
2419
|
+
function createPagesQueries2(fetcher) {
|
|
2420
|
+
const { gqlFetch, gqlFetchGraceful } = fetcher;
|
|
2421
|
+
async function getPages(first = DEFAULT_FIRST2, after) {
|
|
2422
|
+
const data = await gqlFetchGraceful(
|
|
2423
|
+
GQL_GET_PAGES,
|
|
2424
|
+
{ pages: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
|
|
2425
|
+
{ first, after },
|
|
2426
|
+
["wpgraphql", "gql-pages"]
|
|
2427
|
+
);
|
|
2428
|
+
return data.pages;
|
|
2429
|
+
}
|
|
2430
|
+
async function getPageBySlug(slug) {
|
|
2431
|
+
const data = await gqlFetchGraceful(
|
|
2432
|
+
GQL_GET_PAGE_BY_SLUG,
|
|
2433
|
+
{ page: null },
|
|
2434
|
+
{ uri: `/${slug}/` },
|
|
2435
|
+
["wpgraphql", "gql-pages", `gql-page-${slug}`]
|
|
2436
|
+
);
|
|
2437
|
+
return data.page;
|
|
2438
|
+
}
|
|
2439
|
+
async function getPageByUri(uri) {
|
|
2440
|
+
const data = await gqlFetchGraceful(
|
|
2441
|
+
GQL_GET_PAGE_BY_URI,
|
|
2442
|
+
{ page: null },
|
|
2443
|
+
{ uri },
|
|
2444
|
+
["wpgraphql", "gql-pages", `gql-page-uri-${uri.replace(/\//g, "-")}`]
|
|
2445
|
+
);
|
|
2446
|
+
return data.page;
|
|
2447
|
+
}
|
|
2448
|
+
async function getAllPageUris() {
|
|
2449
|
+
try {
|
|
2450
|
+
const all = [];
|
|
2451
|
+
let after = void 0;
|
|
2452
|
+
let hasNextPage = true;
|
|
2453
|
+
while (hasNextPage) {
|
|
2454
|
+
const data = await gqlFetch(GQL_GET_ALL_PAGE_URIS, { first: BATCH_FIRST2, after }, ["wpgraphql"]);
|
|
2455
|
+
all.push(...data.pages.nodes);
|
|
2456
|
+
hasNextPage = data.pages.pageInfo.hasNextPage;
|
|
2457
|
+
after = data.pages.pageInfo.endCursor;
|
|
2458
|
+
}
|
|
2459
|
+
return all;
|
|
2460
|
+
} catch {
|
|
2461
|
+
console.warn("WPGraphQL unavailable, skipping static generation for pages");
|
|
2462
|
+
return [];
|
|
2463
|
+
}
|
|
2464
|
+
}
|
|
2465
|
+
return { getPages, getPageBySlug, getPageByUri, getAllPageUris };
|
|
2466
|
+
}
|
|
2467
|
+
|
|
2468
|
+
// src/integrations/wpGraphQL/core/categories/queries.ts
|
|
2469
|
+
var DEFAULT_FIRST3 = 100;
|
|
2470
|
+
var CATEGORY_FIELDS = `
|
|
2471
|
+
id
|
|
2472
|
+
databaseId
|
|
2473
|
+
name
|
|
2474
|
+
slug
|
|
2475
|
+
description
|
|
2476
|
+
count
|
|
2477
|
+
uri
|
|
2478
|
+
parent {
|
|
2479
|
+
node { databaseId name slug }
|
|
2480
|
+
}
|
|
2481
|
+
`;
|
|
2482
|
+
var GQL_GET_CATEGORIES = `
|
|
2483
|
+
query GetCategories($first: Int, $after: String) {
|
|
2484
|
+
categories(first: $first, after: $after) {
|
|
2485
|
+
nodes { ${CATEGORY_FIELDS} }
|
|
2486
|
+
pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
|
|
2487
|
+
}
|
|
2488
|
+
}
|
|
2489
|
+
`;
|
|
2490
|
+
var GQL_GET_CATEGORY_BY_SLUG = `
|
|
2491
|
+
query GetCategoryBySlug($slug: ID!) {
|
|
2492
|
+
category(id: $slug, idType: SLUG) { ${CATEGORY_FIELDS} }
|
|
2493
|
+
}
|
|
2494
|
+
`;
|
|
2495
|
+
var GQL_GET_CATEGORY_BY_DATABASE_ID = `
|
|
2496
|
+
query GetCategoryByDatabaseId($id: ID!) {
|
|
2497
|
+
category(id: $id, idType: DATABASE_ID) { ${CATEGORY_FIELDS} }
|
|
2498
|
+
}
|
|
2499
|
+
`;
|
|
2500
|
+
function createCategoriesQueries3(fetcher) {
|
|
2501
|
+
const { gqlFetchGraceful } = fetcher;
|
|
2502
|
+
async function getCategories(first = DEFAULT_FIRST3, after) {
|
|
2503
|
+
const data = await gqlFetchGraceful(
|
|
2504
|
+
GQL_GET_CATEGORIES,
|
|
2505
|
+
{ categories: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
|
|
2506
|
+
{ first, after },
|
|
2507
|
+
["wpgraphql", "gql-categories"]
|
|
2508
|
+
);
|
|
2509
|
+
return data.categories;
|
|
2510
|
+
}
|
|
2511
|
+
async function getCategoryBySlug(slug) {
|
|
2512
|
+
const data = await gqlFetchGraceful(
|
|
2513
|
+
GQL_GET_CATEGORY_BY_SLUG,
|
|
2514
|
+
{ category: null },
|
|
2515
|
+
{ slug },
|
|
2516
|
+
["wpgraphql", "gql-categories", `gql-category-${slug}`]
|
|
2517
|
+
);
|
|
2518
|
+
return data.category;
|
|
2519
|
+
}
|
|
2520
|
+
async function getCategoryByDatabaseId(id) {
|
|
2521
|
+
const data = await gqlFetchGraceful(
|
|
2522
|
+
GQL_GET_CATEGORY_BY_DATABASE_ID,
|
|
2523
|
+
{ category: null },
|
|
2524
|
+
{ id: String(id) },
|
|
2525
|
+
["wpgraphql", "gql-categories", `gql-category-id-${id}`]
|
|
2526
|
+
);
|
|
2527
|
+
return data.category;
|
|
2528
|
+
}
|
|
2529
|
+
return { getCategories, getCategoryBySlug, getCategoryByDatabaseId };
|
|
2530
|
+
}
|
|
2531
|
+
|
|
2532
|
+
// src/integrations/wpGraphQL/core/tags/queries.ts
|
|
2533
|
+
var DEFAULT_FIRST4 = 100;
|
|
2534
|
+
var TAG_FIELDS = `
|
|
2535
|
+
id
|
|
2536
|
+
databaseId
|
|
2537
|
+
name
|
|
2538
|
+
slug
|
|
2539
|
+
description
|
|
2540
|
+
count
|
|
2541
|
+
uri
|
|
2542
|
+
`;
|
|
2543
|
+
var GQL_GET_TAGS = `
|
|
2544
|
+
query GetTags($first: Int, $after: String) {
|
|
2545
|
+
tags(first: $first, after: $after) {
|
|
2546
|
+
nodes { ${TAG_FIELDS} }
|
|
2547
|
+
pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
|
|
2548
|
+
}
|
|
2549
|
+
}
|
|
2550
|
+
`;
|
|
2551
|
+
var GQL_GET_TAG_BY_SLUG = `
|
|
2552
|
+
query GetTagBySlug($slug: ID!) {
|
|
2553
|
+
tag(id: $slug, idType: SLUG) { ${TAG_FIELDS} }
|
|
2554
|
+
}
|
|
2555
|
+
`;
|
|
2556
|
+
function createTagsQueries3(fetcher) {
|
|
2557
|
+
const { gqlFetchGraceful } = fetcher;
|
|
2558
|
+
async function getTags(first = DEFAULT_FIRST4, after) {
|
|
2559
|
+
const data = await gqlFetchGraceful(
|
|
2560
|
+
GQL_GET_TAGS,
|
|
2561
|
+
{ tags: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
|
|
2562
|
+
{ first, after },
|
|
2563
|
+
["wpgraphql", "gql-tags"]
|
|
2564
|
+
);
|
|
2565
|
+
return data.tags;
|
|
2566
|
+
}
|
|
2567
|
+
async function getTagBySlug(slug) {
|
|
2568
|
+
const data = await gqlFetchGraceful(
|
|
2569
|
+
GQL_GET_TAG_BY_SLUG,
|
|
2570
|
+
{ tag: null },
|
|
2571
|
+
{ slug },
|
|
2572
|
+
["wpgraphql", "gql-tags", `gql-tag-${slug}`]
|
|
2573
|
+
);
|
|
2574
|
+
return data.tag;
|
|
2575
|
+
}
|
|
2576
|
+
return { getTags, getTagBySlug };
|
|
2577
|
+
}
|
|
2578
|
+
|
|
2579
|
+
// src/integrations/wpGraphQL/core/authors/queries.ts
|
|
2580
|
+
var DEFAULT_FIRST5 = 100;
|
|
2581
|
+
var AUTHOR_FIELDS = `
|
|
2582
|
+
id
|
|
2583
|
+
databaseId
|
|
2584
|
+
name
|
|
2585
|
+
slug
|
|
2586
|
+
description
|
|
2587
|
+
email
|
|
2588
|
+
uri
|
|
2589
|
+
avatar { url width height }
|
|
2590
|
+
`;
|
|
2591
|
+
var GQL_GET_AUTHORS = `
|
|
2592
|
+
query GetAuthors($first: Int, $after: String) {
|
|
2593
|
+
users(first: $first, after: $after) {
|
|
2594
|
+
nodes { ${AUTHOR_FIELDS} }
|
|
2595
|
+
pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
|
|
2596
|
+
}
|
|
2597
|
+
}
|
|
2598
|
+
`;
|
|
2599
|
+
var GQL_GET_AUTHOR_BY_SLUG = `
|
|
2600
|
+
query GetAuthorBySlug($slug: String!) {
|
|
2601
|
+
users(where: { login: $slug }) {
|
|
2602
|
+
nodes { ${AUTHOR_FIELDS} }
|
|
2603
|
+
}
|
|
2604
|
+
}
|
|
2605
|
+
`;
|
|
2606
|
+
function createAuthorsQueries2(fetcher) {
|
|
2607
|
+
const { gqlFetchGraceful } = fetcher;
|
|
2608
|
+
async function getAuthors(first = DEFAULT_FIRST5, after) {
|
|
2609
|
+
const data = await gqlFetchGraceful(
|
|
2610
|
+
GQL_GET_AUTHORS,
|
|
2611
|
+
{ users: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
|
|
2612
|
+
{ first, after },
|
|
2613
|
+
["wpgraphql", "gql-authors"]
|
|
2614
|
+
);
|
|
2615
|
+
return data.users;
|
|
2616
|
+
}
|
|
2617
|
+
async function getAuthorBySlug(slug) {
|
|
2618
|
+
const data = await gqlFetchGraceful(
|
|
2619
|
+
GQL_GET_AUTHOR_BY_SLUG,
|
|
2620
|
+
{ users: { nodes: [] } },
|
|
2621
|
+
{ slug },
|
|
2622
|
+
["wpgraphql", "gql-authors", `gql-author-${slug}`]
|
|
2623
|
+
);
|
|
2624
|
+
return data.users.nodes[0] ?? null;
|
|
2625
|
+
}
|
|
2626
|
+
return { getAuthors, getAuthorBySlug };
|
|
2627
|
+
}
|
|
2628
|
+
|
|
2629
|
+
// src/integrations/wpGraphQL/core/menus/queries.ts
|
|
2630
|
+
var MENU_ITEM_FIELDS = `
|
|
2631
|
+
id
|
|
2632
|
+
databaseId
|
|
2633
|
+
label
|
|
2634
|
+
url
|
|
2635
|
+
parentId
|
|
2636
|
+
order
|
|
2637
|
+
target
|
|
2638
|
+
cssClasses
|
|
2639
|
+
description
|
|
2640
|
+
connectedNode {
|
|
2641
|
+
node {
|
|
2642
|
+
__typename
|
|
2643
|
+
... on Page { id databaseId slug }
|
|
2644
|
+
... on Post { id databaseId slug }
|
|
2645
|
+
... on Category { id databaseId slug }
|
|
2646
|
+
... on Tag { id databaseId slug }
|
|
2647
|
+
}
|
|
2648
|
+
}
|
|
2649
|
+
`;
|
|
2650
|
+
var MENU_FIELDS = `
|
|
2651
|
+
id
|
|
2652
|
+
databaseId
|
|
2653
|
+
name
|
|
2654
|
+
slug
|
|
2655
|
+
locations
|
|
2656
|
+
menuItems(first: 100) {
|
|
2657
|
+
nodes { ${MENU_ITEM_FIELDS} }
|
|
2658
|
+
}
|
|
2659
|
+
`;
|
|
2660
|
+
var GQL_GET_MENUS = `
|
|
2661
|
+
query GetMenus {
|
|
2662
|
+
menus(first: 100) {
|
|
2663
|
+
nodes { ${MENU_FIELDS} }
|
|
2664
|
+
}
|
|
2665
|
+
}
|
|
2666
|
+
`;
|
|
2667
|
+
var GQL_GET_MENU_BY_ID = `
|
|
2668
|
+
query GetMenuById($id: ID!) {
|
|
2669
|
+
menu(id: $id, idType: DATABASE_ID) { ${MENU_FIELDS} }
|
|
2670
|
+
}
|
|
2671
|
+
`;
|
|
2672
|
+
var GQL_GET_MENU_BY_SLUG = `
|
|
2673
|
+
query GetMenuBySlug($id: ID!) {
|
|
2674
|
+
menu(id: $id, idType: SLUG) { ${MENU_FIELDS} }
|
|
2675
|
+
}
|
|
2676
|
+
`;
|
|
2677
|
+
var GQL_GET_MENUS_BY_LOCATION = `
|
|
2678
|
+
query GetMenusByLocation($location: MenuLocationEnum!) {
|
|
2679
|
+
menus(where: { location: $location }, first: 1) {
|
|
2680
|
+
nodes { ${MENU_FIELDS} }
|
|
2681
|
+
}
|
|
2682
|
+
}
|
|
2683
|
+
`;
|
|
2684
|
+
function createMenusQueries2(fetcher) {
|
|
2685
|
+
const { gqlFetch, gqlFetchGraceful } = fetcher;
|
|
2686
|
+
async function getMenus() {
|
|
2687
|
+
const data = await gqlFetchGraceful(
|
|
2688
|
+
GQL_GET_MENUS,
|
|
2689
|
+
{ menus: { nodes: [] } },
|
|
2690
|
+
void 0,
|
|
2691
|
+
["wpgraphql", "gql-menus"]
|
|
2692
|
+
);
|
|
2693
|
+
return data.menus.nodes;
|
|
2694
|
+
}
|
|
2695
|
+
async function getMenuById(id) {
|
|
2696
|
+
const data = await gqlFetchGraceful(
|
|
2697
|
+
GQL_GET_MENU_BY_ID,
|
|
2698
|
+
{ menu: null },
|
|
2699
|
+
{ id: String(id) },
|
|
2700
|
+
["wpgraphql", "gql-menus", `gql-menu-${id}`]
|
|
2701
|
+
);
|
|
2702
|
+
return data.menu;
|
|
2703
|
+
}
|
|
2704
|
+
async function getMenuBySlug(slug) {
|
|
2705
|
+
const data = await gqlFetchGraceful(
|
|
2706
|
+
GQL_GET_MENU_BY_SLUG,
|
|
2707
|
+
{ menu: null },
|
|
2708
|
+
{ id: slug },
|
|
2709
|
+
["wpgraphql", "gql-menus", `gql-menu-${slug}`]
|
|
2710
|
+
);
|
|
2711
|
+
return data.menu;
|
|
2712
|
+
}
|
|
2713
|
+
async function getMenuByLocation(location) {
|
|
2714
|
+
const data = await gqlFetch(
|
|
2715
|
+
GQL_GET_MENUS_BY_LOCATION,
|
|
2716
|
+
{ location: location.toUpperCase() },
|
|
2717
|
+
["wpgraphql", "gql-menus", `gql-menu-location-${location}`]
|
|
2718
|
+
);
|
|
2719
|
+
return data.menus.nodes[0] ?? null;
|
|
2720
|
+
}
|
|
2721
|
+
async function getMenuItems(menuSlug) {
|
|
2722
|
+
const menu = await getMenuBySlug(menuSlug);
|
|
2723
|
+
return menu?.menuItems?.nodes ?? [];
|
|
2724
|
+
}
|
|
2725
|
+
return {
|
|
2726
|
+
getMenus,
|
|
2727
|
+
getMenuById,
|
|
2728
|
+
getMenuBySlug,
|
|
2729
|
+
getMenuByLocation,
|
|
2730
|
+
getMenuItems
|
|
2731
|
+
};
|
|
2732
|
+
}
|
|
2733
|
+
|
|
2734
|
+
// src/integrations/wpGraphQL/core/comments/queries.ts
|
|
2735
|
+
var COMMENT_AUTHOR_FIELDS = `
|
|
2736
|
+
name
|
|
2737
|
+
url
|
|
2738
|
+
avatar { url width height }
|
|
2739
|
+
`;
|
|
2740
|
+
var COMMENT_FIELDS = `
|
|
2741
|
+
id
|
|
2742
|
+
databaseId
|
|
2743
|
+
content(format: RENDERED)
|
|
2744
|
+
date
|
|
2745
|
+
parentId
|
|
2746
|
+
status
|
|
2747
|
+
author { node { ${COMMENT_AUTHOR_FIELDS} } }
|
|
2748
|
+
`;
|
|
2749
|
+
var GQL_GET_COMMENTS_BY_POST = `
|
|
2750
|
+
query GetCommentsByPost($contentId: ID!, $first: Int, $after: String) {
|
|
2751
|
+
comments(
|
|
2752
|
+
first: $first
|
|
2753
|
+
after: $after
|
|
2754
|
+
where: { contentId: $contentId, status: "approve", parent: 0 }
|
|
2755
|
+
) {
|
|
2756
|
+
nodes {
|
|
2757
|
+
${COMMENT_FIELDS}
|
|
2758
|
+
replies(first: 100) {
|
|
2759
|
+
nodes { ${COMMENT_FIELDS} }
|
|
2760
|
+
}
|
|
2761
|
+
}
|
|
2762
|
+
pageInfo { hasNextPage endCursor }
|
|
2763
|
+
}
|
|
2764
|
+
}
|
|
2765
|
+
`;
|
|
2766
|
+
var GQL_GET_ALL_COMMENTS_BY_POST = `
|
|
2767
|
+
query GetAllCommentsByPost($contentId: ID!) {
|
|
2768
|
+
comments(
|
|
2769
|
+
first: 100
|
|
2770
|
+
where: { contentId: $contentId, status: "approve" }
|
|
2771
|
+
) {
|
|
2772
|
+
nodes { ${COMMENT_FIELDS} }
|
|
2773
|
+
}
|
|
2774
|
+
}
|
|
2775
|
+
`;
|
|
2776
|
+
var GQL_GET_COMMENT_BY_ID = `
|
|
2777
|
+
query GetCommentById($id: ID!) {
|
|
2778
|
+
comment(id: $id, idType: DATABASE_ID) { ${COMMENT_FIELDS} }
|
|
2779
|
+
}
|
|
2780
|
+
`;
|
|
2781
|
+
function createCommentsQueries2(fetcher) {
|
|
2782
|
+
const { gqlFetchGraceful } = fetcher;
|
|
2783
|
+
async function getCommentsByPostId(postId, first = 10, after) {
|
|
2784
|
+
const data = await gqlFetchGraceful(
|
|
2785
|
+
GQL_GET_COMMENTS_BY_POST,
|
|
2786
|
+
{ comments: { nodes: [], pageInfo: { hasNextPage: false } } },
|
|
2787
|
+
{ contentId: String(postId), first, after },
|
|
2788
|
+
["wpgraphql", "gql-comments", `gql-comments-post-${postId}`]
|
|
2789
|
+
);
|
|
2790
|
+
return data.comments;
|
|
2791
|
+
}
|
|
2792
|
+
async function getAllCommentsByPostId(postId) {
|
|
2793
|
+
const data = await gqlFetchGraceful(
|
|
2794
|
+
GQL_GET_ALL_COMMENTS_BY_POST,
|
|
2795
|
+
{ comments: { nodes: [] } },
|
|
2796
|
+
{ contentId: String(postId) },
|
|
2797
|
+
["wpgraphql", "gql-comments", `gql-comments-post-${postId}`]
|
|
2798
|
+
);
|
|
2799
|
+
return data.comments.nodes;
|
|
2800
|
+
}
|
|
2801
|
+
async function getCommentById(id) {
|
|
2802
|
+
const data = await gqlFetchGraceful(
|
|
2803
|
+
GQL_GET_COMMENT_BY_ID,
|
|
2804
|
+
{ comment: null },
|
|
2805
|
+
{ id: String(id) },
|
|
2806
|
+
["wpgraphql", "gql-comments", `gql-comment-${id}`]
|
|
2807
|
+
);
|
|
2808
|
+
return data.comment;
|
|
2809
|
+
}
|
|
2810
|
+
return {
|
|
2811
|
+
getCommentsByPostId,
|
|
2812
|
+
getAllCommentsByPostId,
|
|
2813
|
+
getCommentById
|
|
2814
|
+
};
|
|
2815
|
+
}
|
|
2816
|
+
|
|
2817
|
+
// src/integrations/wpGraphQL/core/media/queries.ts
|
|
2818
|
+
var DEFAULT_FIRST6 = 10;
|
|
2819
|
+
var MEDIA_FIELDS = `
|
|
2820
|
+
id
|
|
2821
|
+
databaseId
|
|
2822
|
+
slug
|
|
2823
|
+
title
|
|
2824
|
+
date
|
|
2825
|
+
sourceUrl
|
|
2826
|
+
altText
|
|
2827
|
+
caption
|
|
2828
|
+
description
|
|
2829
|
+
mediaType
|
|
2830
|
+
mimeType
|
|
2831
|
+
uri
|
|
2832
|
+
mediaDetails {
|
|
2833
|
+
width
|
|
2834
|
+
height
|
|
2835
|
+
file
|
|
2836
|
+
sizes { name width height mimeType sourceUrl }
|
|
2837
|
+
}
|
|
2838
|
+
`;
|
|
2839
|
+
var GQL_GET_MEDIA_ITEMS = `
|
|
2840
|
+
query GetMediaItems($first: Int, $after: String) {
|
|
2841
|
+
mediaItems(first: $first, after: $after) {
|
|
2842
|
+
nodes { ${MEDIA_FIELDS} }
|
|
2843
|
+
pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
|
|
2844
|
+
}
|
|
2845
|
+
}
|
|
2846
|
+
`;
|
|
2847
|
+
var GQL_GET_MEDIA_ITEM_BY_ID = `
|
|
2848
|
+
query GetMediaItemById($id: ID!) {
|
|
2849
|
+
mediaItem(id: $id, idType: DATABASE_ID) { ${MEDIA_FIELDS} }
|
|
2850
|
+
}
|
|
2851
|
+
`;
|
|
2852
|
+
var GQL_GET_MEDIA_ITEM_BY_SLUG = `
|
|
2853
|
+
query GetMediaItemBySlug($id: ID!) {
|
|
2854
|
+
mediaItem(id: $id, idType: SLUG) { ${MEDIA_FIELDS} }
|
|
2855
|
+
}
|
|
2856
|
+
`;
|
|
2857
|
+
function createMediaQueries2(fetcher) {
|
|
2858
|
+
const { gqlFetchGraceful } = fetcher;
|
|
2859
|
+
async function getMediaItems(first = DEFAULT_FIRST6, after) {
|
|
2860
|
+
const data = await gqlFetchGraceful(
|
|
2861
|
+
GQL_GET_MEDIA_ITEMS,
|
|
2862
|
+
{ mediaItems: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
|
|
2863
|
+
{ first, after },
|
|
2864
|
+
["wpgraphql", "gql-media"]
|
|
2865
|
+
);
|
|
2866
|
+
return data.mediaItems;
|
|
2867
|
+
}
|
|
2868
|
+
async function getMediaItemById(id) {
|
|
2869
|
+
const data = await gqlFetchGraceful(
|
|
2870
|
+
GQL_GET_MEDIA_ITEM_BY_ID,
|
|
2871
|
+
{ mediaItem: null },
|
|
2872
|
+
{ id: String(id) },
|
|
2873
|
+
["wpgraphql", "gql-media", `gql-media-${id}`]
|
|
2874
|
+
);
|
|
2875
|
+
return data.mediaItem;
|
|
2876
|
+
}
|
|
2877
|
+
async function getMediaItemBySlug(slug) {
|
|
2878
|
+
const data = await gqlFetchGraceful(
|
|
2879
|
+
GQL_GET_MEDIA_ITEM_BY_SLUG,
|
|
2880
|
+
{ mediaItem: null },
|
|
2881
|
+
{ id: slug },
|
|
2882
|
+
["wpgraphql", "gql-media", `gql-media-${slug}`]
|
|
2883
|
+
);
|
|
2884
|
+
return data.mediaItem;
|
|
2885
|
+
}
|
|
2886
|
+
return { getMediaItems, getMediaItemById, getMediaItemBySlug };
|
|
2887
|
+
}
|
|
2888
|
+
|
|
2889
|
+
// src/integrations/wpGraphQL/core/mutations/posts/mutations.ts
|
|
2890
|
+
var MUTATED_POST_FIELDS = `
|
|
2891
|
+
id
|
|
2892
|
+
databaseId
|
|
2893
|
+
slug
|
|
2894
|
+
title
|
|
2895
|
+
status
|
|
2896
|
+
`;
|
|
2897
|
+
var GQL_CREATE_POST = `
|
|
2898
|
+
mutation CreatePost($input: CreatePostInput!) {
|
|
2899
|
+
createPost(input: $input) {
|
|
2900
|
+
post { ${MUTATED_POST_FIELDS} }
|
|
2901
|
+
}
|
|
2902
|
+
}
|
|
2903
|
+
`;
|
|
2904
|
+
var GQL_UPDATE_POST = `
|
|
2905
|
+
mutation UpdatePost($input: UpdatePostInput!) {
|
|
2906
|
+
updatePost(input: $input) {
|
|
2907
|
+
post { ${MUTATED_POST_FIELDS} }
|
|
2908
|
+
}
|
|
2909
|
+
}
|
|
2910
|
+
`;
|
|
2911
|
+
var GQL_DELETE_POST = `
|
|
2912
|
+
mutation DeletePost($input: DeletePostInput!) {
|
|
2913
|
+
deletePost(input: $input) {
|
|
2914
|
+
deletedId
|
|
2915
|
+
post { ${MUTATED_POST_FIELDS} }
|
|
2916
|
+
}
|
|
2917
|
+
}
|
|
2918
|
+
`;
|
|
2919
|
+
function createPostsMutations2(fetcher) {
|
|
2920
|
+
const { gqlMutate } = fetcher;
|
|
2921
|
+
async function createPost(input, authToken) {
|
|
2922
|
+
const data = await gqlMutate(
|
|
2923
|
+
GQL_CREATE_POST,
|
|
2924
|
+
{ input },
|
|
2925
|
+
authToken
|
|
2926
|
+
);
|
|
2927
|
+
return data.createPost.post;
|
|
2928
|
+
}
|
|
2929
|
+
async function updatePost(input, authToken) {
|
|
2930
|
+
const data = await gqlMutate(
|
|
2931
|
+
GQL_UPDATE_POST,
|
|
2932
|
+
{ input },
|
|
2933
|
+
authToken
|
|
2934
|
+
);
|
|
2935
|
+
return data.updatePost.post;
|
|
2936
|
+
}
|
|
2937
|
+
async function deletePost(id, authToken, forceDelete = false) {
|
|
2938
|
+
const data = await gqlMutate(
|
|
2939
|
+
GQL_DELETE_POST,
|
|
2940
|
+
{ input: { id, forceDelete } },
|
|
2941
|
+
authToken
|
|
2942
|
+
);
|
|
2943
|
+
return data.deletePost;
|
|
2944
|
+
}
|
|
2945
|
+
return { createPost, updatePost, deletePost };
|
|
2946
|
+
}
|
|
2947
|
+
|
|
2948
|
+
// src/integrations/wpGraphQL/core/mutations/comments/mutations.ts
|
|
2949
|
+
var MUTATED_COMMENT_FIELDS = `
|
|
2950
|
+
id
|
|
2951
|
+
databaseId
|
|
2952
|
+
content(format: RENDERED)
|
|
2953
|
+
date
|
|
2954
|
+
status
|
|
2955
|
+
parentId
|
|
2956
|
+
author { node { name url } }
|
|
2957
|
+
`;
|
|
2958
|
+
var GQL_CREATE_COMMENT = `
|
|
2959
|
+
mutation CreateComment($input: CreateCommentInput!) {
|
|
2960
|
+
createComment(input: $input) {
|
|
2961
|
+
success
|
|
2962
|
+
comment { ${MUTATED_COMMENT_FIELDS} }
|
|
2963
|
+
}
|
|
2964
|
+
}
|
|
2965
|
+
`;
|
|
2966
|
+
var GQL_UPDATE_COMMENT = `
|
|
2967
|
+
mutation UpdateComment($input: UpdateCommentInput!) {
|
|
2968
|
+
updateComment(input: $input) {
|
|
2969
|
+
comment { ${MUTATED_COMMENT_FIELDS} }
|
|
2970
|
+
}
|
|
2971
|
+
}
|
|
2972
|
+
`;
|
|
2973
|
+
var GQL_DELETE_COMMENT = `
|
|
2974
|
+
mutation DeleteComment($input: DeleteCommentInput!) {
|
|
2975
|
+
deleteComment(input: $input) {
|
|
2976
|
+
deletedId
|
|
2977
|
+
comment { ${MUTATED_COMMENT_FIELDS} }
|
|
2978
|
+
}
|
|
2979
|
+
}
|
|
2980
|
+
`;
|
|
2981
|
+
function createCommentsMutations2(fetcher) {
|
|
2982
|
+
const { gqlMutate } = fetcher;
|
|
2983
|
+
async function createComment(input, authToken) {
|
|
2984
|
+
const gqlInput = {
|
|
2985
|
+
commentOn: input.postId,
|
|
2986
|
+
content: input.content
|
|
2987
|
+
};
|
|
2988
|
+
if (input.authorName) gqlInput["author"] = input.authorName;
|
|
2989
|
+
if (input.authorEmail) gqlInput["authorEmail"] = input.authorEmail;
|
|
2990
|
+
if (input.authorUrl) gqlInput["authorUrl"] = input.authorUrl;
|
|
2991
|
+
if (input.parentId) gqlInput["parent"] = input.parentId;
|
|
2992
|
+
const data = await gqlMutate(
|
|
2993
|
+
GQL_CREATE_COMMENT,
|
|
2994
|
+
{ input: gqlInput },
|
|
2995
|
+
authToken
|
|
2996
|
+
);
|
|
2997
|
+
return data.createComment;
|
|
2998
|
+
}
|
|
2999
|
+
async function updateComment(input, authToken) {
|
|
3000
|
+
const data = await gqlMutate(
|
|
3001
|
+
GQL_UPDATE_COMMENT,
|
|
3002
|
+
{ input },
|
|
3003
|
+
authToken
|
|
3004
|
+
);
|
|
3005
|
+
return data.updateComment.comment;
|
|
3006
|
+
}
|
|
3007
|
+
async function deleteComment(id, authToken, forceDelete = false) {
|
|
3008
|
+
const data = await gqlMutate(
|
|
3009
|
+
GQL_DELETE_COMMENT,
|
|
3010
|
+
{ input: { id, forceDelete } },
|
|
3011
|
+
authToken
|
|
3012
|
+
);
|
|
3013
|
+
return data.deleteComment;
|
|
3014
|
+
}
|
|
3015
|
+
return { createComment, updateComment, deleteComment };
|
|
3016
|
+
}
|
|
3017
|
+
|
|
3018
|
+
// src/integrations/wpGraphQL/core/mutations/pages/mutations.ts
|
|
3019
|
+
var MUTATED_PAGE_FIELDS = `
|
|
3020
|
+
id
|
|
3021
|
+
databaseId
|
|
3022
|
+
slug
|
|
3023
|
+
title
|
|
3024
|
+
status
|
|
3025
|
+
uri
|
|
3026
|
+
`;
|
|
3027
|
+
var GQL_CREATE_PAGE = `
|
|
3028
|
+
mutation CreatePage($input: CreatePageInput!) {
|
|
3029
|
+
createPage(input: $input) {
|
|
3030
|
+
page { ${MUTATED_PAGE_FIELDS} }
|
|
3031
|
+
}
|
|
3032
|
+
}
|
|
3033
|
+
`;
|
|
3034
|
+
var GQL_UPDATE_PAGE = `
|
|
3035
|
+
mutation UpdatePage($input: UpdatePageInput!) {
|
|
3036
|
+
updatePage(input: $input) {
|
|
3037
|
+
page { ${MUTATED_PAGE_FIELDS} }
|
|
3038
|
+
}
|
|
3039
|
+
}
|
|
3040
|
+
`;
|
|
3041
|
+
var GQL_DELETE_PAGE = `
|
|
3042
|
+
mutation DeletePage($input: DeletePageInput!) {
|
|
3043
|
+
deletePage(input: $input) {
|
|
3044
|
+
deletedId
|
|
3045
|
+
page { ${MUTATED_PAGE_FIELDS} }
|
|
3046
|
+
}
|
|
3047
|
+
}
|
|
3048
|
+
`;
|
|
3049
|
+
function createPagesMutations2(fetcher) {
|
|
3050
|
+
const { gqlMutate } = fetcher;
|
|
3051
|
+
async function createPage(input, authToken) {
|
|
3052
|
+
const data = await gqlMutate(
|
|
3053
|
+
GQL_CREATE_PAGE,
|
|
3054
|
+
{ input },
|
|
3055
|
+
authToken
|
|
3056
|
+
);
|
|
3057
|
+
return data.createPage.page;
|
|
3058
|
+
}
|
|
3059
|
+
async function updatePage(input, authToken) {
|
|
3060
|
+
const data = await gqlMutate(
|
|
3061
|
+
GQL_UPDATE_PAGE,
|
|
3062
|
+
{ input },
|
|
3063
|
+
authToken
|
|
3064
|
+
);
|
|
3065
|
+
return data.updatePage.page;
|
|
3066
|
+
}
|
|
3067
|
+
async function deletePage(id, authToken, forceDelete = false) {
|
|
3068
|
+
const data = await gqlMutate(
|
|
3069
|
+
GQL_DELETE_PAGE,
|
|
3070
|
+
{ input: { id, forceDelete } },
|
|
3071
|
+
authToken
|
|
3072
|
+
);
|
|
3073
|
+
return data.deletePage;
|
|
3074
|
+
}
|
|
3075
|
+
return { createPage, updatePage, deletePage };
|
|
3076
|
+
}
|
|
3077
|
+
|
|
3078
|
+
// src/integrations/wpGraphQL/core/mutations/categories/mutations.ts
|
|
3079
|
+
var MUTATED_CATEGORY_FIELDS = `
|
|
3080
|
+
id
|
|
3081
|
+
databaseId
|
|
3082
|
+
name
|
|
3083
|
+
slug
|
|
3084
|
+
`;
|
|
3085
|
+
var GQL_CREATE_CATEGORY = `
|
|
3086
|
+
mutation CreateCategory($input: CreateCategoryInput!) {
|
|
3087
|
+
createCategory(input: $input) {
|
|
3088
|
+
category { ${MUTATED_CATEGORY_FIELDS} }
|
|
3089
|
+
}
|
|
3090
|
+
}
|
|
3091
|
+
`;
|
|
3092
|
+
var GQL_UPDATE_CATEGORY = `
|
|
3093
|
+
mutation UpdateCategory($input: UpdateCategoryInput!) {
|
|
3094
|
+
updateCategory(input: $input) {
|
|
3095
|
+
category { ${MUTATED_CATEGORY_FIELDS} }
|
|
3096
|
+
}
|
|
3097
|
+
}
|
|
3098
|
+
`;
|
|
3099
|
+
var GQL_DELETE_CATEGORY = `
|
|
3100
|
+
mutation DeleteCategory($input: DeleteCategoryInput!) {
|
|
3101
|
+
deleteCategory(input: $input) {
|
|
3102
|
+
deletedId
|
|
3103
|
+
category { ${MUTATED_CATEGORY_FIELDS} }
|
|
3104
|
+
}
|
|
3105
|
+
}
|
|
3106
|
+
`;
|
|
3107
|
+
function createCategoriesMutations3(fetcher) {
|
|
3108
|
+
const { gqlMutate } = fetcher;
|
|
3109
|
+
async function createCategory(input, authToken) {
|
|
3110
|
+
const data = await gqlMutate(
|
|
3111
|
+
GQL_CREATE_CATEGORY,
|
|
3112
|
+
{ input },
|
|
3113
|
+
authToken
|
|
3114
|
+
);
|
|
3115
|
+
return data.createCategory.category;
|
|
3116
|
+
}
|
|
3117
|
+
async function updateCategory(input, authToken) {
|
|
3118
|
+
const data = await gqlMutate(
|
|
3119
|
+
GQL_UPDATE_CATEGORY,
|
|
3120
|
+
{ input },
|
|
3121
|
+
authToken
|
|
3122
|
+
);
|
|
3123
|
+
return data.updateCategory.category;
|
|
3124
|
+
}
|
|
3125
|
+
async function deleteCategory(id, authToken) {
|
|
3126
|
+
const data = await gqlMutate(
|
|
3127
|
+
GQL_DELETE_CATEGORY,
|
|
3128
|
+
{ input: { id } },
|
|
3129
|
+
authToken
|
|
3130
|
+
);
|
|
3131
|
+
return data.deleteCategory;
|
|
3132
|
+
}
|
|
3133
|
+
return { createCategory, updateCategory, deleteCategory };
|
|
3134
|
+
}
|
|
3135
|
+
|
|
3136
|
+
// src/integrations/wpGraphQL/core/mutations/tags/mutations.ts
|
|
3137
|
+
var MUTATED_TAG_FIELDS = `
|
|
3138
|
+
id
|
|
3139
|
+
databaseId
|
|
3140
|
+
name
|
|
3141
|
+
slug
|
|
3142
|
+
`;
|
|
3143
|
+
var GQL_CREATE_TAG = `
|
|
3144
|
+
mutation CreateTag($input: CreateTagInput!) {
|
|
3145
|
+
createTag(input: $input) {
|
|
3146
|
+
tag { ${MUTATED_TAG_FIELDS} }
|
|
3147
|
+
}
|
|
3148
|
+
}
|
|
3149
|
+
`;
|
|
3150
|
+
var GQL_UPDATE_TAG = `
|
|
3151
|
+
mutation UpdateTag($input: UpdateTagInput!) {
|
|
3152
|
+
updateTag(input: $input) {
|
|
3153
|
+
tag { ${MUTATED_TAG_FIELDS} }
|
|
3154
|
+
}
|
|
3155
|
+
}
|
|
3156
|
+
`;
|
|
3157
|
+
var GQL_DELETE_TAG = `
|
|
3158
|
+
mutation DeleteTag($input: DeleteTagInput!) {
|
|
3159
|
+
deleteTag(input: $input) {
|
|
3160
|
+
deletedId
|
|
3161
|
+
tag { ${MUTATED_TAG_FIELDS} }
|
|
3162
|
+
}
|
|
3163
|
+
}
|
|
3164
|
+
`;
|
|
3165
|
+
function createTagsMutations3(fetcher) {
|
|
3166
|
+
const { gqlMutate } = fetcher;
|
|
3167
|
+
async function createTag(input, authToken) {
|
|
3168
|
+
const data = await gqlMutate(
|
|
3169
|
+
GQL_CREATE_TAG,
|
|
3170
|
+
{ input },
|
|
3171
|
+
authToken
|
|
3172
|
+
);
|
|
3173
|
+
return data.createTag.tag;
|
|
3174
|
+
}
|
|
3175
|
+
async function updateTag(input, authToken) {
|
|
3176
|
+
const data = await gqlMutate(
|
|
3177
|
+
GQL_UPDATE_TAG,
|
|
3178
|
+
{ input },
|
|
3179
|
+
authToken
|
|
3180
|
+
);
|
|
3181
|
+
return data.updateTag.tag;
|
|
3182
|
+
}
|
|
3183
|
+
async function deleteTag(id, authToken) {
|
|
3184
|
+
const data = await gqlMutate(
|
|
3185
|
+
GQL_DELETE_TAG,
|
|
3186
|
+
{ input: { id } },
|
|
3187
|
+
authToken
|
|
3188
|
+
);
|
|
3189
|
+
return data.deleteTag;
|
|
3190
|
+
}
|
|
3191
|
+
return { createTag, updateTag, deleteTag };
|
|
3192
|
+
}
|
|
3193
|
+
|
|
3194
|
+
// src/integrations/wpGraphQL/core/mutations/authors/mutations.ts
|
|
3195
|
+
var MUTATED_USER_FIELDS = `
|
|
3196
|
+
id
|
|
3197
|
+
databaseId
|
|
3198
|
+
name
|
|
3199
|
+
slug
|
|
3200
|
+
email
|
|
3201
|
+
`;
|
|
3202
|
+
var GQL_REGISTER_USER = `
|
|
3203
|
+
mutation RegisterUser($input: RegisterUserInput!) {
|
|
3204
|
+
registerUser(input: $input) {
|
|
3205
|
+
user { ${MUTATED_USER_FIELDS} }
|
|
3206
|
+
}
|
|
3207
|
+
}
|
|
3208
|
+
`;
|
|
3209
|
+
var GQL_UPDATE_USER = `
|
|
3210
|
+
mutation UpdateUser($input: UpdateUserInput!) {
|
|
3211
|
+
updateUser(input: $input) {
|
|
3212
|
+
user { ${MUTATED_USER_FIELDS} }
|
|
3213
|
+
}
|
|
3214
|
+
}
|
|
3215
|
+
`;
|
|
3216
|
+
var GQL_DELETE_USER = `
|
|
3217
|
+
mutation DeleteUser($input: DeleteUserInput!) {
|
|
3218
|
+
deleteUser(input: $input) {
|
|
3219
|
+
deletedId
|
|
3220
|
+
user { ${MUTATED_USER_FIELDS} }
|
|
3221
|
+
}
|
|
3222
|
+
}
|
|
3223
|
+
`;
|
|
3224
|
+
function createAuthorsMutations2(fetcher) {
|
|
3225
|
+
const { gqlMutate } = fetcher;
|
|
3226
|
+
async function registerUser(input, authToken) {
|
|
3227
|
+
const data = await gqlMutate(
|
|
3228
|
+
GQL_REGISTER_USER,
|
|
3229
|
+
{ input },
|
|
3230
|
+
authToken
|
|
3231
|
+
);
|
|
3232
|
+
return data.registerUser.user;
|
|
3233
|
+
}
|
|
3234
|
+
async function updateUser(input, authToken) {
|
|
3235
|
+
const data = await gqlMutate(
|
|
3236
|
+
GQL_UPDATE_USER,
|
|
3237
|
+
{ input },
|
|
3238
|
+
authToken
|
|
3239
|
+
);
|
|
3240
|
+
return data.updateUser.user;
|
|
3241
|
+
}
|
|
3242
|
+
async function deleteUser(id, authToken, reassignPosts) {
|
|
3243
|
+
const input = { id };
|
|
3244
|
+
if (reassignPosts) input["reassignId"] = reassignPosts;
|
|
3245
|
+
const data = await gqlMutate(
|
|
3246
|
+
GQL_DELETE_USER,
|
|
3247
|
+
{ input },
|
|
3248
|
+
authToken
|
|
3249
|
+
);
|
|
3250
|
+
return data.deleteUser;
|
|
3251
|
+
}
|
|
3252
|
+
return { registerUser, updateUser, deleteUser };
|
|
3253
|
+
}
|
|
3254
|
+
|
|
3255
|
+
// src/integrations/wpGraphQL/core/mutations/media/mutations.ts
|
|
3256
|
+
var MUTATED_MEDIA_FIELDS = `
|
|
3257
|
+
id
|
|
3258
|
+
databaseId
|
|
3259
|
+
slug
|
|
3260
|
+
title
|
|
3261
|
+
sourceUrl
|
|
3262
|
+
altText
|
|
3263
|
+
`;
|
|
3264
|
+
var GQL_CREATE_MEDIA_ITEM = `
|
|
3265
|
+
mutation CreateMediaItem($input: CreateMediaItemInput!) {
|
|
3266
|
+
createMediaItem(input: $input) {
|
|
3267
|
+
mediaItem { ${MUTATED_MEDIA_FIELDS} }
|
|
3268
|
+
}
|
|
3269
|
+
}
|
|
3270
|
+
`;
|
|
3271
|
+
var GQL_UPDATE_MEDIA_ITEM = `
|
|
3272
|
+
mutation UpdateMediaItem($input: UpdateMediaItemInput!) {
|
|
3273
|
+
updateMediaItem(input: $input) {
|
|
3274
|
+
mediaItem { ${MUTATED_MEDIA_FIELDS} }
|
|
3275
|
+
}
|
|
3276
|
+
}
|
|
3277
|
+
`;
|
|
3278
|
+
var GQL_DELETE_MEDIA_ITEM = `
|
|
3279
|
+
mutation DeleteMediaItem($input: DeleteMediaItemInput!) {
|
|
3280
|
+
deleteMediaItem(input: $input) {
|
|
3281
|
+
deletedId
|
|
3282
|
+
mediaItem { ${MUTATED_MEDIA_FIELDS} }
|
|
3283
|
+
}
|
|
3284
|
+
}
|
|
3285
|
+
`;
|
|
3286
|
+
function createMediaMutations2(fetcher) {
|
|
3287
|
+
const { gqlMutate } = fetcher;
|
|
3288
|
+
async function createMediaItem(input, authToken) {
|
|
3289
|
+
const data = await gqlMutate(
|
|
3290
|
+
GQL_CREATE_MEDIA_ITEM,
|
|
3291
|
+
{ input },
|
|
3292
|
+
authToken
|
|
3293
|
+
);
|
|
3294
|
+
return data.createMediaItem.mediaItem;
|
|
3295
|
+
}
|
|
3296
|
+
async function updateMediaItem(input, authToken) {
|
|
3297
|
+
const data = await gqlMutate(
|
|
3298
|
+
GQL_UPDATE_MEDIA_ITEM,
|
|
3299
|
+
{ input },
|
|
3300
|
+
authToken
|
|
3301
|
+
);
|
|
3302
|
+
return data.updateMediaItem.mediaItem;
|
|
3303
|
+
}
|
|
3304
|
+
async function deleteMediaItem(id, authToken, forceDelete = true) {
|
|
3305
|
+
const data = await gqlMutate(
|
|
3306
|
+
GQL_DELETE_MEDIA_ITEM,
|
|
3307
|
+
{ input: { id, forceDelete } },
|
|
3308
|
+
authToken
|
|
3309
|
+
);
|
|
3310
|
+
return data.deleteMediaItem;
|
|
3311
|
+
}
|
|
3312
|
+
return { createMediaItem, updateMediaItem, deleteMediaItem };
|
|
3313
|
+
}
|
|
3314
|
+
|
|
3315
|
+
// src/integrations/wpGraphQL/core/mutations/index.ts
|
|
3316
|
+
function createWPGraphQLMutationsClient(config) {
|
|
3317
|
+
const fetcher = createWPGraphQLFetcher(config);
|
|
3318
|
+
return {
|
|
3319
|
+
...createPostsMutations2(fetcher),
|
|
3320
|
+
...createCommentsMutations2(fetcher),
|
|
3321
|
+
...createPagesMutations2(fetcher),
|
|
3322
|
+
...createCategoriesMutations3(fetcher),
|
|
3323
|
+
...createTagsMutations3(fetcher),
|
|
3324
|
+
...createAuthorsMutations2(fetcher),
|
|
3325
|
+
...createMediaMutations2(fetcher)
|
|
3326
|
+
};
|
|
3327
|
+
}
|
|
3328
|
+
|
|
3329
|
+
// src/integrations/wpGraphQL/core/index.ts
|
|
3330
|
+
function createWPGraphQLCoreClient(config) {
|
|
3331
|
+
const fetcher = createWPGraphQLFetcher(config);
|
|
3332
|
+
return {
|
|
3333
|
+
...createPostsQueries2(fetcher),
|
|
3334
|
+
...createPagesQueries2(fetcher),
|
|
3335
|
+
...createCategoriesQueries3(fetcher),
|
|
3336
|
+
...createTagsQueries3(fetcher),
|
|
3337
|
+
...createAuthorsQueries2(fetcher),
|
|
3338
|
+
...createMenusQueries2(fetcher),
|
|
3339
|
+
...createCommentsQueries2(fetcher),
|
|
3340
|
+
...createMediaQueries2(fetcher)
|
|
3341
|
+
};
|
|
3342
|
+
}
|
|
3343
|
+
|
|
3344
|
+
// src/integrations/wpGraphQL/yoast/queries.ts
|
|
3345
|
+
var SEO_FIELDS = `
|
|
3346
|
+
seo {
|
|
3347
|
+
title
|
|
3348
|
+
metaDesc
|
|
3349
|
+
canonical
|
|
3350
|
+
opengraphTitle
|
|
3351
|
+
opengraphDescription
|
|
3352
|
+
opengraphImage { sourceUrl altText }
|
|
3353
|
+
twitterTitle
|
|
3354
|
+
twitterDescription
|
|
3355
|
+
twitterImage { sourceUrl }
|
|
3356
|
+
schema { raw }
|
|
3357
|
+
}
|
|
3358
|
+
`;
|
|
3359
|
+
var POST_FIELDS_WITH_SEO = `
|
|
3360
|
+
id
|
|
3361
|
+
databaseId
|
|
3362
|
+
slug
|
|
3363
|
+
title
|
|
3364
|
+
content
|
|
3365
|
+
excerpt
|
|
3366
|
+
date
|
|
3367
|
+
modified
|
|
3368
|
+
status
|
|
3369
|
+
uri
|
|
3370
|
+
author {
|
|
3371
|
+
node {
|
|
3372
|
+
databaseId
|
|
3373
|
+
name
|
|
3374
|
+
slug
|
|
3375
|
+
avatar { url }
|
|
3376
|
+
}
|
|
3377
|
+
}
|
|
3378
|
+
featuredImage {
|
|
3379
|
+
node {
|
|
3380
|
+
sourceUrl
|
|
3381
|
+
altText
|
|
3382
|
+
mediaDetails { width height }
|
|
3383
|
+
}
|
|
3384
|
+
}
|
|
3385
|
+
categories {
|
|
3386
|
+
nodes { databaseId name slug }
|
|
3387
|
+
}
|
|
3388
|
+
tags {
|
|
3389
|
+
nodes { databaseId name slug }
|
|
3390
|
+
}
|
|
3391
|
+
${SEO_FIELDS}
|
|
3392
|
+
`;
|
|
3393
|
+
var PAGE_FIELDS_WITH_SEO = `
|
|
3394
|
+
id
|
|
3395
|
+
databaseId
|
|
3396
|
+
slug
|
|
3397
|
+
title
|
|
3398
|
+
content
|
|
3399
|
+
date
|
|
3400
|
+
modified
|
|
3401
|
+
status
|
|
3402
|
+
uri
|
|
3403
|
+
featuredImage {
|
|
3404
|
+
node {
|
|
3405
|
+
sourceUrl
|
|
3406
|
+
altText
|
|
3407
|
+
mediaDetails { width height }
|
|
3408
|
+
}
|
|
3409
|
+
}
|
|
3410
|
+
${SEO_FIELDS}
|
|
3411
|
+
`;
|
|
3412
|
+
var GQL_GET_POST_WITH_SEO = `
|
|
3413
|
+
query GetPostWithSEO($slug: ID!) {
|
|
3414
|
+
post(id: $slug, idType: SLUG) { ${POST_FIELDS_WITH_SEO} }
|
|
3415
|
+
}
|
|
3416
|
+
`;
|
|
3417
|
+
var GQL_GET_PAGE_WITH_SEO = `
|
|
3418
|
+
query GetPageWithSEO($slug: ID!) {
|
|
3419
|
+
page(id: $slug, idType: SLUG) { ${PAGE_FIELDS_WITH_SEO} }
|
|
3420
|
+
}
|
|
3421
|
+
`;
|
|
3422
|
+
var GQL_GET_PAGE_WITH_SEO_BY_URI = `
|
|
3423
|
+
query GetPageWithSEOByUri($uri: ID!) {
|
|
3424
|
+
page(id: $uri, idType: URI) { ${PAGE_FIELDS_WITH_SEO} }
|
|
3425
|
+
}
|
|
3426
|
+
`;
|
|
3427
|
+
function createYoastQueries(fetcher) {
|
|
3428
|
+
const { gqlFetchGraceful } = fetcher;
|
|
3429
|
+
async function getPostWithSEO(slug) {
|
|
3430
|
+
const data = await gqlFetchGraceful(
|
|
3431
|
+
GQL_GET_POST_WITH_SEO,
|
|
3432
|
+
{ post: null },
|
|
3433
|
+
{ slug },
|
|
3434
|
+
["wpgraphql", "gql-posts", "gql-yoast", `gql-post-${slug}`]
|
|
3435
|
+
);
|
|
3436
|
+
return data.post;
|
|
3437
|
+
}
|
|
3438
|
+
async function getPageWithSEO(slug) {
|
|
3439
|
+
const data = await gqlFetchGraceful(
|
|
3440
|
+
GQL_GET_PAGE_WITH_SEO,
|
|
3441
|
+
{ page: null },
|
|
3442
|
+
{ slug },
|
|
3443
|
+
["wpgraphql", "gql-pages", "gql-yoast", `gql-page-${slug}`]
|
|
3444
|
+
);
|
|
3445
|
+
return data.page;
|
|
3446
|
+
}
|
|
3447
|
+
async function getPageWithSEOByUri(uri) {
|
|
3448
|
+
const data = await gqlFetchGraceful(
|
|
3449
|
+
GQL_GET_PAGE_WITH_SEO_BY_URI,
|
|
3450
|
+
{ page: null },
|
|
3451
|
+
{ uri },
|
|
3452
|
+
["wpgraphql", "gql-pages", "gql-yoast", `gql-page-uri-${uri.replace(/\//g, "-")}`]
|
|
3453
|
+
);
|
|
3454
|
+
return data.page;
|
|
3455
|
+
}
|
|
3456
|
+
return { getPostWithSEO, getPageWithSEO, getPageWithSEOByUri };
|
|
3457
|
+
}
|
|
3458
|
+
|
|
3459
|
+
// src/integrations/wpGraphQL/acf/helpers.ts
|
|
3460
|
+
var BASE_POST_FIELDS = `
|
|
3461
|
+
id databaseId slug title content excerpt date modified status uri
|
|
3462
|
+
author { node { databaseId name slug avatar { url } } }
|
|
3463
|
+
featuredImage { node { sourceUrl altText mediaDetails { width height } } }
|
|
3464
|
+
categories { nodes { databaseId name slug } }
|
|
3465
|
+
tags { nodes { databaseId name slug } }
|
|
3466
|
+
`;
|
|
3467
|
+
var BASE_PAGE_FIELDS = `
|
|
3468
|
+
id databaseId slug title content date modified status uri
|
|
3469
|
+
featuredImage { node { sourceUrl altText mediaDetails { width height } } }
|
|
3470
|
+
`;
|
|
3471
|
+
function buildACFFragment(fieldGroupName, fields) {
|
|
3472
|
+
return `${fieldGroupName} { ${fields.join(" ")} }`;
|
|
3473
|
+
}
|
|
3474
|
+
function buildPostWithACFQuery(fieldGroupName, fields) {
|
|
3475
|
+
return `
|
|
3476
|
+
query GetPostWithACF($slug: ID!) {
|
|
3477
|
+
post(id: $slug, idType: SLUG) {
|
|
3478
|
+
${BASE_POST_FIELDS}
|
|
3479
|
+
${buildACFFragment(fieldGroupName, fields)}
|
|
3480
|
+
}
|
|
3481
|
+
}
|
|
3482
|
+
`;
|
|
3483
|
+
}
|
|
3484
|
+
function buildPageWithACFQuery(fieldGroupName, fields) {
|
|
3485
|
+
return `
|
|
3486
|
+
query GetPageWithACF($slug: ID!) {
|
|
3487
|
+
page(id: $slug, idType: SLUG) {
|
|
3488
|
+
${BASE_PAGE_FIELDS}
|
|
3489
|
+
${buildACFFragment(fieldGroupName, fields)}
|
|
3490
|
+
}
|
|
3491
|
+
}
|
|
3492
|
+
`;
|
|
3493
|
+
}
|
|
3494
|
+
function buildPostsWithACFQuery(fieldGroupName, fields) {
|
|
3495
|
+
return `
|
|
3496
|
+
query GetPostsWithACF($first: Int, $after: String) {
|
|
3497
|
+
posts(first: $first, after: $after) {
|
|
3498
|
+
nodes {
|
|
3499
|
+
${BASE_POST_FIELDS}
|
|
3500
|
+
${buildACFFragment(fieldGroupName, fields)}
|
|
3501
|
+
}
|
|
3502
|
+
pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
|
|
3503
|
+
}
|
|
3504
|
+
}
|
|
3505
|
+
`;
|
|
3506
|
+
}
|
|
3507
|
+
|
|
3508
|
+
// src/integrations/wpGraphQL/woocommerce/products/queries.ts
|
|
3509
|
+
var DEFAULT_FIRST7 = 10;
|
|
3510
|
+
var BATCH_FIRST3 = 100;
|
|
3511
|
+
var PRODUCT_FIELDS = `
|
|
3512
|
+
id
|
|
3513
|
+
databaseId
|
|
3514
|
+
slug
|
|
3515
|
+
name
|
|
3516
|
+
status
|
|
3517
|
+
description
|
|
3518
|
+
shortDescription
|
|
3519
|
+
type
|
|
3520
|
+
onSale
|
|
3521
|
+
featuredImage { node { sourceUrl altText } }
|
|
3522
|
+
galleryImages { nodes { sourceUrl altText } }
|
|
3523
|
+
productCategories { nodes { databaseId name slug } }
|
|
3524
|
+
productTags { nodes { databaseId name slug } }
|
|
3525
|
+
... on SimpleProduct {
|
|
3526
|
+
sku
|
|
3527
|
+
price
|
|
3528
|
+
regularPrice
|
|
3529
|
+
salePrice
|
|
3530
|
+
stockStatus
|
|
3531
|
+
stockQuantity
|
|
3532
|
+
manageStock
|
|
3533
|
+
}
|
|
3534
|
+
... on VariableProduct {
|
|
3535
|
+
price
|
|
3536
|
+
regularPrice
|
|
3537
|
+
salePrice
|
|
3538
|
+
stockStatus
|
|
3539
|
+
stockQuantity
|
|
3540
|
+
manageStock
|
|
3541
|
+
variations {
|
|
3542
|
+
nodes {
|
|
3543
|
+
id
|
|
3544
|
+
databaseId
|
|
3545
|
+
slug
|
|
3546
|
+
sku
|
|
3547
|
+
price
|
|
3548
|
+
regularPrice
|
|
3549
|
+
salePrice
|
|
3550
|
+
onSale
|
|
3551
|
+
stockStatus
|
|
3552
|
+
stockQuantity
|
|
3553
|
+
image { sourceUrl altText }
|
|
3554
|
+
attributes { nodes { name value } }
|
|
3555
|
+
}
|
|
3556
|
+
}
|
|
3557
|
+
}
|
|
3558
|
+
`;
|
|
3559
|
+
var GQL_GET_PRODUCTS = `
|
|
3560
|
+
query GetProducts($first: Int, $after: String, $where: RootQueryToProductConnectionWhereArgs) {
|
|
3561
|
+
products(first: $first, after: $after, where: $where) {
|
|
3562
|
+
nodes { ${PRODUCT_FIELDS} }
|
|
3563
|
+
pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
|
|
3564
|
+
}
|
|
3565
|
+
}
|
|
3566
|
+
`;
|
|
3567
|
+
var GQL_GET_PRODUCT_BY_SLUG = `
|
|
3568
|
+
query GetProductBySlug($slug: ID!) {
|
|
3569
|
+
product(id: $slug, idType: SLUG) { ${PRODUCT_FIELDS} }
|
|
3570
|
+
}
|
|
3571
|
+
`;
|
|
3572
|
+
var GQL_GET_PRODUCT_BY_DATABASE_ID = `
|
|
3573
|
+
query GetProductByDatabaseId($id: ID!) {
|
|
3574
|
+
product(id: $id, idType: DATABASE_ID) { ${PRODUCT_FIELDS} }
|
|
3575
|
+
}
|
|
3576
|
+
`;
|
|
3577
|
+
var GQL_GET_ALL_PRODUCT_SLUGS = `
|
|
3578
|
+
query GetAllProductSlugs($first: Int, $after: String) {
|
|
3579
|
+
products(first: $first, after: $after) {
|
|
3580
|
+
nodes { slug }
|
|
3581
|
+
pageInfo { hasNextPage endCursor }
|
|
3582
|
+
}
|
|
3583
|
+
}
|
|
3584
|
+
`;
|
|
3585
|
+
function createProductsQueries2(fetcher) {
|
|
3586
|
+
const { gqlFetch, gqlFetchGraceful } = fetcher;
|
|
3587
|
+
async function getProducts(first = DEFAULT_FIRST7, after, filter) {
|
|
3588
|
+
const where = {};
|
|
3589
|
+
if (filter?.search) where["search"] = filter.search;
|
|
3590
|
+
if (filter?.onSale !== void 0) where["onSale"] = filter.onSale;
|
|
3591
|
+
if (filter?.featured !== void 0) where["featured"] = filter.featured;
|
|
3592
|
+
if (filter?.stockStatus) where["stockStatus"] = filter.stockStatus;
|
|
3593
|
+
if (filter?.minPrice) where["minPrice"] = filter.minPrice;
|
|
3594
|
+
if (filter?.maxPrice) where["maxPrice"] = filter.maxPrice;
|
|
3595
|
+
if (filter?.categoryId) where["categoryIdIn"] = [filter.categoryId];
|
|
3596
|
+
if (filter?.tagId) where["tagIdIn"] = [filter.tagId];
|
|
3597
|
+
const data = await gqlFetchGraceful(
|
|
3598
|
+
GQL_GET_PRODUCTS,
|
|
3599
|
+
{ products: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
|
|
3600
|
+
{ first, after, where: Object.keys(where).length > 0 ? where : void 0 },
|
|
3601
|
+
["wpgraphql", "gql-products"]
|
|
3602
|
+
);
|
|
3603
|
+
return data.products;
|
|
3604
|
+
}
|
|
3605
|
+
async function getProductBySlug(slug) {
|
|
3606
|
+
const data = await gqlFetchGraceful(
|
|
3607
|
+
GQL_GET_PRODUCT_BY_SLUG,
|
|
3608
|
+
{ product: null },
|
|
3609
|
+
{ slug },
|
|
3610
|
+
["wpgraphql", "gql-products", `gql-product-${slug}`]
|
|
3611
|
+
);
|
|
3612
|
+
return data.product;
|
|
3613
|
+
}
|
|
3614
|
+
async function getProductByDatabaseId(id) {
|
|
3615
|
+
const data = await gqlFetchGraceful(
|
|
3616
|
+
GQL_GET_PRODUCT_BY_DATABASE_ID,
|
|
3617
|
+
{ product: null },
|
|
3618
|
+
{ id: String(id) },
|
|
3619
|
+
["wpgraphql", "gql-products", `gql-product-id-${id}`]
|
|
3620
|
+
);
|
|
3621
|
+
return data.product;
|
|
3622
|
+
}
|
|
3623
|
+
async function getFeaturedProducts(first = DEFAULT_FIRST7) {
|
|
3624
|
+
const connection = await getProducts(first, void 0, { featured: true });
|
|
3625
|
+
return connection.nodes;
|
|
3626
|
+
}
|
|
3627
|
+
async function getOnSaleProducts(first = DEFAULT_FIRST7) {
|
|
3628
|
+
const connection = await getProducts(first, void 0, { onSale: true });
|
|
3629
|
+
return connection.nodes;
|
|
3630
|
+
}
|
|
3631
|
+
async function getAllProductSlugs() {
|
|
3632
|
+
try {
|
|
3633
|
+
const all = [];
|
|
3634
|
+
let after = void 0;
|
|
3635
|
+
let hasNextPage = true;
|
|
3636
|
+
while (hasNextPage) {
|
|
3637
|
+
const data = await gqlFetch(GQL_GET_ALL_PRODUCT_SLUGS, { first: BATCH_FIRST3, after }, ["wpgraphql"]);
|
|
3638
|
+
all.push(...data.products.nodes);
|
|
3639
|
+
hasNextPage = data.products.pageInfo.hasNextPage;
|
|
3640
|
+
after = data.products.pageInfo.endCursor;
|
|
3641
|
+
}
|
|
3642
|
+
return all;
|
|
3643
|
+
} catch {
|
|
3644
|
+
console.warn("WPGraphQL unavailable, skipping static generation for products");
|
|
3645
|
+
return [];
|
|
3646
|
+
}
|
|
3647
|
+
}
|
|
3648
|
+
return {
|
|
3649
|
+
getProducts,
|
|
3650
|
+
getProductBySlug,
|
|
3651
|
+
getProductByDatabaseId,
|
|
3652
|
+
getFeaturedProducts,
|
|
3653
|
+
getOnSaleProducts,
|
|
3654
|
+
getAllProductSlugs
|
|
3655
|
+
};
|
|
3656
|
+
}
|
|
3657
|
+
|
|
3658
|
+
// src/integrations/wpGraphQL/woocommerce/orders/queries.ts
|
|
3659
|
+
var DEFAULT_FIRST8 = 10;
|
|
3660
|
+
var ADDRESS_FIELDS = `
|
|
3661
|
+
firstName lastName address1 address2 city postcode country email phone
|
|
3662
|
+
`;
|
|
3663
|
+
var ORDER_FIELDS = `
|
|
3664
|
+
id
|
|
3665
|
+
databaseId
|
|
3666
|
+
orderNumber
|
|
3667
|
+
status
|
|
3668
|
+
date
|
|
3669
|
+
modified
|
|
3670
|
+
total
|
|
3671
|
+
subtotal
|
|
3672
|
+
totalTax
|
|
3673
|
+
shippingTotal
|
|
3674
|
+
currency
|
|
3675
|
+
billing { ${ADDRESS_FIELDS} }
|
|
3676
|
+
shipping { ${ADDRESS_FIELDS} }
|
|
3677
|
+
lineItems {
|
|
3678
|
+
nodes {
|
|
3679
|
+
productId
|
|
3680
|
+
variationId
|
|
3681
|
+
quantity
|
|
3682
|
+
subtotal
|
|
3683
|
+
total
|
|
3684
|
+
product { node { databaseId name slug } }
|
|
3685
|
+
}
|
|
3686
|
+
}
|
|
3687
|
+
`;
|
|
3688
|
+
var GQL_GET_ORDER = `
|
|
3689
|
+
query GetOrder($id: ID!) {
|
|
3690
|
+
order(id: $id, idType: DATABASE_ID) { ${ORDER_FIELDS} }
|
|
3691
|
+
}
|
|
3692
|
+
`;
|
|
3693
|
+
var GQL_GET_MY_ORDERS = `
|
|
3694
|
+
query GetMyOrders($first: Int, $after: String) {
|
|
3695
|
+
orders(first: $first, after: $after) {
|
|
3696
|
+
nodes { ${ORDER_FIELDS} }
|
|
3697
|
+
pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
|
|
3698
|
+
}
|
|
3699
|
+
}
|
|
3700
|
+
`;
|
|
3701
|
+
function createOrdersQueries2(fetcher) {
|
|
3702
|
+
const { gqlFetchGraceful } = fetcher;
|
|
3703
|
+
async function getOrder(id) {
|
|
3704
|
+
const data = await gqlFetchGraceful(
|
|
3705
|
+
GQL_GET_ORDER,
|
|
3706
|
+
{ order: null },
|
|
3707
|
+
{ id: String(id) },
|
|
3708
|
+
["wpgraphql", "gql-orders", `gql-order-${id}`]
|
|
3709
|
+
);
|
|
3710
|
+
return data.order;
|
|
3711
|
+
}
|
|
3712
|
+
async function getMyOrders(first = DEFAULT_FIRST8, after) {
|
|
3713
|
+
const data = await gqlFetchGraceful(
|
|
3714
|
+
GQL_GET_MY_ORDERS,
|
|
3715
|
+
{ orders: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
|
|
3716
|
+
{ first, after },
|
|
3717
|
+
["wpgraphql", "gql-orders"]
|
|
3718
|
+
);
|
|
3719
|
+
return data.orders;
|
|
3720
|
+
}
|
|
3721
|
+
return { getOrder, getMyOrders };
|
|
3722
|
+
}
|
|
3723
|
+
|
|
3724
|
+
// src/integrations/wpGraphQL/woocommerce/customers/queries.ts
|
|
3725
|
+
var ADDRESS_FIELDS2 = `
|
|
3726
|
+
firstName lastName address1 address2 city postcode country
|
|
3727
|
+
`;
|
|
3728
|
+
var CUSTOMER_FIELDS = `
|
|
3729
|
+
id
|
|
3730
|
+
databaseId
|
|
3731
|
+
email
|
|
3732
|
+
firstName
|
|
3733
|
+
lastName
|
|
3734
|
+
username
|
|
3735
|
+
billing { ${ADDRESS_FIELDS2} phone }
|
|
3736
|
+
shipping { ${ADDRESS_FIELDS2} }
|
|
3737
|
+
`;
|
|
3738
|
+
var GQL_GET_CUSTOMER = `
|
|
3739
|
+
query GetCustomer {
|
|
3740
|
+
customer { ${CUSTOMER_FIELDS} }
|
|
3741
|
+
}
|
|
3742
|
+
`;
|
|
3743
|
+
var GQL_GET_CUSTOMER_BY_ID = `
|
|
3744
|
+
query GetCustomerById($id: ID!) {
|
|
3745
|
+
customer(customerId: $id) { ${CUSTOMER_FIELDS} }
|
|
3746
|
+
}
|
|
3747
|
+
`;
|
|
3748
|
+
function createCustomersQueries2(fetcher) {
|
|
3749
|
+
const { gqlFetchGraceful } = fetcher;
|
|
3750
|
+
async function getCustomer() {
|
|
3751
|
+
const data = await gqlFetchGraceful(
|
|
3752
|
+
GQL_GET_CUSTOMER,
|
|
3753
|
+
{ customer: null },
|
|
3754
|
+
void 0,
|
|
3755
|
+
["wpgraphql", "gql-customer"]
|
|
3756
|
+
);
|
|
3757
|
+
return data.customer;
|
|
3758
|
+
}
|
|
3759
|
+
async function getCustomerById(id) {
|
|
3760
|
+
const data = await gqlFetchGraceful(
|
|
3761
|
+
GQL_GET_CUSTOMER_BY_ID,
|
|
3762
|
+
{ customer: null },
|
|
3763
|
+
{ id: String(id) },
|
|
3764
|
+
["wpgraphql", "gql-customer", `gql-customer-${id}`]
|
|
3765
|
+
);
|
|
3766
|
+
return data.customer;
|
|
3767
|
+
}
|
|
3768
|
+
return { getCustomer, getCustomerById };
|
|
3769
|
+
}
|
|
3770
|
+
|
|
3771
|
+
// src/integrations/wpGraphQL/woocommerce/categories/queries.ts
|
|
3772
|
+
var DEFAULT_FIRST9 = 100;
|
|
3773
|
+
var CATEGORY_FIELDS2 = `
|
|
3774
|
+
id
|
|
3775
|
+
databaseId
|
|
3776
|
+
name
|
|
3777
|
+
slug
|
|
3778
|
+
description
|
|
3779
|
+
count
|
|
3780
|
+
parent { node { id databaseId name slug } }
|
|
3781
|
+
image { sourceUrl altText }
|
|
3782
|
+
`;
|
|
3783
|
+
var GQL_GET_PRODUCT_CATEGORIES = `
|
|
3784
|
+
query GetProductCategories($first: Int, $after: String) {
|
|
3785
|
+
productCategories(first: $first, after: $after) {
|
|
3786
|
+
nodes { ${CATEGORY_FIELDS2} }
|
|
3787
|
+
pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
|
|
3788
|
+
}
|
|
3789
|
+
}
|
|
3790
|
+
`;
|
|
3791
|
+
var GQL_GET_PRODUCT_CATEGORY_BY_SLUG = `
|
|
3792
|
+
query GetProductCategoryBySlug($id: ID!) {
|
|
3793
|
+
productCategory(id: $id, idType: SLUG) { ${CATEGORY_FIELDS2} }
|
|
3794
|
+
}
|
|
3795
|
+
`;
|
|
3796
|
+
var GQL_GET_PRODUCT_CATEGORY_BY_ID = `
|
|
3797
|
+
query GetProductCategoryById($id: ID!) {
|
|
3798
|
+
productCategory(id: $id, idType: DATABASE_ID) { ${CATEGORY_FIELDS2} }
|
|
3799
|
+
}
|
|
3800
|
+
`;
|
|
3801
|
+
function createCategoriesQueries4(fetcher) {
|
|
3802
|
+
const { gqlFetchGraceful } = fetcher;
|
|
3803
|
+
async function getProductCategories(first = DEFAULT_FIRST9, after) {
|
|
3804
|
+
const data = await gqlFetchGraceful(
|
|
3805
|
+
GQL_GET_PRODUCT_CATEGORIES,
|
|
3806
|
+
{ productCategories: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
|
|
3807
|
+
{ first, after },
|
|
3808
|
+
["wpgraphql", "gql-product-categories"]
|
|
3809
|
+
);
|
|
3810
|
+
return data.productCategories;
|
|
3811
|
+
}
|
|
3812
|
+
async function getProductCategoryBySlug(slug) {
|
|
3813
|
+
const data = await gqlFetchGraceful(
|
|
3814
|
+
GQL_GET_PRODUCT_CATEGORY_BY_SLUG,
|
|
3815
|
+
{ productCategory: null },
|
|
3816
|
+
{ id: slug },
|
|
3817
|
+
["wpgraphql", "gql-product-categories", `gql-product-category-${slug}`]
|
|
3818
|
+
);
|
|
3819
|
+
return data.productCategory;
|
|
3820
|
+
}
|
|
3821
|
+
async function getProductCategoryById(id) {
|
|
3822
|
+
const data = await gqlFetchGraceful(
|
|
3823
|
+
GQL_GET_PRODUCT_CATEGORY_BY_ID,
|
|
3824
|
+
{ productCategory: null },
|
|
3825
|
+
{ id: String(id) },
|
|
3826
|
+
["wpgraphql", "gql-product-categories", `gql-product-category-${id}`]
|
|
3827
|
+
);
|
|
3828
|
+
return data.productCategory;
|
|
3829
|
+
}
|
|
3830
|
+
return { getProductCategories, getProductCategoryBySlug, getProductCategoryById };
|
|
3831
|
+
}
|
|
3832
|
+
|
|
3833
|
+
// src/integrations/wpGraphQL/woocommerce/tags/queries.ts
|
|
3834
|
+
var DEFAULT_FIRST10 = 100;
|
|
3835
|
+
var TAG_FIELDS2 = `
|
|
3836
|
+
id
|
|
3837
|
+
databaseId
|
|
3838
|
+
name
|
|
3839
|
+
slug
|
|
3840
|
+
description
|
|
3841
|
+
count
|
|
3842
|
+
`;
|
|
3843
|
+
var GQL_GET_PRODUCT_TAGS = `
|
|
3844
|
+
query GetProductTags($first: Int, $after: String) {
|
|
3845
|
+
productTags(first: $first, after: $after) {
|
|
3846
|
+
nodes { ${TAG_FIELDS2} }
|
|
3847
|
+
pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
|
|
3848
|
+
}
|
|
3849
|
+
}
|
|
3850
|
+
`;
|
|
3851
|
+
var GQL_GET_PRODUCT_TAG_BY_SLUG = `
|
|
3852
|
+
query GetProductTagBySlug($id: ID!) {
|
|
3853
|
+
productTag(id: $id, idType: SLUG) { ${TAG_FIELDS2} }
|
|
3854
|
+
}
|
|
3855
|
+
`;
|
|
3856
|
+
var GQL_GET_PRODUCT_TAG_BY_ID = `
|
|
3857
|
+
query GetProductTagById($id: ID!) {
|
|
3858
|
+
productTag(id: $id, idType: DATABASE_ID) { ${TAG_FIELDS2} }
|
|
3859
|
+
}
|
|
3860
|
+
`;
|
|
3861
|
+
function createTagsQueries4(fetcher) {
|
|
3862
|
+
const { gqlFetchGraceful } = fetcher;
|
|
3863
|
+
async function getProductTags(first = DEFAULT_FIRST10, after) {
|
|
3864
|
+
const data = await gqlFetchGraceful(
|
|
3865
|
+
GQL_GET_PRODUCT_TAGS,
|
|
3866
|
+
{ productTags: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
|
|
3867
|
+
{ first, after },
|
|
3868
|
+
["wpgraphql", "gql-product-tags"]
|
|
3869
|
+
);
|
|
3870
|
+
return data.productTags;
|
|
3871
|
+
}
|
|
3872
|
+
async function getProductTagBySlug(slug) {
|
|
3873
|
+
const data = await gqlFetchGraceful(
|
|
3874
|
+
GQL_GET_PRODUCT_TAG_BY_SLUG,
|
|
3875
|
+
{ productTag: null },
|
|
3876
|
+
{ id: slug },
|
|
3877
|
+
["wpgraphql", "gql-product-tags", `gql-product-tag-${slug}`]
|
|
3878
|
+
);
|
|
3879
|
+
return data.productTag;
|
|
3880
|
+
}
|
|
3881
|
+
async function getProductTagById(id) {
|
|
3882
|
+
const data = await gqlFetchGraceful(
|
|
3883
|
+
GQL_GET_PRODUCT_TAG_BY_ID,
|
|
3884
|
+
{ productTag: null },
|
|
3885
|
+
{ id: String(id) },
|
|
3886
|
+
["wpgraphql", "gql-product-tags", `gql-product-tag-${id}`]
|
|
3887
|
+
);
|
|
3888
|
+
return data.productTag;
|
|
3889
|
+
}
|
|
3890
|
+
return { getProductTags, getProductTagBySlug, getProductTagById };
|
|
3891
|
+
}
|
|
3892
|
+
|
|
3893
|
+
// src/integrations/wpGraphQL/woocommerce/coupons/queries.ts
|
|
3894
|
+
var DEFAULT_FIRST11 = 100;
|
|
3895
|
+
var COUPON_FIELDS = `
|
|
3896
|
+
id
|
|
3897
|
+
databaseId
|
|
3898
|
+
code
|
|
3899
|
+
discountType
|
|
3900
|
+
amount
|
|
3901
|
+
dateExpiry
|
|
3902
|
+
usageCount
|
|
3903
|
+
usageLimit
|
|
3904
|
+
usageLimitPerUser
|
|
3905
|
+
individualUse
|
|
3906
|
+
freeShipping
|
|
3907
|
+
minimumAmount
|
|
3908
|
+
maximumAmount
|
|
3909
|
+
description
|
|
3910
|
+
`;
|
|
3911
|
+
var GQL_GET_COUPONS = `
|
|
3912
|
+
query GetCoupons($first: Int, $after: String) {
|
|
3913
|
+
coupons(first: $first, after: $after) {
|
|
3914
|
+
nodes { ${COUPON_FIELDS} }
|
|
3915
|
+
pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
|
|
3916
|
+
}
|
|
3917
|
+
}
|
|
3918
|
+
`;
|
|
3919
|
+
var GQL_GET_COUPON_BY_CODE = `
|
|
3920
|
+
query GetCouponByCode($id: ID!) {
|
|
3921
|
+
coupon(id: $id, idType: CODE) { ${COUPON_FIELDS} }
|
|
3922
|
+
}
|
|
3923
|
+
`;
|
|
3924
|
+
var GQL_GET_COUPON_BY_ID = `
|
|
3925
|
+
query GetCouponById($id: ID!) {
|
|
3926
|
+
coupon(id: $id, idType: DATABASE_ID) { ${COUPON_FIELDS} }
|
|
3927
|
+
}
|
|
3928
|
+
`;
|
|
3929
|
+
function createCouponsQueries2(fetcher) {
|
|
3930
|
+
const { gqlFetchGraceful } = fetcher;
|
|
3931
|
+
async function getCoupons(first = DEFAULT_FIRST11, after) {
|
|
3932
|
+
const data = await gqlFetchGraceful(
|
|
3933
|
+
GQL_GET_COUPONS,
|
|
3934
|
+
{ coupons: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
|
|
3935
|
+
{ first, after },
|
|
3936
|
+
["wpgraphql", "gql-coupons"]
|
|
3937
|
+
);
|
|
3938
|
+
return data.coupons;
|
|
3939
|
+
}
|
|
3940
|
+
async function getCouponByCode(code) {
|
|
3941
|
+
const data = await gqlFetchGraceful(
|
|
3942
|
+
GQL_GET_COUPON_BY_CODE,
|
|
3943
|
+
{ coupon: null },
|
|
3944
|
+
{ id: code },
|
|
3945
|
+
["wpgraphql", "gql-coupons", `gql-coupon-${code}`]
|
|
3946
|
+
);
|
|
3947
|
+
return data.coupon;
|
|
3948
|
+
}
|
|
3949
|
+
async function getCouponById(id) {
|
|
3950
|
+
const data = await gqlFetchGraceful(
|
|
3951
|
+
GQL_GET_COUPON_BY_ID,
|
|
3952
|
+
{ coupon: null },
|
|
3953
|
+
{ id: String(id) },
|
|
3954
|
+
["wpgraphql", "gql-coupons", `gql-coupon-${id}`]
|
|
3955
|
+
);
|
|
3956
|
+
return data.coupon;
|
|
3957
|
+
}
|
|
3958
|
+
return { getCoupons, getCouponByCode, getCouponById };
|
|
3959
|
+
}
|
|
3960
|
+
|
|
3961
|
+
// src/integrations/wpGraphQL/woocommerce/index.ts
|
|
3962
|
+
function createWPGraphQLWooCommerceClient(config) {
|
|
3963
|
+
const fetcher = createWPGraphQLFetcher(config);
|
|
3964
|
+
return {
|
|
3965
|
+
...createProductsQueries2(fetcher),
|
|
3966
|
+
...createOrdersQueries2(fetcher),
|
|
3967
|
+
...createCustomersQueries2(fetcher),
|
|
3968
|
+
...createCategoriesQueries4(fetcher),
|
|
3969
|
+
...createTagsQueries4(fetcher),
|
|
3970
|
+
...createCouponsQueries2(fetcher)
|
|
3971
|
+
};
|
|
3972
|
+
}
|
|
3973
|
+
|
|
3974
|
+
// src/integrations/wpGraphQL/cpt/queries.ts
|
|
3975
|
+
var DEFAULT_FIRST12 = 10;
|
|
3976
|
+
var BATCH_FIRST4 = 100;
|
|
3977
|
+
var BASE_CPT_FIELDS = `
|
|
3978
|
+
id databaseId slug title date modified status uri
|
|
3979
|
+
`;
|
|
3980
|
+
function createCPTQueries(fetcher, typeName, singularTypeName, extraFields) {
|
|
3981
|
+
const { gqlFetch, gqlFetchGraceful } = fetcher;
|
|
3982
|
+
const fields = extraFields ? `${BASE_CPT_FIELDS} ${extraFields}` : BASE_CPT_FIELDS;
|
|
3983
|
+
const GQL_GET_ITEMS = `
|
|
3984
|
+
query GetCPT_${typeName}($first: Int, $after: String) {
|
|
3985
|
+
${typeName}(first: $first, after: $after) {
|
|
3986
|
+
nodes { ${fields} }
|
|
3987
|
+
pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
|
|
3988
|
+
}
|
|
3989
|
+
}
|
|
3990
|
+
`;
|
|
3991
|
+
const GQL_GET_ITEM_BY_SLUG = `
|
|
3992
|
+
query GetCPT_${singularTypeName}BySlug($slug: ID!) {
|
|
3993
|
+
${singularTypeName}(id: $slug, idType: SLUG) { ${fields} }
|
|
3994
|
+
}
|
|
3995
|
+
`;
|
|
3996
|
+
const GQL_GET_ALL_SLUGS = `
|
|
3997
|
+
query GetAllCPT_${typeName}Slugs($first: Int, $after: String) {
|
|
3998
|
+
${typeName}(first: $first, after: $after) {
|
|
3999
|
+
nodes { slug }
|
|
4000
|
+
pageInfo { hasNextPage endCursor }
|
|
4001
|
+
}
|
|
4002
|
+
}
|
|
4003
|
+
`;
|
|
4004
|
+
async function getItems(first = DEFAULT_FIRST12, after) {
|
|
4005
|
+
const data = await gqlFetchGraceful(
|
|
4006
|
+
GQL_GET_ITEMS,
|
|
4007
|
+
{ [typeName]: { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } } },
|
|
4008
|
+
{ first, after },
|
|
4009
|
+
["wpgraphql", `gql-${typeName}`]
|
|
4010
|
+
);
|
|
4011
|
+
return data[typeName] ?? { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } };
|
|
4012
|
+
}
|
|
4013
|
+
async function getItemBySlug(slug) {
|
|
4014
|
+
const data = await gqlFetchGraceful(
|
|
4015
|
+
GQL_GET_ITEM_BY_SLUG,
|
|
4016
|
+
{ [singularTypeName]: null },
|
|
4017
|
+
{ slug },
|
|
4018
|
+
["wpgraphql", `gql-${typeName}`, `gql-${singularTypeName}-${slug}`]
|
|
4019
|
+
);
|
|
4020
|
+
return data[singularTypeName] ?? null;
|
|
4021
|
+
}
|
|
4022
|
+
async function getAllSlugs() {
|
|
4023
|
+
try {
|
|
4024
|
+
const all = [];
|
|
4025
|
+
let after = void 0;
|
|
4026
|
+
let hasNextPage = true;
|
|
4027
|
+
while (hasNextPage) {
|
|
4028
|
+
const data = await gqlFetch(GQL_GET_ALL_SLUGS, { first: BATCH_FIRST4, after }, ["wpgraphql"]);
|
|
4029
|
+
const connection = data[typeName];
|
|
4030
|
+
if (!connection) break;
|
|
4031
|
+
all.push(...connection.nodes);
|
|
4032
|
+
hasNextPage = connection.pageInfo.hasNextPage;
|
|
4033
|
+
after = connection.pageInfo.endCursor;
|
|
4034
|
+
}
|
|
4035
|
+
return all;
|
|
4036
|
+
} catch {
|
|
4037
|
+
console.warn(`WPGraphQL unavailable, skipping static generation for ${typeName}`);
|
|
4038
|
+
return [];
|
|
4039
|
+
}
|
|
4040
|
+
}
|
|
4041
|
+
return { getItems, getItemBySlug, getAllSlugs };
|
|
4042
|
+
}
|
|
4043
|
+
|
|
4044
|
+
// src/nextjs/revalidation.ts
|
|
4045
|
+
var ACTION_TAG_MAP = {
|
|
4046
|
+
save_post: ["wordpress", "posts"],
|
|
4047
|
+
save_post_post: ["wordpress", "posts"],
|
|
4048
|
+
save_post_page: ["wordpress", "pages"],
|
|
4049
|
+
delete_post: ["wordpress", "posts", "pages"],
|
|
4050
|
+
created_term: ["wordpress", "categories", "tags"],
|
|
4051
|
+
edited_term: ["wordpress", "categories", "tags"],
|
|
4052
|
+
delete_term: ["wordpress", "categories", "tags"],
|
|
4053
|
+
wp_update_nav_menu: ["wordpress", "menus"],
|
|
4054
|
+
woocommerce_product_updated: ["woocommerce", "products"],
|
|
4055
|
+
woocommerce_new_product: ["woocommerce", "products"],
|
|
4056
|
+
woocommerce_delete_product: ["woocommerce", "products"],
|
|
4057
|
+
woocommerce_new_order: ["woocommerce", "orders"],
|
|
4058
|
+
woocommerce_order_status_changed: ["woocommerce", "orders"],
|
|
4059
|
+
woocommerce_update_order: ["woocommerce", "orders"],
|
|
4060
|
+
woocommerce_product_category_updated: ["woocommerce", "categories"],
|
|
4061
|
+
woocommerce_product_tag_updated: ["woocommerce", "tags"]
|
|
4062
|
+
};
|
|
4063
|
+
function extractSecret(request) {
|
|
4064
|
+
const auth = request.headers.get("Authorization");
|
|
4065
|
+
if (auth?.startsWith("Bearer ")) return auth.slice(7);
|
|
4066
|
+
return new URL(request.url).searchParams.get("secret");
|
|
4067
|
+
}
|
|
4068
|
+
function createRevalidationHandler(config, revalidateTag) {
|
|
4069
|
+
return async function handler(request) {
|
|
4070
|
+
if (extractSecret(request) !== config.secret) {
|
|
4071
|
+
return Response.json({ revalidated: false, tags: [], message: "Unauthorized" }, { status: 401 });
|
|
4072
|
+
}
|
|
4073
|
+
let payload;
|
|
4074
|
+
try {
|
|
4075
|
+
payload = await request.json();
|
|
4076
|
+
} catch {
|
|
4077
|
+
return Response.json({ revalidated: false, tags: [], message: "Invalid JSON body" }, { status: 400 });
|
|
4078
|
+
}
|
|
4079
|
+
const { action } = payload;
|
|
4080
|
+
const matched = ACTION_TAG_MAP[action];
|
|
4081
|
+
if (!matched) {
|
|
4082
|
+
return Response.json(
|
|
4083
|
+
{ revalidated: false, tags: [], message: `Unknown action: ${action}` },
|
|
4084
|
+
{ status: 400 }
|
|
4085
|
+
);
|
|
4086
|
+
}
|
|
4087
|
+
const tags = [...new Set(matched)];
|
|
4088
|
+
for (const tag of tags) {
|
|
4089
|
+
revalidateTag(tag);
|
|
4090
|
+
}
|
|
4091
|
+
return Response.json({ revalidated: true, tags });
|
|
4092
|
+
};
|
|
4093
|
+
}
|
|
4094
|
+
|
|
4095
|
+
// src/nextjs/faust.ts
|
|
4096
|
+
function createFaustAuthHandler(config) {
|
|
4097
|
+
const cookieName = config.cookieName ?? "faustwp-rt";
|
|
4098
|
+
return async function handler(request, routePath) {
|
|
4099
|
+
if (routePath === "auth/token") {
|
|
4100
|
+
const url = new URL(request.url);
|
|
4101
|
+
const code = url.searchParams.get("code");
|
|
4102
|
+
const redirectUri = url.searchParams.get("redirect_uri") ?? "/";
|
|
4103
|
+
const refreshToken = parseCookie(request, cookieName);
|
|
4104
|
+
if (!code && !refreshToken) {
|
|
4105
|
+
return Response.json({ error: "Unauthorized" }, { status: 401 });
|
|
4106
|
+
}
|
|
4107
|
+
const wpRes = await fetch(`${config.wpUrl}/?rest_route=/faustwp/v1/authorize`, {
|
|
4108
|
+
method: "POST",
|
|
4109
|
+
headers: {
|
|
4110
|
+
"Content-Type": "application/json",
|
|
4111
|
+
"x-faustwp-secret": config.secretKey
|
|
4112
|
+
},
|
|
4113
|
+
body: JSON.stringify({ code, refreshToken })
|
|
4114
|
+
});
|
|
4115
|
+
if (!wpRes.ok) {
|
|
4116
|
+
const body = await wpRes.text();
|
|
4117
|
+
return new Response(body, { status: wpRes.status });
|
|
4118
|
+
}
|
|
4119
|
+
const data = await wpRes.json();
|
|
4120
|
+
return new Response(null, {
|
|
4121
|
+
status: 302,
|
|
4122
|
+
headers: {
|
|
4123
|
+
Location: new URL(redirectUri, request.url).toString(),
|
|
4124
|
+
"Set-Cookie": buildSetCookie(cookieName, data.refreshToken, 2592e3)
|
|
4125
|
+
}
|
|
4126
|
+
});
|
|
4127
|
+
}
|
|
4128
|
+
if (routePath === "auth/logout") {
|
|
4129
|
+
return new Response(JSON.stringify({}), {
|
|
4130
|
+
status: 200,
|
|
4131
|
+
headers: {
|
|
4132
|
+
"Content-Type": "application/json",
|
|
4133
|
+
"Set-Cookie": `${cookieName}=; Max-Age=0; Path=/; HttpOnly`
|
|
4134
|
+
}
|
|
4135
|
+
});
|
|
4136
|
+
}
|
|
4137
|
+
return Response.json({ error: "Not Found" }, { status: 404 });
|
|
4138
|
+
};
|
|
4139
|
+
}
|
|
4140
|
+
function createPreviewHandler(config, deps) {
|
|
4141
|
+
const previewPath = config.previewPath ?? "posts";
|
|
4142
|
+
return async function handler(request) {
|
|
4143
|
+
const url = new URL(request.url);
|
|
4144
|
+
const postId = url.searchParams.get("postId");
|
|
4145
|
+
const previewPathname = url.searchParams.get("previewPathname");
|
|
4146
|
+
if (!postId) {
|
|
4147
|
+
return new Response("Missing postId", { status: 400 });
|
|
4148
|
+
}
|
|
4149
|
+
const slug = await resolvePreviewSlug(config, postId, previewPathname);
|
|
4150
|
+
if (!slug) {
|
|
4151
|
+
return new Response("Post not found", { status: 404 });
|
|
4152
|
+
}
|
|
4153
|
+
await deps.enableDraftMode();
|
|
4154
|
+
deps.redirect(`/${previewPath}/${slug}?postId=${postId}`);
|
|
4155
|
+
};
|
|
4156
|
+
}
|
|
4157
|
+
function parseCookie(request, name) {
|
|
4158
|
+
const header = request.headers.get("cookie") ?? "";
|
|
4159
|
+
const match = header.match(new RegExp(`(?:^|;\\s*)${name}=([^;]*)`));
|
|
4160
|
+
return match?.[1];
|
|
4161
|
+
}
|
|
4162
|
+
function buildSetCookie(name, value, maxAge) {
|
|
4163
|
+
const secure = process.env.NODE_ENV === "production" ? "; Secure" : "";
|
|
4164
|
+
return `${name}=${value}; HttpOnly; Path=/; SameSite=Strict; Max-Age=${maxAge}${secure}`;
|
|
4165
|
+
}
|
|
4166
|
+
async function resolvePreviewSlug(config, postId, previewPathname) {
|
|
4167
|
+
if (previewPathname && !previewPathname.includes("p=")) {
|
|
4168
|
+
const slug = previewPathname.replace(/\/$/, "").split("/").pop();
|
|
4169
|
+
if (slug) return slug;
|
|
4170
|
+
}
|
|
4171
|
+
const res = await fetch(`${config.wpUrl}/wp-json/wp/v2/posts/${postId}?_fields=slug`, {
|
|
4172
|
+
headers: { "x-faustwp-secret": config.secretKey },
|
|
4173
|
+
cache: "no-store"
|
|
4174
|
+
});
|
|
4175
|
+
if (!res.ok) return null;
|
|
4176
|
+
const data = await res.json();
|
|
4177
|
+
return data.slug ?? `preview-${postId}`;
|
|
4178
|
+
}
|
|
4179
|
+
|
|
4180
|
+
// src/auth/applicationPassword.ts
|
|
4181
|
+
function createApplicationPasswordToken(username, appPassword) {
|
|
4182
|
+
const encoded = Buffer.from(`${username}:${appPassword}`).toString("base64");
|
|
4183
|
+
return `Basic ${encoded}`;
|
|
4184
|
+
}
|
|
4185
|
+
|
|
4186
|
+
// src/auth/types.ts
|
|
4187
|
+
var AuthenticationError = class extends Error {
|
|
4188
|
+
constructor(code, status, message, detail) {
|
|
4189
|
+
super(detail ? `${message}: ${detail}` : message);
|
|
4190
|
+
__publicField(this, "code", code);
|
|
4191
|
+
__publicField(this, "status", status);
|
|
4192
|
+
this.name = "AuthenticationError";
|
|
4193
|
+
}
|
|
4194
|
+
};
|
|
4195
|
+
|
|
4196
|
+
// src/auth/jwt.ts
|
|
4197
|
+
function resolveAuthErrorCode(status) {
|
|
4198
|
+
if (status === 401) return ErrorCode.AUTH_CREDENTIALS_INVALID;
|
|
4199
|
+
if (status === 403) return ErrorCode.AUTH_TOKEN_INVALID;
|
|
4200
|
+
return ErrorCode.AUTH_JWT_FAILED;
|
|
4201
|
+
}
|
|
4202
|
+
async function authenticateJwt(config, credentials) {
|
|
4203
|
+
const url = `${resolveBaseUrl(config)}/wp-json/jwt-auth/v1/token`;
|
|
4204
|
+
const response = await fetch(url, {
|
|
4205
|
+
method: "POST",
|
|
4206
|
+
headers: { "Content-Type": "application/json" },
|
|
4207
|
+
body: JSON.stringify(credentials),
|
|
4208
|
+
cache: "no-store"
|
|
4209
|
+
});
|
|
4210
|
+
if (!response.ok) {
|
|
4211
|
+
const code = resolveAuthErrorCode(response.status);
|
|
4212
|
+
throw new AuthenticationError(
|
|
4213
|
+
code,
|
|
4214
|
+
response.status,
|
|
4215
|
+
resolveMessage(code, config.errorMessages),
|
|
4216
|
+
response.statusText
|
|
4217
|
+
);
|
|
4218
|
+
}
|
|
4219
|
+
return response.json();
|
|
4220
|
+
}
|
|
4221
|
+
async function validateJwtToken(config, token) {
|
|
4222
|
+
const url = `${resolveBaseUrl(config)}/wp-json/jwt-auth/v1/token/validate`;
|
|
4223
|
+
const response = await fetch(url, {
|
|
4224
|
+
method: "POST",
|
|
4225
|
+
headers: { Authorization: `Bearer ${token}` },
|
|
4226
|
+
cache: "no-store"
|
|
4227
|
+
});
|
|
4228
|
+
return response.ok;
|
|
4229
|
+
}
|
|
4230
|
+
|
|
4231
|
+
exports.AuthenticationError = AuthenticationError;
|
|
4232
|
+
exports.ErrorCode = ErrorCode;
|
|
4233
|
+
exports.WPGraphQLError = WPGraphQLError;
|
|
4234
|
+
exports.WooCommerceError = WooCommerceError;
|
|
4235
|
+
exports.WordPressAPIError = WordPressAPIError;
|
|
4236
|
+
exports.authenticateJwt = authenticateJwt;
|
|
4237
|
+
exports.buildACFFragment = buildACFFragment;
|
|
4238
|
+
exports.buildPageWithACFQuery = buildPageWithACFQuery;
|
|
4239
|
+
exports.buildPostWithACFQuery = buildPostWithACFQuery;
|
|
4240
|
+
exports.buildPostsWithACFQuery = buildPostsWithACFQuery;
|
|
4241
|
+
exports.createApplicationPasswordToken = createApplicationPasswordToken;
|
|
4242
|
+
exports.createAuthorsMutations = createAuthorsMutations;
|
|
4243
|
+
exports.createCF7Queries = createCF7Queries;
|
|
4244
|
+
exports.createCPTQueries = createCPTQueries;
|
|
4245
|
+
exports.createCategoriesMutations = createCategoriesMutations;
|
|
4246
|
+
exports.createCommentsMutations = createCommentsMutations;
|
|
4247
|
+
exports.createFaustAuthHandler = createFaustAuthHandler;
|
|
4248
|
+
exports.createMediaMutations = createMediaMutations;
|
|
4249
|
+
exports.createMenusMutations = createMenusMutations;
|
|
4250
|
+
exports.createPagesMutations = createPagesMutations;
|
|
4251
|
+
exports.createPostsMutations = createPostsMutations;
|
|
4252
|
+
exports.createPreviewHandler = createPreviewHandler;
|
|
4253
|
+
exports.createRevalidationHandler = createRevalidationHandler;
|
|
4254
|
+
exports.createTagsMutations = createTagsMutations;
|
|
4255
|
+
exports.createWPGraphQLClient = createWPGraphQLCoreClient;
|
|
4256
|
+
exports.createWPGraphQLCoreClient = createWPGraphQLCoreClient;
|
|
4257
|
+
exports.createWPGraphQLFetcher = createWPGraphQLFetcher;
|
|
4258
|
+
exports.createWPGraphQLMutationsClient = createWPGraphQLMutationsClient;
|
|
4259
|
+
exports.createWPGraphQLWooCommerceClient = createWPGraphQLWooCommerceClient;
|
|
4260
|
+
exports.createWooCommerceClient = createWooCommerceClient;
|
|
4261
|
+
exports.createWooCommerceFetcher = createWooCommerceFetcher;
|
|
4262
|
+
exports.createWordPressClient = createWordPressClient;
|
|
4263
|
+
exports.createWordPressMutationsClient = createWordPressMutationsClient;
|
|
4264
|
+
exports.createYoastQueries = createYoastQueries;
|
|
4265
|
+
exports.defaultMessages = defaultMessages;
|
|
4266
|
+
exports.defaultMessagesPl = defaultMessagesPl;
|
|
4267
|
+
exports.extractOmnibusData = extractOmnibusData;
|
|
4268
|
+
exports.resolveBaseUrl = resolveBaseUrl;
|
|
4269
|
+
exports.resolveMessage = resolveMessage;
|
|
4270
|
+
exports.validateJwtToken = validateJwtToken;
|
|
4271
|
+
exports.withOmnibus = withOmnibus;
|
|
4272
|
+
exports.withOmnibusVariation = withOmnibusVariation;
|
|
4273
|
+
//# sourceMappingURL=index.cjs.map
|
|
4274
|
+
//# sourceMappingURL=index.cjs.map
|