@readyfor/api-client-base 1.22.0-pr1284.dc25e7e → 1.22.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.
Files changed (56) hide show
  1. package/dist/apiClientConfigStore.d.ts +10 -11
  2. package/dist/apiClientConfigStore.js +37 -10
  3. package/dist/apiClientConfigStore.mjs +12 -9
  4. package/dist/apiError.d.ts +25 -24
  5. package/dist/apiError.js +95 -68
  6. package/dist/apiError.mjs +18 -70
  7. package/dist/chunk-3SEO7S3Q.mjs +23 -0
  8. package/dist/chunk-5JS6U5IM.mjs +37 -0
  9. package/dist/chunk-DH33ZDBG.mjs +19 -0
  10. package/dist/chunk-FNLUAQWC.mjs +80 -0
  11. package/dist/chunk-GD4RTKUU.mjs +22 -0
  12. package/dist/chunk-JCZWXJBU.mjs +10 -0
  13. package/dist/chunk-NOC6G3HZ.mjs +21 -0
  14. package/dist/chunk-NYICHGY2.mjs +30 -0
  15. package/dist/chunk-OVR3ZT2S.mjs +118 -0
  16. package/dist/chunk-QXFPBYPL.mjs +25 -0
  17. package/dist/chunk-TZUKIYFN.mjs +14 -0
  18. package/dist/chunk-WBQAMGXK.mjs +0 -0
  19. package/dist/fetcher.d.ts +7 -8
  20. package/dist/fetcher.js +125 -57
  21. package/dist/fetcher.mjs +20 -63
  22. package/dist/index.d.ts +10 -10
  23. package/dist/index.js +38 -31
  24. package/dist/index.mjs +63 -10
  25. package/dist/react/ApiClientConfigProvider.d.ts +9 -10
  26. package/dist/react/ApiClientConfigProvider.js +41 -24
  27. package/dist/react/ApiClientConfigProvider.mjs +12 -22
  28. package/dist/react/index.d.ts +7 -4
  29. package/dist/react/index.js +26 -10
  30. package/dist/react/index.mjs +24 -4
  31. package/dist/react/swr.d.ts +9 -10
  32. package/dist/react/swr.js +37 -24
  33. package/dist/react/swr.mjs +5 -25
  34. package/dist/react/useApiClientConfig.d.ts +5 -5
  35. package/dist/react/useApiClientConfig.js +50 -18
  36. package/dist/react/useApiClientConfig.mjs +15 -19
  37. package/dist/requestUrl.d.ts +2 -3
  38. package/dist/requestUrl.js +49 -14
  39. package/dist/requestUrl.mjs +10 -13
  40. package/dist/store.d.ts +5 -6
  41. package/dist/store.js +43 -20
  42. package/dist/store.mjs +5 -20
  43. package/dist/types.d.ts +11 -5
  44. package/dist/types.js +16 -0
  45. package/dist/types.mjs +1 -1
  46. package/dist/utils/headersInit.d.ts +2 -3
  47. package/dist/utils/headersInit.js +49 -45
  48. package/dist/utils/headersInit.mjs +7 -46
  49. package/dist/utils/requestInit.d.ts +3 -10
  50. package/dist/utils/requestInit.js +31 -14
  51. package/dist/utils/requestInit.mjs +7 -15
  52. package/dist/zod.d.ts +3 -4
  53. package/dist/zod.js +30 -6
  54. package/dist/zod.mjs +7 -6
  55. package/package.json +19 -2
  56. package/dist/_virtual/_rolldown/runtime.js +0 -23
@@ -0,0 +1,30 @@
1
+ // src/utils/headersInit.ts
2
+ var mergeHeadersInit = (baseHeadersInit, overrideHeadersInit) => {
3
+ const base = new Headers(baseHeadersInit);
4
+ const override = new Headers(overrideHeadersInit);
5
+ const setCookies = base.getSetCookie().concat(override.getSetCookie());
6
+ base.delete("set-cookie");
7
+ override.delete("set-cookie");
8
+ const mergedHeaders = new Headers({
9
+ ...Object.fromEntries(base),
10
+ ...Object.fromEntries(override)
11
+ });
12
+ setCookies.forEach((cookie) => {
13
+ mergedHeaders.append("set-cookie", cookie);
14
+ });
15
+ return mergedHeaders;
16
+ };
17
+ var toHeadersInit = (headers) => {
18
+ const result = {};
19
+ for (const [key, value] of Object.entries(headers)) {
20
+ if (value !== void 0) {
21
+ result[key] = String(value);
22
+ }
23
+ }
24
+ return result;
25
+ };
26
+
27
+ export {
28
+ mergeHeadersInit,
29
+ toHeadersInit
30
+ };
@@ -0,0 +1,118 @@
1
+ import {
2
+ HTTPError,
3
+ errorStatusCode
4
+ } from "./chunk-FNLUAQWC.mjs";
5
+ import {
6
+ store
7
+ } from "./chunk-NOC6G3HZ.mjs";
8
+ import {
9
+ mergeRequestInit
10
+ } from "./chunk-TZUKIYFN.mjs";
11
+
12
+ // src/fetcher.ts
13
+ var defaultRequestInit = {
14
+ credentials: "include"
15
+ };
16
+ var createJsonFetcher = (schema, customRequestInit = {}) => (input, requestInit = {}) => fetch(
17
+ input,
18
+ mergeRequestInit(
19
+ defaultRequestInit,
20
+ mergeRequestInit(customRequestInit, requestInit)
21
+ )
22
+ ).then(async (res) => {
23
+ const text = await res.text();
24
+ const body = text ? JSON.parse(text) : {};
25
+ if (res.ok) return body;
26
+ const code = Object.values(errorStatusCode).includes(res.status) ? res.status : 999;
27
+ const error = new HTTPError(code, body);
28
+ throw error;
29
+ }).catch((error) => {
30
+ store.getState().onError?.(error);
31
+ throw error;
32
+ }).then((parsedResponse) => {
33
+ const result = schema.safeParse(parsedResponse);
34
+ const config = store.getState();
35
+ if (result.success) {
36
+ return result.data;
37
+ }
38
+ if (config.showsSchemaParseError) {
39
+ console.error(result.error);
40
+ }
41
+ if (config.forceDeserializeResponse) {
42
+ config.onFailedDeserializeResponse(input, result.error);
43
+ return parsedResponse;
44
+ }
45
+ throw result.error;
46
+ });
47
+ var createTextFetcher = (customRequestInit = {}) => (input, requestInit = {}) => fetch(
48
+ input,
49
+ mergeRequestInit(
50
+ defaultRequestInit,
51
+ mergeRequestInit(customRequestInit, requestInit)
52
+ )
53
+ ).then(async (res) => {
54
+ const body = await res.text();
55
+ if (res.ok) return body;
56
+ const code = Object.values(errorStatusCode).includes(res.status) ? res.status : 999;
57
+ const error = new HTTPError(code, body);
58
+ throw error;
59
+ }).catch((error) => {
60
+ store.getState().onError?.(error);
61
+ throw error;
62
+ });
63
+ var createBlobFetcher = (customRequestInit = {}) => (input, requestInit = {}) => fetch(
64
+ input,
65
+ mergeRequestInit(
66
+ defaultRequestInit,
67
+ mergeRequestInit(customRequestInit, requestInit)
68
+ )
69
+ ).then(async (res) => {
70
+ const body = await res.blob();
71
+ if (res.ok) return { body, headers: res.headers };
72
+ const code = Object.values(errorStatusCode).includes(res.status) ? res.status : 999;
73
+ const error = new HTTPError(code, body);
74
+ throw error;
75
+ }).catch((error) => {
76
+ store.getState().onError?.(error);
77
+ throw error;
78
+ });
79
+ var createFileOrBlobFetcher = (customRequestInit = {}) => (input, requestInit = {}) => fetch(
80
+ input,
81
+ mergeRequestInit(
82
+ defaultRequestInit,
83
+ mergeRequestInit(customRequestInit, requestInit)
84
+ )
85
+ ).then(async (res) => {
86
+ const body = await res.blob();
87
+ if (res.ok) return { body, headers: res.headers };
88
+ const code = Object.values(errorStatusCode).includes(res.status) ? res.status : 999;
89
+ const error = new HTTPError(code, body);
90
+ throw error;
91
+ }).catch((error) => {
92
+ store.getState().onError?.(error);
93
+ throw error;
94
+ });
95
+ var createVoidFetcher = (customRequestInit = {}) => (input, requestInit = {}) => fetch(
96
+ input,
97
+ mergeRequestInit(
98
+ defaultRequestInit,
99
+ mergeRequestInit(customRequestInit, requestInit)
100
+ )
101
+ ).then(async (res) => {
102
+ if (res.ok) return;
103
+ const code = Object.values(errorStatusCode).includes(res.status) ? res.status : 999;
104
+ const body = await res.text();
105
+ const error = new HTTPError(code, body);
106
+ throw error;
107
+ }).catch((error) => {
108
+ store.getState().onError?.(error);
109
+ throw error;
110
+ });
111
+
112
+ export {
113
+ createJsonFetcher,
114
+ createTextFetcher,
115
+ createBlobFetcher,
116
+ createFileOrBlobFetcher,
117
+ createVoidFetcher
118
+ };
@@ -0,0 +1,25 @@
1
+ import {
2
+ createSwrConfig
3
+ } from "./chunk-DH33ZDBG.mjs";
4
+ import {
5
+ store
6
+ } from "./chunk-NOC6G3HZ.mjs";
7
+
8
+ // src/react/ApiClientConfigProvider.tsx
9
+ import { createContext, useContext, useEffect } from "react";
10
+ import { SWRConfig } from "swr";
11
+ import { jsx } from "react/jsx-runtime";
12
+ var ApiClientConfigContext = createContext(store);
13
+ var ApiClientConfigProvider = (props) => {
14
+ const { swr, ...config } = props.config;
15
+ useEffect(() => {
16
+ store.setState(() => config);
17
+ }, [config]);
18
+ return /* @__PURE__ */ jsx(ApiClientConfigContext.Provider, { value: store, children: /* @__PURE__ */ jsx(SWRConfig, { value: createSwrConfig(swr), children: props.children }) });
19
+ };
20
+ var useApiClientConfigContext = () => useContext(ApiClientConfigContext) || store;
21
+
22
+ export {
23
+ ApiClientConfigProvider,
24
+ useApiClientConfigContext
25
+ };
@@ -0,0 +1,14 @@
1
+ import {
2
+ mergeHeadersInit
3
+ } from "./chunk-NYICHGY2.mjs";
4
+
5
+ // src/utils/requestInit.ts
6
+ var mergeRequestInit = ({ headers: baseHeaders, ...base }, { headers: overrideHeaders, ...override }) => ({
7
+ ...base,
8
+ ...override,
9
+ headers: baseHeaders === void 0 ? overrideHeaders : overrideHeaders === void 0 ? baseHeaders : mergeHeadersInit(baseHeaders, overrideHeaders)
10
+ });
11
+
12
+ export {
13
+ mergeRequestInit
14
+ };
File without changes
package/dist/fetcher.d.ts CHANGED
@@ -1,18 +1,17 @@
1
- import { z } from "zod";
1
+ import { z } from 'zod';
2
2
 
3
- //#region src/fetcher.d.ts
4
3
  declare const createJsonFetcher: <T = never>(schema: z.ZodType<T>, customRequestInit?: RequestInit) => (input: RequestInfo, requestInit?: RequestInit) => Promise<T>;
5
4
  declare const createTextFetcher: (customRequestInit?: RequestInit) => (input: RequestInfo, requestInit?: RequestInit) => Promise<string>;
6
5
  type BlobFetcherResponse = {
7
- body: Blob;
8
- headers: Headers;
6
+ body: Blob;
7
+ headers: Headers;
9
8
  };
10
9
  declare const createBlobFetcher: (customRequestInit?: RequestInit) => (input: RequestInfo, requestInit?: RequestInit) => Promise<BlobFetcherResponse>;
11
10
  type FileOrBlobFetcherResponse = {
12
- body: File | Blob;
13
- headers: Headers;
11
+ body: File | Blob;
12
+ headers: Headers;
14
13
  };
15
14
  declare const createFileOrBlobFetcher: (customRequestInit?: RequestInit) => (input: RequestInfo, requestInit?: RequestInit) => Promise<FileOrBlobFetcherResponse>;
16
15
  declare const createVoidFetcher: (customRequestInit?: RequestInit) => (input: RequestInfo, requestInit?: RequestInit) => Promise<void>;
17
- //#endregion
18
- export { BlobFetcherResponse, FileOrBlobFetcherResponse, createBlobFetcher, createFileOrBlobFetcher, createJsonFetcher, createTextFetcher, createVoidFetcher };
16
+
17
+ export { type BlobFetcherResponse, type FileOrBlobFetcherResponse, createBlobFetcher, createFileOrBlobFetcher, createJsonFetcher, createTextFetcher, createVoidFetcher };
package/dist/fetcher.js CHANGED
@@ -1,68 +1,136 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_utils_requestInit = require("./utils/requestInit.js");
3
- const require_apiClientConfigStore = require("./apiClientConfigStore.js");
4
- const require_apiError = require("./apiError.js");
5
- //#region src/fetcher.ts
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) => {
8
- const text = await res.text();
9
- const body = text ? JSON.parse(text) : {};
10
- if (res.ok) return body;
11
- throw new require_apiError.HTTPError(Object.values(require_apiError.errorStatusCode).includes(res.status) ? res.status : 999, body);
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var fetcher_exports = {};
20
+ __export(fetcher_exports, {
21
+ createBlobFetcher: () => createBlobFetcher,
22
+ createFileOrBlobFetcher: () => createFileOrBlobFetcher,
23
+ createJsonFetcher: () => createJsonFetcher,
24
+ createTextFetcher: () => createTextFetcher,
25
+ createVoidFetcher: () => createVoidFetcher
26
+ });
27
+ module.exports = __toCommonJS(fetcher_exports);
28
+ var import_apiError = require("./apiError");
29
+ var import_apiClientConfigStore = require("./apiClientConfigStore");
30
+ var import_requestInit = require("./utils/requestInit");
31
+ const defaultRequestInit = {
32
+ credentials: "include"
33
+ };
34
+ const createJsonFetcher = (schema, customRequestInit = {}) => (input, requestInit = {}) => fetch(
35
+ input,
36
+ (0, import_requestInit.mergeRequestInit)(
37
+ defaultRequestInit,
38
+ (0, import_requestInit.mergeRequestInit)(customRequestInit, requestInit)
39
+ )
40
+ ).then(async (res) => {
41
+ const text = await res.text();
42
+ const body = text ? JSON.parse(text) : {};
43
+ if (res.ok) return body;
44
+ const code = Object.values(import_apiError.errorStatusCode).includes(res.status) ? res.status : 999;
45
+ const error = new import_apiError.HTTPError(code, body);
46
+ throw error;
12
47
  }).catch((error) => {
13
- require_apiClientConfigStore.store.getState().onError?.(error);
14
- throw error;
48
+ import_apiClientConfigStore.store.getState().onError?.(error);
49
+ throw error;
15
50
  }).then((parsedResponse) => {
16
- const result = schema.safeParse(parsedResponse);
17
- const config = require_apiClientConfigStore.store.getState();
18
- if (result.success) return result.data;
19
- if (config.showsSchemaParseError) console.error(result.error);
20
- if (config.forceDeserializeResponse) {
21
- config.onFailedDeserializeResponse(input, result.error);
22
- return parsedResponse;
23
- }
24
- throw result.error;
51
+ const result = schema.safeParse(parsedResponse);
52
+ const config = import_apiClientConfigStore.store.getState();
53
+ if (result.success) {
54
+ return result.data;
55
+ }
56
+ if (config.showsSchemaParseError) {
57
+ console.error(result.error);
58
+ }
59
+ if (config.forceDeserializeResponse) {
60
+ config.onFailedDeserializeResponse(input, result.error);
61
+ return parsedResponse;
62
+ }
63
+ throw result.error;
25
64
  });
26
- const createTextFetcher = (customRequestInit = {}) => (input, requestInit = {}) => fetch(input, require_utils_requestInit.mergeRequestInit(defaultRequestInit, require_utils_requestInit.mergeRequestInit(customRequestInit, requestInit))).then(async (res) => {
27
- const body = await res.text();
28
- if (res.ok) return body;
29
- throw new require_apiError.HTTPError(Object.values(require_apiError.errorStatusCode).includes(res.status) ? res.status : 999, body);
65
+ const createTextFetcher = (customRequestInit = {}) => (input, requestInit = {}) => fetch(
66
+ input,
67
+ (0, import_requestInit.mergeRequestInit)(
68
+ defaultRequestInit,
69
+ (0, import_requestInit.mergeRequestInit)(customRequestInit, requestInit)
70
+ )
71
+ ).then(async (res) => {
72
+ const body = await res.text();
73
+ if (res.ok) return body;
74
+ const code = Object.values(import_apiError.errorStatusCode).includes(res.status) ? res.status : 999;
75
+ const error = new import_apiError.HTTPError(code, body);
76
+ throw error;
30
77
  }).catch((error) => {
31
- require_apiClientConfigStore.store.getState().onError?.(error);
32
- throw error;
78
+ import_apiClientConfigStore.store.getState().onError?.(error);
79
+ throw error;
33
80
  });
34
- const createBlobFetcher = (customRequestInit = {}) => (input, requestInit = {}) => fetch(input, require_utils_requestInit.mergeRequestInit(defaultRequestInit, require_utils_requestInit.mergeRequestInit(customRequestInit, requestInit))).then(async (res) => {
35
- const body = await res.blob();
36
- if (res.ok) return {
37
- body,
38
- headers: res.headers
39
- };
40
- throw new require_apiError.HTTPError(Object.values(require_apiError.errorStatusCode).includes(res.status) ? res.status : 999, body);
81
+ const createBlobFetcher = (customRequestInit = {}) => (input, requestInit = {}) => fetch(
82
+ input,
83
+ (0, import_requestInit.mergeRequestInit)(
84
+ defaultRequestInit,
85
+ (0, import_requestInit.mergeRequestInit)(customRequestInit, requestInit)
86
+ )
87
+ ).then(async (res) => {
88
+ const body = await res.blob();
89
+ if (res.ok) return { body, headers: res.headers };
90
+ const code = Object.values(import_apiError.errorStatusCode).includes(res.status) ? res.status : 999;
91
+ const error = new import_apiError.HTTPError(code, body);
92
+ throw error;
41
93
  }).catch((error) => {
42
- require_apiClientConfigStore.store.getState().onError?.(error);
43
- throw error;
94
+ import_apiClientConfigStore.store.getState().onError?.(error);
95
+ throw error;
44
96
  });
45
- const createFileOrBlobFetcher = (customRequestInit = {}) => (input, requestInit = {}) => fetch(input, require_utils_requestInit.mergeRequestInit(defaultRequestInit, require_utils_requestInit.mergeRequestInit(customRequestInit, requestInit))).then(async (res) => {
46
- const body = await res.blob();
47
- if (res.ok) return {
48
- body,
49
- headers: res.headers
50
- };
51
- throw new require_apiError.HTTPError(Object.values(require_apiError.errorStatusCode).includes(res.status) ? res.status : 999, body);
97
+ const createFileOrBlobFetcher = (customRequestInit = {}) => (input, requestInit = {}) => fetch(
98
+ input,
99
+ (0, import_requestInit.mergeRequestInit)(
100
+ defaultRequestInit,
101
+ (0, import_requestInit.mergeRequestInit)(customRequestInit, requestInit)
102
+ )
103
+ ).then(async (res) => {
104
+ const body = await res.blob();
105
+ if (res.ok) return { body, headers: res.headers };
106
+ const code = Object.values(import_apiError.errorStatusCode).includes(res.status) ? res.status : 999;
107
+ const error = new import_apiError.HTTPError(code, body);
108
+ throw error;
52
109
  }).catch((error) => {
53
- require_apiClientConfigStore.store.getState().onError?.(error);
54
- throw error;
110
+ import_apiClientConfigStore.store.getState().onError?.(error);
111
+ throw error;
55
112
  });
56
- const createVoidFetcher = (customRequestInit = {}) => (input, requestInit = {}) => fetch(input, require_utils_requestInit.mergeRequestInit(defaultRequestInit, require_utils_requestInit.mergeRequestInit(customRequestInit, requestInit))).then(async (res) => {
57
- if (res.ok) return;
58
- throw new require_apiError.HTTPError(Object.values(require_apiError.errorStatusCode).includes(res.status) ? res.status : 999, await res.text());
113
+ const createVoidFetcher = (customRequestInit = {}) => (input, requestInit = {}) => fetch(
114
+ input,
115
+ (0, import_requestInit.mergeRequestInit)(
116
+ defaultRequestInit,
117
+ (0, import_requestInit.mergeRequestInit)(customRequestInit, requestInit)
118
+ )
119
+ ).then(async (res) => {
120
+ if (res.ok) return;
121
+ const code = Object.values(import_apiError.errorStatusCode).includes(res.status) ? res.status : 999;
122
+ const body = await res.text();
123
+ const error = new import_apiError.HTTPError(code, body);
124
+ throw error;
59
125
  }).catch((error) => {
60
- require_apiClientConfigStore.store.getState().onError?.(error);
61
- throw error;
126
+ import_apiClientConfigStore.store.getState().onError?.(error);
127
+ throw error;
128
+ });
129
+ // Annotate the CommonJS export names for ESM import in node:
130
+ 0 && (module.exports = {
131
+ createBlobFetcher,
132
+ createFileOrBlobFetcher,
133
+ createJsonFetcher,
134
+ createTextFetcher,
135
+ createVoidFetcher
62
136
  });
63
- //#endregion
64
- exports.createBlobFetcher = createBlobFetcher;
65
- exports.createFileOrBlobFetcher = createFileOrBlobFetcher;
66
- exports.createJsonFetcher = createJsonFetcher;
67
- exports.createTextFetcher = createTextFetcher;
68
- exports.createVoidFetcher = createVoidFetcher;
package/dist/fetcher.mjs CHANGED
@@ -1,63 +1,20 @@
1
- import { mergeRequestInit } from "./utils/requestInit.mjs";
2
- import { store } from "./apiClientConfigStore.mjs";
3
- import { HTTPError, errorStatusCode } from "./apiError.mjs";
4
- //#region src/fetcher.ts
5
- const defaultRequestInit = { credentials: "include" };
6
- const createJsonFetcher = (schema, customRequestInit = {}) => (input, requestInit = {}) => fetch(input, mergeRequestInit(defaultRequestInit, mergeRequestInit(customRequestInit, requestInit))).then(async (res) => {
7
- const text = await res.text();
8
- const body = text ? JSON.parse(text) : {};
9
- if (res.ok) return body;
10
- throw new HTTPError(Object.values(errorStatusCode).includes(res.status) ? res.status : 999, body);
11
- }).catch((error) => {
12
- store.getState().onError?.(error);
13
- throw error;
14
- }).then((parsedResponse) => {
15
- const result = schema.safeParse(parsedResponse);
16
- const config = store.getState();
17
- if (result.success) return result.data;
18
- if (config.showsSchemaParseError) console.error(result.error);
19
- if (config.forceDeserializeResponse) {
20
- config.onFailedDeserializeResponse(input, result.error);
21
- return parsedResponse;
22
- }
23
- throw result.error;
24
- });
25
- const createTextFetcher = (customRequestInit = {}) => (input, requestInit = {}) => fetch(input, mergeRequestInit(defaultRequestInit, mergeRequestInit(customRequestInit, requestInit))).then(async (res) => {
26
- const body = await res.text();
27
- if (res.ok) return body;
28
- throw new HTTPError(Object.values(errorStatusCode).includes(res.status) ? res.status : 999, body);
29
- }).catch((error) => {
30
- store.getState().onError?.(error);
31
- throw error;
32
- });
33
- const createBlobFetcher = (customRequestInit = {}) => (input, requestInit = {}) => fetch(input, mergeRequestInit(defaultRequestInit, mergeRequestInit(customRequestInit, requestInit))).then(async (res) => {
34
- const body = await res.blob();
35
- if (res.ok) return {
36
- body,
37
- headers: res.headers
38
- };
39
- throw new HTTPError(Object.values(errorStatusCode).includes(res.status) ? res.status : 999, body);
40
- }).catch((error) => {
41
- store.getState().onError?.(error);
42
- throw error;
43
- });
44
- const createFileOrBlobFetcher = (customRequestInit = {}) => (input, requestInit = {}) => fetch(input, mergeRequestInit(defaultRequestInit, mergeRequestInit(customRequestInit, requestInit))).then(async (res) => {
45
- const body = await res.blob();
46
- if (res.ok) return {
47
- body,
48
- headers: res.headers
49
- };
50
- throw new HTTPError(Object.values(errorStatusCode).includes(res.status) ? res.status : 999, body);
51
- }).catch((error) => {
52
- store.getState().onError?.(error);
53
- throw error;
54
- });
55
- const createVoidFetcher = (customRequestInit = {}) => (input, requestInit = {}) => fetch(input, mergeRequestInit(defaultRequestInit, mergeRequestInit(customRequestInit, requestInit))).then(async (res) => {
56
- if (res.ok) return;
57
- throw new HTTPError(Object.values(errorStatusCode).includes(res.status) ? res.status : 999, await res.text());
58
- }).catch((error) => {
59
- store.getState().onError?.(error);
60
- throw error;
61
- });
62
- //#endregion
63
- export { createBlobFetcher, createFileOrBlobFetcher, createJsonFetcher, createTextFetcher, createVoidFetcher };
1
+ import {
2
+ createBlobFetcher,
3
+ createFileOrBlobFetcher,
4
+ createJsonFetcher,
5
+ createTextFetcher,
6
+ createVoidFetcher
7
+ } from "./chunk-OVR3ZT2S.mjs";
8
+ import "./chunk-FNLUAQWC.mjs";
9
+ import "./chunk-NOC6G3HZ.mjs";
10
+ import "./chunk-TZUKIYFN.mjs";
11
+ import "./chunk-NYICHGY2.mjs";
12
+ import "./chunk-3SEO7S3Q.mjs";
13
+ import "./chunk-JCZWXJBU.mjs";
14
+ export {
15
+ createBlobFetcher,
16
+ createFileOrBlobFetcher,
17
+ createJsonFetcher,
18
+ createTextFetcher,
19
+ createVoidFetcher
20
+ };
package/dist/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
- import { Store, createStore } from "./store.js";
2
- import { Config, RequestConfig, buildRequestInitWithDefaultConfig, setApiClientConfig, store } from "./apiClientConfigStore.js";
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";
5
- import { __internal__requestUrl } from "./requestUrl.js";
6
- import { ForceDig, QueryPropsFor } from "./types.js";
7
- import { isZodError, schemaForType } from "./zod.js";
8
- import { mergeRequestInit } from "./utils/requestInit.js";
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 };
1
+ export { Config, RequestConfig, buildRequestInitWithDefaultConfig, setApiClientConfig, store } from './apiClientConfigStore.js';
2
+ export { ErrorStatusCode, HTTPError, errorStatusCode, errorTitle, getErrorStatus, getHttpErrorBody, getHttpErrorBodyReason, isHttpErrorWithStatus } from './apiError.js';
3
+ export { BlobFetcherResponse, FileOrBlobFetcherResponse, createBlobFetcher, createFileOrBlobFetcher, createJsonFetcher, createTextFetcher, createVoidFetcher } from './fetcher.js';
4
+ export { __internal__requestUrl } from './requestUrl.js';
5
+ export { Store, createStore } from './store.js';
6
+ export { ForceDig, QueryPropsFor } from './types.js';
7
+ export { isZodError, schemaForType } from './zod.js';
8
+ export { mergeRequestInit } from './utils/requestInit.js';
9
+ export { mergeHeadersInit, toHeadersInit } from './utils/headersInit.js';
10
+ import 'zod';
package/dist/index.js CHANGED
@@ -1,31 +1,38 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_store = require("./store.js");
3
- const require_utils_headersInit = require("./utils/headersInit.js");
4
- const require_utils_requestInit = require("./utils/requestInit.js");
5
- const require_apiClientConfigStore = require("./apiClientConfigStore.js");
6
- const require_zod = require("./zod.js");
7
- const require_apiError = require("./apiError.js");
8
- const require_fetcher = require("./fetcher.js");
9
- const require_requestUrl = require("./requestUrl.js");
10
- exports.HTTPError = require_apiError.HTTPError;
11
- exports.__internal__requestUrl = require_requestUrl.__internal__requestUrl;
12
- exports.buildRequestInitWithDefaultConfig = require_apiClientConfigStore.buildRequestInitWithDefaultConfig;
13
- exports.createBlobFetcher = require_fetcher.createBlobFetcher;
14
- exports.createFileOrBlobFetcher = require_fetcher.createFileOrBlobFetcher;
15
- exports.createJsonFetcher = require_fetcher.createJsonFetcher;
16
- exports.createStore = require_store.createStore;
17
- exports.createTextFetcher = require_fetcher.createTextFetcher;
18
- exports.createVoidFetcher = require_fetcher.createVoidFetcher;
19
- exports.errorStatusCode = require_apiError.errorStatusCode;
20
- exports.errorTitle = require_apiError.errorTitle;
21
- exports.getErrorStatus = require_apiError.getErrorStatus;
22
- exports.getHttpErrorBody = require_apiError.getHttpErrorBody;
23
- exports.getHttpErrorBodyReason = require_apiError.getHttpErrorBodyReason;
24
- exports.isHttpErrorWithStatus = require_apiError.isHttpErrorWithStatus;
25
- exports.isZodError = require_zod.isZodError;
26
- exports.mergeHeadersInit = require_utils_headersInit.mergeHeadersInit;
27
- exports.mergeRequestInit = require_utils_requestInit.mergeRequestInit;
28
- exports.schemaForType = require_zod.schemaForType;
29
- exports.setApiClientConfig = require_apiClientConfigStore.setApiClientConfig;
30
- exports.store = require_apiClientConfigStore.store;
31
- exports.toHeadersInit = require_utils_headersInit.toHeadersInit;
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
+ var index_exports = {};
17
+ module.exports = __toCommonJS(index_exports);
18
+ __reExport(index_exports, require("./apiClientConfigStore"), module.exports);
19
+ __reExport(index_exports, require("./apiError"), module.exports);
20
+ __reExport(index_exports, require("./fetcher"), module.exports);
21
+ __reExport(index_exports, require("./requestUrl"), module.exports);
22
+ __reExport(index_exports, require("./store"), module.exports);
23
+ __reExport(index_exports, require("./types"), module.exports);
24
+ __reExport(index_exports, require("./zod"), module.exports);
25
+ __reExport(index_exports, require("./utils/requestInit"), module.exports);
26
+ __reExport(index_exports, require("./utils/headersInit"), module.exports);
27
+ // Annotate the CommonJS export names for ESM import in node:
28
+ 0 && (module.exports = {
29
+ ...require("./apiClientConfigStore"),
30
+ ...require("./apiError"),
31
+ ...require("./fetcher"),
32
+ ...require("./requestUrl"),
33
+ ...require("./store"),
34
+ ...require("./types"),
35
+ ...require("./zod"),
36
+ ...require("./utils/requestInit"),
37
+ ...require("./utils/headersInit")
38
+ });