@readyfor/api-client-base 0.155.0 → 0.156.0-pr911.0a4df9b

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,5 +1,4 @@
1
1
  import { Store } from './store.mjs';
2
- import { UrlConfig } from './requestUrl.mjs';
3
2
 
4
3
  type DeserializeResponseConfig = {
5
4
  forceDeserializeResponse?: false;
@@ -10,8 +9,12 @@ type DeserializeResponseConfig = {
10
9
  type LoggingConfig = {
11
10
  showsSchemaParseError?: boolean;
12
11
  };
13
- type Config = UrlConfig & DeserializeResponseConfig & LoggingConfig;
12
+ type RequestConfig = {
13
+ hostName?: string | ((path: string) => string);
14
+ defaultRequestInit?: RequestInit;
15
+ };
16
+ type Config = RequestConfig & DeserializeResponseConfig & LoggingConfig;
14
17
  declare const store: Store<Config>;
15
18
  declare const setApiClientConfig: (config: Config) => void;
16
19
 
17
- export { type Config, setApiClientConfig, store };
20
+ export { type Config, type RequestConfig, setApiClientConfig, store };
@@ -1,5 +1,4 @@
1
1
  import { Store } from './store.js';
2
- import { UrlConfig } from './requestUrl.js';
3
2
 
4
3
  type DeserializeResponseConfig = {
5
4
  forceDeserializeResponse?: false;
@@ -10,8 +9,12 @@ type DeserializeResponseConfig = {
10
9
  type LoggingConfig = {
11
10
  showsSchemaParseError?: boolean;
12
11
  };
13
- type Config = UrlConfig & DeserializeResponseConfig & LoggingConfig;
12
+ type RequestConfig = {
13
+ hostName?: string | ((path: string) => string);
14
+ defaultRequestInit?: RequestInit;
15
+ };
16
+ type Config = RequestConfig & DeserializeResponseConfig & LoggingConfig;
14
17
  declare const store: Store<Config>;
15
18
  declare const setApiClientConfig: (config: Config) => void;
16
19
 
17
- export { type Config, setApiClientConfig, store };
20
+ export { type Config, type RequestConfig, setApiClientConfig, store };
@@ -0,0 +1,62 @@
1
+ import {
2
+ useApiClientConfigContext
3
+ } from "./chunk-VVRQ7D57.mjs";
4
+
5
+ // src/react/useApiClientConfig.ts
6
+ import { useSyncExternalStore } from "use-sync-external-store/shim";
7
+ import { useSyncExternalStoreWithSelector } from "use-sync-external-store/shim/with-selector";
8
+ import { useCallback, useMemo } from "react";
9
+ var useApiClientConfig = () => {
10
+ const store = useApiClientConfigContext();
11
+ return useSyncExternalStore(store.subscribe, store.getState);
12
+ };
13
+ var useApiClientConfigWithSelector = (selector) => {
14
+ const store = useApiClientConfigContext();
15
+ return useSyncExternalStoreWithSelector(
16
+ store.subscribe,
17
+ store.getState,
18
+ null,
19
+ selector
20
+ );
21
+ };
22
+ var useRequestInit = (customRequestInit = {}) => {
23
+ const { defaultRequestInit = {} } = useApiClientConfig();
24
+ const keys = useMemo(
25
+ () => Object.keys({
26
+ ...defaultRequestInit,
27
+ ...customRequestInit
28
+ }),
29
+ [defaultRequestInit, customRequestInit]
30
+ );
31
+ const get = useCallback((key) => {
32
+ if (customRequestInit[key] === void 0) {
33
+ return defaultRequestInit[key];
34
+ }
35
+ if (defaultRequestInit[key] === void 0) {
36
+ return customRequestInit[key];
37
+ }
38
+ if (typeof customRequestInit[key] === "object" && typeof defaultRequestInit[key] === "object") {
39
+ return { ...defaultRequestInit[key], ...customRequestInit[key] };
40
+ }
41
+ if (Array.isArray(customRequestInit[key]) && Array.isArray(defaultRequestInit[key])) {
42
+ return [...defaultRequestInit[key], ...customRequestInit[key]];
43
+ }
44
+ return customRequestInit[key] ?? defaultRequestInit[key];
45
+ }, []);
46
+ return useMemo(
47
+ () => keys.reduce(
48
+ (acc, key) => ({
49
+ ...acc,
50
+ [key]: get(key)
51
+ }),
52
+ {}
53
+ ),
54
+ [keys, get]
55
+ );
56
+ };
57
+
58
+ export {
59
+ useApiClientConfig,
60
+ useApiClientConfigWithSelector,
61
+ useRequestInit
62
+ };
package/dist/index.d.mts CHANGED
@@ -1,7 +1,7 @@
1
- export { Config, setApiClientConfig, store } from './apiClientConfigStore.mjs';
1
+ export { Config, RequestConfig, setApiClientConfig, store } from './apiClientConfigStore.mjs';
2
2
  export { ErrorStatusCode, HTTPError, errorStatusCode, errorTitle, getErrorStatus } from './apiError.mjs';
3
3
  export { BlobFetcherResponse, createBlobFetcher, createJsonFetcher, createTextFetcher, createVoidFetcher } from './fetcher.mjs';
4
- export { UrlConfig, __internal__requestUrl } from './requestUrl.mjs';
4
+ export { __internal__requestUrl } from './requestUrl.mjs';
5
5
  export { Store, createStore } from './store.mjs';
6
6
  export { ForceDig, QueryPropsFor } from './types.mjs';
7
7
  export { isZodError, schemaForType } from './zod.mjs';
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- export { Config, setApiClientConfig, store } from './apiClientConfigStore.js';
1
+ export { Config, RequestConfig, setApiClientConfig, store } from './apiClientConfigStore.js';
2
2
  export { ErrorStatusCode, HTTPError, errorStatusCode, errorTitle, getErrorStatus } from './apiError.js';
3
3
  export { BlobFetcherResponse, createBlobFetcher, createJsonFetcher, createTextFetcher, createVoidFetcher } from './fetcher.js';
4
- export { UrlConfig, __internal__requestUrl } from './requestUrl.js';
4
+ export { __internal__requestUrl } from './requestUrl.js';
5
5
  export { Store, createStore } from './store.js';
6
6
  export { ForceDig, QueryPropsFor } from './types.js';
7
7
  export { isZodError, schemaForType } from './zod.js';
@@ -2,7 +2,6 @@ import { FC, ReactNode } from 'react';
2
2
  import { Config } from '../apiClientConfigStore.mjs';
3
3
  import { Store } from '../store.mjs';
4
4
  import { SWRConfiguration } from 'swr';
5
- import '../requestUrl.mjs';
6
5
 
7
6
  type Configuration = Config & {
8
7
  swr?: SWRConfiguration;
@@ -2,7 +2,6 @@ import { FC, ReactNode } from 'react';
2
2
  import { Config } from '../apiClientConfigStore.js';
3
3
  import { Store } from '../store.js';
4
4
  import { SWRConfiguration } from 'swr';
5
- import '../requestUrl.js';
6
5
 
7
6
  type Configuration = Config & {
8
7
  swr?: SWRConfiguration;
@@ -1,8 +1,7 @@
1
1
  export { ApiClientConfigProvider, useApiClientConfigContext } from './ApiClientConfigProvider.mjs';
2
2
  export { Configuration, createSwrConfig } from './swr.mjs';
3
- export { useApiClientConfig, useApiClientConfigWithSelector } from './useApiClientConfig.mjs';
3
+ export { useApiClientConfig, useApiClientConfigWithSelector, useRequestInit } from './useApiClientConfig.mjs';
4
4
  import 'react';
5
5
  import '../apiClientConfigStore.mjs';
6
6
  import '../store.mjs';
7
- import '../requestUrl.mjs';
8
7
  import 'swr';
@@ -1,8 +1,7 @@
1
1
  export { ApiClientConfigProvider, useApiClientConfigContext } from './ApiClientConfigProvider.js';
2
2
  export { Configuration, createSwrConfig } from './swr.js';
3
- export { useApiClientConfig, useApiClientConfigWithSelector } from './useApiClientConfig.js';
3
+ export { useApiClientConfig, useApiClientConfigWithSelector, useRequestInit } from './useApiClientConfig.js';
4
4
  import 'react';
5
5
  import '../apiClientConfigStore.js';
6
6
  import '../store.js';
7
- import '../requestUrl.js';
8
7
  import 'swr';
@@ -24,7 +24,8 @@ __export(react_exports, {
24
24
  createSwrConfig: () => createSwrConfig,
25
25
  useApiClientConfig: () => useApiClientConfig,
26
26
  useApiClientConfigContext: () => useApiClientConfigContext,
27
- useApiClientConfigWithSelector: () => useApiClientConfigWithSelector
27
+ useApiClientConfigWithSelector: () => useApiClientConfigWithSelector,
28
+ useRequestInit: () => useRequestInit
28
29
  });
29
30
  module.exports = __toCommonJS(react_exports);
30
31
 
@@ -89,6 +90,7 @@ var useApiClientConfigContext = () => (0, import_react2.useContext)(ApiClientCon
89
90
  // src/react/useApiClientConfig.ts
90
91
  var import_shim = require("use-sync-external-store/shim");
91
92
  var import_with_selector = require("use-sync-external-store/shim/with-selector");
93
+ var import_react3 = require("react");
92
94
  var useApiClientConfig = () => {
93
95
  const store2 = useApiClientConfigContext();
94
96
  return (0, import_shim.useSyncExternalStore)(store2.subscribe, store2.getState);
@@ -102,11 +104,47 @@ var useApiClientConfigWithSelector = (selector) => {
102
104
  selector
103
105
  );
104
106
  };
107
+ var useRequestInit = (customRequestInit = {}) => {
108
+ const { defaultRequestInit = {} } = useApiClientConfig();
109
+ const keys = (0, import_react3.useMemo)(
110
+ () => Object.keys({
111
+ ...defaultRequestInit,
112
+ ...customRequestInit
113
+ }),
114
+ [defaultRequestInit, customRequestInit]
115
+ );
116
+ const get = (0, import_react3.useCallback)((key) => {
117
+ if (customRequestInit[key] === void 0) {
118
+ return defaultRequestInit[key];
119
+ }
120
+ if (defaultRequestInit[key] === void 0) {
121
+ return customRequestInit[key];
122
+ }
123
+ if (typeof customRequestInit[key] === "object" && typeof defaultRequestInit[key] === "object") {
124
+ return { ...defaultRequestInit[key], ...customRequestInit[key] };
125
+ }
126
+ if (Array.isArray(customRequestInit[key]) && Array.isArray(defaultRequestInit[key])) {
127
+ return [...defaultRequestInit[key], ...customRequestInit[key]];
128
+ }
129
+ return customRequestInit[key] ?? defaultRequestInit[key];
130
+ }, []);
131
+ return (0, import_react3.useMemo)(
132
+ () => keys.reduce(
133
+ (acc, key) => ({
134
+ ...acc,
135
+ [key]: get(key)
136
+ }),
137
+ {}
138
+ ),
139
+ [keys, get]
140
+ );
141
+ };
105
142
  // Annotate the CommonJS export names for ESM import in node:
106
143
  0 && (module.exports = {
107
144
  ApiClientConfigProvider,
108
145
  createSwrConfig,
109
146
  useApiClientConfig,
110
147
  useApiClientConfigContext,
111
- useApiClientConfigWithSelector
148
+ useApiClientConfigWithSelector,
149
+ useRequestInit
112
150
  });
@@ -1,7 +1,8 @@
1
1
  import {
2
2
  useApiClientConfig,
3
- useApiClientConfigWithSelector
4
- } from "../chunk-H3C7VSOJ.mjs";
3
+ useApiClientConfigWithSelector,
4
+ useRequestInit
5
+ } from "../chunk-4D7SUTWE.mjs";
5
6
  import {
6
7
  ApiClientConfigProvider,
7
8
  useApiClientConfigContext
@@ -16,5 +17,6 @@ export {
16
17
  createSwrConfig,
17
18
  useApiClientConfig,
18
19
  useApiClientConfigContext,
19
- useApiClientConfigWithSelector
20
+ useApiClientConfigWithSelector,
21
+ useRequestInit
20
22
  };
@@ -1,8 +1,8 @@
1
1
  import { Config } from '../apiClientConfigStore.mjs';
2
2
  import '../store.mjs';
3
- import '../requestUrl.mjs';
4
3
 
5
4
  declare const useApiClientConfig: () => Config;
6
5
  declare const useApiClientConfigWithSelector: <T>(selector: (state: Config) => T) => T;
6
+ declare const useRequestInit: (customRequestInit?: RequestInit) => RequestInit;
7
7
 
8
- export { useApiClientConfig, useApiClientConfigWithSelector };
8
+ export { useApiClientConfig, useApiClientConfigWithSelector, useRequestInit };
@@ -1,8 +1,8 @@
1
1
  import { Config } from '../apiClientConfigStore.js';
2
2
  import '../store.js';
3
- import '../requestUrl.js';
4
3
 
5
4
  declare const useApiClientConfig: () => Config;
6
5
  declare const useApiClientConfigWithSelector: <T>(selector: (state: Config) => T) => T;
6
+ declare const useRequestInit: (customRequestInit?: RequestInit) => RequestInit;
7
7
 
8
- export { useApiClientConfig, useApiClientConfigWithSelector };
8
+ export { useApiClientConfig, useApiClientConfigWithSelector, useRequestInit };
@@ -21,7 +21,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var useApiClientConfig_exports = {};
22
22
  __export(useApiClientConfig_exports, {
23
23
  useApiClientConfig: () => useApiClientConfig,
24
- useApiClientConfigWithSelector: () => useApiClientConfigWithSelector
24
+ useApiClientConfigWithSelector: () => useApiClientConfigWithSelector,
25
+ useRequestInit: () => useRequestInit
25
26
  });
26
27
  module.exports = __toCommonJS(useApiClientConfig_exports);
27
28
 
@@ -66,6 +67,7 @@ var useApiClientConfigContext = () => (0, import_react2.useContext)(ApiClientCon
66
67
  // src/react/useApiClientConfig.ts
67
68
  var import_shim = require("use-sync-external-store/shim");
68
69
  var import_with_selector = require("use-sync-external-store/shim/with-selector");
70
+ var import_react3 = require("react");
69
71
  var useApiClientConfig = () => {
70
72
  const store2 = useApiClientConfigContext();
71
73
  return (0, import_shim.useSyncExternalStore)(store2.subscribe, store2.getState);
@@ -79,8 +81,44 @@ var useApiClientConfigWithSelector = (selector) => {
79
81
  selector
80
82
  );
81
83
  };
84
+ var useRequestInit = (customRequestInit = {}) => {
85
+ const { defaultRequestInit = {} } = useApiClientConfig();
86
+ const keys = (0, import_react3.useMemo)(
87
+ () => Object.keys({
88
+ ...defaultRequestInit,
89
+ ...customRequestInit
90
+ }),
91
+ [defaultRequestInit, customRequestInit]
92
+ );
93
+ const get = (0, import_react3.useCallback)((key) => {
94
+ if (customRequestInit[key] === void 0) {
95
+ return defaultRequestInit[key];
96
+ }
97
+ if (defaultRequestInit[key] === void 0) {
98
+ return customRequestInit[key];
99
+ }
100
+ if (typeof customRequestInit[key] === "object" && typeof defaultRequestInit[key] === "object") {
101
+ return { ...defaultRequestInit[key], ...customRequestInit[key] };
102
+ }
103
+ if (Array.isArray(customRequestInit[key]) && Array.isArray(defaultRequestInit[key])) {
104
+ return [...defaultRequestInit[key], ...customRequestInit[key]];
105
+ }
106
+ return customRequestInit[key] ?? defaultRequestInit[key];
107
+ }, []);
108
+ return (0, import_react3.useMemo)(
109
+ () => keys.reduce(
110
+ (acc, key) => ({
111
+ ...acc,
112
+ [key]: get(key)
113
+ }),
114
+ {}
115
+ ),
116
+ [keys, get]
117
+ );
118
+ };
82
119
  // Annotate the CommonJS export names for ESM import in node:
83
120
  0 && (module.exports = {
84
121
  useApiClientConfig,
85
- useApiClientConfigWithSelector
122
+ useApiClientConfigWithSelector,
123
+ useRequestInit
86
124
  });
@@ -1,12 +1,14 @@
1
1
  import {
2
2
  useApiClientConfig,
3
- useApiClientConfigWithSelector
4
- } from "../chunk-H3C7VSOJ.mjs";
3
+ useApiClientConfigWithSelector,
4
+ useRequestInit
5
+ } from "../chunk-4D7SUTWE.mjs";
5
6
  import "../chunk-VVRQ7D57.mjs";
6
7
  import "../chunk-DHYJM4DQ.mjs";
7
8
  import "../chunk-472P3XVV.mjs";
8
9
  import "../chunk-3SEO7S3Q.mjs";
9
10
  export {
10
11
  useApiClientConfig,
11
- useApiClientConfigWithSelector
12
+ useApiClientConfigWithSelector,
13
+ useRequestInit
12
14
  };
@@ -1,6 +1,3 @@
1
- type UrlConfig = {
2
- hostName?: string | ((path: string) => string);
3
- };
4
1
  declare function __internal__requestUrl(...args: any[]): string;
5
2
 
6
- export { type UrlConfig, __internal__requestUrl };
3
+ export { __internal__requestUrl };
@@ -1,6 +1,3 @@
1
- type UrlConfig = {
2
- hostName?: string | ((path: string) => string);
3
- };
4
1
  declare function __internal__requestUrl(...args: any[]): string;
5
2
 
6
- export { type UrlConfig, __internal__requestUrl };
3
+ export { __internal__requestUrl };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@readyfor/api-client-base",
3
- "version": "0.155.0",
3
+ "version": "0.156.0-pr911.0a4df9b",
4
4
  "license": "SEE LICENSE IN LICENSE.md",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -20,9 +20,6 @@
20
20
  "require": "./dist/react/index.js"
21
21
  }
22
22
  },
23
- "scripts": {
24
- "build": "tsup"
25
- },
26
23
  "dependencies": {
27
24
  "qs": "6.13.1",
28
25
  "zod": "3.23.8"
@@ -63,5 +60,7 @@
63
60
  "src"
64
61
  ]
65
62
  },
66
- "gitHead": "21fc605f4dafdd6c9dce6be563d4246e4f76b359"
67
- }
63
+ "scripts": {
64
+ "build": "tsup"
65
+ }
66
+ }
@@ -1,25 +0,0 @@
1
- import {
2
- useApiClientConfigContext
3
- } from "./chunk-VVRQ7D57.mjs";
4
-
5
- // src/react/useApiClientConfig.ts
6
- import { useSyncExternalStore } from "use-sync-external-store/shim";
7
- import { useSyncExternalStoreWithSelector } from "use-sync-external-store/shim/with-selector";
8
- var useApiClientConfig = () => {
9
- const store = useApiClientConfigContext();
10
- return useSyncExternalStore(store.subscribe, store.getState);
11
- };
12
- var useApiClientConfigWithSelector = (selector) => {
13
- const store = useApiClientConfigContext();
14
- return useSyncExternalStoreWithSelector(
15
- store.subscribe,
16
- store.getState,
17
- null,
18
- selector
19
- );
20
- };
21
-
22
- export {
23
- useApiClientConfig,
24
- useApiClientConfigWithSelector
25
- };