@szymonpiatek/nextwordpress 0.0.7 → 0.0.9

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.
@@ -1,3 +1,33 @@
1
+ declare const ErrorCode: {
2
+ readonly WP_REQUEST_FAILED: "WP_REQUEST_FAILED";
3
+ readonly WP_NOT_FOUND: "WP_NOT_FOUND";
4
+ readonly WP_UNAUTHORIZED: "WP_UNAUTHORIZED";
5
+ readonly WP_FORBIDDEN: "WP_FORBIDDEN";
6
+ readonly GQL_REQUEST_FAILED: "GQL_REQUEST_FAILED";
7
+ readonly GQL_NO_DATA: "GQL_NO_DATA";
8
+ readonly GQL_ERRORS_IN_RESPONSE: "GQL_ERRORS_IN_RESPONSE";
9
+ readonly WOO_REQUEST_FAILED: "WOO_REQUEST_FAILED";
10
+ readonly WOO_NOT_FOUND: "WOO_NOT_FOUND";
11
+ readonly WOO_UNAUTHORIZED: "WOO_UNAUTHORIZED";
12
+ readonly WOO_FORBIDDEN: "WOO_FORBIDDEN";
13
+ readonly WOO_COUPON_NOT_FOUND: "WOO_COUPON_NOT_FOUND";
14
+ readonly WOO_PRODUCT_NOT_FOUND: "WOO_PRODUCT_NOT_FOUND";
15
+ readonly WOO_ORDER_NOT_FOUND: "WOO_ORDER_NOT_FOUND";
16
+ readonly WOO_CUSTOMER_NOT_FOUND: "WOO_CUSTOMER_NOT_FOUND";
17
+ readonly WOO_CATEGORY_NOT_FOUND: "WOO_CATEGORY_NOT_FOUND";
18
+ readonly WOO_TAG_NOT_FOUND: "WOO_TAG_NOT_FOUND";
19
+ readonly WOO_REVIEW_NOT_FOUND: "WOO_REVIEW_NOT_FOUND";
20
+ readonly WOO_WEBHOOK_NOT_FOUND: "WOO_WEBHOOK_NOT_FOUND";
21
+ readonly WOO_SHIPPING_ZONE_NOT_FOUND: "WOO_SHIPPING_ZONE_NOT_FOUND";
22
+ readonly AUTH_JWT_FAILED: "AUTH_JWT_FAILED";
23
+ readonly AUTH_CREDENTIALS_INVALID: "AUTH_CREDENTIALS_INVALID";
24
+ readonly AUTH_TOKEN_INVALID: "AUTH_TOKEN_INVALID";
25
+ };
26
+ type ErrorCode = (typeof ErrorCode)[keyof typeof ErrorCode];
27
+ declare const defaultMessages: Record<ErrorCode, string>;
28
+ declare const defaultMessagesPl: Record<ErrorCode, string>;
29
+ declare function resolveMessage(code: ErrorCode, overrides?: Partial<Record<ErrorCode, string>>): string;
30
+
1
31
  interface NextWordpressConfig {
2
32
  /** Used in server components / SSR (e.g., internal Docker hostname). */
3
33
  serverURL: string;
@@ -5,6 +35,8 @@ interface NextWordpressConfig {
5
35
  clientURL: string;
6
36
  /** Cache TTL in seconds for Next.js ISR revalidation (default: 300). */
7
37
  cacheTTL?: number;
38
+ /** Override default error messages by error code. */
39
+ errorMessages?: Partial<Record<ErrorCode, string>>;
8
40
  }
9
41
  interface WPEntity {
10
42
  id: number;
@@ -47,8 +79,9 @@ interface JwtAuthResponse {
47
79
  user_display_name: string;
48
80
  }
49
81
  declare class AuthenticationError extends Error {
50
- status: number;
51
- constructor(message: string, status: number);
82
+ readonly code: ErrorCode;
83
+ readonly status: number;
84
+ constructor(code: ErrorCode, status: number, message: string, detail?: string);
52
85
  }
53
86
 
54
87
  interface MediaSize {
@@ -219,6 +252,12 @@ interface WordPressResponse<T> {
219
252
  data: T;
220
253
  headers: WordPressPaginationHeaders;
221
254
  }
255
+ declare class WordPressAPIError extends Error {
256
+ readonly code: ErrorCode;
257
+ readonly status: number;
258
+ readonly endpoint: string;
259
+ constructor(code: ErrorCode, status: number, endpoint: string, message: string, detail?: string);
260
+ }
222
261
 
223
262
  interface WooCommerceConfig {
224
263
  serverURL: string;
@@ -226,6 +265,8 @@ interface WooCommerceConfig {
226
265
  consumerKey: string;
227
266
  consumerSecret: string;
228
267
  cacheTTL?: number;
268
+ /** Override default error messages by error code. */
269
+ errorMessages?: Partial<Record<ErrorCode, string>>;
229
270
  }
230
271
  interface WooCommercePaginationHeaders {
231
272
  total: number;
@@ -235,6 +276,13 @@ interface WooCommerceResponse<T> {
235
276
  data: T;
236
277
  headers: WooCommercePaginationHeaders;
237
278
  }
279
+ declare class WooCommerceError extends Error {
280
+ readonly code: ErrorCode;
281
+ readonly status: number;
282
+ readonly endpoint: string;
283
+ readonly upstreamCode?: string | undefined;
284
+ constructor(code: ErrorCode, status: number, endpoint: string, message: string, upstreamCode?: string | undefined, detail?: string);
285
+ }
238
286
 
239
287
  interface WCImage {
240
288
  id: number;
@@ -541,10 +589,11 @@ interface GQLError {
541
589
  path?: string[];
542
590
  }
543
591
  declare class WPGraphQLError extends Error {
592
+ readonly code: ErrorCode;
544
593
  readonly status: number;
545
594
  readonly endpoint: string;
546
595
  readonly gqlErrors?: GQLError[] | undefined;
547
- constructor(message: string, status: number, endpoint: string, gqlErrors?: GQLError[] | undefined);
596
+ constructor(code: ErrorCode, status: number, endpoint: string, message: string, gqlErrors?: GQLError[] | undefined);
548
597
  }
549
598
 
550
599
  interface GQLPostFilter {
@@ -601,4 +650,4 @@ interface GQLPost {
601
650
  };
602
651
  }
603
652
 
604
- export { type Author as A, type BlockType as B, type WCProductAttribute as C, type WCProductDefaultAttribute as D, type EditorBlock as E, type FeaturedMedia as F, type GQLPost as G, type WCShippingLine as H, WPGraphQLError as I, type JwtAuthCredentials as J, type WooCommercePaginationHeaders as K, type MediaDetails as M, type NextWordpressConfig as N, type Post as P, type RenderedTitle as R, type SearchResult as S, type Taxonomy as T, type UpdateCustomerInput as U, type WordPressResponse as W, type WooCommerceConfig as a, type WCProduct as b, type WCProductFilterParams as c, type WooCommerceResponse as d, type WCCreateOrderInput as e, type WCOrder as f, type WCCustomer as g, type WPGraphQLConfig as h, type GQLPostFilter as i, type GQLConnection as j, type JwtAuthResponse as k, type WPEntity as l, type RenderedContent as m, type WCImage as n, type WCProductVariation as o, type WCAddress as p, AuthenticationError as q, type EmbeddedAuthor as r, type EmbeddedTerm as s, type GQLError as t, type GQLPageInfo as u, type MediaSize as v, type PostEmbedded as w, type TemplatePart as x, type WCDimensions as y, type WCOrderLineItem as z };
653
+ export { type Author as A, type BlockType as B, type WCOrderLineItem as C, type WCProductAttribute as D, type EditorBlock as E, type FeaturedMedia as F, type GQLPost as G, type WCProductDefaultAttribute as H, type WCShippingLine as I, type JwtAuthCredentials as J, WPGraphQLError as K, WooCommerceError as L, type MediaDetails as M, type NextWordpressConfig as N, type WooCommercePaginationHeaders as O, type Post as P, WordPressAPIError as Q, type RenderedTitle as R, type SearchResult as S, type Taxonomy as T, type UpdateCustomerInput as U, defaultMessages as V, type WordPressResponse as W, defaultMessagesPl as X, resolveMessage as Y, type WooCommerceConfig as a, type WCProduct as b, type WCProductFilterParams as c, type WooCommerceResponse as d, type WCCreateOrderInput as e, type WCOrder as f, type WCCustomer as g, type WPGraphQLConfig as h, type GQLPostFilter as i, type GQLConnection as j, type JwtAuthResponse as k, type WPEntity as l, type RenderedContent as m, type WCImage as n, type WCProductVariation as o, type WCAddress as p, AuthenticationError as q, type EmbeddedAuthor as r, type EmbeddedTerm as s, ErrorCode as t, type GQLError as u, type GQLPageInfo as v, type MediaSize as w, type PostEmbedded as x, type TemplatePart as y, type WCDimensions as z };
@@ -1,3 +1,33 @@
1
+ declare const ErrorCode: {
2
+ readonly WP_REQUEST_FAILED: "WP_REQUEST_FAILED";
3
+ readonly WP_NOT_FOUND: "WP_NOT_FOUND";
4
+ readonly WP_UNAUTHORIZED: "WP_UNAUTHORIZED";
5
+ readonly WP_FORBIDDEN: "WP_FORBIDDEN";
6
+ readonly GQL_REQUEST_FAILED: "GQL_REQUEST_FAILED";
7
+ readonly GQL_NO_DATA: "GQL_NO_DATA";
8
+ readonly GQL_ERRORS_IN_RESPONSE: "GQL_ERRORS_IN_RESPONSE";
9
+ readonly WOO_REQUEST_FAILED: "WOO_REQUEST_FAILED";
10
+ readonly WOO_NOT_FOUND: "WOO_NOT_FOUND";
11
+ readonly WOO_UNAUTHORIZED: "WOO_UNAUTHORIZED";
12
+ readonly WOO_FORBIDDEN: "WOO_FORBIDDEN";
13
+ readonly WOO_COUPON_NOT_FOUND: "WOO_COUPON_NOT_FOUND";
14
+ readonly WOO_PRODUCT_NOT_FOUND: "WOO_PRODUCT_NOT_FOUND";
15
+ readonly WOO_ORDER_NOT_FOUND: "WOO_ORDER_NOT_FOUND";
16
+ readonly WOO_CUSTOMER_NOT_FOUND: "WOO_CUSTOMER_NOT_FOUND";
17
+ readonly WOO_CATEGORY_NOT_FOUND: "WOO_CATEGORY_NOT_FOUND";
18
+ readonly WOO_TAG_NOT_FOUND: "WOO_TAG_NOT_FOUND";
19
+ readonly WOO_REVIEW_NOT_FOUND: "WOO_REVIEW_NOT_FOUND";
20
+ readonly WOO_WEBHOOK_NOT_FOUND: "WOO_WEBHOOK_NOT_FOUND";
21
+ readonly WOO_SHIPPING_ZONE_NOT_FOUND: "WOO_SHIPPING_ZONE_NOT_FOUND";
22
+ readonly AUTH_JWT_FAILED: "AUTH_JWT_FAILED";
23
+ readonly AUTH_CREDENTIALS_INVALID: "AUTH_CREDENTIALS_INVALID";
24
+ readonly AUTH_TOKEN_INVALID: "AUTH_TOKEN_INVALID";
25
+ };
26
+ type ErrorCode = (typeof ErrorCode)[keyof typeof ErrorCode];
27
+ declare const defaultMessages: Record<ErrorCode, string>;
28
+ declare const defaultMessagesPl: Record<ErrorCode, string>;
29
+ declare function resolveMessage(code: ErrorCode, overrides?: Partial<Record<ErrorCode, string>>): string;
30
+
1
31
  interface NextWordpressConfig {
2
32
  /** Used in server components / SSR (e.g., internal Docker hostname). */
3
33
  serverURL: string;
@@ -5,6 +35,8 @@ interface NextWordpressConfig {
5
35
  clientURL: string;
6
36
  /** Cache TTL in seconds for Next.js ISR revalidation (default: 300). */
7
37
  cacheTTL?: number;
38
+ /** Override default error messages by error code. */
39
+ errorMessages?: Partial<Record<ErrorCode, string>>;
8
40
  }
9
41
  interface WPEntity {
10
42
  id: number;
@@ -47,8 +79,9 @@ interface JwtAuthResponse {
47
79
  user_display_name: string;
48
80
  }
49
81
  declare class AuthenticationError extends Error {
50
- status: number;
51
- constructor(message: string, status: number);
82
+ readonly code: ErrorCode;
83
+ readonly status: number;
84
+ constructor(code: ErrorCode, status: number, message: string, detail?: string);
52
85
  }
53
86
 
54
87
  interface MediaSize {
@@ -219,6 +252,12 @@ interface WordPressResponse<T> {
219
252
  data: T;
220
253
  headers: WordPressPaginationHeaders;
221
254
  }
255
+ declare class WordPressAPIError extends Error {
256
+ readonly code: ErrorCode;
257
+ readonly status: number;
258
+ readonly endpoint: string;
259
+ constructor(code: ErrorCode, status: number, endpoint: string, message: string, detail?: string);
260
+ }
222
261
 
223
262
  interface WooCommerceConfig {
224
263
  serverURL: string;
@@ -226,6 +265,8 @@ interface WooCommerceConfig {
226
265
  consumerKey: string;
227
266
  consumerSecret: string;
228
267
  cacheTTL?: number;
268
+ /** Override default error messages by error code. */
269
+ errorMessages?: Partial<Record<ErrorCode, string>>;
229
270
  }
230
271
  interface WooCommercePaginationHeaders {
231
272
  total: number;
@@ -235,6 +276,13 @@ interface WooCommerceResponse<T> {
235
276
  data: T;
236
277
  headers: WooCommercePaginationHeaders;
237
278
  }
279
+ declare class WooCommerceError extends Error {
280
+ readonly code: ErrorCode;
281
+ readonly status: number;
282
+ readonly endpoint: string;
283
+ readonly upstreamCode?: string | undefined;
284
+ constructor(code: ErrorCode, status: number, endpoint: string, message: string, upstreamCode?: string | undefined, detail?: string);
285
+ }
238
286
 
239
287
  interface WCImage {
240
288
  id: number;
@@ -541,10 +589,11 @@ interface GQLError {
541
589
  path?: string[];
542
590
  }
543
591
  declare class WPGraphQLError extends Error {
592
+ readonly code: ErrorCode;
544
593
  readonly status: number;
545
594
  readonly endpoint: string;
546
595
  readonly gqlErrors?: GQLError[] | undefined;
547
- constructor(message: string, status: number, endpoint: string, gqlErrors?: GQLError[] | undefined);
596
+ constructor(code: ErrorCode, status: number, endpoint: string, message: string, gqlErrors?: GQLError[] | undefined);
548
597
  }
549
598
 
550
599
  interface GQLPostFilter {
@@ -601,4 +650,4 @@ interface GQLPost {
601
650
  };
602
651
  }
603
652
 
604
- export { type Author as A, type BlockType as B, type WCProductAttribute as C, type WCProductDefaultAttribute as D, type EditorBlock as E, type FeaturedMedia as F, type GQLPost as G, type WCShippingLine as H, WPGraphQLError as I, type JwtAuthCredentials as J, type WooCommercePaginationHeaders as K, type MediaDetails as M, type NextWordpressConfig as N, type Post as P, type RenderedTitle as R, type SearchResult as S, type Taxonomy as T, type UpdateCustomerInput as U, type WordPressResponse as W, type WooCommerceConfig as a, type WCProduct as b, type WCProductFilterParams as c, type WooCommerceResponse as d, type WCCreateOrderInput as e, type WCOrder as f, type WCCustomer as g, type WPGraphQLConfig as h, type GQLPostFilter as i, type GQLConnection as j, type JwtAuthResponse as k, type WPEntity as l, type RenderedContent as m, type WCImage as n, type WCProductVariation as o, type WCAddress as p, AuthenticationError as q, type EmbeddedAuthor as r, type EmbeddedTerm as s, type GQLError as t, type GQLPageInfo as u, type MediaSize as v, type PostEmbedded as w, type TemplatePart as x, type WCDimensions as y, type WCOrderLineItem as z };
653
+ export { type Author as A, type BlockType as B, type WCOrderLineItem as C, type WCProductAttribute as D, type EditorBlock as E, type FeaturedMedia as F, type GQLPost as G, type WCProductDefaultAttribute as H, type WCShippingLine as I, type JwtAuthCredentials as J, WPGraphQLError as K, WooCommerceError as L, type MediaDetails as M, type NextWordpressConfig as N, type WooCommercePaginationHeaders as O, type Post as P, WordPressAPIError as Q, type RenderedTitle as R, type SearchResult as S, type Taxonomy as T, type UpdateCustomerInput as U, defaultMessages as V, type WordPressResponse as W, defaultMessagesPl as X, resolveMessage as Y, type WooCommerceConfig as a, type WCProduct as b, type WCProductFilterParams as c, type WooCommerceResponse as d, type WCCreateOrderInput as e, type WCOrder as f, type WCCustomer as g, type WPGraphQLConfig as h, type GQLPostFilter as i, type GQLConnection as j, type JwtAuthResponse as k, type WPEntity as l, type RenderedContent as m, type WCImage as n, type WCProductVariation as o, type WCAddress as p, AuthenticationError as q, type EmbeddedAuthor as r, type EmbeddedTerm as s, ErrorCode as t, type GQLError as u, type GQLPageInfo as v, type MediaSize as w, type PostEmbedded as x, type TemplatePart as y, type WCDimensions as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@szymonpiatek/nextwordpress",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "description": "Szymon Piątek - Next.js WordPress client (types, queries, fetcher)",
5
5
  "license": "UNLICENSED",
6
6
  "private": false,
@@ -42,15 +42,22 @@
42
42
  "lint:fix": "eslint \"src/**/*.ts\" --fix",
43
43
  "format": "prettier --write \"src/**/*.{ts,md,json}\"",
44
44
  "typecheck": "tsc --noEmit",
45
- "prepublishOnly": "npm run lint && npm run test && npm run clean && npm run build"
45
+ "prepublishOnly": "npm run lint && npm run test && npm run clean && npm run build",
46
+ "docs:dev": "typedoc && vitepress dev ../docs",
47
+ "docs:build": "typedoc && vitepress build ../docs",
48
+ "docs:preview": "vitepress preview ../docs"
46
49
  },
47
50
  "peerDependencies": {
48
51
  "react": ">=18.0.0",
49
52
  "swr": ">=2.0.0"
50
53
  },
51
54
  "peerDependenciesMeta": {
52
- "react": { "optional": true },
53
- "swr": { "optional": true }
55
+ "react": {
56
+ "optional": true
57
+ },
58
+ "swr": {
59
+ "optional": true
60
+ }
54
61
  },
55
62
  "dependencies": {
56
63
  "zod": "^3.23.8"
@@ -72,8 +79,11 @@
72
79
  "swr": "^2.4.1",
73
80
  "ts-jest": "^29.2.5",
74
81
  "tsup": "^8.3.5",
82
+ "typedoc": "^0.28.19",
83
+ "typedoc-plugin-markdown": "^4.12.0",
75
84
  "typescript": "^5.6.3",
76
- "typescript-eslint": "^8.15.0"
85
+ "typescript-eslint": "^8.15.0",
86
+ "vitepress": "^1.6.4"
77
87
  },
78
88
  "repository": {
79
89
  "type": "git",