immich-rtk-query 2.4.1

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,24 @@
1
+ This is free and unencumbered software released into the public domain.
2
+
3
+ Anyone is free to copy, modify, publish, use, compile, sell, or
4
+ distribute this software, either in source code form or as a compiled
5
+ binary, for any purpose, commercial or non-commercial, and by any
6
+ means.
7
+
8
+ In jurisdictions that recognize copyright laws, the author or authors
9
+ of this software dedicate any and all copyright interest in the
10
+ software to the public domain. We make this dedication for the benefit
11
+ of the public at large and to the detriment of our heirs and
12
+ successors. We intend this dedication to be an overt act of
13
+ relinquishment in perpetuity of all present and future rights to this
14
+ software under copyright law.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ For more information, please refer to <https://unlicense.org>
package/README.md ADDED
@@ -0,0 +1,318 @@
1
+ <a name="readme-top"></a>
2
+
3
+ <!-- PROJECT SHIELDS -->
4
+ [![Contributors][contributors-shield]][contributors-url]
5
+ [![Forks][forks-shield]][forks-url]
6
+ [![Stargazers][stars-shield]][stars-url]
7
+ [![Issues][issues-shield]][issues-url]
8
+ [![License: Unlicense][license-shield]][license-url]
9
+
10
+ <!-- PROJECT LOGO -->
11
+ <br />
12
+ <div align="center">
13
+ <h3 align="center">Immich RTK Query</h3>
14
+
15
+ <p align="center">
16
+ A type-safe RTK Query API client for the Immich photo management platform
17
+ <br />
18
+ <a href="#usage"><strong>Explore the docs ยป</strong></a>
19
+ <br />
20
+ <br />
21
+ <a href="https://github.com/othneildrew/immich-rtk-query/issues">Report Bug</a>
22
+ ยท
23
+ <a href="https://github.com/othneildrew/immich-rtk-query/issues">Request Feature</a>
24
+ </p>
25
+ </div>
26
+
27
+ <!-- TABLE OF CONTENTS -->
28
+ <details>
29
+ <summary>Table of Contents</summary>
30
+ <ol>
31
+ <li>
32
+ <a href="#about-the-project">About The Project</a>
33
+ <ul>
34
+ <li><a href="#built-with">Built With</a></li>
35
+ </ul>
36
+ </li>
37
+ <li>
38
+ <a href="#getting-started">Getting Started</a>
39
+ <ul>
40
+ <li><a href="#prerequisites">Prerequisites</a></li>
41
+ <li><a href="#installation">Installation</a></li>
42
+ </ul>
43
+ </li>
44
+ <li><a href="#usage">Usage</a></li>
45
+ <li><a href="#roadmap">Roadmap</a></li>
46
+ <li><a href="#contributing">Contributing</a></li>
47
+ <li><a href="#license">License</a></li>
48
+ <li><a href="#contact">Contact</a></li>
49
+ <li><a href="#acknowledgments">Acknowledgments</a></li>
50
+ </ol>
51
+ </details>
52
+
53
+ <!-- ABOUT THE PROJECT -->
54
+ ## About The Project
55
+
56
+ Immich RTK Query is a fully type-safe API client for [Immich](https://immich.app/), the open-source photo and video management platform. This package provides auto-generated TypeScript types and React Query hooks for all Immich API endpoints, making it easy to integrate Immich into your React applications with full type safety and excellent developer experience.
57
+
58
+ ### Key Features
59
+
60
+ * ๐Ÿ”’ **Fully Type-Safe** - Auto-generated TypeScript types from Immich's OpenAPI specification
61
+ * โšก **React Query Hooks** - Use `useGetAssetsQuery`, `useUploadAssetMutation`, and more
62
+ * ๐Ÿ”„ **Automatic Caching** - Powered by RTK Query for optimal performance
63
+ * ๐Ÿ“ฆ **Tree-Shakeable** - Import only what you need
64
+ * ๐ŸŽฏ **Always Up-to-Date** - Generated from official Immich API specs
65
+
66
+ <p align="right">(<a href="#readme-top">back to top</a>)</p>
67
+
68
+ ### Built With
69
+
70
+ [![React][React.js]][React-url]
71
+ [![Redux][Redux]][Redux-url]
72
+ [![TypeScript][TypeScript]][TypeScript-url]
73
+
74
+ <p align="right">(<a href="#readme-top">back to top</a>)</p>
75
+
76
+ <!-- GETTING STARTED -->
77
+ ## Getting Started
78
+
79
+ ### Prerequisites
80
+
81
+ This package requires the following peer dependencies:
82
+ * React 18.0.0 or higher
83
+ * React Redux 8.0.0 or higher
84
+ * Redux Toolkit 2.11.2 or higher
85
+
86
+ ### Installation
87
+
88
+ Install the package via npm:
89
+
90
+ ```bash
91
+ npm install immich-rtk-query
92
+ ```
93
+
94
+ Or using yarn:
95
+
96
+ ```bash
97
+ yarn add immich-rtk-query
98
+ ```
99
+
100
+ Or using pnpm:
101
+
102
+ ```bash
103
+ pnpm add immich-rtk-query
104
+ ```
105
+
106
+ <p align="right">(<a href="#readme-top">back to top</a>)</p>
107
+
108
+ <!-- USAGE EXAMPLES -->
109
+ ## Usage
110
+
111
+ ### 1. Configure Your Redux Store
112
+
113
+ First, add the Immich API to your Redux store:
114
+
115
+ ```typescript
116
+ import { configureStore } from '@reduxjs/toolkit'
117
+ import { immichApi } from 'immich-rtk-query'
118
+
119
+ export const store = configureStore({
120
+ reducer: {
121
+ [immichApi.reducerPath]: immichApi.reducer,
122
+ },
123
+ middleware: (getDefaultMiddleware) =>
124
+ getDefaultMiddleware().concat(immichApi.middleware),
125
+ })
126
+ ```
127
+
128
+ ### 2. Configure the Base URL and Authentication
129
+
130
+ Before using the API, configure it with your Immich instance URL and authentication. Call `configureImmichApi` before your app starts:
131
+
132
+ ```typescript
133
+ import { configureImmichApi, immichApi } from 'immich-rtk-query'
134
+
135
+ // Configure the API with your Immich instance
136
+ configureImmichApi({
137
+ baseUrl: 'https://your-immich-instance.com/api',
138
+ prepareHeaders: (headers, { getState }) => {
139
+ // Add authentication
140
+ const apiKey = localStorage.getItem('immich-api-key')
141
+ if (apiKey) {
142
+ headers.set('x-api-key', apiKey)
143
+ }
144
+ return headers
145
+ },
146
+ // All fetchBaseQuery options are supported:
147
+ credentials: 'include', // Include cookies
148
+ // mode: 'cors',
149
+ // cache: 'no-cache',
150
+ // etc.
151
+ })
152
+
153
+ // Then set up your store
154
+ export const store = configureStore({
155
+ reducer: {
156
+ [immichApi.reducerPath]: immichApi.reducer,
157
+ },
158
+ middleware: (getDefaultMiddleware) =>
159
+ getDefaultMiddleware().concat(immichApi.middleware),
160
+ })
161
+ ```
162
+
163
+ **Note:**
164
+ - Call `configureImmichApi` once, before rendering your app
165
+ - All `fetchBaseQuery` options are supported (baseUrl, prepareHeaders, credentials, headers, mode, cache, etc.)
166
+ - The base API uses `baseUrl: '/'` by default if not configured
167
+
168
+ ### 3. Use the Hooks in Your Components
169
+
170
+ ```typescript
171
+ import {
172
+ useGetAllAssetsQuery,
173
+ useUploadAssetMutation,
174
+ useCreateAlbumMutation,
175
+ } from 'immich-rtk-query'
176
+
177
+ function MyPhotosComponent() {
178
+ // Fetch assets with automatic caching and refetching
179
+ const { data: assets, isLoading, error } = useGetAllAssetsQuery({
180
+ take: 100,
181
+ })
182
+
183
+ // Mutations for creating/updating data
184
+ const [uploadAsset, { isLoading: isUploading }] = useUploadAssetMutation()
185
+ const [createAlbum] = useCreateAlbumMutation()
186
+
187
+ const handleUpload = async (file: File) => {
188
+ try {
189
+ await uploadAsset({
190
+ assetData: file,
191
+ // ... other upload parameters
192
+ }).unwrap()
193
+ } catch (err) {
194
+ console.error('Upload failed:', err)
195
+ }
196
+ }
197
+
198
+ if (isLoading) return <div>Loading...</div>
199
+ if (error) return <div>Error loading assets</div>
200
+
201
+ return (
202
+ <div>
203
+ {assets?.map((asset) => (
204
+ <img key={asset.id} src={asset.thumbnailUrl} alt={asset.originalFileName} />
205
+ ))}
206
+ </div>
207
+ )
208
+ }
209
+ ```
210
+
211
+ ### 4. Advanced: Custom Endpoints
212
+
213
+ You can inject custom endpoints into the API:
214
+
215
+ ```typescript
216
+ import { immichApi } from 'immich-rtk-query'
217
+
218
+ const extendedApi = immichApi.injectEndpoints({
219
+ endpoints: (builder) => ({
220
+ getMyCustomData: builder.query({
221
+ query: () => '/custom-endpoint',
222
+ }),
223
+ }),
224
+ })
225
+
226
+ export const { useGetMyCustomDataQuery } = extendedApi
227
+ ```
228
+
229
+ <p align="right">(<a href="#readme-top">back to top</a>)</p>
230
+
231
+ <!-- ROADMAP -->
232
+ ## Roadmap
233
+
234
+ - [x] Auto-generate TypeScript types from Immich OpenAPI spec
235
+ - [x] Generate React Query hooks
236
+ - [x] Support for all Immich API endpoints
237
+ - [x] Add usage examples repository
238
+ - [ ] Add integration tests
239
+ - [ ] Support for custom transformers
240
+ - [ ] Automatic updates when Immich API changes
241
+
242
+ See the [open issues](https://github.com/othneildrew/immich-rtk-query/issues) for a full list of proposed features (and known issues).
243
+
244
+ <p align="right">(<a href="#readme-top">back to top</a>)</p>
245
+
246
+ <!-- CONTRIBUTING -->
247
+ ## Contributing
248
+
249
+ Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.
250
+
251
+ If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement".
252
+ Don't forget to give the project a star! Thanks again!
253
+
254
+ 1. Fork the Project
255
+ 2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
256
+ 3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)
257
+ 4. Push to the Branch (`git push origin feature/AmazingFeature`)
258
+ 5. Open a Pull Request
259
+
260
+ ### Development
261
+
262
+ To regenerate the API types from the latest Immich OpenAPI specification:
263
+
264
+ ```bash
265
+ npm run generate
266
+ ```
267
+
268
+ To build the package:
269
+
270
+ ```bash
271
+ npm run build
272
+ ```
273
+
274
+ <p align="right">(<a href="#readme-top">back to top</a>)</p>
275
+
276
+ <!-- LICENSE -->
277
+ ## License
278
+
279
+ This is free and unencumbered software released into the public domain. See `LICENSE` for more information.
280
+
281
+ <p align="right">(<a href="#readme-top">back to top</a>)</p>
282
+
283
+ <!-- CONTACT -->
284
+ ## Contact
285
+
286
+ Othneil Drew - [LinkedIn](https://linkedin.com/in/othneildrew)
287
+
288
+ Project Link: [https://github.com/othneildrew/immich-rtk-query](https://github.com/othneildrew/immich-rtk-query)
289
+
290
+ <p align="right">(<a href="#readme-top">back to top</a>)</p>
291
+
292
+ <!-- ACKNOWLEDGMENTS -->
293
+ ## Acknowledgments
294
+
295
+ * [Immich](https://immich.app/) - The amazing open-source photo management platform
296
+ * [RTK Query](https://redux-toolkit.js.org/rtk-query/overview) - Powerful data fetching and caching
297
+ * [RTK Query Codegen](https://redux-toolkit.js.org/rtk-query/usage/code-generation) - OpenAPI code generation for RTK Query
298
+ * [Best-README-Template](https://github.com/othneildrew/Best-README-Template) - README template
299
+
300
+ <p align="right">(<a href="#readme-top">back to top</a>)</p>
301
+
302
+ <!-- MARKDOWN LINKS & IMAGES -->
303
+ [contributors-shield]: https://img.shields.io/github/contributors/othneildrew/immich-rtk-query.svg?style=for-the-badge
304
+ [contributors-url]: https://github.com/othneildrew/immich-rtk-query/graphs/contributors
305
+ [forks-shield]: https://img.shields.io/github/forks/othneildrew/immich-rtk-query.svg?style=for-the-badge
306
+ [forks-url]: https://github.com/othneildrew/immich-rtk-query/network/members
307
+ [stars-shield]: https://img.shields.io/github/stars/othneildrew/immich-rtk-query.svg?style=for-the-badge
308
+ [stars-url]: https://github.com/othneildrew/immich-rtk-query/stargazers
309
+ [issues-shield]: https://img.shields.io/github/issues/othneildrew/immich-rtk-query.svg?style=for-the-badge
310
+ [issues-url]: https://github.com/othneildrew/immich-rtk-query/issues
311
+ [license-shield]: https://img.shields.io/github/license/othneildrew/immich-rtk-query.svg?style=for-the-badge
312
+ [license-url]: https://github.com/othneildrew/immich-rtk-query/blob/master/LICENSE
313
+ [React.js]: https://img.shields.io/badge/React-20232A?style=for-the-badge&logo=react&logoColor=61DAFB
314
+ [React-url]: https://reactjs.org/
315
+ [Redux]: https://img.shields.io/badge/Redux-593D88?style=for-the-badge&logo=redux&logoColor=white
316
+ [Redux-url]: https://redux.js.org/
317
+ [TypeScript]: https://img.shields.io/badge/TypeScript-007ACC?style=for-the-badge&logo=typescript&logoColor=white
318
+ [TypeScript-url]: https://www.typescriptlang.org/
package/dist/auth.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Login to a custom Immich server (bypasses configured baseUrl)
3
+ * Use this for initial login when server URL is provided by the user
4
+ */
5
+ export declare function loginToServer(serverUrl: string, credentials: {
6
+ email: string;
7
+ password: string;
8
+ }): Promise<unknown>;
9
+ //# sourceMappingURL=auth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAsB,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,oBAetG"}
package/dist/auth.js ADDED
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Login to a custom Immich server (bypasses configured baseUrl)
3
+ * Use this for initial login when server URL is provided by the user
4
+ */
5
+ export async function loginToServer(serverUrl, credentials) {
6
+ const response = await fetch(`${serverUrl}/api/auth/login`, {
7
+ method: 'POST',
8
+ headers: {
9
+ 'Content-Type': 'application/json',
10
+ },
11
+ body: JSON.stringify(credentials),
12
+ });
13
+ if (!response.ok) {
14
+ const error = await response.json().catch(() => ({ message: 'Login failed' }));
15
+ throw new Error(error.message || 'Login failed');
16
+ }
17
+ return response.json();
18
+ }
@@ -0,0 +1,5 @@
1
+ import { type FetchBaseQueryArgs } from '@reduxjs/toolkit/query/react';
2
+ export type ImmichApiConfig = FetchBaseQueryArgs;
3
+ export declare const configureImmichApi: (config: ImmichApiConfig) => void;
4
+ export declare const immichApi: import("@reduxjs/toolkit/query").Api<(args: any, api: import("@reduxjs/toolkit/query").BaseQueryApi, extraOptions: {}) => Promise<import("@reduxjs/toolkit/query").QueryReturnValue<unknown, unknown, {}>>, {}, "immichApi", never, typeof import("@reduxjs/toolkit/query").coreModuleName | typeof import("@reduxjs/toolkit/query/react").reactHooksModuleName>;
5
+ //# sourceMappingURL=emptyApi.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emptyApi.d.ts","sourceRoot":"","sources":["../src/emptyApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+C,KAAK,kBAAkB,EAAE,MAAM,8BAA8B,CAAA;AAGnH,MAAM,MAAM,eAAe,GAAG,kBAAkB,CAAA;AAKhD,eAAO,MAAM,kBAAkB,GAAI,QAAQ,eAAe,SAKzD,CAAA;AAGD,eAAO,MAAM,SAAS,kWAQpB,CAAA"}
@@ -0,0 +1,19 @@
1
+ import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
2
+ let customBaseQuery;
3
+ // Function to configure the API before it's used
4
+ export const configureImmichApi = (config) => {
5
+ customBaseQuery = fetchBaseQuery({
6
+ baseUrl: '/',
7
+ ...config,
8
+ });
9
+ };
10
+ // Base API instance - will use custom config if provided via configureImmichApi
11
+ export const immichApi = createApi({
12
+ reducerPath: 'immichApi',
13
+ baseQuery: async (...args) => {
14
+ // Use custom base query if configured, otherwise use default
15
+ const baseQuery = customBaseQuery || fetchBaseQuery({ baseUrl: '/' });
16
+ return baseQuery(...args);
17
+ },
18
+ endpoints: () => ({}),
19
+ });