@szymonpiatek/nextwordpress 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/hooks/index.cjs +168 -29
- package/dist/hooks/index.cjs.map +1 -1
- package/dist/hooks/index.d.cts +1 -1
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/index.js +168 -29
- package/dist/hooks/index.js.map +1 -1
- package/dist/index.cjs +200 -29
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +195 -30
- package/dist/index.js.map +1 -1
- package/dist/{types-Be60n09c.d.cts → types-Dxb6tuW_.d.cts} +53 -4
- package/dist/{types-Be60n09c.d.ts → types-Dxb6tuW_.d.ts} +53 -4
- package/package.json +15 -5
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { N as NextWordpressConfig, J as JwtAuthCredentials, k as JwtAuthResponse, a as WooCommerceConfig, d as WooCommerceResponse, W as WordPressResponse, T as Taxonomy, l as WPEntity, R as RenderedTitle, m as RenderedContent, P as Post, A as Author, F as FeaturedMedia, n as WCImage, o as WCProductVariation, b as WCProduct, g as WCCustomer, p as WCAddress, U as UpdateCustomerInput, e as WCCreateOrderInput, f as WCOrder, c as WCProductFilterParams, h as WPGraphQLConfig, j as GQLConnection, i as GQLPostFilter, G as GQLPost } from './types-
|
|
2
|
-
export { q as AuthenticationError, B as BlockType, E as EditorBlock, r as EmbeddedAuthor, s as EmbeddedTerm, t as
|
|
1
|
+
import { N as NextWordpressConfig, J as JwtAuthCredentials, k as JwtAuthResponse, a as WooCommerceConfig, d as WooCommerceResponse, W as WordPressResponse, T as Taxonomy, l as WPEntity, R as RenderedTitle, m as RenderedContent, P as Post, A as Author, F as FeaturedMedia, n as WCImage, o as WCProductVariation, b as WCProduct, g as WCCustomer, p as WCAddress, U as UpdateCustomerInput, e as WCCreateOrderInput, f as WCOrder, c as WCProductFilterParams, h as WPGraphQLConfig, j as GQLConnection, i as GQLPostFilter, G as GQLPost } from './types-Dxb6tuW_.cjs';
|
|
2
|
+
export { q as AuthenticationError, B as BlockType, E as EditorBlock, r as EmbeddedAuthor, s as EmbeddedTerm, t as ErrorCode, u as GQLError, v as GQLPageInfo, M as MediaDetails, w as MediaSize, x as PostEmbedded, S as SearchResult, y as TemplatePart, z as WCDimensions, C as WCOrderLineItem, D as WCProductAttribute, H as WCProductDefaultAttribute, I as WCShippingLine, K as WPGraphQLError, L as WooCommerceError, O as WooCommercePaginationHeaders, Q as WordPressAPIError, V as defaultMessages, X as defaultMessagesPl, Y as resolveMessage } from './types-Dxb6tuW_.cjs';
|
|
3
3
|
|
|
4
4
|
declare function createApplicationPasswordToken(username: string, appPassword: string): string;
|
|
5
5
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { N as NextWordpressConfig, J as JwtAuthCredentials, k as JwtAuthResponse, a as WooCommerceConfig, d as WooCommerceResponse, W as WordPressResponse, T as Taxonomy, l as WPEntity, R as RenderedTitle, m as RenderedContent, P as Post, A as Author, F as FeaturedMedia, n as WCImage, o as WCProductVariation, b as WCProduct, g as WCCustomer, p as WCAddress, U as UpdateCustomerInput, e as WCCreateOrderInput, f as WCOrder, c as WCProductFilterParams, h as WPGraphQLConfig, j as GQLConnection, i as GQLPostFilter, G as GQLPost } from './types-
|
|
2
|
-
export { q as AuthenticationError, B as BlockType, E as EditorBlock, r as EmbeddedAuthor, s as EmbeddedTerm, t as
|
|
1
|
+
import { N as NextWordpressConfig, J as JwtAuthCredentials, k as JwtAuthResponse, a as WooCommerceConfig, d as WooCommerceResponse, W as WordPressResponse, T as Taxonomy, l as WPEntity, R as RenderedTitle, m as RenderedContent, P as Post, A as Author, F as FeaturedMedia, n as WCImage, o as WCProductVariation, b as WCProduct, g as WCCustomer, p as WCAddress, U as UpdateCustomerInput, e as WCCreateOrderInput, f as WCOrder, c as WCProductFilterParams, h as WPGraphQLConfig, j as GQLConnection, i as GQLPostFilter, G as GQLPost } from './types-Dxb6tuW_.js';
|
|
2
|
+
export { q as AuthenticationError, B as BlockType, E as EditorBlock, r as EmbeddedAuthor, s as EmbeddedTerm, t as ErrorCode, u as GQLError, v as GQLPageInfo, M as MediaDetails, w as MediaSize, x as PostEmbedded, S as SearchResult, y as TemplatePart, z as WCDimensions, C as WCOrderLineItem, D as WCProductAttribute, H as WCProductDefaultAttribute, I as WCShippingLine, K as WPGraphQLError, L as WooCommerceError, O as WooCommercePaginationHeaders, Q as WordPressAPIError, V as defaultMessages, X as defaultMessagesPl, Y as resolveMessage } from './types-Dxb6tuW_.js';
|
|
3
3
|
|
|
4
4
|
declare function createApplicationPasswordToken(username: string, appPassword: string): string;
|
|
5
5
|
|
package/dist/index.js
CHANGED
|
@@ -7,10 +7,96 @@ function resolveBaseUrl(config) {
|
|
|
7
7
|
return typeof window === "undefined" ? config.serverURL : config.clientURL;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
// src/shared/errors/codes.ts
|
|
11
|
+
var ErrorCode = {
|
|
12
|
+
// WordPress REST API
|
|
13
|
+
WP_REQUEST_FAILED: "WP_REQUEST_FAILED",
|
|
14
|
+
WP_NOT_FOUND: "WP_NOT_FOUND",
|
|
15
|
+
WP_UNAUTHORIZED: "WP_UNAUTHORIZED",
|
|
16
|
+
WP_FORBIDDEN: "WP_FORBIDDEN",
|
|
17
|
+
// WPGraphQL
|
|
18
|
+
GQL_REQUEST_FAILED: "GQL_REQUEST_FAILED",
|
|
19
|
+
GQL_NO_DATA: "GQL_NO_DATA",
|
|
20
|
+
GQL_ERRORS_IN_RESPONSE: "GQL_ERRORS_IN_RESPONSE",
|
|
21
|
+
// WooCommerce — generic
|
|
22
|
+
WOO_REQUEST_FAILED: "WOO_REQUEST_FAILED",
|
|
23
|
+
WOO_NOT_FOUND: "WOO_NOT_FOUND",
|
|
24
|
+
WOO_UNAUTHORIZED: "WOO_UNAUTHORIZED",
|
|
25
|
+
WOO_FORBIDDEN: "WOO_FORBIDDEN",
|
|
26
|
+
// WooCommerce — resource-specific
|
|
27
|
+
WOO_COUPON_NOT_FOUND: "WOO_COUPON_NOT_FOUND",
|
|
28
|
+
WOO_PRODUCT_NOT_FOUND: "WOO_PRODUCT_NOT_FOUND",
|
|
29
|
+
WOO_ORDER_NOT_FOUND: "WOO_ORDER_NOT_FOUND",
|
|
30
|
+
WOO_CUSTOMER_NOT_FOUND: "WOO_CUSTOMER_NOT_FOUND",
|
|
31
|
+
WOO_CATEGORY_NOT_FOUND: "WOO_CATEGORY_NOT_FOUND",
|
|
32
|
+
WOO_TAG_NOT_FOUND: "WOO_TAG_NOT_FOUND",
|
|
33
|
+
WOO_REVIEW_NOT_FOUND: "WOO_REVIEW_NOT_FOUND",
|
|
34
|
+
WOO_WEBHOOK_NOT_FOUND: "WOO_WEBHOOK_NOT_FOUND",
|
|
35
|
+
WOO_SHIPPING_ZONE_NOT_FOUND: "WOO_SHIPPING_ZONE_NOT_FOUND",
|
|
36
|
+
// Auth
|
|
37
|
+
AUTH_JWT_FAILED: "AUTH_JWT_FAILED",
|
|
38
|
+
AUTH_CREDENTIALS_INVALID: "AUTH_CREDENTIALS_INVALID",
|
|
39
|
+
AUTH_TOKEN_INVALID: "AUTH_TOKEN_INVALID"
|
|
40
|
+
};
|
|
41
|
+
var defaultMessages = {
|
|
42
|
+
WP_REQUEST_FAILED: "WordPress API request failed",
|
|
43
|
+
WP_NOT_FOUND: "WordPress resource not found",
|
|
44
|
+
WP_UNAUTHORIZED: "WordPress authentication required",
|
|
45
|
+
WP_FORBIDDEN: "WordPress access denied",
|
|
46
|
+
GQL_REQUEST_FAILED: "WPGraphQL request failed",
|
|
47
|
+
GQL_NO_DATA: "No data returned from WPGraphQL",
|
|
48
|
+
GQL_ERRORS_IN_RESPONSE: "WPGraphQL returned errors",
|
|
49
|
+
WOO_REQUEST_FAILED: "WooCommerce API request failed",
|
|
50
|
+
WOO_NOT_FOUND: "WooCommerce resource not found",
|
|
51
|
+
WOO_UNAUTHORIZED: "WooCommerce authentication required",
|
|
52
|
+
WOO_FORBIDDEN: "WooCommerce access denied",
|
|
53
|
+
WOO_COUPON_NOT_FOUND: "Coupon not found",
|
|
54
|
+
WOO_PRODUCT_NOT_FOUND: "Product not found",
|
|
55
|
+
WOO_ORDER_NOT_FOUND: "Order not found",
|
|
56
|
+
WOO_CUSTOMER_NOT_FOUND: "Customer not found",
|
|
57
|
+
WOO_CATEGORY_NOT_FOUND: "Category not found",
|
|
58
|
+
WOO_TAG_NOT_FOUND: "Tag not found",
|
|
59
|
+
WOO_REVIEW_NOT_FOUND: "Product review not found",
|
|
60
|
+
WOO_WEBHOOK_NOT_FOUND: "Webhook not found",
|
|
61
|
+
WOO_SHIPPING_ZONE_NOT_FOUND: "Shipping zone not found",
|
|
62
|
+
AUTH_JWT_FAILED: "JWT authentication failed",
|
|
63
|
+
AUTH_CREDENTIALS_INVALID: "Invalid credentials",
|
|
64
|
+
AUTH_TOKEN_INVALID: "JWT token is invalid or expired"
|
|
65
|
+
};
|
|
66
|
+
var defaultMessagesPl = {
|
|
67
|
+
WP_REQUEST_FAILED: "B\u0142\u0105d \u017C\u0105dania do WordPress API",
|
|
68
|
+
WP_NOT_FOUND: "Zas\xF3b WordPress nie istnieje",
|
|
69
|
+
WP_UNAUTHORIZED: "Wymagane uwierzytelnienie WordPress",
|
|
70
|
+
WP_FORBIDDEN: "Brak dost\u0119pu do zasobu WordPress",
|
|
71
|
+
GQL_REQUEST_FAILED: "B\u0142\u0105d \u017C\u0105dania WPGraphQL",
|
|
72
|
+
GQL_NO_DATA: "WPGraphQL nie zwr\xF3ci\u0142o danych",
|
|
73
|
+
GQL_ERRORS_IN_RESPONSE: "WPGraphQL zwr\xF3ci\u0142o b\u0142\u0119dy",
|
|
74
|
+
WOO_REQUEST_FAILED: "B\u0142\u0105d \u017C\u0105dania do WooCommerce API",
|
|
75
|
+
WOO_NOT_FOUND: "Zas\xF3b WooCommerce nie istnieje",
|
|
76
|
+
WOO_UNAUTHORIZED: "Wymagane uwierzytelnienie WooCommerce",
|
|
77
|
+
WOO_FORBIDDEN: "Brak dost\u0119pu do zasobu WooCommerce",
|
|
78
|
+
WOO_COUPON_NOT_FOUND: "Kupon nie istnieje",
|
|
79
|
+
WOO_PRODUCT_NOT_FOUND: "Produkt nie istnieje",
|
|
80
|
+
WOO_ORDER_NOT_FOUND: "Zam\xF3wienie nie istnieje",
|
|
81
|
+
WOO_CUSTOMER_NOT_FOUND: "Klient nie istnieje",
|
|
82
|
+
WOO_CATEGORY_NOT_FOUND: "Kategoria produkt\xF3w nie istnieje",
|
|
83
|
+
WOO_TAG_NOT_FOUND: "Tag produkt\xF3w nie istnieje",
|
|
84
|
+
WOO_REVIEW_NOT_FOUND: "Opinia o produkcie nie istnieje",
|
|
85
|
+
WOO_WEBHOOK_NOT_FOUND: "Webhook nie istnieje",
|
|
86
|
+
WOO_SHIPPING_ZONE_NOT_FOUND: "Strefa wysy\u0142ki nie istnieje",
|
|
87
|
+
AUTH_JWT_FAILED: "B\u0142\u0105d uwierzytelnienia JWT",
|
|
88
|
+
AUTH_CREDENTIALS_INVALID: "Nieprawid\u0142owe dane logowania",
|
|
89
|
+
AUTH_TOKEN_INVALID: "Token JWT jest nieprawid\u0142owy lub wygas\u0142"
|
|
90
|
+
};
|
|
91
|
+
function resolveMessage(code, overrides) {
|
|
92
|
+
return overrides?.[code] ?? defaultMessages[code];
|
|
93
|
+
}
|
|
94
|
+
|
|
10
95
|
// src/integrations/restApi/core/client/types.ts
|
|
11
96
|
var WordPressAPIError = class extends Error {
|
|
12
|
-
constructor(
|
|
13
|
-
super(message);
|
|
97
|
+
constructor(code, status, endpoint, message, detail) {
|
|
98
|
+
super(detail ? `${message}: ${detail}` : message);
|
|
99
|
+
__publicField(this, "code", code);
|
|
14
100
|
__publicField(this, "status", status);
|
|
15
101
|
__publicField(this, "endpoint", endpoint);
|
|
16
102
|
this.name = "WordPressAPIError";
|
|
@@ -33,19 +119,28 @@ function buildUrl(config, path, query) {
|
|
|
33
119
|
|
|
34
120
|
// src/integrations/restApi/core/client/fetcher.ts
|
|
35
121
|
var USER_AGENT = "NextWordpress Client";
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
if (
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
response.status,
|
|
42
|
-
url
|
|
43
|
-
);
|
|
44
|
-
}
|
|
45
|
-
return response;
|
|
122
|
+
function resolveWpErrorCode(status) {
|
|
123
|
+
if (status === 401) return ErrorCode.WP_UNAUTHORIZED;
|
|
124
|
+
if (status === 403) return ErrorCode.WP_FORBIDDEN;
|
|
125
|
+
if (status === 404) return ErrorCode.WP_NOT_FOUND;
|
|
126
|
+
return ErrorCode.WP_REQUEST_FAILED;
|
|
46
127
|
}
|
|
47
128
|
function createFetcher(config) {
|
|
48
129
|
const cacheTtl = config.cacheTTL ?? 300;
|
|
130
|
+
async function doFetch(url, init = {}) {
|
|
131
|
+
const response = await fetch(url, init);
|
|
132
|
+
if (!response.ok) {
|
|
133
|
+
const code = resolveWpErrorCode(response.status);
|
|
134
|
+
throw new WordPressAPIError(
|
|
135
|
+
code,
|
|
136
|
+
response.status,
|
|
137
|
+
url,
|
|
138
|
+
resolveMessage(code, config.errorMessages),
|
|
139
|
+
response.statusText
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
return response;
|
|
143
|
+
}
|
|
49
144
|
async function wpFetch(path, query, tags = ["wordpress"]) {
|
|
50
145
|
const url = buildUrl(config, path, query);
|
|
51
146
|
const res = await doFetch(url, {
|
|
@@ -708,6 +803,42 @@ function withOmnibusVariation(variation) {
|
|
|
708
803
|
};
|
|
709
804
|
}
|
|
710
805
|
|
|
806
|
+
// src/integrations/restApi/woocommerce/client/types.ts
|
|
807
|
+
var WooCommerceError = class extends Error {
|
|
808
|
+
constructor(code, status, endpoint, message, upstreamCode, detail) {
|
|
809
|
+
super(detail ? `${message}: ${detail}` : message);
|
|
810
|
+
__publicField(this, "code", code);
|
|
811
|
+
__publicField(this, "status", status);
|
|
812
|
+
__publicField(this, "endpoint", endpoint);
|
|
813
|
+
__publicField(this, "upstreamCode", upstreamCode);
|
|
814
|
+
this.name = "WooCommerceError";
|
|
815
|
+
}
|
|
816
|
+
};
|
|
817
|
+
|
|
818
|
+
// src/integrations/restApi/woocommerce/client/errorMap.ts
|
|
819
|
+
var upstreamToErrorCode = {
|
|
820
|
+
woocommerce_rest_coupon_invalid_id: ErrorCode.WOO_COUPON_NOT_FOUND,
|
|
821
|
+
woocommerce_rest_product_invalid_id: ErrorCode.WOO_PRODUCT_NOT_FOUND,
|
|
822
|
+
woocommerce_rest_order_invalid_id: ErrorCode.WOO_ORDER_NOT_FOUND,
|
|
823
|
+
woocommerce_rest_customer_invalid_id: ErrorCode.WOO_CUSTOMER_NOT_FOUND,
|
|
824
|
+
woocommerce_rest_term_invalid: ErrorCode.WOO_CATEGORY_NOT_FOUND,
|
|
825
|
+
woocommerce_rest_review_invalid_id: ErrorCode.WOO_REVIEW_NOT_FOUND,
|
|
826
|
+
woocommerce_rest_webhook_invalid_id: ErrorCode.WOO_WEBHOOK_NOT_FOUND,
|
|
827
|
+
woocommerce_rest_shipping_zone_invalid_id: ErrorCode.WOO_SHIPPING_ZONE_NOT_FOUND
|
|
828
|
+
};
|
|
829
|
+
function resolveWooErrorCode(status, upstreamCode) {
|
|
830
|
+
if (status === 401) return ErrorCode.WOO_UNAUTHORIZED;
|
|
831
|
+
if (status === 403) return ErrorCode.WOO_FORBIDDEN;
|
|
832
|
+
if (status === 404) {
|
|
833
|
+
if (upstreamCode) {
|
|
834
|
+
const mapped = upstreamToErrorCode[upstreamCode];
|
|
835
|
+
if (mapped) return mapped;
|
|
836
|
+
}
|
|
837
|
+
return ErrorCode.WOO_NOT_FOUND;
|
|
838
|
+
}
|
|
839
|
+
return ErrorCode.WOO_REQUEST_FAILED;
|
|
840
|
+
}
|
|
841
|
+
|
|
711
842
|
// src/integrations/restApi/woocommerce/client/fetcher.ts
|
|
712
843
|
var USER_AGENT2 = "NextWordpress WooCommerce Client";
|
|
713
844
|
var DEFAULT_CACHE_TTL = 3600;
|
|
@@ -728,6 +859,18 @@ function createWooCommerceFetcher(config) {
|
|
|
728
859
|
const base = typeof window !== "undefined" && config.clientURL ? config.clientURL : config.serverURL;
|
|
729
860
|
return `${base}${path}?${toQueryString(withAuth(query))}`;
|
|
730
861
|
}
|
|
862
|
+
async function throwWooError(response, url) {
|
|
863
|
+
const body = await response.json().catch(() => ({}));
|
|
864
|
+
const errorCode = resolveWooErrorCode(response.status, body.code);
|
|
865
|
+
throw new WooCommerceError(
|
|
866
|
+
errorCode,
|
|
867
|
+
response.status,
|
|
868
|
+
url,
|
|
869
|
+
resolveMessage(errorCode, config.errorMessages),
|
|
870
|
+
body.code,
|
|
871
|
+
body.message
|
|
872
|
+
);
|
|
873
|
+
}
|
|
731
874
|
async function wcFetch(path, query, tags = ["woocommerce"], options) {
|
|
732
875
|
const url = buildUrl2(path, query);
|
|
733
876
|
const isMutation = options?.method && options.method !== "GET";
|
|
@@ -742,9 +885,7 @@ function createWooCommerceFetcher(config) {
|
|
|
742
885
|
next: isMutation || noStore ? void 0 : { tags, revalidate: cacheTTL }
|
|
743
886
|
});
|
|
744
887
|
if (!response.ok) {
|
|
745
|
-
|
|
746
|
-
const detail = body.message ? ` \u2013 ${body.message}` : "";
|
|
747
|
-
throw new Error(`WooCommerce API ${response.status}: ${response.statusText}${detail} [${url}]`);
|
|
888
|
+
await throwWooError(response, url);
|
|
748
889
|
}
|
|
749
890
|
return response.json();
|
|
750
891
|
}
|
|
@@ -763,7 +904,7 @@ function createWooCommerceFetcher(config) {
|
|
|
763
904
|
next: { tags, revalidate: cacheTTL }
|
|
764
905
|
});
|
|
765
906
|
if (!response.ok) {
|
|
766
|
-
|
|
907
|
+
await throwWooError(response, url);
|
|
767
908
|
}
|
|
768
909
|
return {
|
|
769
910
|
data: await response.json(),
|
|
@@ -1960,8 +2101,9 @@ function createWooCommerceClient(config) {
|
|
|
1960
2101
|
|
|
1961
2102
|
// src/integrations/wpGraphQL/client/types.ts
|
|
1962
2103
|
var WPGraphQLError = class extends Error {
|
|
1963
|
-
constructor(
|
|
2104
|
+
constructor(code, status, endpoint, message, gqlErrors) {
|
|
1964
2105
|
super(message);
|
|
2106
|
+
__publicField(this, "code", code);
|
|
1965
2107
|
__publicField(this, "status", status);
|
|
1966
2108
|
__publicField(this, "endpoint", endpoint);
|
|
1967
2109
|
__publicField(this, "gqlErrors", gqlErrors);
|
|
@@ -1986,22 +2128,29 @@ function createWPGraphQLFetcher(config) {
|
|
|
1986
2128
|
});
|
|
1987
2129
|
if (!response.ok) {
|
|
1988
2130
|
throw new WPGraphQLError(
|
|
1989
|
-
|
|
2131
|
+
ErrorCode.GQL_REQUEST_FAILED,
|
|
1990
2132
|
response.status,
|
|
1991
|
-
url
|
|
2133
|
+
url,
|
|
2134
|
+
resolveMessage(ErrorCode.GQL_REQUEST_FAILED, config.errorMessages)
|
|
1992
2135
|
);
|
|
1993
2136
|
}
|
|
1994
2137
|
const parsed = await response.json();
|
|
1995
2138
|
if (parsed.errors && parsed.errors.length > 0) {
|
|
1996
2139
|
throw new WPGraphQLError(
|
|
1997
|
-
|
|
2140
|
+
ErrorCode.GQL_ERRORS_IN_RESPONSE,
|
|
1998
2141
|
200,
|
|
1999
2142
|
url,
|
|
2143
|
+
resolveMessage(ErrorCode.GQL_ERRORS_IN_RESPONSE, config.errorMessages),
|
|
2000
2144
|
parsed.errors
|
|
2001
2145
|
);
|
|
2002
2146
|
}
|
|
2003
2147
|
if (parsed.data === void 0) {
|
|
2004
|
-
throw new WPGraphQLError(
|
|
2148
|
+
throw new WPGraphQLError(
|
|
2149
|
+
ErrorCode.GQL_NO_DATA,
|
|
2150
|
+
200,
|
|
2151
|
+
url,
|
|
2152
|
+
resolveMessage(ErrorCode.GQL_NO_DATA, config.errorMessages)
|
|
2153
|
+
);
|
|
2005
2154
|
}
|
|
2006
2155
|
return parsed.data;
|
|
2007
2156
|
}
|
|
@@ -2029,22 +2178,29 @@ function createWPGraphQLFetcher(config) {
|
|
|
2029
2178
|
});
|
|
2030
2179
|
if (!response.ok) {
|
|
2031
2180
|
throw new WPGraphQLError(
|
|
2032
|
-
|
|
2181
|
+
ErrorCode.GQL_REQUEST_FAILED,
|
|
2033
2182
|
response.status,
|
|
2034
|
-
url
|
|
2183
|
+
url,
|
|
2184
|
+
resolveMessage(ErrorCode.GQL_REQUEST_FAILED, config.errorMessages)
|
|
2035
2185
|
);
|
|
2036
2186
|
}
|
|
2037
2187
|
const parsed = await response.json();
|
|
2038
2188
|
if (parsed.errors && parsed.errors.length > 0) {
|
|
2039
2189
|
throw new WPGraphQLError(
|
|
2040
|
-
|
|
2190
|
+
ErrorCode.GQL_ERRORS_IN_RESPONSE,
|
|
2041
2191
|
200,
|
|
2042
2192
|
url,
|
|
2193
|
+
resolveMessage(ErrorCode.GQL_ERRORS_IN_RESPONSE, config.errorMessages),
|
|
2043
2194
|
parsed.errors
|
|
2044
2195
|
);
|
|
2045
2196
|
}
|
|
2046
2197
|
if (parsed.data === void 0) {
|
|
2047
|
-
throw new WPGraphQLError(
|
|
2198
|
+
throw new WPGraphQLError(
|
|
2199
|
+
ErrorCode.GQL_NO_DATA,
|
|
2200
|
+
200,
|
|
2201
|
+
url,
|
|
2202
|
+
resolveMessage(ErrorCode.GQL_NO_DATA, config.errorMessages)
|
|
2203
|
+
);
|
|
2048
2204
|
}
|
|
2049
2205
|
return parsed.data;
|
|
2050
2206
|
}
|
|
@@ -4027,14 +4183,20 @@ function createApplicationPasswordToken(username, appPassword) {
|
|
|
4027
4183
|
|
|
4028
4184
|
// src/auth/types.ts
|
|
4029
4185
|
var AuthenticationError = class extends Error {
|
|
4030
|
-
constructor(message,
|
|
4031
|
-
super(message);
|
|
4186
|
+
constructor(code, status, message, detail) {
|
|
4187
|
+
super(detail ? `${message}: ${detail}` : message);
|
|
4188
|
+
__publicField(this, "code", code);
|
|
4032
4189
|
__publicField(this, "status", status);
|
|
4033
4190
|
this.name = "AuthenticationError";
|
|
4034
4191
|
}
|
|
4035
4192
|
};
|
|
4036
4193
|
|
|
4037
4194
|
// src/auth/jwt.ts
|
|
4195
|
+
function resolveAuthErrorCode(status) {
|
|
4196
|
+
if (status === 401) return ErrorCode.AUTH_CREDENTIALS_INVALID;
|
|
4197
|
+
if (status === 403) return ErrorCode.AUTH_TOKEN_INVALID;
|
|
4198
|
+
return ErrorCode.AUTH_JWT_FAILED;
|
|
4199
|
+
}
|
|
4038
4200
|
async function authenticateJwt(config, credentials) {
|
|
4039
4201
|
const url = `${resolveBaseUrl(config)}/wp-json/jwt-auth/v1/token`;
|
|
4040
4202
|
const response = await fetch(url, {
|
|
@@ -4044,9 +4206,12 @@ async function authenticateJwt(config, credentials) {
|
|
|
4044
4206
|
cache: "no-store"
|
|
4045
4207
|
});
|
|
4046
4208
|
if (!response.ok) {
|
|
4209
|
+
const code = resolveAuthErrorCode(response.status);
|
|
4047
4210
|
throw new AuthenticationError(
|
|
4048
|
-
|
|
4049
|
-
response.status
|
|
4211
|
+
code,
|
|
4212
|
+
response.status,
|
|
4213
|
+
resolveMessage(code, config.errorMessages),
|
|
4214
|
+
response.statusText
|
|
4050
4215
|
);
|
|
4051
4216
|
}
|
|
4052
4217
|
return response.json();
|
|
@@ -4061,6 +4226,6 @@ async function validateJwtToken(config, token) {
|
|
|
4061
4226
|
return response.ok;
|
|
4062
4227
|
}
|
|
4063
4228
|
|
|
4064
|
-
export { AuthenticationError, WPGraphQLError, authenticateJwt, buildACFFragment, buildPageWithACFQuery, buildPostWithACFQuery, buildPostsWithACFQuery, createApplicationPasswordToken, createAuthorsMutations, createCF7Queries, createCPTQueries, createCategoriesMutations, createCommentsMutations, createFaustAuthHandler, createMediaMutations, createMenusMutations, createPagesMutations, createPostsMutations, createPreviewHandler, createRevalidationHandler, createTagsMutations, createWPGraphQLCoreClient as createWPGraphQLClient, createWPGraphQLCoreClient, createWPGraphQLFetcher, createWPGraphQLMutationsClient, createWPGraphQLWooCommerceClient, createWooCommerceClient, createWooCommerceFetcher, createWordPressClient, createWordPressMutationsClient, createYoastQueries, extractOmnibusData, resolveBaseUrl, validateJwtToken, withOmnibus, withOmnibusVariation };
|
|
4229
|
+
export { AuthenticationError, ErrorCode, WPGraphQLError, WooCommerceError, WordPressAPIError, authenticateJwt, buildACFFragment, buildPageWithACFQuery, buildPostWithACFQuery, buildPostsWithACFQuery, createApplicationPasswordToken, createAuthorsMutations, createCF7Queries, createCPTQueries, createCategoriesMutations, createCommentsMutations, createFaustAuthHandler, createMediaMutations, createMenusMutations, createPagesMutations, createPostsMutations, createPreviewHandler, createRevalidationHandler, createTagsMutations, createWPGraphQLCoreClient as createWPGraphQLClient, createWPGraphQLCoreClient, createWPGraphQLFetcher, createWPGraphQLMutationsClient, createWPGraphQLWooCommerceClient, createWooCommerceClient, createWooCommerceFetcher, createWordPressClient, createWordPressMutationsClient, createYoastQueries, defaultMessages, defaultMessagesPl, extractOmnibusData, resolveBaseUrl, resolveMessage, validateJwtToken, withOmnibus, withOmnibusVariation };
|
|
4065
4230
|
//# sourceMappingURL=index.js.map
|
|
4066
4231
|
//# sourceMappingURL=index.js.map
|