@geekmidas/client 10.0.0-alpha.99 → 10.0.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/CHANGELOG.md +154 -0
- package/README.md +57 -40
- package/dist/auth-fetcher.cjs +5 -7
- package/dist/auth-fetcher.cjs.map +1 -1
- package/dist/auth-fetcher.d.cts +17 -15
- package/dist/auth-fetcher.d.cts.map +1 -1
- package/dist/auth-fetcher.d.mts +17 -15
- package/dist/auth-fetcher.d.mts.map +1 -1
- package/dist/auth-fetcher.mjs +5 -6
- package/dist/auth-fetcher.mjs.map +1 -1
- package/dist/chunk-CUT6urMc.cjs +30 -0
- package/dist/endpoint-hooks.cjs +15 -11
- package/dist/endpoint-hooks.cjs.map +1 -1
- package/dist/endpoint-hooks.d.cts +7 -4
- package/dist/endpoint-hooks.d.cts.map +1 -1
- package/dist/endpoint-hooks.d.mts +7 -4
- package/dist/endpoint-hooks.d.mts.map +1 -1
- package/dist/endpoint-hooks.mjs +9 -5
- package/dist/endpoint-hooks.mjs.map +1 -1
- package/dist/fetcher-CakjC9C7.mjs +88 -0
- package/dist/fetcher-CakjC9C7.mjs.map +1 -0
- package/dist/fetcher-CwnSqc4D.cjs +100 -0
- package/dist/fetcher-CwnSqc4D.cjs.map +1 -0
- package/dist/fetcher.cjs +3 -115
- package/dist/fetcher.d.cts +8 -7
- package/dist/fetcher.d.cts.map +1 -1
- package/dist/fetcher.d.mts +8 -7
- package/dist/fetcher.d.mts.map +1 -1
- package/dist/fetcher.mjs +2 -90
- package/dist/infer.d.cts +13 -10
- package/dist/infer.d.cts.map +1 -1
- package/dist/infer.d.mts +13 -10
- package/dist/infer.d.mts.map +1 -1
- package/dist/infer.mjs +0 -1
- package/dist/openapi-hooks.cjs +16 -13
- package/dist/openapi-hooks.cjs.map +1 -1
- package/dist/openapi-hooks.d.cts +11 -8
- package/dist/openapi-hooks.d.cts.map +1 -1
- package/dist/openapi-hooks.d.mts +11 -8
- package/dist/openapi-hooks.d.mts.map +1 -1
- package/dist/openapi-hooks.mjs +12 -9
- package/dist/openapi-hooks.mjs.map +1 -1
- package/dist/openapi-types.d.cts +6 -5
- package/dist/openapi-types.d.cts.map +1 -1
- package/dist/openapi-types.d.mts +6 -5
- package/dist/openapi-types.d.mts.map +1 -1
- package/dist/openapi.cjs +526 -0
- package/dist/openapi.cjs.map +1 -0
- package/dist/openapi.mjs +501 -0
- package/dist/openapi.mjs.map +1 -0
- package/dist/react-query.cjs +16 -17
- package/dist/react-query.cjs.map +1 -1
- package/dist/react-query.d.cts +17 -12
- package/dist/react-query.d.cts.map +1 -1
- package/dist/react-query.d.mts +17 -12
- package/dist/react-query.d.mts.map +1 -1
- package/dist/react-query.mjs +9 -10
- package/dist/react-query.mjs.map +1 -1
- package/dist/types-D8Jrl4o3.d.mts +110 -0
- package/dist/types-D8Jrl4o3.d.mts.map +1 -0
- package/dist/types-DMQMHePI.d.cts +110 -0
- package/dist/types-DMQMHePI.d.cts.map +1 -0
- package/dist/types.d.cts +2 -122
- package/dist/types.d.mts +2 -122
- package/dist/types.mjs +0 -1
- package/package.json +15 -31
- package/src/__tests__/auth-fetcher.spec.ts +505 -0
- package/src/__tests__/endpoint-hooks.spec.tsx +374 -0
- package/src/__tests__/fetcher.spec.ts +580 -0
- package/src/__tests__/infer.integration.spec.ts +188 -0
- package/src/__tests__/infer.spec.ts +189 -0
- package/src/__tests__/method-restrictions.spec.tsx +227 -0
- package/src/__tests__/mutation-inference.spec.tsx +343 -0
- package/src/__tests__/openapi-hooks.spec.tsx +557 -0
- package/src/__tests__/react-query-infinite.spec.tsx +1003 -0
- package/src/__tests__/react-query-invalidation.spec.tsx +239 -0
- package/src/__tests__/react-query.spec.tsx +582 -0
- package/src/__tests__/setup.ts +281 -0
- package/src/__tests__/types.spec.ts +134 -0
- package/src/__tests__/url-parsing.spec.ts +196 -0
- package/src/auth-fetcher.ts +288 -0
- package/src/endpoint-hooks.ts +346 -0
- package/src/fetcher.ts +171 -0
- package/src/infer.ts +162 -0
- package/src/openapi-hooks.ts +193 -0
- package/src/openapi-types.d.ts +440 -0
- package/src/openapi.json +595 -0
- package/src/react-query.ts +341 -0
- package/src/types.ts +226 -0
- package/tsconfig.json +12 -0
- package/dist/fetcher.cjs.map +0 -1
- package/dist/fetcher.mjs.map +0 -1
- package/dist/index.cjs +0 -15
- package/dist/index.d.cts +0 -7
- package/dist/index.d.mts +0 -7
- package/dist/index.mjs +0 -7
- package/dist/methods.cjs +0 -21
- package/dist/methods.cjs.map +0 -1
- package/dist/methods.d.cts +0 -23
- package/dist/methods.d.cts.map +0 -1
- package/dist/methods.d.mts +0 -23
- package/dist/methods.d.mts.map +0 -1
- package/dist/methods.mjs +0 -19
- package/dist/methods.mjs.map +0 -1
- package/dist/telemetry-g3BE86Wd.d.cts +0 -68
- package/dist/telemetry-g3BE86Wd.d.cts.map +0 -1
- package/dist/telemetry-g3BE86Wd.d.mts +0 -68
- package/dist/telemetry-g3BE86Wd.d.mts.map +0 -1
- package/dist/telemetry.cjs +0 -128
- package/dist/telemetry.cjs.map +0 -1
- package/dist/telemetry.d.cts +0 -2
- package/dist/telemetry.d.mts +0 -2
- package/dist/telemetry.mjs +0 -125
- package/dist/telemetry.mjs.map +0 -1
- package/dist/types.d.cts.map +0 -1
- package/dist/types.d.mts.map +0 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
# @geekmidas/client
|
|
2
|
+
|
|
3
|
+
## 10.0.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`4235b31`](https://github.com/geekmidas/toolbox/commit/4235b31416c39b08ce151606d4b46a34b8ef7896), [`a920ff4`](https://github.com/geekmidas/toolbox/commit/a920ff4e3a66edf4e9d5b0183cf9f17d7111391f)]:
|
|
8
|
+
- @geekmidas/constructs@10.0.0
|
|
9
|
+
- @geekmidas/schema@10.0.0
|
|
10
|
+
|
|
11
|
+
## 9.0.2
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [#12](https://github.com/geekmidas/toolbox/pull/12) [`d53863a`](https://github.com/geekmidas/toolbox/commit/d53863a84db2e4ab5420e08f79128b637043fc42) Thanks [@geekmidas](https://github.com/geekmidas)! - Align every published package on a single version and keep them in step.
|
|
16
|
+
|
|
17
|
+
All packages now share one version, enforced by a changesets `fixed` group. The
|
|
18
|
+
baseline is 9.0.1 — @geekmidas/client's published version — so nothing moves
|
|
19
|
+
backwards; this release takes the whole set to 9.0.2 together.
|
|
20
|
+
|
|
21
|
+
Independent versions made "which version of the docs applies to me"
|
|
22
|
+
unanswerable: a reader on constructs@7 and cli@2 was on no version at all. One
|
|
23
|
+
number per release makes versioned documentation possible, and lets 9 freeze as
|
|
24
|
+
the current paradigm while the constructs rework is developed against it.
|
|
25
|
+
|
|
26
|
+
Every release now publishes every package, and a major anywhere is a major
|
|
27
|
+
everywhere. Peer ranges get simpler in return.
|
|
28
|
+
|
|
29
|
+
- Updated dependencies [[`d53863a`](https://github.com/geekmidas/toolbox/commit/d53863a84db2e4ab5420e08f79128b637043fc42)]:
|
|
30
|
+
- @geekmidas/constructs@9.0.2
|
|
31
|
+
- @geekmidas/schema@9.0.2
|
|
32
|
+
|
|
33
|
+
## 9.0.1
|
|
34
|
+
|
|
35
|
+
### Patch Changes
|
|
36
|
+
|
|
37
|
+
- 🐛 [#11](https://github.com/geekmidas/toolbox/pull/11) [`40f4dc0`](https://github.com/geekmidas/toolbox/commit/40f4dc095911b2223a255029d8f776caf7781309) Thanks [@geekmidas](https://github.com/geekmidas)! - Patch release across all packages to realign published versions with the
|
|
38
|
+
registry. The previous release only published the four packages that had
|
|
39
|
+
version bumps; the remaining packages failed with "cannot publish over the
|
|
40
|
+
previously published versions" because their versions were unchanged.
|
|
41
|
+
- Updated dependencies [[`40f4dc0`](https://github.com/geekmidas/toolbox/commit/40f4dc095911b2223a255029d8f776caf7781309)]:
|
|
42
|
+
- @geekmidas/constructs@7.0.1
|
|
43
|
+
- @geekmidas/schema@1.0.4
|
|
44
|
+
|
|
45
|
+
## 9.0.0
|
|
46
|
+
|
|
47
|
+
### Patch Changes
|
|
48
|
+
|
|
49
|
+
- Updated dependencies []:
|
|
50
|
+
- @geekmidas/constructs@7.0.0
|
|
51
|
+
|
|
52
|
+
## 8.0.0
|
|
53
|
+
|
|
54
|
+
### Patch Changes
|
|
55
|
+
|
|
56
|
+
- Updated dependencies []:
|
|
57
|
+
- @geekmidas/constructs@6.0.0
|
|
58
|
+
|
|
59
|
+
## 7.0.0
|
|
60
|
+
|
|
61
|
+
### Patch Changes
|
|
62
|
+
|
|
63
|
+
- Updated dependencies [[`b004fd8`](https://github.com/geekmidas/toolbox/commit/b004fd8ee74b5f20a047260b16669d16d8fc03b4), [`0dad77e`](https://github.com/geekmidas/toolbox/commit/0dad77e574000e4018033b956ed4bb95935911a5)]:
|
|
64
|
+
- @geekmidas/constructs@5.0.0
|
|
65
|
+
|
|
66
|
+
## 6.0.0
|
|
67
|
+
|
|
68
|
+
### Patch Changes
|
|
69
|
+
|
|
70
|
+
- Updated dependencies [[`811d740`](https://github.com/geekmidas/toolbox/commit/811d740ae3875d59ad1b0dc50261266963c8cb76)]:
|
|
71
|
+
- @geekmidas/constructs@4.0.0
|
|
72
|
+
|
|
73
|
+
## 5.0.0
|
|
74
|
+
|
|
75
|
+
### Patch Changes
|
|
76
|
+
|
|
77
|
+
- Updated dependencies [[`a20be2f`](https://github.com/geekmidas/toolbox/commit/a20be2faa4795600358904b751fa947d3cbb4c45), [`07093f5`](https://github.com/geekmidas/toolbox/commit/07093f5f911bf1ee48e53275da3cce398cc78ff6)]:
|
|
78
|
+
- @geekmidas/constructs@3.1.0
|
|
79
|
+
|
|
80
|
+
## 4.0.5
|
|
81
|
+
|
|
82
|
+
### Patch Changes
|
|
83
|
+
|
|
84
|
+
- 🐛 [`d70c6c0`](https://github.com/geekmidas/toolbox/commit/d70c6c0aeb8a79da2473ac77dbd8255a4a2f5651) Thanks [@geekmidas](https://github.com/geekmidas)! - Fix `package.json` exports so TypeScript declarations resolve correctly under NodeNext/Bundler module resolution. Each subpath export now nests `types` inside its `import`/`require` condition, pointing at the `.d.mts` and `.d.cts` files that `tsdown` actually emits (previously the exports referenced non-existent `.d.ts` files, causing type-resolution failures for consumers). Both ESM (`.mjs`) and CJS (`.cjs`) runtime entry points are preserved. Additionally, `@geekmidas/ui` had `import` paths pointing at `.js` files that were never emitted — those are corrected to `.mjs`.
|
|
85
|
+
|
|
86
|
+
- Updated dependencies [[`d70c6c0`](https://github.com/geekmidas/toolbox/commit/d70c6c0aeb8a79da2473ac77dbd8255a4a2f5651)]:
|
|
87
|
+
- @geekmidas/constructs@3.0.12
|
|
88
|
+
- @geekmidas/schema@1.0.2
|
|
89
|
+
|
|
90
|
+
## 4.0.4
|
|
91
|
+
|
|
92
|
+
### Patch Changes
|
|
93
|
+
|
|
94
|
+
- ✨ [`6f8f28a`](https://github.com/geekmidas/toolbox/commit/6f8f28a1317c0b519fd2067a2cd39b73c0585755) Thanks [@geekmidas](https://github.com/geekmidas)! - Add method preservation on the client and add query helpers to hooks
|
|
95
|
+
|
|
96
|
+
## 4.0.3
|
|
97
|
+
|
|
98
|
+
### Patch Changes
|
|
99
|
+
|
|
100
|
+
- ✨ [`54589f8`](https://github.com/geekmidas/toolbox/commit/54589f89d4707c287a133be5c7dbb224b86d630c) Thanks [@geekmidas](https://github.com/geekmidas)! - Add ok discriminator for wrapped clients
|
|
101
|
+
|
|
102
|
+
## 4.0.2
|
|
103
|
+
|
|
104
|
+
### Patch Changes
|
|
105
|
+
|
|
106
|
+
- ✨ [`414e7e1`](https://github.com/geekmidas/toolbox/commit/414e7e1f8ca038e397a5533279bf3a2f6f193a6d) Thanks [@geekmidas](https://github.com/geekmidas)! - Add .wrap on the fetch client for no throw handling
|
|
107
|
+
|
|
108
|
+
## 4.0.1
|
|
109
|
+
|
|
110
|
+
### Patch Changes
|
|
111
|
+
|
|
112
|
+
- [`a39b41f`](https://github.com/geekmidas/toolbox/commit/a39b41fae9c6cfbde8e6d78bf5a11fbb9e59f67d) Thanks [@geekmidas](https://github.com/geekmidas)! - Use qs to process query params instead of custom solution
|
|
113
|
+
|
|
114
|
+
- Updated dependencies [[`a39b41f`](https://github.com/geekmidas/toolbox/commit/a39b41fae9c6cfbde8e6d78bf5a11fbb9e59f67d)]:
|
|
115
|
+
- @geekmidas/constructs@3.0.3
|
|
116
|
+
|
|
117
|
+
## 4.0.0
|
|
118
|
+
|
|
119
|
+
### Patch Changes
|
|
120
|
+
|
|
121
|
+
- ✨ [`be4f7a9`](https://github.com/geekmidas/toolbox/commit/be4f7a9bd5de7f08adbca582916d6902e0c24de2) Thanks [@geekmidas](https://github.com/geekmidas)! - Add partition support for manifest generation. Users can now group constructs (routes, functions, crons, subscribers) into named partitions by providing a `partition` callback per construct type in the config. Manifests output partitioned fields as `Record<string, T[]>` while remaining flat `T[]` arrays when no partitions are configured.
|
|
122
|
+
|
|
123
|
+
Fix mutation type inference in endpoint hooks by using `UseMutationResult` and `UseQueryResult` types directly instead of `ReturnType<typeof useMutation>`, which could resolve to `never` for complex path definitions.
|
|
124
|
+
|
|
125
|
+
Add `FileCache` implementation that persists cache entries to a JSON file on disk. Default location is `process.cwd()/.gkm/cache.json`. Uses an in-process mutex combined with `proper-lockfile` for safe concurrent and cross-process writes.
|
|
126
|
+
|
|
127
|
+
- Updated dependencies []:
|
|
128
|
+
- @geekmidas/constructs@3.0.0
|
|
129
|
+
|
|
130
|
+
## 3.0.0
|
|
131
|
+
|
|
132
|
+
### Patch Changes
|
|
133
|
+
|
|
134
|
+
- Updated dependencies [[`83a24de`](https://github.com/geekmidas/toolbox/commit/83a24de902b3fadd98444cab552ecd84f32b6661)]:
|
|
135
|
+
- @geekmidas/constructs@2.0.0
|
|
136
|
+
|
|
137
|
+
## 2.0.0
|
|
138
|
+
|
|
139
|
+
### Patch Changes
|
|
140
|
+
|
|
141
|
+
- Updated dependencies [[`73511d9`](https://github.com/geekmidas/toolbox/commit/73511d912062eb0776935168c9f72d42c7c854a6)]:
|
|
142
|
+
- @geekmidas/constructs@1.1.0
|
|
143
|
+
|
|
144
|
+
## 1.0.0
|
|
145
|
+
|
|
146
|
+
### Major Changes
|
|
147
|
+
|
|
148
|
+
- [`ff7b115`](https://github.com/geekmidas/toolbox/commit/ff7b11599f60f84ac6cdc73714c853ecf786b2e8) Thanks [@geekmidas](https://github.com/geekmidas)! - Version 1 Stable release
|
|
149
|
+
|
|
150
|
+
### Patch Changes
|
|
151
|
+
|
|
152
|
+
- Updated dependencies [[`ff7b115`](https://github.com/geekmidas/toolbox/commit/ff7b11599f60f84ac6cdc73714c853ecf786b2e8)]:
|
|
153
|
+
- @geekmidas/constructs@1.0.0
|
|
154
|
+
- @geekmidas/schema@1.0.0
|
package/README.md
CHANGED
|
@@ -40,8 +40,8 @@ import { createEndpointHooks } from '@geekmidas/client/endpoint-hooks';
|
|
|
40
40
|
// React Query client (class-based)
|
|
41
41
|
import { createTypedQueryClient } from '@geekmidas/client/react-query';
|
|
42
42
|
|
|
43
|
-
// OpenAPI hooks
|
|
44
|
-
import {
|
|
43
|
+
// OpenAPI hooks generation
|
|
44
|
+
import { generateReactQueryHooks } from '@geekmidas/client/openapi';
|
|
45
45
|
|
|
46
46
|
// Type utilities
|
|
47
47
|
import type { TypedApiFunction, FilteredRequestConfig } from '@geekmidas/client/types';
|
|
@@ -76,7 +76,7 @@ interface API {
|
|
|
76
76
|
email: string;
|
|
77
77
|
};
|
|
78
78
|
};
|
|
79
|
-
'GET /users
|
|
79
|
+
'GET /users/:id': {
|
|
80
80
|
params: {
|
|
81
81
|
id: string;
|
|
82
82
|
};
|
|
@@ -102,7 +102,7 @@ const user = await api('POST /users', {
|
|
|
102
102
|
});
|
|
103
103
|
// user is typed as { id: string; name: string; email: string }
|
|
104
104
|
|
|
105
|
-
const singleUser = await api('GET /users
|
|
105
|
+
const singleUser = await api('GET /users/:id', {
|
|
106
106
|
params: { id: '123' }
|
|
107
107
|
});
|
|
108
108
|
// singleUser is typed as { id: string; name: string; email: string }
|
|
@@ -280,26 +280,6 @@ function CreateUser() {
|
|
|
280
280
|
}
|
|
281
281
|
```
|
|
282
282
|
|
|
283
|
-
### Method Calls
|
|
284
|
-
|
|
285
|
-
Every client also answers by method — the same request as
|
|
286
|
-
`api('POST /users', …)`, with the method as the call:
|
|
287
|
-
|
|
288
|
-
```typescript
|
|
289
|
-
await api.get('/health'); // declares nothing → no second argument
|
|
290
|
-
await api.get('/users/{id}', { params: { id: '123' } }); // path params → argument required
|
|
291
|
-
await api.post('/users', { body: { name: 'Ada', email } }); // body → argument required
|
|
292
|
-
await api.get('/search', { query: { q: 'ada' } }); // required query key → required
|
|
293
|
-
await api.get('/users', { query: { page: 2 } }); // optional query → optional
|
|
294
|
-
|
|
295
|
-
await api.post('/users', { body: { name: 'Ada' } }); // ❌ `email` is missing
|
|
296
|
-
await api.get('/health', { body: {} }); // ❌ GET /health takes no body
|
|
297
|
-
await api.post('/health'); // ❌ /health has no POST
|
|
298
|
-
```
|
|
299
|
-
|
|
300
|
-
The route autocompletes per method — only routes with a `POST` appear in
|
|
301
|
-
`api.post` — and the second argument has only the keys the endpoint declares.
|
|
302
|
-
|
|
303
283
|
### Type-Safe Config Requirements
|
|
304
284
|
|
|
305
285
|
The generated client enforces config requirements at the type level:
|
|
@@ -399,11 +379,48 @@ const api = Object.assign(fetcher, hooks);
|
|
|
399
379
|
|
|
400
380
|
## OpenAPI Code Generation
|
|
401
381
|
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
382
|
+
Generate React Query hooks from OpenAPI specifications:
|
|
383
|
+
|
|
384
|
+
```bash
|
|
385
|
+
# Using CLI
|
|
386
|
+
pnpm gkm generate:react-query --input api-docs.json --output ./src/api
|
|
387
|
+
|
|
388
|
+
# Programmatic usage
|
|
389
|
+
import { generateReactQueryHooks } from '@geekmidas/client/openapi';
|
|
390
|
+
import fs from 'fs/promises';
|
|
391
|
+
|
|
392
|
+
const spec = JSON.parse(await fs.readFile('api-docs.json', 'utf-8'));
|
|
393
|
+
const code = await generateReactQueryHooks(spec);
|
|
394
|
+
await fs.writeFile('./src/api/generated.ts', code);
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
Generated hooks example:
|
|
398
|
+
|
|
399
|
+
```typescript
|
|
400
|
+
// Generated from OpenAPI spec
|
|
401
|
+
export const api = createTypedQueryClient<{
|
|
402
|
+
'GET /users': {
|
|
403
|
+
response: User[];
|
|
404
|
+
};
|
|
405
|
+
'POST /users': {
|
|
406
|
+
body: CreateUserRequest;
|
|
407
|
+
response: User;
|
|
408
|
+
};
|
|
409
|
+
// ... all your endpoints
|
|
410
|
+
}>({
|
|
411
|
+
baseUrl: process.env.REACT_APP_API_URL
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
// Use generated hooks
|
|
415
|
+
function MyComponent() {
|
|
416
|
+
const { data: users } = api.useQuery('GET /users');
|
|
417
|
+
const createUser = api.useMutation('POST /users');
|
|
418
|
+
|
|
419
|
+
return (
|
|
420
|
+
// Your component
|
|
421
|
+
);
|
|
422
|
+
}
|
|
423
|
+
```
|
|
407
424
|
|
|
408
425
|
## Advanced Features
|
|
409
426
|
|
|
@@ -416,14 +433,14 @@ Type-safe cache invalidation:
|
|
|
416
433
|
await api.invalidateQueries('GET /users');
|
|
417
434
|
|
|
418
435
|
// Invalidate with params
|
|
419
|
-
await api.invalidateQueries('GET /users
|
|
436
|
+
await api.invalidateQueries('GET /users/:id', {
|
|
420
437
|
params: { id: '123' }
|
|
421
438
|
});
|
|
422
439
|
|
|
423
440
|
// Invalidate multiple queries
|
|
424
441
|
await Promise.all([
|
|
425
442
|
api.invalidateQueries('GET /users'),
|
|
426
|
-
api.invalidateQueries('GET /users
|
|
443
|
+
api.invalidateQueries('GET /users/:id')
|
|
427
444
|
]);
|
|
428
445
|
```
|
|
429
446
|
|
|
@@ -432,20 +449,20 @@ await Promise.all([
|
|
|
432
449
|
Implement optimistic UI updates:
|
|
433
450
|
|
|
434
451
|
```typescript
|
|
435
|
-
const updateUser = api.useMutation('PUT /users
|
|
452
|
+
const updateUser = api.useMutation('PUT /users/:id', {
|
|
436
453
|
onMutate: async (variables) => {
|
|
437
454
|
// Cancel outgoing refetches
|
|
438
|
-
await api.cancelQueries('GET /users
|
|
455
|
+
await api.cancelQueries('GET /users/:id', {
|
|
439
456
|
params: { id: variables.params.id }
|
|
440
457
|
});
|
|
441
458
|
|
|
442
459
|
// Snapshot previous value
|
|
443
|
-
const previousUser = api.getQueryData('GET /users
|
|
460
|
+
const previousUser = api.getQueryData('GET /users/:id', {
|
|
444
461
|
params: { id: variables.params.id }
|
|
445
462
|
});
|
|
446
463
|
|
|
447
464
|
// Optimistically update
|
|
448
|
-
api.setQueryData('GET /users
|
|
465
|
+
api.setQueryData('GET /users/:id', {
|
|
449
466
|
params: { id: variables.params.id }
|
|
450
467
|
}, variables.body);
|
|
451
468
|
|
|
@@ -454,14 +471,14 @@ const updateUser = api.useMutation('PUT /users/{id}', {
|
|
|
454
471
|
onError: (err, variables, context) => {
|
|
455
472
|
// Rollback on error
|
|
456
473
|
if (context?.previousUser) {
|
|
457
|
-
api.setQueryData('GET /users
|
|
474
|
+
api.setQueryData('GET /users/:id', {
|
|
458
475
|
params: { id: variables.params.id }
|
|
459
476
|
}, context.previousUser);
|
|
460
477
|
}
|
|
461
478
|
},
|
|
462
479
|
onSettled: (data, error, variables) => {
|
|
463
480
|
// Refetch after mutation
|
|
464
|
-
api.invalidateQueries('GET /users
|
|
481
|
+
api.invalidateQueries('GET /users/:id', {
|
|
465
482
|
params: { id: variables.params.id }
|
|
466
483
|
});
|
|
467
484
|
}
|
|
@@ -482,7 +499,7 @@ const api = createTypedFetcher<API>({
|
|
|
482
499
|
});
|
|
483
500
|
|
|
484
501
|
// Per-request headers
|
|
485
|
-
const user = await api('GET /users
|
|
502
|
+
const user = await api('GET /users/:id', {
|
|
486
503
|
params: { id: '123' },
|
|
487
504
|
headers: {
|
|
488
505
|
'X-Request-ID': requestId
|
|
@@ -498,7 +515,7 @@ Handle errors with full type safety:
|
|
|
498
515
|
import { HttpError } from '@geekmidas/errors';
|
|
499
516
|
|
|
500
517
|
try {
|
|
501
|
-
const user = await api('GET /users
|
|
518
|
+
const user = await api('GET /users/:id', {
|
|
502
519
|
params: { id: '123' }
|
|
503
520
|
});
|
|
504
521
|
} catch (error) {
|
|
@@ -558,7 +575,7 @@ function UsersList() {
|
|
|
558
575
|
|
|
559
576
|
const handleUserHover = (userId: string) => {
|
|
560
577
|
// Prefetch user details on hover
|
|
561
|
-
api.prefetchQuery('GET /users
|
|
578
|
+
api.prefetchQuery('GET /users/:id', {
|
|
562
579
|
params: { id: userId }
|
|
563
580
|
});
|
|
564
581
|
};
|
package/dist/auth-fetcher.cjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const require_fetcher = require("./fetcher.cjs");
|
|
1
|
+
const require_fetcher = require('./fetcher-CwnSqc4D.cjs');
|
|
2
|
+
|
|
4
3
|
//#region src/auth-fetcher.ts
|
|
5
4
|
/**
|
|
6
5
|
* Creates an auth-aware fetcher that automatically applies the correct
|
|
@@ -31,7 +30,7 @@ const require_fetcher = require("./fetcher.cjs");
|
|
|
31
30
|
* ```
|
|
32
31
|
*/
|
|
33
32
|
function createAuthAwareFetcher(options) {
|
|
34
|
-
const { endpointAuth, securitySchemes, authStrategies, onRequest: userOnRequest
|
|
33
|
+
const { endpointAuth, securitySchemes, authStrategies, onRequest: userOnRequest,...fetcherOptions } = options;
|
|
35
34
|
const baseFetcher = new require_fetcher.TypedFetcher({
|
|
36
35
|
...fetcherOptions,
|
|
37
36
|
onRequest: userOnRequest
|
|
@@ -54,8 +53,7 @@ function createAuthAwareFetcher(options) {
|
|
|
54
53
|
};
|
|
55
54
|
return baseFetcher.request(endpoint, mergedConfig);
|
|
56
55
|
};
|
|
57
|
-
|
|
58
|
-
return Object.assign(api, require_methods.methodCalls(api));
|
|
56
|
+
return fetcher;
|
|
59
57
|
}
|
|
60
58
|
/**
|
|
61
59
|
* Resolves auth headers based on the strategy and scheme.
|
|
@@ -73,7 +71,7 @@ async function resolveAuthHeaders(strategy, scheme) {
|
|
|
73
71
|
default: return {};
|
|
74
72
|
}
|
|
75
73
|
}
|
|
74
|
+
|
|
76
75
|
//#endregion
|
|
77
76
|
exports.createAuthAwareFetcher = createAuthAwareFetcher;
|
|
78
|
-
|
|
79
77
|
//# sourceMappingURL=auth-fetcher.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth-fetcher.cjs","names":["TypedFetcher","
|
|
1
|
+
{"version":3,"file":"auth-fetcher.cjs","names":["options: AuthFetcherOptions<EndpointAuth, SecuritySchemes> & {\n\t\tbaseURL: string;\n\t}","TypedFetcher","endpoint: T","config?: FilteredRequestConfig<Paths, T>","authHeaders: Record<string, string>","strategy: AuthStrategy","scheme: SecuritySchemeObject"],"sources":["../src/auth-fetcher.ts"],"sourcesContent":["import { TypedFetcher } from './fetcher';\nimport type {\n\tExtractEndpointResponse,\n\tFetcherOptions,\n\tFilteredRequestConfig,\n\tTypedApiFunction,\n\tTypedEndpoint,\n} from './types';\n\nexport type { FetcherOptions } from './types';\n\n/**\n * Security scheme object matching OpenAPI 3.1 specification.\n */\nexport interface SecuritySchemeObject {\n\ttype: 'apiKey' | 'http' | 'mutualTLS' | 'oauth2' | 'openIdConnect';\n\tdescription?: string;\n\tname?: string;\n\tin?: 'query' | 'header' | 'cookie';\n\tscheme?: string;\n\tbearerFormat?: string;\n\tflows?: Record<string, unknown>;\n\topenIdConnectUrl?: string;\n\t[key: string]: unknown;\n}\n\n/**\n * Extract all non-null security scheme IDs that are actually used in the API.\n * This gives us the union of scheme names that endpoints require.\n */\nexport type UsedSecuritySchemes<\n\tEndpointAuth extends Record<string, string | null>,\n> = NonNullable<EndpointAuth[keyof EndpointAuth]>;\n\n/**\n * Interface for token storage and retrieval.\n * Compatible with @geekmidas/auth TokenClient.\n */\nexport interface TokenProvider {\n\t/**\n\t * Get a valid access token, refreshing if necessary.\n\t */\n\tgetValidAccessToken(): Promise<string | null>;\n\n\t/**\n\t * Create Authorization headers from the current token.\n\t */\n\tcreateValidAuthHeaders(): Promise<Record<string, string>>;\n}\n\n/**\n * Interface for API key providers.\n */\nexport interface ApiKeyProvider {\n\t/**\n\t * Get the API key value.\n\t */\n\tgetApiKey(): Promise<string> | string;\n}\n\n/**\n * Interface for AWS SigV4 request signing.\n */\nexport interface AwsSigner {\n\t/**\n\t * Sign a request with AWS SigV4.\n\t * @param url - The request URL\n\t * @param init - The request init object\n\t * @returns Headers to add to the request\n\t */\n\tsign(url: string, init: RequestInit): Promise<Record<string, string>>;\n}\n\n/**\n * Auth strategy configuration for a specific security scheme type.\n */\nexport type AuthStrategy =\n\t| { type: 'bearer'; tokenProvider: TokenProvider }\n\t| { type: 'apiKey'; apiKeyProvider: ApiKeyProvider; headerName?: string }\n\t| { type: 'iam'; signer: AwsSigner }\n\t| { type: 'none' };\n\n/**\n * Options for creating an auth-aware fetcher.\n *\n * @template EndpointAuth - Map of endpoint strings to their auth scheme (or null for public)\n * @template SecuritySchemes - Available security scheme definitions\n */\nexport interface AuthFetcherOptions<\n\tEndpointAuth extends Record<string, string | null>,\n\tSecuritySchemes extends Record<string, SecuritySchemeObject>,\n> extends Omit<FetcherOptions, 'onRequest'> {\n\t/**\n\t * Runtime map of endpoints to their required auth scheme.\n\t * Generated by `gkm openapi --ts`.\n\t */\n\tendpointAuth: EndpointAuth;\n\n\t/**\n\t * Security scheme definitions.\n\t * Generated by `gkm openapi --ts`.\n\t */\n\tsecuritySchemes: SecuritySchemes;\n\n\t/**\n\t * Auth strategies for security schemes that are actually used.\n\t * Only schemes referenced in endpointAuth are required.\n\t *\n\t * @example\n\t * ```typescript\n\t * // If endpointAuth has: { 'GET /users': 'jwt', 'POST /data': 'iam', 'GET /public': null }\n\t * // Then authStrategies must include strategies for 'jwt' and 'iam'\n\t * authStrategies: {\n\t * jwt: { type: 'bearer', tokenProvider },\n\t * iam: { type: 'iam', signer: awsSigner },\n\t * }\n\t * ```\n\t */\n\tauthStrategies: Record<UsedSecuritySchemes<EndpointAuth>, AuthStrategy>;\n\n\t/**\n\t * Optional request interceptor (runs after auth headers are added).\n\t */\n\tonRequest?: (config: RequestInit) => RequestInit | Promise<RequestInit>;\n}\n\n/**\n * Creates an auth-aware fetcher that automatically applies the correct\n * authentication based on the endpoint being called.\n *\n * @example\n * ```typescript\n * import { endpointAuth, securitySchemes, paths } from './openapi';\n * import { TokenClient } from '@geekmidas/auth/client';\n *\n * const tokenClient = new TokenClient({ ... });\n *\n * const api = createAuthAwareFetcher<paths>({\n * baseURL: 'https://api.example.com',\n * endpointAuth,\n * securitySchemes,\n * authStrategies: {\n * bearer: { type: 'bearer', tokenProvider: tokenClient },\n * iam: { type: 'iam', signer: awsSigner },\n * },\n * });\n *\n * // Bearer auth automatically applied\n * const user = await api('GET /users/{id}', { params: { id: '123' } });\n *\n * // IAM SigV4 auth automatically applied\n * const tenant = await api('POST /tenants', { body: { name: 'Acme' } });\n * ```\n */\nexport function createAuthAwareFetcher<\n\tPaths,\n\tEndpointAuth extends Record<string, string | null> = Record<\n\t\tstring,\n\t\tstring | null\n\t>,\n\tSecuritySchemes extends Record<string, SecuritySchemeObject> = Record<\n\t\tstring,\n\t\tSecuritySchemeObject\n\t>,\n>(\n\toptions: AuthFetcherOptions<EndpointAuth, SecuritySchemes> & {\n\t\tbaseURL: string;\n\t},\n): TypedApiFunction<Paths> {\n\tconst {\n\t\tendpointAuth,\n\t\tsecuritySchemes,\n\t\tauthStrategies,\n\t\tonRequest: userOnRequest,\n\t\t...fetcherOptions\n\t} = options;\n\n\t// Create base fetcher with user's onRequest if provided\n\tconst baseFetcher = new TypedFetcher<Paths>({\n\t\t...fetcherOptions,\n\t\tonRequest: userOnRequest,\n\t});\n\n\tconst fetcher = async <T extends TypedEndpoint<Paths>>(\n\t\tendpoint: T,\n\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t): Promise<ExtractEndpointResponse<Paths, T>> => {\n\t\t// Look up auth requirement for this endpoint\n\t\tconst schemeName = endpointAuth[endpoint as keyof EndpointAuth] as\n\t\t\t| string\n\t\t\t| null;\n\n\t\tlet authHeaders: Record<string, string> = {};\n\n\t\tif (schemeName) {\n\t\t\tconst scheme = securitySchemes[schemeName as keyof SecuritySchemes];\n\t\t\t// Since authStrategies is now required to have all used schemes,\n\t\t\t// we can safely access it - TypeScript ensures the strategy exists\n\t\t\tconst strategy =\n\t\t\t\tauthStrategies[schemeName as UsedSecuritySchemes<EndpointAuth>];\n\n\t\t\tif (strategy && scheme) {\n\t\t\t\tauthHeaders = await resolveAuthHeaders(strategy, scheme);\n\t\t\t}\n\t\t}\n\n\t\t// Merge auth headers with config headers\n\t\tconst existingHeaders =\n\t\t\tconfig && 'headers' in config && config.headers\n\t\t\t\t? (config.headers as Record<string, string>)\n\t\t\t\t: {};\n\n\t\tconst mergedConfig = {\n\t\t\t...config,\n\t\t\theaders: {\n\t\t\t\t...authHeaders,\n\t\t\t\t...existingHeaders,\n\t\t\t},\n\t\t} as unknown as FilteredRequestConfig<Paths, T>;\n\n\t\treturn baseFetcher.request(endpoint, mergedConfig);\n\t};\n\n\treturn fetcher as TypedApiFunction<Paths>;\n}\n\n/**\n * Resolves auth headers based on the strategy and scheme.\n */\nasync function resolveAuthHeaders(\n\tstrategy: AuthStrategy,\n\tscheme: SecuritySchemeObject,\n): Promise<Record<string, string>> {\n\tswitch (strategy.type) {\n\t\tcase 'bearer': {\n\t\t\treturn strategy.tokenProvider.createValidAuthHeaders();\n\t\t}\n\n\t\tcase 'apiKey': {\n\t\t\tconst apiKey = await strategy.apiKeyProvider.getApiKey();\n\t\t\tconst headerName = strategy.headerName || scheme.name || 'X-API-Key';\n\n\t\t\tif (scheme.in === 'header' || !scheme.in) {\n\t\t\t\treturn { [headerName]: apiKey };\n\t\t\t}\n\t\t\t// Note: query and cookie API keys are handled differently\n\t\t\t// For now, we only support header-based API keys\n\t\t\treturn {};\n\t\t}\n\n\t\tcase 'iam': {\n\t\t\t// IAM signing requires the full URL and request config\n\t\t\t// This is a simplified version - full implementation would need\n\t\t\t// access to the complete request\n\t\t\t// For now, return empty - the actual signing should be done\n\t\t\t// in a custom onRequest interceptor if needed\n\t\t\treturn {};\n\t\t}\n\t\tdefault:\n\t\t\treturn {};\n\t}\n}\n\n/**\n * Type helper to extract the security scheme ID from an endpoint.\n */\nexport type GetEndpointAuth<\n\tEndpointAuth extends Record<string, string | null>,\n\tEndpoint extends keyof EndpointAuth,\n> = EndpointAuth[Endpoint];\n\n/**\n * Type helper to get all authenticated endpoints.\n */\nexport type AuthenticatedEndpoints<\n\tEndpointAuth extends Record<string, string | null>,\n> = {\n\t[K in keyof EndpointAuth]: EndpointAuth[K] extends null ? never : K;\n}[keyof EndpointAuth];\n\n/**\n * Type helper to get all public endpoints.\n */\nexport type PublicEndpoints<\n\tEndpointAuth extends Record<string, string | null>,\n> = {\n\t[K in keyof EndpointAuth]: EndpointAuth[K] extends null ? K : never;\n}[keyof EndpointAuth];\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0JA,SAAgB,uBAWfA,SAG0B;CAC1B,MAAM,EACL,cACA,iBACA,gBACA,WAAW,cACX,GAAG,gBACH,GAAG;CAGJ,MAAM,cAAc,IAAIC,6BAAoB;EAC3C,GAAG;EACH,WAAW;CACX;CAED,MAAM,UAAU,OACfC,UACAC,WACgD;EAEhD,MAAM,aAAa,aAAa;EAIhC,IAAIC,cAAsC,CAAE;AAE5C,MAAI,YAAY;GACf,MAAM,SAAS,gBAAgB;GAG/B,MAAM,WACL,eAAe;AAEhB,OAAI,YAAY,OACf,eAAc,MAAM,mBAAmB,UAAU,OAAO;EAEzD;EAGD,MAAM,kBACL,UAAU,aAAa,UAAU,OAAO,UACpC,OAAO,UACR,CAAE;EAEN,MAAM,eAAe;GACpB,GAAG;GACH,SAAS;IACR,GAAG;IACH,GAAG;GACH;EACD;AAED,SAAO,YAAY,QAAQ,UAAU,aAAa;CAClD;AAED,QAAO;AACP;;;;AAKD,eAAe,mBACdC,UACAC,QACkC;AAClC,SAAQ,SAAS,MAAjB;EACC,KAAK,SACJ,QAAO,SAAS,cAAc,wBAAwB;EAGvD,KAAK,UAAU;GACd,MAAM,SAAS,MAAM,SAAS,eAAe,WAAW;GACxD,MAAM,aAAa,SAAS,cAAc,OAAO,QAAQ;AAEzD,OAAI,OAAO,OAAO,aAAa,OAAO,GACrC,QAAO,GAAG,aAAa,OAAQ;AAIhC,UAAO,CAAE;EACT;EAED,KAAK,MAMJ,QAAO,CAAE;EAEV,QACC,QAAO,CAAE;CACV;AACD"}
|
package/dist/auth-fetcher.d.cts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { FetcherOptions, TypedApiFunction } from "./types.cjs";
|
|
2
|
-
|
|
1
|
+
import { FetcherOptions, TypedApiFunction } from "./types-DMQMHePI.cjs";
|
|
2
|
+
|
|
3
3
|
//#region src/auth-fetcher.d.ts
|
|
4
|
+
|
|
4
5
|
/**
|
|
5
6
|
* Security scheme object matching OpenAPI 3.1 specification.
|
|
6
7
|
*/
|
|
7
|
-
|
|
8
|
+
interface SecuritySchemeObject {
|
|
8
9
|
type: 'apiKey' | 'http' | 'mutualTLS' | 'oauth2' | 'openIdConnect';
|
|
9
10
|
description?: string;
|
|
10
11
|
name?: string;
|
|
@@ -19,12 +20,12 @@ export interface SecuritySchemeObject {
|
|
|
19
20
|
* Extract all non-null security scheme IDs that are actually used in the API.
|
|
20
21
|
* This gives us the union of scheme names that endpoints require.
|
|
21
22
|
*/
|
|
22
|
-
|
|
23
|
+
type UsedSecuritySchemes<EndpointAuth extends Record<string, string | null>> = NonNullable<EndpointAuth[keyof EndpointAuth]>;
|
|
23
24
|
/**
|
|
24
25
|
* Interface for token storage and retrieval.
|
|
25
26
|
* Compatible with @geekmidas/auth TokenClient.
|
|
26
27
|
*/
|
|
27
|
-
|
|
28
|
+
interface TokenProvider {
|
|
28
29
|
/**
|
|
29
30
|
* Get a valid access token, refreshing if necessary.
|
|
30
31
|
*/
|
|
@@ -37,7 +38,7 @@ export interface TokenProvider {
|
|
|
37
38
|
/**
|
|
38
39
|
* Interface for API key providers.
|
|
39
40
|
*/
|
|
40
|
-
|
|
41
|
+
interface ApiKeyProvider {
|
|
41
42
|
/**
|
|
42
43
|
* Get the API key value.
|
|
43
44
|
*/
|
|
@@ -46,7 +47,7 @@ export interface ApiKeyProvider {
|
|
|
46
47
|
/**
|
|
47
48
|
* Interface for AWS SigV4 request signing.
|
|
48
49
|
*/
|
|
49
|
-
|
|
50
|
+
interface AwsSigner {
|
|
50
51
|
/**
|
|
51
52
|
* Sign a request with AWS SigV4.
|
|
52
53
|
* @param url - The request URL
|
|
@@ -58,7 +59,7 @@ export interface AwsSigner {
|
|
|
58
59
|
/**
|
|
59
60
|
* Auth strategy configuration for a specific security scheme type.
|
|
60
61
|
*/
|
|
61
|
-
|
|
62
|
+
type AuthStrategy = {
|
|
62
63
|
type: 'bearer';
|
|
63
64
|
tokenProvider: TokenProvider;
|
|
64
65
|
} | {
|
|
@@ -77,7 +78,7 @@ export type AuthStrategy = {
|
|
|
77
78
|
* @template EndpointAuth - Map of endpoint strings to their auth scheme (or null for public)
|
|
78
79
|
* @template SecuritySchemes - Available security scheme definitions
|
|
79
80
|
*/
|
|
80
|
-
|
|
81
|
+
interface AuthFetcherOptions<EndpointAuth extends Record<string, string | null>, SecuritySchemes extends Record<string, SecuritySchemeObject>> extends Omit<FetcherOptions, 'onRequest'> {
|
|
81
82
|
/**
|
|
82
83
|
* Runtime map of endpoints to their required auth scheme.
|
|
83
84
|
* Generated by `gkm openapi --ts`.
|
|
@@ -136,21 +137,22 @@ export interface AuthFetcherOptions<EndpointAuth extends Record<string, string |
|
|
|
136
137
|
* const tenant = await api('POST /tenants', { body: { name: 'Acme' } });
|
|
137
138
|
* ```
|
|
138
139
|
*/
|
|
139
|
-
|
|
140
|
+
declare function createAuthAwareFetcher<Paths, EndpointAuth extends Record<string, string | null> = Record<string, string | null>, SecuritySchemes extends Record<string, SecuritySchemeObject> = Record<string, SecuritySchemeObject>>(options: AuthFetcherOptions<EndpointAuth, SecuritySchemes> & {
|
|
140
141
|
baseURL: string;
|
|
141
|
-
}): TypedApiFunction<Paths
|
|
142
|
+
}): TypedApiFunction<Paths>;
|
|
142
143
|
/**
|
|
143
144
|
* Type helper to extract the security scheme ID from an endpoint.
|
|
144
145
|
*/
|
|
145
|
-
|
|
146
|
+
type GetEndpointAuth<EndpointAuth extends Record<string, string | null>, Endpoint extends keyof EndpointAuth> = EndpointAuth[Endpoint];
|
|
146
147
|
/**
|
|
147
148
|
* Type helper to get all authenticated endpoints.
|
|
148
149
|
*/
|
|
149
|
-
|
|
150
|
+
type AuthenticatedEndpoints<EndpointAuth extends Record<string, string | null>> = { [K in keyof EndpointAuth]: EndpointAuth[K] extends null ? never : K }[keyof EndpointAuth];
|
|
150
151
|
/**
|
|
151
152
|
* Type helper to get all public endpoints.
|
|
152
153
|
*/
|
|
153
|
-
|
|
154
|
+
type PublicEndpoints<EndpointAuth extends Record<string, string | null>> = { [K in keyof EndpointAuth]: EndpointAuth[K] extends null ? K : never }[keyof EndpointAuth];
|
|
155
|
+
//# sourceMappingURL=auth-fetcher.d.ts.map
|
|
154
156
|
//#endregion
|
|
155
|
-
export
|
|
157
|
+
export { ApiKeyProvider, AuthFetcherOptions, AuthStrategy, AuthenticatedEndpoints, AwsSigner, FetcherOptions, GetEndpointAuth, PublicEndpoints, SecuritySchemeObject, TokenProvider, UsedSecuritySchemes, createAuthAwareFetcher };
|
|
156
158
|
//# sourceMappingURL=auth-fetcher.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth-fetcher.d.cts","names":[],"sources":["../src/auth-fetcher.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"auth-fetcher.d.cts","names":[],"sources":["../src/auth-fetcher.ts"],"sourcesContent":[],"mappings":";;;;;AAcA;AAgBA;AAA+B,UAhBd,oBAAA,CAgBc;EAAA,IACT,EAAA,QAAA,GAAA,MAAA,GAAA,WAAA,GAAA,QAAA,GAAA,eAAA;EAAM,WACZ,CAAA,EAAA,MAAA;EAAY,IAAO,CAAA,EAAA,MAAA;EAAY,EAAA,CAA3C,EAAA,OAAA,GAAA,QAAA,GAAA,QAAA;EAAW,MAAA,CAAA,EAAA,MAAA;EAME,YAAA,CAAA,EAAA,MAAa;EAAA,KAAA,CAAA,EAjBrB,MAiBqB,CAAA,MAAA,EAAA,OAAA,CAAA;EAAA,gBAIN,CAAA,EAAA,MAAA;EAAO,CAAA,GAKI,EAAA,MAAA,CAAA,EAAA,OAAA;;AAAD;AAMlC;AAUA;;AAOyB,KAxCb,mBAwCa,CAAA,qBAvCH,MAuCG,CAAA,MAAA,EAAA,MAAA,GAAA,IAAA,CAAA,CAAA,GAtCrB,WAsCqB,CAtCT,YAsCS,CAAA,MAtCU,YAsCV,CAAA,CAAA;;;AAAqB;AAM9C;AAAwB,UAtCP,aAAA,CAsCO;EAAA;;;EAGW,mBAAA,EAAA,EArCX,OAqCW,CAAA,MAAA,GAAA,IAAA,CAAA;EASlB;;;EACW,sBACY,EAAA,EA3Cb,OA2Ca,CA3CL,MA2CK,CAAA,MAAA,EAAA,MAAA,CAAA,CAAA;;;;;AA4BI,UAjE3B,cAAA,CAiE2B;EAAY;;;EAAjC,SAKD,EAAA,EAlER,OAkEQ,CAAA,MAAA,CAAA,GAAA,MAAA;;;;;AAhCR,UA5BG,SAAA,CA4BH;EA+DE;;;;;;EAMe,IAE7B,CAAA,GAAA,EAAA,MAAA,EAAA,IAAA,EA5FuB,WA4FvB,CAAA,EA5FqC,OA4FrC,CA5F6C,MA4F7C,CAAA,MAAA,EAAA,MAAA,CAAA,CAAA;;;;;AAMkB,KA5FR,YAAA,GA4FQ;EAAK,IAAtB,EAAA,QAAA;EAAgB,aAAA,EA3FiB,aA2FjB;AAkGnB,CAAA,GAAY;EAAe,IAAA,EAAA,QAAA;EAAA,cACL,EA7Le,cA6Lf;EAAM,UACJ,CAAA,EAAA,MAAA;CAAY,GAAA;EACpB,IAAC,EAAA,KAAA;EAAQ,MAAA,EA9LC,SA8LD;AAKzB,CAAA,GAAY;EAAsB,IAAA,EAAA,MAAA;CAAA;;;;;;AAId;AAKR,UAnMK,kBAmMU,CAAA,qBAlML,MAkMK,CAAA,MAAA,EAAA,MAAA,GAAA,IAAA,CAAA,EAAA,wBAjMF,MAiME,CAAA,MAAA,EAjMa,oBAiMb,CAAA,CAAA,SAhMjB,IAgMiB,CAhMZ,cAgMY,EAAA,WAAA,CAAA,CAAA;EAAA;;;;EAGa,YAAC,EA9L1B,YA8L0B;EAAC;;AACtB;;mBAzLF;;;;;;;;;;;;;;;kBAgBD,OAAO,oBAAoB,eAAe;;;;uBAKrC,gBAAgB,cAAc,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA+B5C,mDAEM,gCAAgC,uDAI7B,eAAe,wBAAwB,eAE9D,gCAGQ,mBAAmB,cAAc;;IAGxC,iBAAiB;;;;KAkGR,qCACU,sDACE,gBACpB,aAAa;;;;KAKL,4CACU,+CAET,eAAe,aAAa,0BAA0B,UAC3D;;;;KAKI,qCACU,+CAET,eAAe,aAAa,kBAAkB,kBACnD"}
|
package/dist/auth-fetcher.d.mts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { FetcherOptions, TypedApiFunction } from "./types.mjs";
|
|
2
|
-
|
|
1
|
+
import { FetcherOptions, TypedApiFunction } from "./types-D8Jrl4o3.mjs";
|
|
2
|
+
|
|
3
3
|
//#region src/auth-fetcher.d.ts
|
|
4
|
+
|
|
4
5
|
/**
|
|
5
6
|
* Security scheme object matching OpenAPI 3.1 specification.
|
|
6
7
|
*/
|
|
7
|
-
|
|
8
|
+
interface SecuritySchemeObject {
|
|
8
9
|
type: 'apiKey' | 'http' | 'mutualTLS' | 'oauth2' | 'openIdConnect';
|
|
9
10
|
description?: string;
|
|
10
11
|
name?: string;
|
|
@@ -19,12 +20,12 @@ export interface SecuritySchemeObject {
|
|
|
19
20
|
* Extract all non-null security scheme IDs that are actually used in the API.
|
|
20
21
|
* This gives us the union of scheme names that endpoints require.
|
|
21
22
|
*/
|
|
22
|
-
|
|
23
|
+
type UsedSecuritySchemes<EndpointAuth extends Record<string, string | null>> = NonNullable<EndpointAuth[keyof EndpointAuth]>;
|
|
23
24
|
/**
|
|
24
25
|
* Interface for token storage and retrieval.
|
|
25
26
|
* Compatible with @geekmidas/auth TokenClient.
|
|
26
27
|
*/
|
|
27
|
-
|
|
28
|
+
interface TokenProvider {
|
|
28
29
|
/**
|
|
29
30
|
* Get a valid access token, refreshing if necessary.
|
|
30
31
|
*/
|
|
@@ -37,7 +38,7 @@ export interface TokenProvider {
|
|
|
37
38
|
/**
|
|
38
39
|
* Interface for API key providers.
|
|
39
40
|
*/
|
|
40
|
-
|
|
41
|
+
interface ApiKeyProvider {
|
|
41
42
|
/**
|
|
42
43
|
* Get the API key value.
|
|
43
44
|
*/
|
|
@@ -46,7 +47,7 @@ export interface ApiKeyProvider {
|
|
|
46
47
|
/**
|
|
47
48
|
* Interface for AWS SigV4 request signing.
|
|
48
49
|
*/
|
|
49
|
-
|
|
50
|
+
interface AwsSigner {
|
|
50
51
|
/**
|
|
51
52
|
* Sign a request with AWS SigV4.
|
|
52
53
|
* @param url - The request URL
|
|
@@ -58,7 +59,7 @@ export interface AwsSigner {
|
|
|
58
59
|
/**
|
|
59
60
|
* Auth strategy configuration for a specific security scheme type.
|
|
60
61
|
*/
|
|
61
|
-
|
|
62
|
+
type AuthStrategy = {
|
|
62
63
|
type: 'bearer';
|
|
63
64
|
tokenProvider: TokenProvider;
|
|
64
65
|
} | {
|
|
@@ -77,7 +78,7 @@ export type AuthStrategy = {
|
|
|
77
78
|
* @template EndpointAuth - Map of endpoint strings to their auth scheme (or null for public)
|
|
78
79
|
* @template SecuritySchemes - Available security scheme definitions
|
|
79
80
|
*/
|
|
80
|
-
|
|
81
|
+
interface AuthFetcherOptions<EndpointAuth extends Record<string, string | null>, SecuritySchemes extends Record<string, SecuritySchemeObject>> extends Omit<FetcherOptions, 'onRequest'> {
|
|
81
82
|
/**
|
|
82
83
|
* Runtime map of endpoints to their required auth scheme.
|
|
83
84
|
* Generated by `gkm openapi --ts`.
|
|
@@ -136,21 +137,22 @@ export interface AuthFetcherOptions<EndpointAuth extends Record<string, string |
|
|
|
136
137
|
* const tenant = await api('POST /tenants', { body: { name: 'Acme' } });
|
|
137
138
|
* ```
|
|
138
139
|
*/
|
|
139
|
-
|
|
140
|
+
declare function createAuthAwareFetcher<Paths, EndpointAuth extends Record<string, string | null> = Record<string, string | null>, SecuritySchemes extends Record<string, SecuritySchemeObject> = Record<string, SecuritySchemeObject>>(options: AuthFetcherOptions<EndpointAuth, SecuritySchemes> & {
|
|
140
141
|
baseURL: string;
|
|
141
|
-
}): TypedApiFunction<Paths
|
|
142
|
+
}): TypedApiFunction<Paths>;
|
|
142
143
|
/**
|
|
143
144
|
* Type helper to extract the security scheme ID from an endpoint.
|
|
144
145
|
*/
|
|
145
|
-
|
|
146
|
+
type GetEndpointAuth<EndpointAuth extends Record<string, string | null>, Endpoint extends keyof EndpointAuth> = EndpointAuth[Endpoint];
|
|
146
147
|
/**
|
|
147
148
|
* Type helper to get all authenticated endpoints.
|
|
148
149
|
*/
|
|
149
|
-
|
|
150
|
+
type AuthenticatedEndpoints<EndpointAuth extends Record<string, string | null>> = { [K in keyof EndpointAuth]: EndpointAuth[K] extends null ? never : K }[keyof EndpointAuth];
|
|
150
151
|
/**
|
|
151
152
|
* Type helper to get all public endpoints.
|
|
152
153
|
*/
|
|
153
|
-
|
|
154
|
+
type PublicEndpoints<EndpointAuth extends Record<string, string | null>> = { [K in keyof EndpointAuth]: EndpointAuth[K] extends null ? K : never }[keyof EndpointAuth];
|
|
155
|
+
//# sourceMappingURL=auth-fetcher.d.ts.map
|
|
154
156
|
//#endregion
|
|
155
|
-
export
|
|
157
|
+
export { ApiKeyProvider, AuthFetcherOptions, AuthStrategy, AuthenticatedEndpoints, AwsSigner, FetcherOptions, GetEndpointAuth, PublicEndpoints, SecuritySchemeObject, TokenProvider, UsedSecuritySchemes, createAuthAwareFetcher };
|
|
156
158
|
//# sourceMappingURL=auth-fetcher.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth-fetcher.d.mts","names":[],"sources":["../src/auth-fetcher.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"auth-fetcher.d.mts","names":[],"sources":["../src/auth-fetcher.ts"],"sourcesContent":[],"mappings":";;;;;AAcA;AAgBA;AAA+B,UAhBd,oBAAA,CAgBc;EAAA,IACT,EAAA,QAAA,GAAA,MAAA,GAAA,WAAA,GAAA,QAAA,GAAA,eAAA;EAAM,WACZ,CAAA,EAAA,MAAA;EAAY,IAAO,CAAA,EAAA,MAAA;EAAY,EAAA,CAA3C,EAAA,OAAA,GAAA,QAAA,GAAA,QAAA;EAAW,MAAA,CAAA,EAAA,MAAA;EAME,YAAA,CAAA,EAAA,MAAa;EAAA,KAAA,CAAA,EAjBrB,MAiBqB,CAAA,MAAA,EAAA,OAAA,CAAA;EAAA,gBAIN,CAAA,EAAA,MAAA;EAAO,CAAA,GAKI,EAAA,MAAA,CAAA,EAAA,OAAA;;AAAD;AAMlC;AAUA;;AAOyB,KAxCb,mBAwCa,CAAA,qBAvCH,MAuCG,CAAA,MAAA,EAAA,MAAA,GAAA,IAAA,CAAA,CAAA,GAtCrB,WAsCqB,CAtCT,YAsCS,CAAA,MAtCU,YAsCV,CAAA,CAAA;;;AAAqB;AAM9C;AAAwB,UAtCP,aAAA,CAsCO;EAAA;;;EAGW,mBAAA,EAAA,EArCX,OAqCW,CAAA,MAAA,GAAA,IAAA,CAAA;EASlB;;;EACW,sBACY,EAAA,EA3Cb,OA2Ca,CA3CL,MA2CK,CAAA,MAAA,EAAA,MAAA,CAAA,CAAA;;;;;AA4BI,UAjE3B,cAAA,CAiE2B;EAAY;;;EAAjC,SAKD,EAAA,EAlER,OAkEQ,CAAA,MAAA,CAAA,GAAA,MAAA;;;;;AAhCR,UA5BG,SAAA,CA4BH;EA+DE;;;;;;EAMe,IAE7B,CAAA,GAAA,EAAA,MAAA,EAAA,IAAA,EA5FuB,WA4FvB,CAAA,EA5FqC,OA4FrC,CA5F6C,MA4F7C,CAAA,MAAA,EAAA,MAAA,CAAA,CAAA;;;;;AAMkB,KA5FR,YAAA,GA4FQ;EAAK,IAAtB,EAAA,QAAA;EAAgB,aAAA,EA3FiB,aA2FjB;AAkGnB,CAAA,GAAY;EAAe,IAAA,EAAA,QAAA;EAAA,cACL,EA7Le,cA6Lf;EAAM,UACJ,CAAA,EAAA,MAAA;CAAY,GAAA;EACpB,IAAC,EAAA,KAAA;EAAQ,MAAA,EA9LC,SA8LD;AAKzB,CAAA,GAAY;EAAsB,IAAA,EAAA,MAAA;CAAA;;;;;;AAId;AAKR,UAnMK,kBAmMU,CAAA,qBAlML,MAkMK,CAAA,MAAA,EAAA,MAAA,GAAA,IAAA,CAAA,EAAA,wBAjMF,MAiME,CAAA,MAAA,EAjMa,oBAiMb,CAAA,CAAA,SAhMjB,IAgMiB,CAhMZ,cAgMY,EAAA,WAAA,CAAA,CAAA;EAAA;;;;EAGa,YAAC,EA9L1B,YA8L0B;EAAC;;AACtB;;mBAzLF;;;;;;;;;;;;;;;kBAgBD,OAAO,oBAAoB,eAAe;;;;uBAKrC,gBAAgB,cAAc,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA+B5C,mDAEM,gCAAgC,uDAI7B,eAAe,wBAAwB,eAE9D,gCAGQ,mBAAmB,cAAc;;IAGxC,iBAAiB;;;;KAkGR,qCACU,sDACE,gBACpB,aAAa;;;;KAKL,4CACU,+CAET,eAAe,aAAa,0BAA0B,UAC3D;;;;KAKI,qCACU,+CAET,eAAe,aAAa,kBAAkB,kBACnD"}
|