@szymonpiatek/nextwordpress 0.0.15 → 0.0.16
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 +181 -118
- package/dist/client/index.cjs.map +1 -1
- package/dist/client/index.d.cts +3 -3
- package/dist/client/index.d.ts +3 -3
- package/dist/client/index.js +179 -118
- package/dist/client/index.js.map +1 -1
- package/dist/hooks/index.cjs +181 -118
- package/dist/hooks/index.cjs.map +1 -1
- package/dist/hooks/index.d.cts +15 -3
- package/dist/hooks/index.d.ts +15 -3
- package/dist/hooks/index.js +179 -118
- package/dist/hooks/index.js.map +1 -1
- package/dist/index.cjs +43 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -10
- package/dist/index.d.ts +12 -10
- package/dist/index.js +43 -1
- package/dist/index.js.map +1 -1
- package/dist/server/index.cjs +43 -1
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.d.cts +1 -1
- package/dist/server/index.d.ts +1 -1
- package/dist/server/index.js +43 -1
- package/dist/server/index.js.map +1 -1
- package/dist/{types-D6rih4G8.d.cts → types-CvO7Ijbs.d.cts} +52 -28
- package/dist/{types-D6rih4G8.d.ts → types-CvO7Ijbs.d.ts} +52 -28
- package/package.json +1 -1
package/dist/client/index.cjs
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
var react = require('react');
|
|
4
4
|
var jsxRuntime = require('react/jsx-runtime');
|
|
5
|
-
var useSWR2 = require('swr');
|
|
6
5
|
var useSWRMutation = require('swr/mutation');
|
|
6
|
+
var useSWR2 = require('swr');
|
|
7
7
|
|
|
8
8
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
9
|
|
|
10
|
-
var useSWR2__default = /*#__PURE__*/_interopDefault(useSWR2);
|
|
11
10
|
var useSWRMutation__default = /*#__PURE__*/_interopDefault(useSWRMutation);
|
|
11
|
+
var useSWR2__default = /*#__PURE__*/_interopDefault(useSWR2);
|
|
12
12
|
|
|
13
13
|
var __defProp = Object.defineProperty;
|
|
14
14
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
@@ -79,6 +79,8 @@ var defaultMessages = {
|
|
|
79
79
|
AUTH_JWT_FAILED: "JWT authentication failed",
|
|
80
80
|
AUTH_CREDENTIALS_INVALID: "Invalid credentials",
|
|
81
81
|
AUTH_TOKEN_INVALID: "JWT token is invalid or expired",
|
|
82
|
+
AUTH_PASSWORD_RESET_REQUESTED: "Password reset email sent. Check your inbox.",
|
|
83
|
+
AUTH_PASSWORD_RESET_FAILED: "Password reset failed. The link may be invalid or expired.",
|
|
82
84
|
CF7_MAIL_SENT: "Thank you for your message.",
|
|
83
85
|
CF7_MAIL_FAILED: "There was an error trying to send your message.",
|
|
84
86
|
CF7_VALIDATION_FAILED: "One or more fields have an error. Please check and try again.",
|
|
@@ -196,6 +198,173 @@ function useAuth() {
|
|
|
196
198
|
if (!ctx) throw new Error("useAuth must be used within an AuthProvider");
|
|
197
199
|
return ctx;
|
|
198
200
|
}
|
|
201
|
+
|
|
202
|
+
// src/integrations/wpGraphQL/client/types.ts
|
|
203
|
+
var WPGraphQLError = class extends Error {
|
|
204
|
+
constructor(code, status, endpoint, message, gqlErrors) {
|
|
205
|
+
super(message);
|
|
206
|
+
__publicField(this, "code", code);
|
|
207
|
+
__publicField(this, "status", status);
|
|
208
|
+
__publicField(this, "endpoint", endpoint);
|
|
209
|
+
__publicField(this, "gqlErrors", gqlErrors);
|
|
210
|
+
this.name = "WPGraphQLError";
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
// src/integrations/wpGraphQL/client/fetcher.ts
|
|
215
|
+
var USER_AGENT = "NextWordpress WPGraphQL Client";
|
|
216
|
+
function createWPGraphQLFetcher(config) {
|
|
217
|
+
const url = `${resolveBaseUrl(config)}/graphql`;
|
|
218
|
+
const cacheTTL = config.cacheTTL ?? 300;
|
|
219
|
+
async function gqlFetch(document2, variables, tags = ["wpgraphql"]) {
|
|
220
|
+
const response = await fetch(url, {
|
|
221
|
+
method: "POST",
|
|
222
|
+
headers: {
|
|
223
|
+
"Content-Type": "application/json",
|
|
224
|
+
"User-Agent": USER_AGENT
|
|
225
|
+
},
|
|
226
|
+
body: JSON.stringify({ query: document2, variables }),
|
|
227
|
+
next: { tags, revalidate: cacheTTL }
|
|
228
|
+
});
|
|
229
|
+
if (!response.ok) {
|
|
230
|
+
throw new WPGraphQLError(
|
|
231
|
+
ErrorCode.GQL_REQUEST_FAILED,
|
|
232
|
+
response.status,
|
|
233
|
+
url,
|
|
234
|
+
resolveMessage(ErrorCode.GQL_REQUEST_FAILED, config.errorMessages)
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
const parsed = await response.json();
|
|
238
|
+
if (parsed.errors && parsed.errors.length > 0) {
|
|
239
|
+
throw new WPGraphQLError(
|
|
240
|
+
ErrorCode.GQL_ERRORS_IN_RESPONSE,
|
|
241
|
+
200,
|
|
242
|
+
url,
|
|
243
|
+
resolveMessage(ErrorCode.GQL_ERRORS_IN_RESPONSE, config.errorMessages),
|
|
244
|
+
parsed.errors
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
if (parsed.data === void 0) {
|
|
248
|
+
throw new WPGraphQLError(
|
|
249
|
+
ErrorCode.GQL_NO_DATA,
|
|
250
|
+
200,
|
|
251
|
+
url,
|
|
252
|
+
resolveMessage(ErrorCode.GQL_NO_DATA, config.errorMessages)
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
return parsed.data;
|
|
256
|
+
}
|
|
257
|
+
async function gqlFetchGraceful(document2, fallback, variables, tags = ["wpgraphql"]) {
|
|
258
|
+
try {
|
|
259
|
+
return await gqlFetch(document2, variables, tags);
|
|
260
|
+
} catch {
|
|
261
|
+
console.warn(`WPGraphQL fetch failed for query`);
|
|
262
|
+
return fallback;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
async function gqlMutate(document2, variables, authToken) {
|
|
266
|
+
const headers = {
|
|
267
|
+
"Content-Type": "application/json",
|
|
268
|
+
"User-Agent": USER_AGENT
|
|
269
|
+
};
|
|
270
|
+
if (authToken) {
|
|
271
|
+
headers["Authorization"] = authToken;
|
|
272
|
+
}
|
|
273
|
+
const response = await fetch(url, {
|
|
274
|
+
method: "POST",
|
|
275
|
+
headers,
|
|
276
|
+
body: JSON.stringify({ query: document2, variables }),
|
|
277
|
+
cache: "no-store"
|
|
278
|
+
});
|
|
279
|
+
if (!response.ok) {
|
|
280
|
+
throw new WPGraphQLError(
|
|
281
|
+
ErrorCode.GQL_REQUEST_FAILED,
|
|
282
|
+
response.status,
|
|
283
|
+
url,
|
|
284
|
+
resolveMessage(ErrorCode.GQL_REQUEST_FAILED, config.errorMessages)
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
const parsed = await response.json();
|
|
288
|
+
if (parsed.errors && parsed.errors.length > 0) {
|
|
289
|
+
throw new WPGraphQLError(
|
|
290
|
+
ErrorCode.GQL_ERRORS_IN_RESPONSE,
|
|
291
|
+
200,
|
|
292
|
+
url,
|
|
293
|
+
resolveMessage(ErrorCode.GQL_ERRORS_IN_RESPONSE, config.errorMessages),
|
|
294
|
+
parsed.errors
|
|
295
|
+
);
|
|
296
|
+
}
|
|
297
|
+
if (parsed.data === void 0) {
|
|
298
|
+
throw new WPGraphQLError(
|
|
299
|
+
ErrorCode.GQL_NO_DATA,
|
|
300
|
+
200,
|
|
301
|
+
url,
|
|
302
|
+
resolveMessage(ErrorCode.GQL_NO_DATA, config.errorMessages)
|
|
303
|
+
);
|
|
304
|
+
}
|
|
305
|
+
return parsed.data;
|
|
306
|
+
}
|
|
307
|
+
return { gqlFetch, gqlFetchGraceful, gqlMutate };
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// src/integrations/wpGraphQL/core/mutations/passwordReset/mutations.ts
|
|
311
|
+
var GQL_SEND_PASSWORD_RESET_EMAIL = `
|
|
312
|
+
mutation SendPasswordResetEmail($input: SendPasswordResetEmailInput!) {
|
|
313
|
+
sendPasswordResetEmail(input: $input) {
|
|
314
|
+
success
|
|
315
|
+
user {
|
|
316
|
+
email
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
`;
|
|
321
|
+
var GQL_RESET_USER_PASSWORD = `
|
|
322
|
+
mutation ResetUserPassword($input: ResetUserPasswordInput!) {
|
|
323
|
+
resetUserPassword(input: $input) {
|
|
324
|
+
user {
|
|
325
|
+
id
|
|
326
|
+
databaseId
|
|
327
|
+
email
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
`;
|
|
332
|
+
function createPasswordResetMutations(fetcher) {
|
|
333
|
+
const { gqlMutate } = fetcher;
|
|
334
|
+
async function sendPasswordResetEmail(input) {
|
|
335
|
+
const data = await gqlMutate(GQL_SEND_PASSWORD_RESET_EMAIL, { input });
|
|
336
|
+
return data.sendPasswordResetEmail;
|
|
337
|
+
}
|
|
338
|
+
async function resetUserPassword(input) {
|
|
339
|
+
const data = await gqlMutate(GQL_RESET_USER_PASSWORD, { input });
|
|
340
|
+
return data.resetUserPassword;
|
|
341
|
+
}
|
|
342
|
+
return { sendPasswordResetEmail, resetUserPassword };
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// src/hooks/auth/useSendPasswordResetEmail.ts
|
|
346
|
+
function useSendPasswordResetEmail(config) {
|
|
347
|
+
return useSWRMutation__default.default(
|
|
348
|
+
`send-password-reset:${config.serverURL}`,
|
|
349
|
+
async (_, { arg }) => {
|
|
350
|
+
return createPasswordResetMutations(createWPGraphQLFetcher(config)).sendPasswordResetEmail({
|
|
351
|
+
username: arg.username
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
);
|
|
355
|
+
}
|
|
356
|
+
function useResetUserPassword(config) {
|
|
357
|
+
return useSWRMutation__default.default(
|
|
358
|
+
`reset-user-password:${config.serverURL}`,
|
|
359
|
+
async (_, { arg }) => {
|
|
360
|
+
return createPasswordResetMutations(createWPGraphQLFetcher(config)).resetUserPassword({
|
|
361
|
+
key: arg.key,
|
|
362
|
+
login: arg.login,
|
|
363
|
+
password: arg.password
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
);
|
|
367
|
+
}
|
|
199
368
|
function readConsentFromDocument(cookieName) {
|
|
200
369
|
if (typeof document === "undefined") return null;
|
|
201
370
|
const match = document.cookie.match(new RegExp(`(?:^|;\\s*)${cookieName}=([^;]*)`));
|
|
@@ -261,7 +430,7 @@ function buildUrl(config, path, query) {
|
|
|
261
430
|
}
|
|
262
431
|
|
|
263
432
|
// src/integrations/restApi/core/client/fetcher.ts
|
|
264
|
-
var
|
|
433
|
+
var USER_AGENT2 = "NextWordpress Client";
|
|
265
434
|
function resolveWpErrorCode(status) {
|
|
266
435
|
if (status === 401) return ErrorCode.WP_UNAUTHORIZED;
|
|
267
436
|
if (status === 403) return ErrorCode.WP_FORBIDDEN;
|
|
@@ -287,7 +456,7 @@ function createFetcher(config) {
|
|
|
287
456
|
async function wpFetch(path, query, tags = ["wordpress"]) {
|
|
288
457
|
const url = buildUrl(config, path, query);
|
|
289
458
|
const res = await doFetch(url, {
|
|
290
|
-
headers: { "User-Agent":
|
|
459
|
+
headers: { "User-Agent": USER_AGENT2 },
|
|
291
460
|
next: { tags, revalidate: cacheTtl }
|
|
292
461
|
});
|
|
293
462
|
return await res.json();
|
|
@@ -303,7 +472,7 @@ function createFetcher(config) {
|
|
|
303
472
|
async function wpFetchPaginated(path, query, tags = ["wordpress"]) {
|
|
304
473
|
const url = buildUrl(config, path, query);
|
|
305
474
|
const res = await doFetch(url, {
|
|
306
|
-
headers: { "User-Agent":
|
|
475
|
+
headers: { "User-Agent": USER_AGENT2 },
|
|
307
476
|
next: { tags, revalidate: cacheTtl }
|
|
308
477
|
});
|
|
309
478
|
return {
|
|
@@ -327,7 +496,7 @@ function createFetcher(config) {
|
|
|
327
496
|
const url = buildUrl(config, path);
|
|
328
497
|
const headers = {
|
|
329
498
|
"Content-Type": "application/json",
|
|
330
|
-
"User-Agent":
|
|
499
|
+
"User-Agent": USER_AGENT2
|
|
331
500
|
};
|
|
332
501
|
if (authToken) {
|
|
333
502
|
headers["Authorization"] = authToken.startsWith("Basic ") || authToken.startsWith("Bearer ") ? authToken : `Bearer ${authToken}`;
|
|
@@ -347,7 +516,7 @@ function createFetcher(config) {
|
|
|
347
516
|
headers: {
|
|
348
517
|
"Content-Disposition": `attachment; filename="${filename}"`,
|
|
349
518
|
"Content-Type": mimeType,
|
|
350
|
-
"User-Agent":
|
|
519
|
+
"User-Agent": USER_AGENT2,
|
|
351
520
|
"Authorization": authToken.startsWith("Basic ") || authToken.startsWith("Bearer ") ? authToken : `Bearer ${authToken}`
|
|
352
521
|
},
|
|
353
522
|
body: file,
|
|
@@ -569,7 +738,7 @@ function resolveWooErrorCode(status, upstreamCode) {
|
|
|
569
738
|
}
|
|
570
739
|
|
|
571
740
|
// src/integrations/restApi/woocommerce/client/fetcher.ts
|
|
572
|
-
var
|
|
741
|
+
var USER_AGENT3 = "NextWordpress WooCommerce Client";
|
|
573
742
|
var DEFAULT_CACHE_TTL = 3600;
|
|
574
743
|
function toQueryString(params) {
|
|
575
744
|
const pairs = [];
|
|
@@ -607,7 +776,7 @@ function createWooCommerceFetcher(config) {
|
|
|
607
776
|
const response = await fetch(url, {
|
|
608
777
|
...options,
|
|
609
778
|
headers: {
|
|
610
|
-
"User-Agent":
|
|
779
|
+
"User-Agent": USER_AGENT3,
|
|
611
780
|
"Content-Type": "application/json",
|
|
612
781
|
...options?.headers
|
|
613
782
|
},
|
|
@@ -629,7 +798,7 @@ function createWooCommerceFetcher(config) {
|
|
|
629
798
|
async function wcFetchPaginated(path, query, tags = ["woocommerce"]) {
|
|
630
799
|
const url = buildUrl2(path, query);
|
|
631
800
|
const response = await fetch(url, {
|
|
632
|
-
headers: { "User-Agent":
|
|
801
|
+
headers: { "User-Agent": USER_AGENT3 },
|
|
633
802
|
next: { tags, revalidate: cacheTTL }
|
|
634
803
|
});
|
|
635
804
|
if (!response.ok) {
|
|
@@ -1097,114 +1266,6 @@ function useCustomer() {
|
|
|
1097
1266
|
return ctx;
|
|
1098
1267
|
}
|
|
1099
1268
|
|
|
1100
|
-
// src/integrations/wpGraphQL/client/types.ts
|
|
1101
|
-
var WPGraphQLError = class extends Error {
|
|
1102
|
-
constructor(code, status, endpoint, message, gqlErrors) {
|
|
1103
|
-
super(message);
|
|
1104
|
-
__publicField(this, "code", code);
|
|
1105
|
-
__publicField(this, "status", status);
|
|
1106
|
-
__publicField(this, "endpoint", endpoint);
|
|
1107
|
-
__publicField(this, "gqlErrors", gqlErrors);
|
|
1108
|
-
this.name = "WPGraphQLError";
|
|
1109
|
-
}
|
|
1110
|
-
};
|
|
1111
|
-
|
|
1112
|
-
// src/integrations/wpGraphQL/client/fetcher.ts
|
|
1113
|
-
var USER_AGENT3 = "NextWordpress WPGraphQL Client";
|
|
1114
|
-
function createWPGraphQLFetcher(config) {
|
|
1115
|
-
const url = `${resolveBaseUrl(config)}/graphql`;
|
|
1116
|
-
const cacheTTL = config.cacheTTL ?? 300;
|
|
1117
|
-
async function gqlFetch(document2, variables, tags = ["wpgraphql"]) {
|
|
1118
|
-
const response = await fetch(url, {
|
|
1119
|
-
method: "POST",
|
|
1120
|
-
headers: {
|
|
1121
|
-
"Content-Type": "application/json",
|
|
1122
|
-
"User-Agent": USER_AGENT3
|
|
1123
|
-
},
|
|
1124
|
-
body: JSON.stringify({ query: document2, variables }),
|
|
1125
|
-
next: { tags, revalidate: cacheTTL }
|
|
1126
|
-
});
|
|
1127
|
-
if (!response.ok) {
|
|
1128
|
-
throw new WPGraphQLError(
|
|
1129
|
-
ErrorCode.GQL_REQUEST_FAILED,
|
|
1130
|
-
response.status,
|
|
1131
|
-
url,
|
|
1132
|
-
resolveMessage(ErrorCode.GQL_REQUEST_FAILED, config.errorMessages)
|
|
1133
|
-
);
|
|
1134
|
-
}
|
|
1135
|
-
const parsed = await response.json();
|
|
1136
|
-
if (parsed.errors && parsed.errors.length > 0) {
|
|
1137
|
-
throw new WPGraphQLError(
|
|
1138
|
-
ErrorCode.GQL_ERRORS_IN_RESPONSE,
|
|
1139
|
-
200,
|
|
1140
|
-
url,
|
|
1141
|
-
resolveMessage(ErrorCode.GQL_ERRORS_IN_RESPONSE, config.errorMessages),
|
|
1142
|
-
parsed.errors
|
|
1143
|
-
);
|
|
1144
|
-
}
|
|
1145
|
-
if (parsed.data === void 0) {
|
|
1146
|
-
throw new WPGraphQLError(
|
|
1147
|
-
ErrorCode.GQL_NO_DATA,
|
|
1148
|
-
200,
|
|
1149
|
-
url,
|
|
1150
|
-
resolveMessage(ErrorCode.GQL_NO_DATA, config.errorMessages)
|
|
1151
|
-
);
|
|
1152
|
-
}
|
|
1153
|
-
return parsed.data;
|
|
1154
|
-
}
|
|
1155
|
-
async function gqlFetchGraceful(document2, fallback, variables, tags = ["wpgraphql"]) {
|
|
1156
|
-
try {
|
|
1157
|
-
return await gqlFetch(document2, variables, tags);
|
|
1158
|
-
} catch {
|
|
1159
|
-
console.warn(`WPGraphQL fetch failed for query`);
|
|
1160
|
-
return fallback;
|
|
1161
|
-
}
|
|
1162
|
-
}
|
|
1163
|
-
async function gqlMutate(document2, variables, authToken) {
|
|
1164
|
-
const headers = {
|
|
1165
|
-
"Content-Type": "application/json",
|
|
1166
|
-
"User-Agent": USER_AGENT3
|
|
1167
|
-
};
|
|
1168
|
-
if (authToken) {
|
|
1169
|
-
headers["Authorization"] = authToken;
|
|
1170
|
-
}
|
|
1171
|
-
const response = await fetch(url, {
|
|
1172
|
-
method: "POST",
|
|
1173
|
-
headers,
|
|
1174
|
-
body: JSON.stringify({ query: document2, variables }),
|
|
1175
|
-
cache: "no-store"
|
|
1176
|
-
});
|
|
1177
|
-
if (!response.ok) {
|
|
1178
|
-
throw new WPGraphQLError(
|
|
1179
|
-
ErrorCode.GQL_REQUEST_FAILED,
|
|
1180
|
-
response.status,
|
|
1181
|
-
url,
|
|
1182
|
-
resolveMessage(ErrorCode.GQL_REQUEST_FAILED, config.errorMessages)
|
|
1183
|
-
);
|
|
1184
|
-
}
|
|
1185
|
-
const parsed = await response.json();
|
|
1186
|
-
if (parsed.errors && parsed.errors.length > 0) {
|
|
1187
|
-
throw new WPGraphQLError(
|
|
1188
|
-
ErrorCode.GQL_ERRORS_IN_RESPONSE,
|
|
1189
|
-
200,
|
|
1190
|
-
url,
|
|
1191
|
-
resolveMessage(ErrorCode.GQL_ERRORS_IN_RESPONSE, config.errorMessages),
|
|
1192
|
-
parsed.errors
|
|
1193
|
-
);
|
|
1194
|
-
}
|
|
1195
|
-
if (parsed.data === void 0) {
|
|
1196
|
-
throw new WPGraphQLError(
|
|
1197
|
-
ErrorCode.GQL_NO_DATA,
|
|
1198
|
-
200,
|
|
1199
|
-
url,
|
|
1200
|
-
resolveMessage(ErrorCode.GQL_NO_DATA, config.errorMessages)
|
|
1201
|
-
);
|
|
1202
|
-
}
|
|
1203
|
-
return parsed.data;
|
|
1204
|
-
}
|
|
1205
|
-
return { gqlFetch, gqlFetchGraceful, gqlMutate };
|
|
1206
|
-
}
|
|
1207
|
-
|
|
1208
1269
|
// src/integrations/wpGraphQL/core/posts/queries.ts
|
|
1209
1270
|
var DEFAULT_FIRST = 10;
|
|
1210
1271
|
var BATCH_FIRST = 100;
|
|
@@ -1542,6 +1603,8 @@ exports.useProduct = useProduct;
|
|
|
1542
1603
|
exports.useProductBySlug = useProductBySlug;
|
|
1543
1604
|
exports.useProducts = useProducts;
|
|
1544
1605
|
exports.useProductsPaginated = useProductsPaginated;
|
|
1606
|
+
exports.useResetUserPassword = useResetUserPassword;
|
|
1607
|
+
exports.useSendPasswordResetEmail = useSendPasswordResetEmail;
|
|
1545
1608
|
exports.useWPGraphQL = useWPGraphQL;
|
|
1546
1609
|
exports.useWPULike = useWPULike;
|
|
1547
1610
|
exports.useWPULikeCheck = useWPULikeCheck;
|