kizlo 0.18.0 → 0.20.0

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.
@@ -112,6 +112,7 @@ var WordPressTransport = class {
112
112
  headers: response.headers
113
113
  });
114
114
  const expectedContentType = input.responseContentTypes?.[String(response.status)] ?? input.responseContentTypes?.default;
115
+ const acceptsData = response.ok || input.dataResponseStatuses?.includes(String(response.status)) === true || input.dataResponseStatuses?.includes("default") === true;
115
116
  const contentType = response.headers.get("content-type")?.split(";", 1)[0]?.trim().toLowerCase() || expectedContentType || "application/json";
116
117
  let body;
117
118
  try {
@@ -127,7 +128,7 @@ var WordPressTransport = class {
127
128
  })
128
129
  };
129
130
  }
130
- if (response.ok && typeof body === "string" && body.trim() === "") return {
131
+ if (acceptsData && typeof body === "string" && body.trim() === "") return {
131
132
  data: null,
132
133
  status: response.status,
133
134
  headers: response.headers,
@@ -147,10 +148,11 @@ var WordPressTransport = class {
147
148
  headers: response.headers,
148
149
  error: new WP_Error({
149
150
  code: data.code,
150
- message: data.message
151
+ message: data.message,
152
+ data: data.data
151
153
  })
152
154
  };
153
- return {
155
+ if (!acceptsData) return {
154
156
  data: null,
155
157
  status: response.status,
156
158
  headers: response.headers,
@@ -48,7 +48,7 @@ interface WordPressCustomFieldsRegistry {}
48
48
  * so a freshly scaffolded project compiles against endpoints it has not described yet.
49
49
  */
50
50
  type ActiveWordPressClient = WordPressClientRegistry extends {
51
- endpoints: infer TEndpoints extends object;
51
+ introspection: infer TEndpoints extends object;
52
52
  } ? WP_Client<TEndpoints> & WordPressTransport : WordPressTransport;
53
53
  /** Every raw WordPress operation path generated for the active project. */
54
54
  type WP_EndpointPath = keyof WordPressEndpointRegistry extends never ? string : Extract<keyof WordPressEndpointRegistry, string>;
@@ -113,6 +113,7 @@ type WP_CommonErrorCode = "rest_no_route" | "rest_cookie_invalid_nonce" | "inval
113
113
  interface WP_ErrorData<T extends string> {
114
114
  code: T | WP_CommonErrorCode;
115
115
  message: string;
116
+ data?: unknown;
116
117
  }
117
118
  interface WP_ListMetadata {
118
119
  page: number;
@@ -145,6 +146,7 @@ interface WP_RequestInput {
145
146
  method: WP_RequestMethod;
146
147
  requestContentType?: WP_RequestContentType;
147
148
  responseContentTypes?: Record<string, WP_ResponseContentType | undefined>;
149
+ dataResponseStatuses?: string[];
148
150
  signal?: AbortSignal;
149
151
  timeout?: Duration;
150
152
  }
@@ -170,6 +172,8 @@ interface WP_EndpointDefinition {
170
172
  pathParameters: string[];
171
173
  requestContentType?: WP_RequestContentType;
172
174
  responseContentTypes: Record<string, WP_ResponseContentType | undefined>;
175
+ /** Non-2xx statuses whose declared body is data rather than a WordPress error envelope. */
176
+ dataResponseStatuses?: string[];
173
177
  }
174
178
  interface WordPressCredentials {
175
179
  url: string;
@@ -2,6 +2,7 @@
2
2
  declare function isWordPressResourceError<TCode extends string>(data: unknown): data is {
3
3
  code: TCode;
4
4
  message: string;
5
+ data?: unknown;
5
6
  };
6
7
  //#endregion
7
8
  export { isWordPressResourceError };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kizlo",
3
- "version": "0.18.0",
3
+ "version": "0.20.0",
4
4
  "type": "module",
5
5
  "description": "A headless WordPress framework for TypeScript.",
6
6
  "keywords": [