@geekmidas/client 10.0.0-alpha.12 → 10.0.0-alpha.14

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 (99) hide show
  1. package/README.md +6 -44
  2. package/dist/auth-fetcher.cjs +76 -3
  3. package/dist/auth-fetcher.cjs.map +1 -0
  4. package/dist/auth-fetcher.d.cts +155 -3
  5. package/dist/auth-fetcher.d.cts.map +1 -0
  6. package/dist/auth-fetcher.d.mts +155 -3
  7. package/dist/auth-fetcher.d.mts.map +1 -0
  8. package/dist/auth-fetcher.mjs +75 -3
  9. package/dist/auth-fetcher.mjs.map +1 -0
  10. package/dist/endpoint-hooks.cjs +11 -15
  11. package/dist/endpoint-hooks.cjs.map +1 -1
  12. package/dist/endpoint-hooks.d.cts +4 -7
  13. package/dist/endpoint-hooks.d.cts.map +1 -1
  14. package/dist/endpoint-hooks.d.mts +4 -7
  15. package/dist/endpoint-hooks.d.mts.map +1 -1
  16. package/dist/endpoint-hooks.mjs +5 -9
  17. package/dist/endpoint-hooks.mjs.map +1 -1
  18. package/dist/fetcher.cjs +110 -3
  19. package/dist/fetcher.cjs.map +1 -0
  20. package/dist/fetcher.d.cts +22 -3
  21. package/dist/fetcher.d.cts.map +1 -0
  22. package/dist/fetcher.d.mts +22 -3
  23. package/dist/fetcher.d.mts.map +1 -0
  24. package/dist/fetcher.mjs +85 -2
  25. package/dist/fetcher.mjs.map +1 -0
  26. package/dist/index.cjs +6 -6
  27. package/dist/index.d.cts +4 -4
  28. package/dist/index.d.mts +4 -4
  29. package/dist/index.mjs +5 -6
  30. package/dist/infer.cjs +0 -1
  31. package/dist/infer.d.cts +130 -2
  32. package/dist/infer.d.cts.map +1 -0
  33. package/dist/infer.d.mts +130 -2
  34. package/dist/infer.d.mts.map +1 -0
  35. package/dist/infer.mjs +1 -1
  36. package/dist/openapi-hooks.cjs +13 -16
  37. package/dist/openapi-hooks.cjs.map +1 -1
  38. package/dist/openapi-hooks.d.cts +8 -11
  39. package/dist/openapi-hooks.d.cts.map +1 -1
  40. package/dist/openapi-hooks.d.mts +8 -11
  41. package/dist/openapi-hooks.d.mts.map +1 -1
  42. package/dist/openapi-hooks.mjs +9 -12
  43. package/dist/openapi-hooks.mjs.map +1 -1
  44. package/dist/openapi-types.d.cts +5 -6
  45. package/dist/openapi-types.d.cts.map +1 -1
  46. package/dist/openapi-types.d.mts +5 -6
  47. package/dist/openapi-types.d.mts.map +1 -1
  48. package/dist/openapi.cjs +25 -23
  49. package/dist/openapi.cjs.map +1 -1
  50. package/dist/openapi.d.cts +494 -0
  51. package/dist/openapi.d.cts.map +1 -0
  52. package/dist/openapi.d.mts +494 -0
  53. package/dist/openapi.d.mts.map +1 -0
  54. package/dist/openapi.mjs +1 -1
  55. package/dist/openapi.mjs.map +1 -1
  56. package/dist/react-query.cjs +17 -16
  57. package/dist/react-query.cjs.map +1 -1
  58. package/dist/react-query.d.cts +12 -17
  59. package/dist/react-query.d.cts.map +1 -1
  60. package/dist/react-query.d.mts +12 -17
  61. package/dist/react-query.d.mts.map +1 -1
  62. package/dist/react-query.mjs +10 -9
  63. package/dist/react-query.mjs.map +1 -1
  64. package/dist/types.cjs +0 -1
  65. package/dist/types.d.cts +109 -2
  66. package/dist/types.d.cts.map +1 -0
  67. package/dist/types.d.mts +109 -2
  68. package/dist/types.d.mts.map +1 -0
  69. package/dist/types.mjs +1 -1
  70. package/package.json +5 -5
  71. package/dist/auth-fetcher-CBYuL6rx.d.cts +0 -158
  72. package/dist/auth-fetcher-CBYuL6rx.d.cts.map +0 -1
  73. package/dist/auth-fetcher-DOj0iz21.mjs +0 -77
  74. package/dist/auth-fetcher-DOj0iz21.mjs.map +0 -1
  75. package/dist/auth-fetcher-DxS8zOLc.d.mts +0 -158
  76. package/dist/auth-fetcher-DxS8zOLc.d.mts.map +0 -1
  77. package/dist/auth-fetcher-HILABmws.cjs +0 -82
  78. package/dist/auth-fetcher-HILABmws.cjs.map +0 -1
  79. package/dist/chunk-CUT6urMc.cjs +0 -30
  80. package/dist/fetcher-C1xtCKpT.d.mts +0 -25
  81. package/dist/fetcher-C1xtCKpT.d.mts.map +0 -1
  82. package/dist/fetcher-CakjC9C7.mjs +0 -88
  83. package/dist/fetcher-CakjC9C7.mjs.map +0 -1
  84. package/dist/fetcher-CwnSqc4D.cjs +0 -100
  85. package/dist/fetcher-CwnSqc4D.cjs.map +0 -1
  86. package/dist/fetcher-cDrfwN-Y.d.cts +0 -25
  87. package/dist/fetcher-cDrfwN-Y.d.cts.map +0 -1
  88. package/dist/infer-6KKCgmg1.cjs +0 -0
  89. package/dist/infer-CPRqfabW.d.cts +0 -133
  90. package/dist/infer-CPRqfabW.d.cts.map +0 -1
  91. package/dist/infer-D9CgpOuc.d.mts +0 -133
  92. package/dist/infer-D9CgpOuc.d.mts.map +0 -1
  93. package/dist/infer-uCUq1whM.mjs +0 -0
  94. package/dist/types-BH8WgGrm.mjs +0 -0
  95. package/dist/types-BMGM6sZc.d.mts +0 -110
  96. package/dist/types-BMGM6sZc.d.mts.map +0 -1
  97. package/dist/types-DMQMHePI.d.cts +0 -110
  98. package/dist/types-DMQMHePI.d.cts.map +0 -1
  99. package/dist/types-a8gm_IaQ.cjs +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 generation
44
- import { generateReactQueryHooks } from '@geekmidas/client/openapi';
43
+ // OpenAPI hooks from a paths type
44
+ import { createOpenAPIHooks } from '@geekmidas/client/openapi';
45
45
 
46
46
  // Type utilities
47
47
  import type { TypedApiFunction, FilteredRequestConfig } from '@geekmidas/client/types';
@@ -379,48 +379,10 @@ const api = Object.assign(fetcher, hooks);
379
379
 
380
380
  ## OpenAPI Code Generation
381
381
 
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
- ```
382
+ Each surface's typed client is written by `gkm build` (and kept current by
383
+ `gkm dev`) to `.gkm/openapi/<surface>.ts`: its `createApi()` returns a typed
384
+ fetcher with React Query hooks, built from the endpoints themselves rather
385
+ than from a spec file.
424
386
 
425
387
  ## Advanced Features
426
388
 
@@ -1,4 +1,77 @@
1
- require('./fetcher-CwnSqc4D.cjs');
2
- const require_auth_fetcher = require('./auth-fetcher-HILABmws.cjs');
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_fetcher = require("./fetcher.cjs");
3
+ //#region src/auth-fetcher.ts
4
+ /**
5
+ * Creates an auth-aware fetcher that automatically applies the correct
6
+ * authentication based on the endpoint being called.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * import { endpointAuth, securitySchemes, paths } from './openapi';
11
+ * import { TokenClient } from '@geekmidas/auth/client';
12
+ *
13
+ * const tokenClient = new TokenClient({ ... });
14
+ *
15
+ * const api = createAuthAwareFetcher<paths>({
16
+ * baseURL: 'https://api.example.com',
17
+ * endpointAuth,
18
+ * securitySchemes,
19
+ * authStrategies: {
20
+ * bearer: { type: 'bearer', tokenProvider: tokenClient },
21
+ * iam: { type: 'iam', signer: awsSigner },
22
+ * },
23
+ * });
24
+ *
25
+ * // Bearer auth automatically applied
26
+ * const user = await api('GET /users/{id}', { params: { id: '123' } });
27
+ *
28
+ * // IAM SigV4 auth automatically applied
29
+ * const tenant = await api('POST /tenants', { body: { name: 'Acme' } });
30
+ * ```
31
+ */
32
+ function createAuthAwareFetcher(options) {
33
+ const { endpointAuth, securitySchemes, authStrategies, onRequest: userOnRequest, ...fetcherOptions } = options;
34
+ const baseFetcher = new require_fetcher.TypedFetcher({
35
+ ...fetcherOptions,
36
+ onRequest: userOnRequest
37
+ });
38
+ const fetcher = async (endpoint, config) => {
39
+ const schemeName = endpointAuth[endpoint];
40
+ let authHeaders = {};
41
+ if (schemeName) {
42
+ const scheme = securitySchemes[schemeName];
43
+ const strategy = authStrategies[schemeName];
44
+ if (strategy && scheme) authHeaders = await resolveAuthHeaders(strategy, scheme);
45
+ }
46
+ const existingHeaders = config && "headers" in config && config.headers ? config.headers : {};
47
+ const mergedConfig = {
48
+ ...config,
49
+ headers: {
50
+ ...authHeaders,
51
+ ...existingHeaders
52
+ }
53
+ };
54
+ return baseFetcher.request(endpoint, mergedConfig);
55
+ };
56
+ return fetcher;
57
+ }
58
+ /**
59
+ * Resolves auth headers based on the strategy and scheme.
60
+ */
61
+ async function resolveAuthHeaders(strategy, scheme) {
62
+ switch (strategy.type) {
63
+ case "bearer": return strategy.tokenProvider.createValidAuthHeaders();
64
+ case "apiKey": {
65
+ const apiKey = await strategy.apiKeyProvider.getApiKey();
66
+ const headerName = strategy.headerName || scheme.name || "X-API-Key";
67
+ if (scheme.in === "header" || !scheme.in) return { [headerName]: apiKey };
68
+ return {};
69
+ }
70
+ case "iam": return {};
71
+ default: return {};
72
+ }
73
+ }
74
+ //#endregion
75
+ exports.createAuthAwareFetcher = createAuthAwareFetcher;
3
76
 
4
- exports.createAuthAwareFetcher = require_auth_fetcher.createAuthAwareFetcher;
77
+ //# sourceMappingURL=auth-fetcher.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-fetcher.cjs","names":["TypedFetcher"],"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,uBAWf,SAG0B;CAC1B,MAAM,EACL,cACA,iBACA,gBACA,WAAW,eACX,GAAG,mBACA;CAGJ,MAAM,cAAc,IAAIA,gBAAAA,aAAoB;EAC3C,GAAG;EACH,WAAW;CACZ,CAAC;CAED,MAAM,UAAU,OACf,UACA,WACgD;EAEhD,MAAM,aAAa,aAAa;EAIhC,IAAI,cAAsC,CAAC;EAE3C,IAAI,YAAY;GACf,MAAM,SAAS,gBAAgB;GAG/B,MAAM,WACL,eAAe;GAEhB,IAAI,YAAY,QACf,cAAc,MAAM,mBAAmB,UAAU,MAAM;EAEzD;EAGA,MAAM,kBACL,UAAU,aAAa,UAAU,OAAO,UACpC,OAAO,UACR,CAAC;EAEL,MAAM,eAAe;GACpB,GAAG;GACH,SAAS;IACR,GAAG;IACH,GAAG;GACJ;EACD;EAEA,OAAO,YAAY,QAAQ,UAAU,YAAY;CAClD;CAEA,OAAO;AACR;;;;AAKA,eAAe,mBACd,UACA,QACkC;CAClC,QAAQ,SAAS,MAAjB;EACC,KAAK,UACJ,OAAO,SAAS,cAAc,uBAAuB;EAGtD,KAAK,UAAU;GACd,MAAM,SAAS,MAAM,SAAS,eAAe,UAAU;GACvD,MAAM,aAAa,SAAS,cAAc,OAAO,QAAQ;GAEzD,IAAI,OAAO,OAAO,YAAY,CAAC,OAAO,IACrC,OAAO,GAAG,aAAa,OAAO;GAI/B,OAAO,CAAC;EACT;EAEA,KAAK,OAMJ,OAAO,CAAC;EAET,SACC,OAAO,CAAC;CACV;AACD"}
@@ -1,3 +1,155 @@
1
- import { FetcherOptions } from "./types-DMQMHePI.cjs";
2
- import { ApiKeyProvider, AuthFetcherOptions, AuthStrategy, AuthenticatedEndpoints, AwsSigner, GetEndpointAuth, PublicEndpoints, SecuritySchemeObject, TokenProvider, UsedSecuritySchemes, createAuthAwareFetcher } from "./auth-fetcher-CBYuL6rx.cjs";
3
- export { ApiKeyProvider, AuthFetcherOptions, AuthStrategy, AuthenticatedEndpoints, AwsSigner, FetcherOptions, GetEndpointAuth, PublicEndpoints, SecuritySchemeObject, TokenProvider, UsedSecuritySchemes, createAuthAwareFetcher };
1
+ import { FetcherOptions, TypedApiFunction } from "./types.cjs";
2
+ //#region src/auth-fetcher.d.ts
3
+ /**
4
+ * Security scheme object matching OpenAPI 3.1 specification.
5
+ */
6
+ export interface SecuritySchemeObject {
7
+ type: 'apiKey' | 'http' | 'mutualTLS' | 'oauth2' | 'openIdConnect';
8
+ description?: string;
9
+ name?: string;
10
+ in?: 'query' | 'header' | 'cookie';
11
+ scheme?: string;
12
+ bearerFormat?: string;
13
+ flows?: Record<string, unknown>;
14
+ openIdConnectUrl?: string;
15
+ [key: string]: unknown;
16
+ }
17
+ /**
18
+ * Extract all non-null security scheme IDs that are actually used in the API.
19
+ * This gives us the union of scheme names that endpoints require.
20
+ */
21
+ export type UsedSecuritySchemes<EndpointAuth extends Record<string, string | null>> = NonNullable<EndpointAuth[keyof EndpointAuth]>;
22
+ /**
23
+ * Interface for token storage and retrieval.
24
+ * Compatible with @geekmidas/auth TokenClient.
25
+ */
26
+ export interface TokenProvider {
27
+ /**
28
+ * Get a valid access token, refreshing if necessary.
29
+ */
30
+ getValidAccessToken(): Promise<string | null>;
31
+ /**
32
+ * Create Authorization headers from the current token.
33
+ */
34
+ createValidAuthHeaders(): Promise<Record<string, string>>;
35
+ }
36
+ /**
37
+ * Interface for API key providers.
38
+ */
39
+ export interface ApiKeyProvider {
40
+ /**
41
+ * Get the API key value.
42
+ */
43
+ getApiKey(): Promise<string> | string;
44
+ }
45
+ /**
46
+ * Interface for AWS SigV4 request signing.
47
+ */
48
+ export interface AwsSigner {
49
+ /**
50
+ * Sign a request with AWS SigV4.
51
+ * @param url - The request URL
52
+ * @param init - The request init object
53
+ * @returns Headers to add to the request
54
+ */
55
+ sign(url: string, init: RequestInit): Promise<Record<string, string>>;
56
+ }
57
+ /**
58
+ * Auth strategy configuration for a specific security scheme type.
59
+ */
60
+ export type AuthStrategy = {
61
+ type: 'bearer';
62
+ tokenProvider: TokenProvider;
63
+ } | {
64
+ type: 'apiKey';
65
+ apiKeyProvider: ApiKeyProvider;
66
+ headerName?: string;
67
+ } | {
68
+ type: 'iam';
69
+ signer: AwsSigner;
70
+ } | {
71
+ type: 'none';
72
+ };
73
+ /**
74
+ * Options for creating an auth-aware fetcher.
75
+ *
76
+ * @template EndpointAuth - Map of endpoint strings to their auth scheme (or null for public)
77
+ * @template SecuritySchemes - Available security scheme definitions
78
+ */
79
+ export interface AuthFetcherOptions<EndpointAuth extends Record<string, string | null>, SecuritySchemes extends Record<string, SecuritySchemeObject>> extends Omit<FetcherOptions, 'onRequest'> {
80
+ /**
81
+ * Runtime map of endpoints to their required auth scheme.
82
+ * Generated by `gkm openapi --ts`.
83
+ */
84
+ endpointAuth: EndpointAuth;
85
+ /**
86
+ * Security scheme definitions.
87
+ * Generated by `gkm openapi --ts`.
88
+ */
89
+ securitySchemes: SecuritySchemes;
90
+ /**
91
+ * Auth strategies for security schemes that are actually used.
92
+ * Only schemes referenced in endpointAuth are required.
93
+ *
94
+ * @example
95
+ * ```typescript
96
+ * // If endpointAuth has: { 'GET /users': 'jwt', 'POST /data': 'iam', 'GET /public': null }
97
+ * // Then authStrategies must include strategies for 'jwt' and 'iam'
98
+ * authStrategies: {
99
+ * jwt: { type: 'bearer', tokenProvider },
100
+ * iam: { type: 'iam', signer: awsSigner },
101
+ * }
102
+ * ```
103
+ */
104
+ authStrategies: Record<UsedSecuritySchemes<EndpointAuth>, AuthStrategy>;
105
+ /**
106
+ * Optional request interceptor (runs after auth headers are added).
107
+ */
108
+ onRequest?: (config: RequestInit) => RequestInit | Promise<RequestInit>;
109
+ }
110
+ /**
111
+ * Creates an auth-aware fetcher that automatically applies the correct
112
+ * authentication based on the endpoint being called.
113
+ *
114
+ * @example
115
+ * ```typescript
116
+ * import { endpointAuth, securitySchemes, paths } from './openapi';
117
+ * import { TokenClient } from '@geekmidas/auth/client';
118
+ *
119
+ * const tokenClient = new TokenClient({ ... });
120
+ *
121
+ * const api = createAuthAwareFetcher<paths>({
122
+ * baseURL: 'https://api.example.com',
123
+ * endpointAuth,
124
+ * securitySchemes,
125
+ * authStrategies: {
126
+ * bearer: { type: 'bearer', tokenProvider: tokenClient },
127
+ * iam: { type: 'iam', signer: awsSigner },
128
+ * },
129
+ * });
130
+ *
131
+ * // Bearer auth automatically applied
132
+ * const user = await api('GET /users/{id}', { params: { id: '123' } });
133
+ *
134
+ * // IAM SigV4 auth automatically applied
135
+ * const tenant = await api('POST /tenants', { body: { name: 'Acme' } });
136
+ * ```
137
+ */
138
+ export 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> & {
139
+ baseURL: string;
140
+ }): TypedApiFunction<Paths>;
141
+ /**
142
+ * Type helper to extract the security scheme ID from an endpoint.
143
+ */
144
+ export type GetEndpointAuth<EndpointAuth extends Record<string, string | null>, Endpoint extends keyof EndpointAuth> = EndpointAuth[Endpoint];
145
+ /**
146
+ * Type helper to get all authenticated endpoints.
147
+ */
148
+ export type AuthenticatedEndpoints<EndpointAuth extends Record<string, string | null>> = { [K in keyof EndpointAuth]: EndpointAuth[K] extends null ? never : K; }[keyof EndpointAuth];
149
+ /**
150
+ * Type helper to get all public endpoints.
151
+ */
152
+ export type PublicEndpoints<EndpointAuth extends Record<string, string | null>> = { [K in keyof EndpointAuth]: EndpointAuth[K] extends null ? K : never; }[keyof EndpointAuth];
153
+ //#endregion
154
+ export type { FetcherOptions };
155
+ //# sourceMappingURL=auth-fetcher.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-fetcher.d.cts","names":[],"sources":["../src/auth-fetcher.ts"],"mappings":";;;;;iBAciB;EAChB;EACA;EACA;EACA;EACA;EACA;EACA,QAAQ;EACR;GACC;;;;;;YAOU,oBACX,qBAAqB,iCAClB,YAAY,mBAAmB;;;;;iBAMlB;;;;EAIhB,uBAAuB;;;;EAKvB,0BAA0B,QAAQ;;;;;iBAMlB;;;;EAIhB,aAAa;;;;;iBAMG;;;;;;;EAOhB,KAAK,aAAa,MAAM,cAAc,QAAQ;;;;;YAMnC;EACP;EAAgB,eAAe;;EAC/B;EAAgB,gBAAgB;EAAgB;;EAChD;EAAa,QAAQ;;EACrB;;;;;;;;iBAQY,mBAChB,qBAAqB,+BACrB,wBAAwB,eAAe,+BAC9B,KAAK;;;;;EAKd,cAAc;;;;;EAMd,iBAAiB;;;;;;;;;;;;;;;EAgBjB,gBAAgB,OAAO,oBAAoB,eAAe;;;;EAK1D,aAAa,QAAQ,gBAAgB,cAAc,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA+B5C,uBACf,OACA,qBAAqB,gCAAgC,+BAIrD,wBAAwB,eAAe,wBAAwB,eAE9D,uBAGD,SAAS,mBAAmB,cAAc;EACzC;IAEC,iBAAiB;;;;YAkGR,gBACX,qBAAqB,+BACrB,uBAAuB,gBACpB,aAAa;;;;YAKL,uBACX,qBAAqB,oCAEpB,WAAW,eAAe,aAAa,0BAA0B,WAC3D;;;;YAKI,gBACX,qBAAqB,oCAEpB,WAAW,eAAe,aAAa,kBAAkB,mBACnD"}
@@ -1,3 +1,155 @@
1
- import { FetcherOptions } from "./types-BMGM6sZc.mjs";
2
- import { ApiKeyProvider, AuthFetcherOptions, AuthStrategy, AuthenticatedEndpoints, AwsSigner, GetEndpointAuth, PublicEndpoints, SecuritySchemeObject, TokenProvider, UsedSecuritySchemes, createAuthAwareFetcher } from "./auth-fetcher-DxS8zOLc.mjs";
3
- export { ApiKeyProvider, AuthFetcherOptions, AuthStrategy, AuthenticatedEndpoints, AwsSigner, FetcherOptions, GetEndpointAuth, PublicEndpoints, SecuritySchemeObject, TokenProvider, UsedSecuritySchemes, createAuthAwareFetcher };
1
+ import { FetcherOptions, TypedApiFunction } from "./types.mjs";
2
+ //#region src/auth-fetcher.d.ts
3
+ /**
4
+ * Security scheme object matching OpenAPI 3.1 specification.
5
+ */
6
+ export interface SecuritySchemeObject {
7
+ type: 'apiKey' | 'http' | 'mutualTLS' | 'oauth2' | 'openIdConnect';
8
+ description?: string;
9
+ name?: string;
10
+ in?: 'query' | 'header' | 'cookie';
11
+ scheme?: string;
12
+ bearerFormat?: string;
13
+ flows?: Record<string, unknown>;
14
+ openIdConnectUrl?: string;
15
+ [key: string]: unknown;
16
+ }
17
+ /**
18
+ * Extract all non-null security scheme IDs that are actually used in the API.
19
+ * This gives us the union of scheme names that endpoints require.
20
+ */
21
+ export type UsedSecuritySchemes<EndpointAuth extends Record<string, string | null>> = NonNullable<EndpointAuth[keyof EndpointAuth]>;
22
+ /**
23
+ * Interface for token storage and retrieval.
24
+ * Compatible with @geekmidas/auth TokenClient.
25
+ */
26
+ export interface TokenProvider {
27
+ /**
28
+ * Get a valid access token, refreshing if necessary.
29
+ */
30
+ getValidAccessToken(): Promise<string | null>;
31
+ /**
32
+ * Create Authorization headers from the current token.
33
+ */
34
+ createValidAuthHeaders(): Promise<Record<string, string>>;
35
+ }
36
+ /**
37
+ * Interface for API key providers.
38
+ */
39
+ export interface ApiKeyProvider {
40
+ /**
41
+ * Get the API key value.
42
+ */
43
+ getApiKey(): Promise<string> | string;
44
+ }
45
+ /**
46
+ * Interface for AWS SigV4 request signing.
47
+ */
48
+ export interface AwsSigner {
49
+ /**
50
+ * Sign a request with AWS SigV4.
51
+ * @param url - The request URL
52
+ * @param init - The request init object
53
+ * @returns Headers to add to the request
54
+ */
55
+ sign(url: string, init: RequestInit): Promise<Record<string, string>>;
56
+ }
57
+ /**
58
+ * Auth strategy configuration for a specific security scheme type.
59
+ */
60
+ export type AuthStrategy = {
61
+ type: 'bearer';
62
+ tokenProvider: TokenProvider;
63
+ } | {
64
+ type: 'apiKey';
65
+ apiKeyProvider: ApiKeyProvider;
66
+ headerName?: string;
67
+ } | {
68
+ type: 'iam';
69
+ signer: AwsSigner;
70
+ } | {
71
+ type: 'none';
72
+ };
73
+ /**
74
+ * Options for creating an auth-aware fetcher.
75
+ *
76
+ * @template EndpointAuth - Map of endpoint strings to their auth scheme (or null for public)
77
+ * @template SecuritySchemes - Available security scheme definitions
78
+ */
79
+ export interface AuthFetcherOptions<EndpointAuth extends Record<string, string | null>, SecuritySchemes extends Record<string, SecuritySchemeObject>> extends Omit<FetcherOptions, 'onRequest'> {
80
+ /**
81
+ * Runtime map of endpoints to their required auth scheme.
82
+ * Generated by `gkm openapi --ts`.
83
+ */
84
+ endpointAuth: EndpointAuth;
85
+ /**
86
+ * Security scheme definitions.
87
+ * Generated by `gkm openapi --ts`.
88
+ */
89
+ securitySchemes: SecuritySchemes;
90
+ /**
91
+ * Auth strategies for security schemes that are actually used.
92
+ * Only schemes referenced in endpointAuth are required.
93
+ *
94
+ * @example
95
+ * ```typescript
96
+ * // If endpointAuth has: { 'GET /users': 'jwt', 'POST /data': 'iam', 'GET /public': null }
97
+ * // Then authStrategies must include strategies for 'jwt' and 'iam'
98
+ * authStrategies: {
99
+ * jwt: { type: 'bearer', tokenProvider },
100
+ * iam: { type: 'iam', signer: awsSigner },
101
+ * }
102
+ * ```
103
+ */
104
+ authStrategies: Record<UsedSecuritySchemes<EndpointAuth>, AuthStrategy>;
105
+ /**
106
+ * Optional request interceptor (runs after auth headers are added).
107
+ */
108
+ onRequest?: (config: RequestInit) => RequestInit | Promise<RequestInit>;
109
+ }
110
+ /**
111
+ * Creates an auth-aware fetcher that automatically applies the correct
112
+ * authentication based on the endpoint being called.
113
+ *
114
+ * @example
115
+ * ```typescript
116
+ * import { endpointAuth, securitySchemes, paths } from './openapi';
117
+ * import { TokenClient } from '@geekmidas/auth/client';
118
+ *
119
+ * const tokenClient = new TokenClient({ ... });
120
+ *
121
+ * const api = createAuthAwareFetcher<paths>({
122
+ * baseURL: 'https://api.example.com',
123
+ * endpointAuth,
124
+ * securitySchemes,
125
+ * authStrategies: {
126
+ * bearer: { type: 'bearer', tokenProvider: tokenClient },
127
+ * iam: { type: 'iam', signer: awsSigner },
128
+ * },
129
+ * });
130
+ *
131
+ * // Bearer auth automatically applied
132
+ * const user = await api('GET /users/{id}', { params: { id: '123' } });
133
+ *
134
+ * // IAM SigV4 auth automatically applied
135
+ * const tenant = await api('POST /tenants', { body: { name: 'Acme' } });
136
+ * ```
137
+ */
138
+ export 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> & {
139
+ baseURL: string;
140
+ }): TypedApiFunction<Paths>;
141
+ /**
142
+ * Type helper to extract the security scheme ID from an endpoint.
143
+ */
144
+ export type GetEndpointAuth<EndpointAuth extends Record<string, string | null>, Endpoint extends keyof EndpointAuth> = EndpointAuth[Endpoint];
145
+ /**
146
+ * Type helper to get all authenticated endpoints.
147
+ */
148
+ export type AuthenticatedEndpoints<EndpointAuth extends Record<string, string | null>> = { [K in keyof EndpointAuth]: EndpointAuth[K] extends null ? never : K; }[keyof EndpointAuth];
149
+ /**
150
+ * Type helper to get all public endpoints.
151
+ */
152
+ export type PublicEndpoints<EndpointAuth extends Record<string, string | null>> = { [K in keyof EndpointAuth]: EndpointAuth[K] extends null ? K : never; }[keyof EndpointAuth];
153
+ //#endregion
154
+ export type { FetcherOptions };
155
+ //# sourceMappingURL=auth-fetcher.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-fetcher.d.mts","names":[],"sources":["../src/auth-fetcher.ts"],"mappings":";;;;;iBAciB;EAChB;EACA;EACA;EACA;EACA;EACA;EACA,QAAQ;EACR;GACC;;;;;;YAOU,oBACX,qBAAqB,iCAClB,YAAY,mBAAmB;;;;;iBAMlB;;;;EAIhB,uBAAuB;;;;EAKvB,0BAA0B,QAAQ;;;;;iBAMlB;;;;EAIhB,aAAa;;;;;iBAMG;;;;;;;EAOhB,KAAK,aAAa,MAAM,cAAc,QAAQ;;;;;YAMnC;EACP;EAAgB,eAAe;;EAC/B;EAAgB,gBAAgB;EAAgB;;EAChD;EAAa,QAAQ;;EACrB;;;;;;;;iBAQY,mBAChB,qBAAqB,+BACrB,wBAAwB,eAAe,+BAC9B,KAAK;;;;;EAKd,cAAc;;;;;EAMd,iBAAiB;;;;;;;;;;;;;;;EAgBjB,gBAAgB,OAAO,oBAAoB,eAAe;;;;EAK1D,aAAa,QAAQ,gBAAgB,cAAc,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA+B5C,uBACf,OACA,qBAAqB,gCAAgC,+BAIrD,wBAAwB,eAAe,wBAAwB,eAE9D,uBAGD,SAAS,mBAAmB,cAAc;EACzC;IAEC,iBAAiB;;;;YAkGR,gBACX,qBAAqB,+BACrB,uBAAuB,gBACpB,aAAa;;;;YAKL,uBACX,qBAAqB,oCAEpB,WAAW,eAAe,aAAa,0BAA0B,WAC3D;;;;YAKI,gBACX,qBAAqB,oCAEpB,WAAW,eAAe,aAAa,kBAAkB,mBACnD"}
@@ -1,4 +1,76 @@
1
- import "./fetcher-CakjC9C7.mjs";
2
- import { createAuthAwareFetcher } from "./auth-fetcher-DOj0iz21.mjs";
1
+ import { TypedFetcher } from "./fetcher.mjs";
2
+ //#region src/auth-fetcher.ts
3
+ /**
4
+ * Creates an auth-aware fetcher that automatically applies the correct
5
+ * authentication based on the endpoint being called.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import { endpointAuth, securitySchemes, paths } from './openapi';
10
+ * import { TokenClient } from '@geekmidas/auth/client';
11
+ *
12
+ * const tokenClient = new TokenClient({ ... });
13
+ *
14
+ * const api = createAuthAwareFetcher<paths>({
15
+ * baseURL: 'https://api.example.com',
16
+ * endpointAuth,
17
+ * securitySchemes,
18
+ * authStrategies: {
19
+ * bearer: { type: 'bearer', tokenProvider: tokenClient },
20
+ * iam: { type: 'iam', signer: awsSigner },
21
+ * },
22
+ * });
23
+ *
24
+ * // Bearer auth automatically applied
25
+ * const user = await api('GET /users/{id}', { params: { id: '123' } });
26
+ *
27
+ * // IAM SigV4 auth automatically applied
28
+ * const tenant = await api('POST /tenants', { body: { name: 'Acme' } });
29
+ * ```
30
+ */
31
+ function createAuthAwareFetcher(options) {
32
+ const { endpointAuth, securitySchemes, authStrategies, onRequest: userOnRequest, ...fetcherOptions } = options;
33
+ const baseFetcher = new TypedFetcher({
34
+ ...fetcherOptions,
35
+ onRequest: userOnRequest
36
+ });
37
+ const fetcher = async (endpoint, config) => {
38
+ const schemeName = endpointAuth[endpoint];
39
+ let authHeaders = {};
40
+ if (schemeName) {
41
+ const scheme = securitySchemes[schemeName];
42
+ const strategy = authStrategies[schemeName];
43
+ if (strategy && scheme) authHeaders = await resolveAuthHeaders(strategy, scheme);
44
+ }
45
+ const existingHeaders = config && "headers" in config && config.headers ? config.headers : {};
46
+ const mergedConfig = {
47
+ ...config,
48
+ headers: {
49
+ ...authHeaders,
50
+ ...existingHeaders
51
+ }
52
+ };
53
+ return baseFetcher.request(endpoint, mergedConfig);
54
+ };
55
+ return fetcher;
56
+ }
57
+ /**
58
+ * Resolves auth headers based on the strategy and scheme.
59
+ */
60
+ async function resolveAuthHeaders(strategy, scheme) {
61
+ switch (strategy.type) {
62
+ case "bearer": return strategy.tokenProvider.createValidAuthHeaders();
63
+ case "apiKey": {
64
+ const apiKey = await strategy.apiKeyProvider.getApiKey();
65
+ const headerName = strategy.headerName || scheme.name || "X-API-Key";
66
+ if (scheme.in === "header" || !scheme.in) return { [headerName]: apiKey };
67
+ return {};
68
+ }
69
+ case "iam": return {};
70
+ default: return {};
71
+ }
72
+ }
73
+ //#endregion
74
+ export { createAuthAwareFetcher };
3
75
 
4
- export { createAuthAwareFetcher };
76
+ //# sourceMappingURL=auth-fetcher.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-fetcher.mjs","names":[],"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,uBAWf,SAG0B;CAC1B,MAAM,EACL,cACA,iBACA,gBACA,WAAW,eACX,GAAG,mBACA;CAGJ,MAAM,cAAc,IAAI,aAAoB;EAC3C,GAAG;EACH,WAAW;CACZ,CAAC;CAED,MAAM,UAAU,OACf,UACA,WACgD;EAEhD,MAAM,aAAa,aAAa;EAIhC,IAAI,cAAsC,CAAC;EAE3C,IAAI,YAAY;GACf,MAAM,SAAS,gBAAgB;GAG/B,MAAM,WACL,eAAe;GAEhB,IAAI,YAAY,QACf,cAAc,MAAM,mBAAmB,UAAU,MAAM;EAEzD;EAGA,MAAM,kBACL,UAAU,aAAa,UAAU,OAAO,UACpC,OAAO,UACR,CAAC;EAEL,MAAM,eAAe;GACpB,GAAG;GACH,SAAS;IACR,GAAG;IACH,GAAG;GACJ;EACD;EAEA,OAAO,YAAY,QAAQ,UAAU,YAAY;CAClD;CAEA,OAAO;AACR;;;;AAKA,eAAe,mBACd,UACA,QACkC;CAClC,QAAQ,SAAS,MAAjB;EACC,KAAK,UACJ,OAAO,SAAS,cAAc,uBAAuB;EAGtD,KAAK,UAAU;GACd,MAAM,SAAS,MAAM,SAAS,eAAe,UAAU;GACvD,MAAM,aAAa,SAAS,cAAc,OAAO,QAAQ;GAEzD,IAAI,OAAO,OAAO,YAAY,CAAC,OAAO,IACrC,OAAO,GAAG,aAAa,OAAO;GAI/B,OAAO,CAAC;EACT;EAEA,KAAK,OAMJ,OAAO,CAAC;EAET,SACC,OAAO,CAAC;CACV;AACD"}
@@ -1,7 +1,6 @@
1
- const require_chunk = require('./chunk-CUT6urMc.cjs');
2
- const __tanstack_react_query = require_chunk.__toESM(require("@tanstack/react-query"));
3
- const react = require_chunk.__toESM(require("react"));
4
-
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let _tanstack_react_query = require("@tanstack/react-query");
3
+ let react = require("react");
5
4
  //#region src/endpoint-hooks.ts
6
5
  /**
7
6
  * Build query key from endpoint and config
@@ -43,7 +42,7 @@ function createEndpointHooks(fetcher, options = {}) {
43
42
  queryKey,
44
43
  queryOptions
45
44
  ]);
46
- return (0, __tanstack_react_query.useQuery)(memoizedOptions);
45
+ return (0, _tanstack_react_query.useQuery)(memoizedOptions);
47
46
  },
48
47
  useMutation: (endpoint, mutationOptions) => {
49
48
  const memoizedOptions = (0, react.useMemo)(() => ({
@@ -54,9 +53,9 @@ function createEndpointHooks(fetcher, options = {}) {
54
53
  fetcher,
55
54
  mutationOptions
56
55
  ]);
57
- return (0, __tanstack_react_query.useMutation)(memoizedOptions);
56
+ return (0, _tanstack_react_query.useMutation)(memoizedOptions);
58
57
  },
59
- useInfiniteQuery: (endpoint, options$1, config) => {
58
+ useInfiniteQuery: (endpoint, options, config) => {
60
59
  const queryKey = buildQueryKey(endpoint, config);
61
60
  const memoizedOptions = (0, react.useMemo)(() => ({
62
61
  queryKey,
@@ -71,21 +70,18 @@ function createEndpointHooks(fetcher, options = {}) {
71
70
  ...pageQuery
72
71
  }
73
72
  };
74
- } else if (pageParam !== void 0 && !config) {
75
- const pageQuery = typeof pageParam === "object" ? pageParam : { page: pageParam };
76
- mergedConfig = { query: pageQuery };
77
- }
73
+ } else if (pageParam !== void 0 && !config) mergedConfig = { query: typeof pageParam === "object" ? pageParam : { page: pageParam } };
78
74
  return fetcher(endpoint, mergedConfig);
79
75
  },
80
- ...options$1
76
+ ...options
81
77
  }), [
82
78
  endpoint,
83
79
  config,
84
80
  fetcher,
85
81
  queryKey,
86
- options$1
82
+ options
87
83
  ]);
88
- return (0, __tanstack_react_query.useInfiniteQuery)(memoizedOptions);
84
+ return (0, _tanstack_react_query.useInfiniteQuery)(memoizedOptions);
89
85
  },
90
86
  invalidateQueries: (endpoint, config) => {
91
87
  if (!options.queryClient) throw new Error("queryClient is required for invalidateQueries. Pass it to createEndpointHooks options.");
@@ -102,7 +98,7 @@ function createEndpointHooks(fetcher, options = {}) {
102
98
  buildQueryKey
103
99
  };
104
100
  }
105
-
106
101
  //#endregion
107
102
  exports.createEndpointHooks = createEndpointHooks;
103
+
108
104
  //# sourceMappingURL=endpoint-hooks.cjs.map