@readyfor/api-client-base 1.71.0 → 1.73.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.
package/dist/fetcher.d.ts CHANGED
@@ -1,17 +1,23 @@
1
1
  import { z } from "zod";
2
2
  //#region src/fetcher.d.ts
3
- declare const createJsonFetcher: <T = never>(schema: z.ZodType<T>, customRequestInit?: RequestInit) => (input: RequestInfo, requestInit?: RequestInit) => Promise<T>;
4
- declare const createTextFetcher: (customRequestInit?: RequestInit) => (input: RequestInfo, requestInit?: RequestInit) => Promise<string>;
3
+ type FetcherOptions = {
4
+ /**
5
+ * フェッチャー本体が後段でボディを読むため、ここでボディを消費してはいけない。
6
+ */
7
+ onResponse?: (res: Response) => void;
8
+ };
9
+ declare const createJsonFetcher: <T = never>(schema: z.ZodType<T>, customRequestInit?: RequestInit, options?: FetcherOptions) => (input: RequestInfo, requestInit?: RequestInit) => Promise<T>;
10
+ declare const createTextFetcher: (customRequestInit?: RequestInit, options?: FetcherOptions) => (input: RequestInfo, requestInit?: RequestInit) => Promise<string>;
5
11
  type BlobFetcherResponse = {
6
12
  body: Blob;
7
13
  headers: Headers;
8
14
  };
9
- declare const createBlobFetcher: (customRequestInit?: RequestInit) => (input: RequestInfo, requestInit?: RequestInit) => Promise<BlobFetcherResponse>;
15
+ declare const createBlobFetcher: (customRequestInit?: RequestInit, options?: FetcherOptions) => (input: RequestInfo, requestInit?: RequestInit) => Promise<BlobFetcherResponse>;
10
16
  type FileOrBlobFetcherResponse = {
11
17
  body: File | Blob;
12
18
  headers: Headers;
13
19
  };
14
- declare const createFileOrBlobFetcher: (customRequestInit?: RequestInit) => (input: RequestInfo, requestInit?: RequestInit) => Promise<FileOrBlobFetcherResponse>;
15
- declare const createVoidFetcher: (customRequestInit?: RequestInit) => (input: RequestInfo, requestInit?: RequestInit) => Promise<void>;
20
+ declare const createFileOrBlobFetcher: (customRequestInit?: RequestInit, options?: FetcherOptions) => (input: RequestInfo, requestInit?: RequestInit) => Promise<FileOrBlobFetcherResponse>;
21
+ declare const createVoidFetcher: (customRequestInit?: RequestInit, options?: FetcherOptions) => (input: RequestInfo, requestInit?: RequestInit) => Promise<void>;
16
22
  //#endregion
17
- export { BlobFetcherResponse, FileOrBlobFetcherResponse, createBlobFetcher, createFileOrBlobFetcher, createJsonFetcher, createTextFetcher, createVoidFetcher };
23
+ export { BlobFetcherResponse, FetcherOptions, FileOrBlobFetcherResponse, createBlobFetcher, createFileOrBlobFetcher, createJsonFetcher, createTextFetcher, createVoidFetcher };
package/dist/fetcher.js CHANGED
@@ -4,7 +4,8 @@ const require_apiClientConfigStore = require("./apiClientConfigStore.js");
4
4
  const require_apiError = require("./apiError.js");
5
5
  //#region src/fetcher.ts
6
6
  const defaultRequestInit = { credentials: "include" };
7
- const createJsonFetcher = (schema, customRequestInit = {}) => (input, requestInit = {}) => fetch(input, require_utils_requestInit.mergeRequestInit(defaultRequestInit, require_utils_requestInit.mergeRequestInit(customRequestInit, requestInit))).then(async (res) => {
7
+ const createJsonFetcher = (schema, customRequestInit = {}, options = {}) => (input, requestInit = {}) => fetch(input, require_utils_requestInit.mergeRequestInit(defaultRequestInit, require_utils_requestInit.mergeRequestInit(customRequestInit, requestInit))).then(async (res) => {
8
+ options.onResponse?.(res);
8
9
  const text = await res.text();
9
10
  const body = text ? JSON.parse(text) : {};
10
11
  if (res.ok) return body;
@@ -23,7 +24,8 @@ const createJsonFetcher = (schema, customRequestInit = {}) => (input, requestIni
23
24
  }
24
25
  throw result.error;
25
26
  });
26
- const createTextFetcher = (customRequestInit = {}) => (input, requestInit = {}) => fetch(input, require_utils_requestInit.mergeRequestInit(defaultRequestInit, require_utils_requestInit.mergeRequestInit(customRequestInit, requestInit))).then(async (res) => {
27
+ const createTextFetcher = (customRequestInit = {}, options = {}) => (input, requestInit = {}) => fetch(input, require_utils_requestInit.mergeRequestInit(defaultRequestInit, require_utils_requestInit.mergeRequestInit(customRequestInit, requestInit))).then(async (res) => {
28
+ options.onResponse?.(res);
27
29
  const body = await res.text();
28
30
  if (res.ok) return body;
29
31
  throw new require_apiError.HTTPError(Object.values(require_apiError.errorStatusCode).includes(res.status) ? res.status : 999, body);
@@ -31,7 +33,8 @@ const createTextFetcher = (customRequestInit = {}) => (input, requestInit = {})
31
33
  require_apiClientConfigStore.store.getState().onError?.(error);
32
34
  throw error;
33
35
  });
34
- const createBlobFetcher = (customRequestInit = {}) => (input, requestInit = {}) => fetch(input, require_utils_requestInit.mergeRequestInit(defaultRequestInit, require_utils_requestInit.mergeRequestInit(customRequestInit, requestInit))).then(async (res) => {
36
+ const createBlobFetcher = (customRequestInit = {}, options = {}) => (input, requestInit = {}) => fetch(input, require_utils_requestInit.mergeRequestInit(defaultRequestInit, require_utils_requestInit.mergeRequestInit(customRequestInit, requestInit))).then(async (res) => {
37
+ options.onResponse?.(res);
35
38
  const body = await res.blob();
36
39
  if (res.ok) return {
37
40
  body,
@@ -42,7 +45,8 @@ const createBlobFetcher = (customRequestInit = {}) => (input, requestInit = {})
42
45
  require_apiClientConfigStore.store.getState().onError?.(error);
43
46
  throw error;
44
47
  });
45
- const createFileOrBlobFetcher = (customRequestInit = {}) => (input, requestInit = {}) => fetch(input, require_utils_requestInit.mergeRequestInit(defaultRequestInit, require_utils_requestInit.mergeRequestInit(customRequestInit, requestInit))).then(async (res) => {
48
+ const createFileOrBlobFetcher = (customRequestInit = {}, options = {}) => (input, requestInit = {}) => fetch(input, require_utils_requestInit.mergeRequestInit(defaultRequestInit, require_utils_requestInit.mergeRequestInit(customRequestInit, requestInit))).then(async (res) => {
49
+ options.onResponse?.(res);
46
50
  const body = await res.blob();
47
51
  if (res.ok) return {
48
52
  body,
@@ -53,7 +57,8 @@ const createFileOrBlobFetcher = (customRequestInit = {}) => (input, requestInit
53
57
  require_apiClientConfigStore.store.getState().onError?.(error);
54
58
  throw error;
55
59
  });
56
- const createVoidFetcher = (customRequestInit = {}) => (input, requestInit = {}) => fetch(input, require_utils_requestInit.mergeRequestInit(defaultRequestInit, require_utils_requestInit.mergeRequestInit(customRequestInit, requestInit))).then(async (res) => {
60
+ const createVoidFetcher = (customRequestInit = {}, options = {}) => (input, requestInit = {}) => fetch(input, require_utils_requestInit.mergeRequestInit(defaultRequestInit, require_utils_requestInit.mergeRequestInit(customRequestInit, requestInit))).then(async (res) => {
61
+ options.onResponse?.(res);
57
62
  if (res.ok) return;
58
63
  throw new require_apiError.HTTPError(Object.values(require_apiError.errorStatusCode).includes(res.status) ? res.status : 999, await res.text());
59
64
  }).catch((error) => {
package/dist/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import { Store, createStore } from "./store.js";
2
2
  import { Config, RequestConfig, buildRequestInitWithDefaultConfig, setApiClientConfig, store } from "./apiClientConfigStore.js";
3
3
  import { ErrorStatusCode, HTTPError, errorStatusCode, errorTitle, getErrorStatus, getHttpErrorBody, getHttpErrorBodyReason, isHttpErrorWithStatus } from "./apiError.js";
4
- import { BlobFetcherResponse, FileOrBlobFetcherResponse, createBlobFetcher, createFileOrBlobFetcher, createJsonFetcher, createTextFetcher, createVoidFetcher } from "./fetcher.js";
4
+ import { BlobFetcherResponse, FetcherOptions, FileOrBlobFetcherResponse, createBlobFetcher, createFileOrBlobFetcher, createJsonFetcher, createTextFetcher, createVoidFetcher } from "./fetcher.js";
5
5
  import { __internal__requestUrl } from "./requestUrl.js";
6
6
  import { ForceDig, QueryPropsFor } from "./types.js";
7
7
  import { isZodError, schemaForType } from "./zod.js";
8
8
  import { mergeRequestInit } from "./utils/requestInit.js";
9
9
  import { mergeHeadersInit, toHeadersInit } from "./utils/headersInit.js";
10
- export { BlobFetcherResponse, Config, ErrorStatusCode, FileOrBlobFetcherResponse, ForceDig, HTTPError, QueryPropsFor, RequestConfig, Store, __internal__requestUrl, buildRequestInitWithDefaultConfig, createBlobFetcher, createFileOrBlobFetcher, createJsonFetcher, createStore, createTextFetcher, createVoidFetcher, errorStatusCode, errorTitle, getErrorStatus, getHttpErrorBody, getHttpErrorBodyReason, isHttpErrorWithStatus, isZodError, mergeHeadersInit, mergeRequestInit, schemaForType, setApiClientConfig, store, toHeadersInit };
10
+ export { BlobFetcherResponse, Config, ErrorStatusCode, FetcherOptions, FileOrBlobFetcherResponse, ForceDig, HTTPError, QueryPropsFor, RequestConfig, Store, __internal__requestUrl, buildRequestInitWithDefaultConfig, createBlobFetcher, createFileOrBlobFetcher, createJsonFetcher, createStore, createTextFetcher, createVoidFetcher, errorStatusCode, errorTitle, getErrorStatus, getHttpErrorBody, getHttpErrorBodyReason, isHttpErrorWithStatus, isZodError, mergeHeadersInit, mergeRequestInit, schemaForType, setApiClientConfig, store, toHeadersInit };
package/dist/index.mjs CHANGED
@@ -79,7 +79,8 @@ const getErrorStatus = (response) => {
79
79
  //#endregion
80
80
  //#region src/fetcher.ts
81
81
  const defaultRequestInit = { credentials: "include" };
82
- const createJsonFetcher = (schema, customRequestInit = {}) => (input, requestInit = {}) => fetch(input, mergeRequestInit(defaultRequestInit, mergeRequestInit(customRequestInit, requestInit))).then(async (res) => {
82
+ const createJsonFetcher = (schema, customRequestInit = {}, options = {}) => (input, requestInit = {}) => fetch(input, mergeRequestInit(defaultRequestInit, mergeRequestInit(customRequestInit, requestInit))).then(async (res) => {
83
+ options.onResponse?.(res);
83
84
  const text = await res.text();
84
85
  const body = text ? JSON.parse(text) : {};
85
86
  if (res.ok) return body;
@@ -98,7 +99,8 @@ const createJsonFetcher = (schema, customRequestInit = {}) => (input, requestIni
98
99
  }
99
100
  throw result.error;
100
101
  });
101
- const createTextFetcher = (customRequestInit = {}) => (input, requestInit = {}) => fetch(input, mergeRequestInit(defaultRequestInit, mergeRequestInit(customRequestInit, requestInit))).then(async (res) => {
102
+ const createTextFetcher = (customRequestInit = {}, options = {}) => (input, requestInit = {}) => fetch(input, mergeRequestInit(defaultRequestInit, mergeRequestInit(customRequestInit, requestInit))).then(async (res) => {
103
+ options.onResponse?.(res);
102
104
  const body = await res.text();
103
105
  if (res.ok) return body;
104
106
  throw new HTTPError(Object.values(errorStatusCode).includes(res.status) ? res.status : 999, body);
@@ -106,7 +108,8 @@ const createTextFetcher = (customRequestInit = {}) => (input, requestInit = {})
106
108
  store.getState().onError?.(error);
107
109
  throw error;
108
110
  });
109
- const createBlobFetcher = (customRequestInit = {}) => (input, requestInit = {}) => fetch(input, mergeRequestInit(defaultRequestInit, mergeRequestInit(customRequestInit, requestInit))).then(async (res) => {
111
+ const createBlobFetcher = (customRequestInit = {}, options = {}) => (input, requestInit = {}) => fetch(input, mergeRequestInit(defaultRequestInit, mergeRequestInit(customRequestInit, requestInit))).then(async (res) => {
112
+ options.onResponse?.(res);
110
113
  const body = await res.blob();
111
114
  if (res.ok) return {
112
115
  body,
@@ -117,7 +120,8 @@ const createBlobFetcher = (customRequestInit = {}) => (input, requestInit = {})
117
120
  store.getState().onError?.(error);
118
121
  throw error;
119
122
  });
120
- const createFileOrBlobFetcher = (customRequestInit = {}) => (input, requestInit = {}) => fetch(input, mergeRequestInit(defaultRequestInit, mergeRequestInit(customRequestInit, requestInit))).then(async (res) => {
123
+ const createFileOrBlobFetcher = (customRequestInit = {}, options = {}) => (input, requestInit = {}) => fetch(input, mergeRequestInit(defaultRequestInit, mergeRequestInit(customRequestInit, requestInit))).then(async (res) => {
124
+ options.onResponse?.(res);
121
125
  const body = await res.blob();
122
126
  if (res.ok) return {
123
127
  body,
@@ -128,7 +132,8 @@ const createFileOrBlobFetcher = (customRequestInit = {}) => (input, requestInit
128
132
  store.getState().onError?.(error);
129
133
  throw error;
130
134
  });
131
- const createVoidFetcher = (customRequestInit = {}) => (input, requestInit = {}) => fetch(input, mergeRequestInit(defaultRequestInit, mergeRequestInit(customRequestInit, requestInit))).then(async (res) => {
135
+ const createVoidFetcher = (customRequestInit = {}, options = {}) => (input, requestInit = {}) => fetch(input, mergeRequestInit(defaultRequestInit, mergeRequestInit(customRequestInit, requestInit))).then(async (res) => {
136
+ options.onResponse?.(res);
132
137
  if (res.ok) return;
133
138
  throw new HTTPError(Object.values(errorStatusCode).includes(res.status) ? res.status : 999, await res.text());
134
139
  }).catch((error) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@readyfor/api-client-base",
3
- "version": "1.71.0",
3
+ "version": "1.73.0",
4
4
  "license": "SEE LICENSE IN LICENSE.md",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",