@confighub/rtk-query 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) ConfigHub, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,57 @@
1
+ # @confighub/rtk-query
2
+
3
+ An [RTK Query](https://redux-toolkit.js.org/rtk-query/overview) client for the
4
+ [ConfigHub](https://confighub.com) API — generated endpoints, hooks, and cache tags,
5
+ with bearer auth. Use this if your app is already on Redux Toolkit and you want the
6
+ `useListUnitsQuery(...)` style with automatic caching and invalidation.
7
+
8
+ If you are not on Redux, use [`@confighub/api`](https://www.npmjs.com/package/@confighub/api)
9
+ instead — a tiny framework-agnostic client. The two are parallel: same version-pegged
10
+ spec, same `getToken` auth seam, different generator. They share no code.
11
+
12
+ ## Setup
13
+
14
+ Configure the api once, then add it to your store:
15
+
16
+ ```ts
17
+ import { configureStore } from '@reduxjs/toolkit';
18
+ import { confighubApi, configureConfigHub } from '@confighub/rtk-query';
19
+ import { getAccessToken } from '@confighub/react-auth';
20
+
21
+ configureConfigHub({
22
+ baseUrl: 'https://hub.confighub.com',
23
+ getToken: getAccessToken, // any () => string | undefined; token source is your choice
24
+ });
25
+
26
+ export const store = configureStore({
27
+ reducer: { [confighubApi.reducerPath]: confighubApi.reducer },
28
+ middleware: (getDefault) => getDefault().concat(confighubApi.middleware),
29
+ });
30
+ ```
31
+
32
+ Wrap your app in the react-redux `<Provider store={store}>` as usual.
33
+
34
+ ## Use
35
+
36
+ ```tsx
37
+ import { useListSpacesQuery, useListUnitsQuery } from '@confighub/rtk-query';
38
+ import { skipToken } from '@reduxjs/toolkit/query';
39
+
40
+ function Spaces() {
41
+ const { data: spaces, isLoading } = useListSpacesQuery();
42
+ const [spaceId, setSpaceId] = useState<string | null>(null);
43
+ const { data: units } = useListUnitsQuery(spaceId ? { spaceId } : skipToken);
44
+ // ...
45
+ }
46
+ ```
47
+
48
+ ## Notes
49
+
50
+ - `baseUrl` is the instance origin; the client targets `{baseUrl}/api`. Same value as
51
+ the auth provider.
52
+ - The api is a module singleton, so `baseUrl`/`getToken` are set at configure time, not
53
+ per instance — the one ergonomic difference from `@confighub/api`.
54
+ - A 401 calls your `onUnauthorized` (if provided); it does not redirect.
55
+ - Peer deps: `@reduxjs/toolkit`, `react`, `react-redux`.
56
+ - Endpoints and types are regenerated from the pinned server spec (`.spec-version`) by
57
+ `@rtk-query/codegen-openapi`.