@geekmidas/client 0.3.0 → 0.4.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.
Files changed (57) hide show
  1. package/dist/auth-fetcher.cjs +2 -2
  2. package/dist/auth-fetcher.cjs.map +1 -1
  3. package/dist/auth-fetcher.d.cts +2 -1
  4. package/dist/auth-fetcher.d.cts.map +1 -0
  5. package/dist/auth-fetcher.d.mts +2 -1
  6. package/dist/auth-fetcher.d.mts.map +1 -0
  7. package/dist/auth-fetcher.mjs +2 -2
  8. package/dist/auth-fetcher.mjs.map +1 -1
  9. package/dist/endpoint-hooks.cjs.map +1 -1
  10. package/dist/endpoint-hooks.d.cts +1 -1
  11. package/dist/endpoint-hooks.d.cts.map +1 -0
  12. package/dist/endpoint-hooks.d.mts +1 -1
  13. package/dist/endpoint-hooks.d.mts.map +1 -0
  14. package/dist/endpoint-hooks.mjs.map +1 -1
  15. package/dist/{fetcher-DLDD_7Sa.mjs → fetcher-5fnBE7Dk.mjs} +2 -2
  16. package/dist/{fetcher-DLDD_7Sa.mjs.map → fetcher-5fnBE7Dk.mjs.map} +1 -1
  17. package/dist/{fetcher-KdwHgdAl.cjs → fetcher-CgLEaIAC.cjs} +2 -2
  18. package/dist/{fetcher-KdwHgdAl.cjs.map → fetcher-CgLEaIAC.cjs.map} +1 -1
  19. package/dist/fetcher.cjs +1 -1
  20. package/dist/fetcher.d.cts +3 -1
  21. package/dist/fetcher.d.cts.map +1 -0
  22. package/dist/fetcher.d.mts +3 -1
  23. package/dist/fetcher.d.mts.map +1 -0
  24. package/dist/fetcher.mjs +1 -1
  25. package/dist/infer.d.cts.map +1 -0
  26. package/dist/infer.d.mts.map +1 -0
  27. package/dist/openapi-hooks.cjs +3 -5
  28. package/dist/openapi-hooks.cjs.map +1 -1
  29. package/dist/openapi-hooks.d.cts +2 -2
  30. package/dist/openapi-hooks.d.cts.map +1 -0
  31. package/dist/openapi-hooks.d.mts +5 -5
  32. package/dist/openapi-hooks.d.mts.map +1 -0
  33. package/dist/openapi-hooks.mjs +3 -5
  34. package/dist/openapi-hooks.mjs.map +1 -1
  35. package/dist/openapi-types.d.cts.map +1 -0
  36. package/dist/openapi-types.d.mts.map +1 -0
  37. package/dist/react-query.cjs +1 -1
  38. package/dist/react-query.d.cts +3 -1
  39. package/dist/react-query.d.cts.map +1 -0
  40. package/dist/react-query.d.mts +10 -8
  41. package/dist/react-query.d.mts.map +1 -0
  42. package/dist/react-query.mjs +1 -1
  43. package/dist/{types-D4OSWveN.d.cts → types-FxummKaL.d.mts} +7 -5
  44. package/dist/types-FxummKaL.d.mts.map +1 -0
  45. package/dist/{types-Cdv1XAWr.d.mts → types-vutATyWv.d.cts} +7 -5
  46. package/dist/types-vutATyWv.d.cts.map +1 -0
  47. package/dist/types.d.cts +1 -1
  48. package/dist/types.d.mts +1 -1
  49. package/package.json +6 -5
  50. package/src/__tests__/auth-fetcher.spec.ts +505 -0
  51. package/src/__tests__/openapi-hooks.spec.tsx +7 -8
  52. package/src/auth-fetcher.ts +1 -1
  53. package/src/endpoint-hooks.ts +14 -8
  54. package/src/fetcher.ts +1 -1
  55. package/src/openapi-hooks.ts +3 -3
  56. package/src/types.ts +6 -4
  57. package/tsconfig.json +12 -0
@@ -1,4 +1,4 @@
1
- const require_fetcher = require('./fetcher-KdwHgdAl.cjs');
1
+ const require_fetcher = require('./fetcher-CgLEaIAC.cjs');
2
2
 
3
3
  //#region src/auth-fetcher.ts
4
4
  /**
@@ -41,7 +41,7 @@ function createAuthAwareFetcher(options) {
41
41
  if (schemeName) {
42
42
  const scheme = securitySchemes[schemeName];
43
43
  const strategy = authStrategies[schemeName];
44
- if (strategy) authHeaders = await resolveAuthHeaders(strategy, scheme);
44
+ if (strategy && scheme) authHeaders = await resolveAuthHeaders(strategy, scheme);
45
45
  }
46
46
  const existingHeaders = config && "headers" in config && config.headers ? config.headers : {};
47
47
  const mergedConfig = {
@@ -1 +1 @@
1
- {"version":3,"file":"auth-fetcher.cjs","names":["options: AuthFetcherOptions<EndpointAuth, SecuritySchemes> & {\n baseURL: string;\n }","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 ExtractEndpointResponse,\n FetcherOptions,\n FilteredRequestConfig,\n TypedApiFunction,\n TypedEndpoint,\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 type: 'apiKey' | 'http' | 'mutualTLS' | 'oauth2' | 'openIdConnect';\n description?: string;\n name?: string;\n in?: 'query' | 'header' | 'cookie';\n scheme?: string;\n bearerFormat?: string;\n flows?: Record<string, unknown>;\n openIdConnectUrl?: string;\n [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 EndpointAuth 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 /**\n * Get a valid access token, refreshing if necessary.\n */\n getValidAccessToken(): Promise<string | null>;\n\n /**\n * Create Authorization headers from the current token.\n */\n createValidAuthHeaders(): Promise<Record<string, string>>;\n}\n\n/**\n * Interface for API key providers.\n */\nexport interface ApiKeyProvider {\n /**\n * Get the API key value.\n */\n getApiKey(): Promise<string> | string;\n}\n\n/**\n * Interface for AWS SigV4 request signing.\n */\nexport interface AwsSigner {\n /**\n * Sign a request with AWS SigV4.\n * @param url - The request URL\n * @param init - The request init object\n * @returns Headers to add to the request\n */\n sign(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 | { type: 'bearer'; tokenProvider: TokenProvider }\n | { type: 'apiKey'; apiKeyProvider: ApiKeyProvider; headerName?: string }\n | { type: 'iam'; signer: AwsSigner }\n | { 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 EndpointAuth extends Record<string, string | null>,\n SecuritySchemes extends Record<string, SecuritySchemeObject>,\n> extends Omit<FetcherOptions, 'onRequest'> {\n /**\n * Runtime map of endpoints to their required auth scheme.\n * Generated by `gkm openapi --ts`.\n */\n endpointAuth: EndpointAuth;\n\n /**\n * Security scheme definitions.\n * Generated by `gkm openapi --ts`.\n */\n securitySchemes: SecuritySchemes;\n\n /**\n * Auth strategies for security schemes that are actually used.\n * Only schemes referenced in endpointAuth are required.\n *\n * @example\n * ```typescript\n * // If endpointAuth has: { 'GET /users': 'jwt', 'POST /data': 'iam', 'GET /public': null }\n * // Then authStrategies must include strategies for 'jwt' and 'iam'\n * authStrategies: {\n * jwt: { type: 'bearer', tokenProvider },\n * iam: { type: 'iam', signer: awsSigner },\n * }\n * ```\n */\n authStrategies: Record<UsedSecuritySchemes<EndpointAuth>, AuthStrategy>;\n\n /**\n * Optional request interceptor (runs after auth headers are added).\n */\n onRequest?: (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 Paths,\n EndpointAuth extends Record<string, string | null> = Record<\n string,\n string | null\n >,\n SecuritySchemes extends Record<string, SecuritySchemeObject> = Record<\n string,\n SecuritySchemeObject\n >,\n>(\n options: AuthFetcherOptions<EndpointAuth, SecuritySchemes> & {\n baseURL: string;\n },\n): TypedApiFunction<Paths> {\n const {\n endpointAuth,\n securitySchemes,\n authStrategies,\n onRequest: userOnRequest,\n ...fetcherOptions\n } = options;\n\n // Create base fetcher with user's onRequest if provided\n const baseFetcher = new TypedFetcher<Paths>({\n ...fetcherOptions,\n onRequest: userOnRequest,\n });\n\n const fetcher = async <T extends TypedEndpoint<Paths>>(\n endpoint: T,\n config?: FilteredRequestConfig<Paths, T>,\n ): Promise<ExtractEndpointResponse<Paths, T>> => {\n // Look up auth requirement for this endpoint\n const schemeName = endpointAuth[endpoint as keyof EndpointAuth] as\n | string\n | null;\n\n let authHeaders: Record<string, string> = {};\n\n if (schemeName) {\n const scheme = securitySchemes[schemeName as keyof SecuritySchemes];\n // Since authStrategies is now required to have all used schemes,\n // we can safely access it - TypeScript ensures the strategy exists\n const strategy =\n authStrategies[schemeName as UsedSecuritySchemes<EndpointAuth>];\n\n if (strategy) {\n authHeaders = await resolveAuthHeaders(strategy, scheme);\n }\n }\n\n // Merge auth headers with config headers\n const existingHeaders =\n config && 'headers' in config && config.headers\n ? (config.headers as Record<string, string>)\n : {};\n\n const mergedConfig = {\n ...config,\n headers: {\n ...authHeaders,\n ...existingHeaders,\n },\n } as unknown as FilteredRequestConfig<Paths, T>;\n\n return baseFetcher.request(endpoint, mergedConfig);\n };\n\n return fetcher as TypedApiFunction<Paths>;\n}\n\n/**\n * Resolves auth headers based on the strategy and scheme.\n */\nasync function resolveAuthHeaders(\n strategy: AuthStrategy,\n scheme: SecuritySchemeObject,\n): Promise<Record<string, string>> {\n switch (strategy.type) {\n case 'bearer': {\n return strategy.tokenProvider.createValidAuthHeaders();\n }\n\n case 'apiKey': {\n const apiKey = await strategy.apiKeyProvider.getApiKey();\n const headerName = strategy.headerName || scheme.name || 'X-API-Key';\n\n if (scheme.in === 'header' || !scheme.in) {\n return { [headerName]: apiKey };\n }\n // Note: query and cookie API keys are handled differently\n // For now, we only support header-based API keys\n return {};\n }\n\n case 'iam': {\n // IAM signing requires the full URL and request config\n // This is a simplified version - full implementation would need\n // access to the complete request\n // For now, return empty - the actual signing should be done\n // in a custom onRequest interceptor if needed\n return {};\n }\n\n case 'none':\n default:\n return {};\n }\n}\n\n/**\n * Type helper to extract the security scheme ID from an endpoint.\n */\nexport type GetEndpointAuth<\n EndpointAuth extends Record<string, string | null>,\n Endpoint extends keyof EndpointAuth,\n> = EndpointAuth[Endpoint];\n\n/**\n * Type helper to get all authenticated endpoints.\n */\nexport type AuthenticatedEndpoints<\n EndpointAuth extends Record<string, string | null>,\n> = {\n [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 EndpointAuth extends Record<string, string | null>,\n> = {\n [K in keyof EndpointAuth]: EndpointAuth[K] extends null ? K : never;\n}[keyof EndpointAuth];\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0JA,SAAgB,uBAWdA,SAGyB;CACzB,MAAM,EACJ,cACA,iBACA,gBACA,WAAW,cACX,GAAG,gBACJ,GAAG;CAGJ,MAAM,cAAc,IAAIC,6BAAoB;EAC1C,GAAG;EACH,WAAW;CACZ;CAED,MAAM,UAAU,OACdC,UACAC,WAC+C;EAE/C,MAAM,aAAa,aAAa;EAIhC,IAAIC,cAAsC,CAAE;AAE5C,MAAI,YAAY;GACd,MAAM,SAAS,gBAAgB;GAG/B,MAAM,WACJ,eAAe;AAEjB,OAAI,SACF,eAAc,MAAM,mBAAmB,UAAU,OAAO;EAE3D;EAGD,MAAM,kBACJ,UAAU,aAAa,UAAU,OAAO,UACnC,OAAO,UACR,CAAE;EAER,MAAM,eAAe;GACnB,GAAG;GACH,SAAS;IACP,GAAG;IACH,GAAG;GACJ;EACF;AAED,SAAO,YAAY,QAAQ,UAAU,aAAa;CACnD;AAED,QAAO;AACR;;;;AAKD,eAAe,mBACbC,UACAC,QACiC;AACjC,SAAQ,SAAS,MAAjB;EACE,KAAK,SACH,QAAO,SAAS,cAAc,wBAAwB;EAGxD,KAAK,UAAU;GACb,MAAM,SAAS,MAAM,SAAS,eAAe,WAAW;GACxD,MAAM,aAAa,SAAS,cAAc,OAAO,QAAQ;AAEzD,OAAI,OAAO,OAAO,aAAa,OAAO,GACpC,QAAO,GAAG,aAAa,OAAQ;AAIjC,UAAO,CAAE;EACV;EAED,KAAK,MAMH,QAAO,CAAE;EAGX,KAAK;EACL,QACE,QAAO,CAAE;CACZ;AACF"}
1
+ {"version":3,"file":"auth-fetcher.cjs","names":["options: AuthFetcherOptions<EndpointAuth, SecuritySchemes> & {\n baseURL: string;\n }","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 ExtractEndpointResponse,\n FetcherOptions,\n FilteredRequestConfig,\n TypedApiFunction,\n TypedEndpoint,\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 type: 'apiKey' | 'http' | 'mutualTLS' | 'oauth2' | 'openIdConnect';\n description?: string;\n name?: string;\n in?: 'query' | 'header' | 'cookie';\n scheme?: string;\n bearerFormat?: string;\n flows?: Record<string, unknown>;\n openIdConnectUrl?: string;\n [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 EndpointAuth 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 /**\n * Get a valid access token, refreshing if necessary.\n */\n getValidAccessToken(): Promise<string | null>;\n\n /**\n * Create Authorization headers from the current token.\n */\n createValidAuthHeaders(): Promise<Record<string, string>>;\n}\n\n/**\n * Interface for API key providers.\n */\nexport interface ApiKeyProvider {\n /**\n * Get the API key value.\n */\n getApiKey(): Promise<string> | string;\n}\n\n/**\n * Interface for AWS SigV4 request signing.\n */\nexport interface AwsSigner {\n /**\n * Sign a request with AWS SigV4.\n * @param url - The request URL\n * @param init - The request init object\n * @returns Headers to add to the request\n */\n sign(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 | { type: 'bearer'; tokenProvider: TokenProvider }\n | { type: 'apiKey'; apiKeyProvider: ApiKeyProvider; headerName?: string }\n | { type: 'iam'; signer: AwsSigner }\n | { 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 EndpointAuth extends Record<string, string | null>,\n SecuritySchemes extends Record<string, SecuritySchemeObject>,\n> extends Omit<FetcherOptions, 'onRequest'> {\n /**\n * Runtime map of endpoints to their required auth scheme.\n * Generated by `gkm openapi --ts`.\n */\n endpointAuth: EndpointAuth;\n\n /**\n * Security scheme definitions.\n * Generated by `gkm openapi --ts`.\n */\n securitySchemes: SecuritySchemes;\n\n /**\n * Auth strategies for security schemes that are actually used.\n * Only schemes referenced in endpointAuth are required.\n *\n * @example\n * ```typescript\n * // If endpointAuth has: { 'GET /users': 'jwt', 'POST /data': 'iam', 'GET /public': null }\n * // Then authStrategies must include strategies for 'jwt' and 'iam'\n * authStrategies: {\n * jwt: { type: 'bearer', tokenProvider },\n * iam: { type: 'iam', signer: awsSigner },\n * }\n * ```\n */\n authStrategies: Record<UsedSecuritySchemes<EndpointAuth>, AuthStrategy>;\n\n /**\n * Optional request interceptor (runs after auth headers are added).\n */\n onRequest?: (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 Paths,\n EndpointAuth extends Record<string, string | null> = Record<\n string,\n string | null\n >,\n SecuritySchemes extends Record<string, SecuritySchemeObject> = Record<\n string,\n SecuritySchemeObject\n >,\n>(\n options: AuthFetcherOptions<EndpointAuth, SecuritySchemes> & {\n baseURL: string;\n },\n): TypedApiFunction<Paths> {\n const {\n endpointAuth,\n securitySchemes,\n authStrategies,\n onRequest: userOnRequest,\n ...fetcherOptions\n } = options;\n\n // Create base fetcher with user's onRequest if provided\n const baseFetcher = new TypedFetcher<Paths>({\n ...fetcherOptions,\n onRequest: userOnRequest,\n });\n\n const fetcher = async <T extends TypedEndpoint<Paths>>(\n endpoint: T,\n config?: FilteredRequestConfig<Paths, T>,\n ): Promise<ExtractEndpointResponse<Paths, T>> => {\n // Look up auth requirement for this endpoint\n const schemeName = endpointAuth[endpoint as keyof EndpointAuth] as\n | string\n | null;\n\n let authHeaders: Record<string, string> = {};\n\n if (schemeName) {\n const scheme = securitySchemes[schemeName as keyof SecuritySchemes];\n // Since authStrategies is now required to have all used schemes,\n // we can safely access it - TypeScript ensures the strategy exists\n const strategy =\n authStrategies[schemeName as UsedSecuritySchemes<EndpointAuth>];\n\n if (strategy && scheme) {\n authHeaders = await resolveAuthHeaders(strategy, scheme);\n }\n }\n\n // Merge auth headers with config headers\n const existingHeaders =\n config && 'headers' in config && config.headers\n ? (config.headers as Record<string, string>)\n : {};\n\n const mergedConfig = {\n ...config,\n headers: {\n ...authHeaders,\n ...existingHeaders,\n },\n } as unknown as FilteredRequestConfig<Paths, T>;\n\n return baseFetcher.request(endpoint, mergedConfig);\n };\n\n return fetcher as TypedApiFunction<Paths>;\n}\n\n/**\n * Resolves auth headers based on the strategy and scheme.\n */\nasync function resolveAuthHeaders(\n strategy: AuthStrategy,\n scheme: SecuritySchemeObject,\n): Promise<Record<string, string>> {\n switch (strategy.type) {\n case 'bearer': {\n return strategy.tokenProvider.createValidAuthHeaders();\n }\n\n case 'apiKey': {\n const apiKey = await strategy.apiKeyProvider.getApiKey();\n const headerName = strategy.headerName || scheme.name || 'X-API-Key';\n\n if (scheme.in === 'header' || !scheme.in) {\n return { [headerName]: apiKey };\n }\n // Note: query and cookie API keys are handled differently\n // For now, we only support header-based API keys\n return {};\n }\n\n case 'iam': {\n // IAM signing requires the full URL and request config\n // This is a simplified version - full implementation would need\n // access to the complete request\n // For now, return empty - the actual signing should be done\n // in a custom onRequest interceptor if needed\n return {};\n }\n\n case 'none':\n default:\n return {};\n }\n}\n\n/**\n * Type helper to extract the security scheme ID from an endpoint.\n */\nexport type GetEndpointAuth<\n EndpointAuth extends Record<string, string | null>,\n Endpoint extends keyof EndpointAuth,\n> = EndpointAuth[Endpoint];\n\n/**\n * Type helper to get all authenticated endpoints.\n */\nexport type AuthenticatedEndpoints<\n EndpointAuth extends Record<string, string | null>,\n> = {\n [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 EndpointAuth extends Record<string, string | null>,\n> = {\n [K in keyof EndpointAuth]: EndpointAuth[K] extends null ? K : never;\n}[keyof EndpointAuth];\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0JA,SAAgB,uBAWdA,SAGyB;CACzB,MAAM,EACJ,cACA,iBACA,gBACA,WAAW,cACX,GAAG,gBACJ,GAAG;CAGJ,MAAM,cAAc,IAAIC,6BAAoB;EAC1C,GAAG;EACH,WAAW;CACZ;CAED,MAAM,UAAU,OACdC,UACAC,WAC+C;EAE/C,MAAM,aAAa,aAAa;EAIhC,IAAIC,cAAsC,CAAE;AAE5C,MAAI,YAAY;GACd,MAAM,SAAS,gBAAgB;GAG/B,MAAM,WACJ,eAAe;AAEjB,OAAI,YAAY,OACd,eAAc,MAAM,mBAAmB,UAAU,OAAO;EAE3D;EAGD,MAAM,kBACJ,UAAU,aAAa,UAAU,OAAO,UACnC,OAAO,UACR,CAAE;EAER,MAAM,eAAe;GACnB,GAAG;GACH,SAAS;IACP,GAAG;IACH,GAAG;GACJ;EACF;AAED,SAAO,YAAY,QAAQ,UAAU,aAAa;CACnD;AAED,QAAO;AACR;;;;AAKD,eAAe,mBACbC,UACAC,QACiC;AACjC,SAAQ,SAAS,MAAjB;EACE,KAAK,SACH,QAAO,SAAS,cAAc,wBAAwB;EAGxD,KAAK,UAAU;GACb,MAAM,SAAS,MAAM,SAAS,eAAe,WAAW;GACxD,MAAM,aAAa,SAAS,cAAc,OAAO,QAAQ;AAEzD,OAAI,OAAO,OAAO,aAAa,OAAO,GACpC,QAAO,GAAG,aAAa,OAAQ;AAIjC,UAAO,CAAE;EACV;EAED,KAAK,MAMH,QAAO,CAAE;EAGX,KAAK;EACL,QACE,QAAO,CAAE;CACZ;AACF"}
@@ -1,4 +1,4 @@
1
- import { FetcherOptions, TypedApiFunction } from "./types-D4OSWveN.cjs";
1
+ import { FetcherOptions, TypedApiFunction } from "./types-vutATyWv.cjs";
2
2
 
3
3
  //#region src/auth-fetcher.d.ts
4
4
 
@@ -152,6 +152,7 @@ type AuthenticatedEndpoints<EndpointAuth extends Record<string, string | null>>
152
152
  * Type helper to get all public endpoints.
153
153
  */
154
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
155
156
  //#endregion
156
157
  export { ApiKeyProvider, AuthFetcherOptions, AuthStrategy, AuthenticatedEndpoints, AwsSigner, FetcherOptions, GetEndpointAuth, PublicEndpoints, SecuritySchemeObject, TokenProvider, UsedSecuritySchemes, createAuthAwareFetcher };
157
158
  //# sourceMappingURL=auth-fetcher.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-fetcher.d.cts","names":[],"sources":["../src/auth-fetcher.ts"],"sourcesContent":[],"mappings":";;;;;AAcA;AAgBA;AAA+B,UAhBd,oBAAA,CAgBc;EAAA,IACR,EAAA,QAAA,GAAA,MAAA,GAAA,WAAA,GAAA,QAAA,GAAA,eAAA;EAAM,WACb,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,EAjBpB,MAiBoB,CAAA,MAAA,EAAA,OAAA,CAAA;EAAA,gBAIL,CAAA,EAAA,MAAA;EAAO,CAAA,GAKI,EAAA,MAAA,CAAA,EAAA,OAAA;;AAAD;AAMnC;AAUA;;AAO0B,KAxCd,mBAwCc,CAAA,qBAvCH,MAuCG,CAAA,MAAA,EAAA,MAAA,GAAA,IAAA,CAAA,CAAA,GAtCtB,WAsCsB,CAtCV,YAsCU,CAAA,MAtCS,YAsCT,CAAA,CAAA;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AAe,wBAAwB,eAE7D,gCAGO,mBAAmB,cAAc;;IAGzC,iBAAiB;;;;KAoGR,qCACW,sDACE,gBACrB,aAAa;;;;KAKL,4CACW,+CAET,eAAe,aAAa,0BAA0B,UAC5D;;;;KAKI,qCACW,+CAET,eAAe,aAAa,kBAAkB,kBACpD"}
@@ -1,4 +1,4 @@
1
- import { FetcherOptions, TypedApiFunction } from "./types-Cdv1XAWr.mjs";
1
+ import { FetcherOptions, TypedApiFunction } from "./types-FxummKaL.mjs";
2
2
 
3
3
  //#region src/auth-fetcher.d.ts
4
4
 
@@ -152,6 +152,7 @@ type AuthenticatedEndpoints<EndpointAuth extends Record<string, string | null>>
152
152
  * Type helper to get all public endpoints.
153
153
  */
154
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
155
156
  //#endregion
156
157
  export { ApiKeyProvider, AuthFetcherOptions, AuthStrategy, AuthenticatedEndpoints, AwsSigner, FetcherOptions, GetEndpointAuth, PublicEndpoints, SecuritySchemeObject, TokenProvider, UsedSecuritySchemes, createAuthAwareFetcher };
157
158
  //# sourceMappingURL=auth-fetcher.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-fetcher.d.mts","names":[],"sources":["../src/auth-fetcher.ts"],"sourcesContent":[],"mappings":";;;;;AAcA;AAgBA;AAA+B,UAhBd,oBAAA,CAgBc;EAAA,IACR,EAAA,QAAA,GAAA,MAAA,GAAA,WAAA,GAAA,QAAA,GAAA,eAAA;EAAM,WACb,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,EAjBpB,MAiBoB,CAAA,MAAA,EAAA,OAA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AlMjB,IAkMiB,CAlMZ,cAkMY,EAAA,WAAA,CAAA,CAAA;EAAA;;;;EAGc,YAAC,EAhM1B,YAgM0B;EAAC;;AACvB;;mBA3LD;;;;;;;;;;;;;;;kBAgBD,OAAO,oBAAoB,eAAe;;;;uBAKrC,gBAAgB,cAAc,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA+B7C,mDAEO,gCAAgC,uDAI7B,eAAe,wBAAwB,eAE7D,gCAGO,mBAAmB,cAAc;;IAGzC,iBAAiB;;;;KAoGR,qCACW,sDACE,gBACrB,aAAa;;;;KAKL,4CACW,+CAET,eAAe,aAAa,0BAA0B,UAC5D;;;;KAKI,qCACW,+CAET,eAAe,aAAa,kBAAkB,kBACpD"}
@@ -1,4 +1,4 @@
1
- import { TypedFetcher } from "./fetcher-DLDD_7Sa.mjs";
1
+ import { TypedFetcher } from "./fetcher-5fnBE7Dk.mjs";
2
2
 
3
3
  //#region src/auth-fetcher.ts
4
4
  /**
@@ -41,7 +41,7 @@ function createAuthAwareFetcher(options) {
41
41
  if (schemeName) {
42
42
  const scheme = securitySchemes[schemeName];
43
43
  const strategy = authStrategies[schemeName];
44
- if (strategy) authHeaders = await resolveAuthHeaders(strategy, scheme);
44
+ if (strategy && scheme) authHeaders = await resolveAuthHeaders(strategy, scheme);
45
45
  }
46
46
  const existingHeaders = config && "headers" in config && config.headers ? config.headers : {};
47
47
  const mergedConfig = {
@@ -1 +1 @@
1
- {"version":3,"file":"auth-fetcher.mjs","names":["options: AuthFetcherOptions<EndpointAuth, SecuritySchemes> & {\n baseURL: string;\n }","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 ExtractEndpointResponse,\n FetcherOptions,\n FilteredRequestConfig,\n TypedApiFunction,\n TypedEndpoint,\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 type: 'apiKey' | 'http' | 'mutualTLS' | 'oauth2' | 'openIdConnect';\n description?: string;\n name?: string;\n in?: 'query' | 'header' | 'cookie';\n scheme?: string;\n bearerFormat?: string;\n flows?: Record<string, unknown>;\n openIdConnectUrl?: string;\n [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 EndpointAuth 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 /**\n * Get a valid access token, refreshing if necessary.\n */\n getValidAccessToken(): Promise<string | null>;\n\n /**\n * Create Authorization headers from the current token.\n */\n createValidAuthHeaders(): Promise<Record<string, string>>;\n}\n\n/**\n * Interface for API key providers.\n */\nexport interface ApiKeyProvider {\n /**\n * Get the API key value.\n */\n getApiKey(): Promise<string> | string;\n}\n\n/**\n * Interface for AWS SigV4 request signing.\n */\nexport interface AwsSigner {\n /**\n * Sign a request with AWS SigV4.\n * @param url - The request URL\n * @param init - The request init object\n * @returns Headers to add to the request\n */\n sign(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 | { type: 'bearer'; tokenProvider: TokenProvider }\n | { type: 'apiKey'; apiKeyProvider: ApiKeyProvider; headerName?: string }\n | { type: 'iam'; signer: AwsSigner }\n | { 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 EndpointAuth extends Record<string, string | null>,\n SecuritySchemes extends Record<string, SecuritySchemeObject>,\n> extends Omit<FetcherOptions, 'onRequest'> {\n /**\n * Runtime map of endpoints to their required auth scheme.\n * Generated by `gkm openapi --ts`.\n */\n endpointAuth: EndpointAuth;\n\n /**\n * Security scheme definitions.\n * Generated by `gkm openapi --ts`.\n */\n securitySchemes: SecuritySchemes;\n\n /**\n * Auth strategies for security schemes that are actually used.\n * Only schemes referenced in endpointAuth are required.\n *\n * @example\n * ```typescript\n * // If endpointAuth has: { 'GET /users': 'jwt', 'POST /data': 'iam', 'GET /public': null }\n * // Then authStrategies must include strategies for 'jwt' and 'iam'\n * authStrategies: {\n * jwt: { type: 'bearer', tokenProvider },\n * iam: { type: 'iam', signer: awsSigner },\n * }\n * ```\n */\n authStrategies: Record<UsedSecuritySchemes<EndpointAuth>, AuthStrategy>;\n\n /**\n * Optional request interceptor (runs after auth headers are added).\n */\n onRequest?: (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 Paths,\n EndpointAuth extends Record<string, string | null> = Record<\n string,\n string | null\n >,\n SecuritySchemes extends Record<string, SecuritySchemeObject> = Record<\n string,\n SecuritySchemeObject\n >,\n>(\n options: AuthFetcherOptions<EndpointAuth, SecuritySchemes> & {\n baseURL: string;\n },\n): TypedApiFunction<Paths> {\n const {\n endpointAuth,\n securitySchemes,\n authStrategies,\n onRequest: userOnRequest,\n ...fetcherOptions\n } = options;\n\n // Create base fetcher with user's onRequest if provided\n const baseFetcher = new TypedFetcher<Paths>({\n ...fetcherOptions,\n onRequest: userOnRequest,\n });\n\n const fetcher = async <T extends TypedEndpoint<Paths>>(\n endpoint: T,\n config?: FilteredRequestConfig<Paths, T>,\n ): Promise<ExtractEndpointResponse<Paths, T>> => {\n // Look up auth requirement for this endpoint\n const schemeName = endpointAuth[endpoint as keyof EndpointAuth] as\n | string\n | null;\n\n let authHeaders: Record<string, string> = {};\n\n if (schemeName) {\n const scheme = securitySchemes[schemeName as keyof SecuritySchemes];\n // Since authStrategies is now required to have all used schemes,\n // we can safely access it - TypeScript ensures the strategy exists\n const strategy =\n authStrategies[schemeName as UsedSecuritySchemes<EndpointAuth>];\n\n if (strategy) {\n authHeaders = await resolveAuthHeaders(strategy, scheme);\n }\n }\n\n // Merge auth headers with config headers\n const existingHeaders =\n config && 'headers' in config && config.headers\n ? (config.headers as Record<string, string>)\n : {};\n\n const mergedConfig = {\n ...config,\n headers: {\n ...authHeaders,\n ...existingHeaders,\n },\n } as unknown as FilteredRequestConfig<Paths, T>;\n\n return baseFetcher.request(endpoint, mergedConfig);\n };\n\n return fetcher as TypedApiFunction<Paths>;\n}\n\n/**\n * Resolves auth headers based on the strategy and scheme.\n */\nasync function resolveAuthHeaders(\n strategy: AuthStrategy,\n scheme: SecuritySchemeObject,\n): Promise<Record<string, string>> {\n switch (strategy.type) {\n case 'bearer': {\n return strategy.tokenProvider.createValidAuthHeaders();\n }\n\n case 'apiKey': {\n const apiKey = await strategy.apiKeyProvider.getApiKey();\n const headerName = strategy.headerName || scheme.name || 'X-API-Key';\n\n if (scheme.in === 'header' || !scheme.in) {\n return { [headerName]: apiKey };\n }\n // Note: query and cookie API keys are handled differently\n // For now, we only support header-based API keys\n return {};\n }\n\n case 'iam': {\n // IAM signing requires the full URL and request config\n // This is a simplified version - full implementation would need\n // access to the complete request\n // For now, return empty - the actual signing should be done\n // in a custom onRequest interceptor if needed\n return {};\n }\n\n case 'none':\n default:\n return {};\n }\n}\n\n/**\n * Type helper to extract the security scheme ID from an endpoint.\n */\nexport type GetEndpointAuth<\n EndpointAuth extends Record<string, string | null>,\n Endpoint extends keyof EndpointAuth,\n> = EndpointAuth[Endpoint];\n\n/**\n * Type helper to get all authenticated endpoints.\n */\nexport type AuthenticatedEndpoints<\n EndpointAuth extends Record<string, string | null>,\n> = {\n [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 EndpointAuth extends Record<string, string | null>,\n> = {\n [K in keyof EndpointAuth]: EndpointAuth[K] extends null ? K : never;\n}[keyof EndpointAuth];\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0JA,SAAgB,uBAWdA,SAGyB;CACzB,MAAM,EACJ,cACA,iBACA,gBACA,WAAW,cACX,GAAG,gBACJ,GAAG;CAGJ,MAAM,cAAc,IAAI,aAAoB;EAC1C,GAAG;EACH,WAAW;CACZ;CAED,MAAM,UAAU,OACdC,UACAC,WAC+C;EAE/C,MAAM,aAAa,aAAa;EAIhC,IAAIC,cAAsC,CAAE;AAE5C,MAAI,YAAY;GACd,MAAM,SAAS,gBAAgB;GAG/B,MAAM,WACJ,eAAe;AAEjB,OAAI,SACF,eAAc,MAAM,mBAAmB,UAAU,OAAO;EAE3D;EAGD,MAAM,kBACJ,UAAU,aAAa,UAAU,OAAO,UACnC,OAAO,UACR,CAAE;EAER,MAAM,eAAe;GACnB,GAAG;GACH,SAAS;IACP,GAAG;IACH,GAAG;GACJ;EACF;AAED,SAAO,YAAY,QAAQ,UAAU,aAAa;CACnD;AAED,QAAO;AACR;;;;AAKD,eAAe,mBACbC,UACAC,QACiC;AACjC,SAAQ,SAAS,MAAjB;EACE,KAAK,SACH,QAAO,SAAS,cAAc,wBAAwB;EAGxD,KAAK,UAAU;GACb,MAAM,SAAS,MAAM,SAAS,eAAe,WAAW;GACxD,MAAM,aAAa,SAAS,cAAc,OAAO,QAAQ;AAEzD,OAAI,OAAO,OAAO,aAAa,OAAO,GACpC,QAAO,GAAG,aAAa,OAAQ;AAIjC,UAAO,CAAE;EACV;EAED,KAAK,MAMH,QAAO,CAAE;EAGX,KAAK;EACL,QACE,QAAO,CAAE;CACZ;AACF"}
1
+ {"version":3,"file":"auth-fetcher.mjs","names":["options: AuthFetcherOptions<EndpointAuth, SecuritySchemes> & {\n baseURL: string;\n }","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 ExtractEndpointResponse,\n FetcherOptions,\n FilteredRequestConfig,\n TypedApiFunction,\n TypedEndpoint,\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 type: 'apiKey' | 'http' | 'mutualTLS' | 'oauth2' | 'openIdConnect';\n description?: string;\n name?: string;\n in?: 'query' | 'header' | 'cookie';\n scheme?: string;\n bearerFormat?: string;\n flows?: Record<string, unknown>;\n openIdConnectUrl?: string;\n [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 EndpointAuth 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 /**\n * Get a valid access token, refreshing if necessary.\n */\n getValidAccessToken(): Promise<string | null>;\n\n /**\n * Create Authorization headers from the current token.\n */\n createValidAuthHeaders(): Promise<Record<string, string>>;\n}\n\n/**\n * Interface for API key providers.\n */\nexport interface ApiKeyProvider {\n /**\n * Get the API key value.\n */\n getApiKey(): Promise<string> | string;\n}\n\n/**\n * Interface for AWS SigV4 request signing.\n */\nexport interface AwsSigner {\n /**\n * Sign a request with AWS SigV4.\n * @param url - The request URL\n * @param init - The request init object\n * @returns Headers to add to the request\n */\n sign(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 | { type: 'bearer'; tokenProvider: TokenProvider }\n | { type: 'apiKey'; apiKeyProvider: ApiKeyProvider; headerName?: string }\n | { type: 'iam'; signer: AwsSigner }\n | { 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 EndpointAuth extends Record<string, string | null>,\n SecuritySchemes extends Record<string, SecuritySchemeObject>,\n> extends Omit<FetcherOptions, 'onRequest'> {\n /**\n * Runtime map of endpoints to their required auth scheme.\n * Generated by `gkm openapi --ts`.\n */\n endpointAuth: EndpointAuth;\n\n /**\n * Security scheme definitions.\n * Generated by `gkm openapi --ts`.\n */\n securitySchemes: SecuritySchemes;\n\n /**\n * Auth strategies for security schemes that are actually used.\n * Only schemes referenced in endpointAuth are required.\n *\n * @example\n * ```typescript\n * // If endpointAuth has: { 'GET /users': 'jwt', 'POST /data': 'iam', 'GET /public': null }\n * // Then authStrategies must include strategies for 'jwt' and 'iam'\n * authStrategies: {\n * jwt: { type: 'bearer', tokenProvider },\n * iam: { type: 'iam', signer: awsSigner },\n * }\n * ```\n */\n authStrategies: Record<UsedSecuritySchemes<EndpointAuth>, AuthStrategy>;\n\n /**\n * Optional request interceptor (runs after auth headers are added).\n */\n onRequest?: (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 Paths,\n EndpointAuth extends Record<string, string | null> = Record<\n string,\n string | null\n >,\n SecuritySchemes extends Record<string, SecuritySchemeObject> = Record<\n string,\n SecuritySchemeObject\n >,\n>(\n options: AuthFetcherOptions<EndpointAuth, SecuritySchemes> & {\n baseURL: string;\n },\n): TypedApiFunction<Paths> {\n const {\n endpointAuth,\n securitySchemes,\n authStrategies,\n onRequest: userOnRequest,\n ...fetcherOptions\n } = options;\n\n // Create base fetcher with user's onRequest if provided\n const baseFetcher = new TypedFetcher<Paths>({\n ...fetcherOptions,\n onRequest: userOnRequest,\n });\n\n const fetcher = async <T extends TypedEndpoint<Paths>>(\n endpoint: T,\n config?: FilteredRequestConfig<Paths, T>,\n ): Promise<ExtractEndpointResponse<Paths, T>> => {\n // Look up auth requirement for this endpoint\n const schemeName = endpointAuth[endpoint as keyof EndpointAuth] as\n | string\n | null;\n\n let authHeaders: Record<string, string> = {};\n\n if (schemeName) {\n const scheme = securitySchemes[schemeName as keyof SecuritySchemes];\n // Since authStrategies is now required to have all used schemes,\n // we can safely access it - TypeScript ensures the strategy exists\n const strategy =\n authStrategies[schemeName as UsedSecuritySchemes<EndpointAuth>];\n\n if (strategy && scheme) {\n authHeaders = await resolveAuthHeaders(strategy, scheme);\n }\n }\n\n // Merge auth headers with config headers\n const existingHeaders =\n config && 'headers' in config && config.headers\n ? (config.headers as Record<string, string>)\n : {};\n\n const mergedConfig = {\n ...config,\n headers: {\n ...authHeaders,\n ...existingHeaders,\n },\n } as unknown as FilteredRequestConfig<Paths, T>;\n\n return baseFetcher.request(endpoint, mergedConfig);\n };\n\n return fetcher as TypedApiFunction<Paths>;\n}\n\n/**\n * Resolves auth headers based on the strategy and scheme.\n */\nasync function resolveAuthHeaders(\n strategy: AuthStrategy,\n scheme: SecuritySchemeObject,\n): Promise<Record<string, string>> {\n switch (strategy.type) {\n case 'bearer': {\n return strategy.tokenProvider.createValidAuthHeaders();\n }\n\n case 'apiKey': {\n const apiKey = await strategy.apiKeyProvider.getApiKey();\n const headerName = strategy.headerName || scheme.name || 'X-API-Key';\n\n if (scheme.in === 'header' || !scheme.in) {\n return { [headerName]: apiKey };\n }\n // Note: query and cookie API keys are handled differently\n // For now, we only support header-based API keys\n return {};\n }\n\n case 'iam': {\n // IAM signing requires the full URL and request config\n // This is a simplified version - full implementation would need\n // access to the complete request\n // For now, return empty - the actual signing should be done\n // in a custom onRequest interceptor if needed\n return {};\n }\n\n case 'none':\n default:\n return {};\n }\n}\n\n/**\n * Type helper to extract the security scheme ID from an endpoint.\n */\nexport type GetEndpointAuth<\n EndpointAuth extends Record<string, string | null>,\n Endpoint extends keyof EndpointAuth,\n> = EndpointAuth[Endpoint];\n\n/**\n * Type helper to get all authenticated endpoints.\n */\nexport type AuthenticatedEndpoints<\n EndpointAuth extends Record<string, string | null>,\n> = {\n [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 EndpointAuth extends Record<string, string | null>,\n> = {\n [K in keyof EndpointAuth]: EndpointAuth[K] extends null ? K : never;\n}[keyof EndpointAuth];\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0JA,SAAgB,uBAWdA,SAGyB;CACzB,MAAM,EACJ,cACA,iBACA,gBACA,WAAW,cACX,GAAG,gBACJ,GAAG;CAGJ,MAAM,cAAc,IAAI,aAAoB;EAC1C,GAAG;EACH,WAAW;CACZ;CAED,MAAM,UAAU,OACdC,UACAC,WAC+C;EAE/C,MAAM,aAAa,aAAa;EAIhC,IAAIC,cAAsC,CAAE;AAE5C,MAAI,YAAY;GACd,MAAM,SAAS,gBAAgB;GAG/B,MAAM,WACJ,eAAe;AAEjB,OAAI,YAAY,OACd,eAAc,MAAM,mBAAmB,UAAU,OAAO;EAE3D;EAGD,MAAM,kBACJ,UAAU,aAAa,UAAU,OAAO,UACnC,OAAO,UACR,CAAE;EAER,MAAM,eAAe;GACnB,GAAG;GACH,SAAS;IACP,GAAG;IACH,GAAG;GACJ;EACF;AAED,SAAO,YAAY,QAAQ,UAAU,aAAa;CACnD;AAED,QAAO;AACR;;;;AAKD,eAAe,mBACbC,UACAC,QACiC;AACjC,SAAQ,SAAS,MAAjB;EACE,KAAK,SACH,QAAO,SAAS,cAAc,wBAAwB;EAGxD,KAAK,UAAU;GACb,MAAM,SAAS,MAAM,SAAS,eAAe,WAAW;GACxD,MAAM,aAAa,SAAS,cAAc,OAAO,QAAQ;AAEzD,OAAI,OAAO,OAAO,aAAa,OAAO,GACpC,QAAO,GAAG,aAAa,OAAQ;AAIjC,UAAO,CAAE;EACV;EAED,KAAK,MAMH,QAAO,CAAE;EAGX,KAAK;EACL,QACE,QAAO,CAAE;CACZ;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"endpoint-hooks.cjs","names":["endpoint: T","config?: FilteredRequestConfig<Paths, T>","key: unknown[]","fetcher: TypedApiFunction<Paths>","options: CreateEndpointHooksOptions","mutationOptions?: Omit<\n UseMutationOptions<\n ExtractEndpointResponse<Paths, T>,\n Error,\n FilteredRequestConfig<Paths, T>\n >,\n 'mutationFn'\n >","config: FilteredRequestConfig<Paths, T>"],"sources":["../src/endpoint-hooks.ts"],"sourcesContent":["import type {\n QueryClient,\n UseMutationOptions,\n UseQueryOptions,\n} from '@tanstack/react-query';\nimport { useMutation, useQuery } from '@tanstack/react-query';\nimport { useMemo } from 'react';\nimport type {\n ExtractEndpointResponse,\n FilteredRequestConfig,\n IsConfigRequired,\n MutationEndpoint,\n QueryEndpoint,\n TypedApiFunction,\n} from './types';\n\n/**\n * Build query key from endpoint and config\n */\nfunction buildQueryKey<Paths, T extends QueryEndpoint<Paths>>(\n endpoint: T,\n config?: FilteredRequestConfig<Paths, T>,\n): unknown[] {\n const key: unknown[] = [endpoint];\n\n if (config && 'params' in config && config.params) {\n key.push({ params: config.params });\n }\n\n if (config && 'query' in config && config.query) {\n key.push({ query: config.query });\n }\n\n return key;\n}\n\n/**\n * Options for creating endpoint-based hooks\n */\nexport interface CreateEndpointHooksOptions {\n queryClient?: QueryClient;\n}\n\n/**\n * Hook options type that conditionally requires config\n */\ntype UseQueryArgs<Paths, T extends QueryEndpoint<Paths>> = IsConfigRequired<\n Paths,\n T\n> extends true\n ? [\n config: FilteredRequestConfig<Paths, T>,\n options?: Omit<\n UseQueryOptions<ExtractEndpointResponse<Paths, T>, Error>,\n 'queryKey' | 'queryFn'\n >,\n ]\n : [\n config?: FilteredRequestConfig<Paths, T>,\n options?: Omit<\n UseQueryOptions<ExtractEndpointResponse<Paths, T>, Error>,\n 'queryKey' | 'queryFn'\n >,\n ];\n\n/**\n * Endpoint-based React Query hooks\n */\nexport interface EndpointHooks<Paths> {\n /**\n * Use query hook for GET endpoints.\n * Config is required when endpoint has path params.\n */\n useQuery: <T extends QueryEndpoint<Paths>>(\n endpoint: T,\n ...args: UseQueryArgs<Paths, T>\n ) => ReturnType<typeof useQuery<ExtractEndpointResponse<Paths, T>, Error>>;\n\n /**\n * Use mutation hook for POST, PUT, PATCH, DELETE endpoints.\n * Config with params/body is passed to mutate().\n */\n useMutation: <T extends MutationEndpoint<Paths>>(\n endpoint: T,\n options?: Omit<\n UseMutationOptions<\n ExtractEndpointResponse<Paths, T>,\n Error,\n FilteredRequestConfig<Paths, T>\n >,\n 'mutationFn'\n >,\n ) => ReturnType<\n typeof useMutation<\n ExtractEndpointResponse<Paths, T>,\n Error,\n FilteredRequestConfig<Paths, T>\n >\n >;\n\n /**\n * Build a query key for manual cache operations\n */\n buildQueryKey: <T extends QueryEndpoint<Paths>>(\n endpoint: T,\n config?: FilteredRequestConfig<Paths, T>,\n ) => unknown[];\n}\n\n/**\n * Create endpoint-based React Query hooks from a typed fetcher.\n *\n * @example\n * ```typescript\n * const fetcher = createAuthAwareFetcher<paths>({ ... });\n * const hooks = createEndpointHooks<paths>(fetcher);\n *\n * // In a component\n * const { data } = hooks.useQuery('GET /users/{id}', { params: { id: '123' } });\n *\n * const mutation = hooks.useMutation('POST /users');\n * await mutation.mutateAsync({ body: { name: 'John' } });\n * ```\n */\nexport function createEndpointHooks<Paths>(\n fetcher: TypedApiFunction<Paths>,\n options: CreateEndpointHooksOptions = {},\n): EndpointHooks<Paths> {\n return {\n useQuery: <T extends QueryEndpoint<Paths>>(\n endpoint: T,\n ...args: UseQueryArgs<Paths, T>\n ) => {\n // Parse args - config is first, options is second\n const [config, queryOptions] = args as [\n FilteredRequestConfig<Paths, T> | undefined,\n (\n | Omit<\n UseQueryOptions<ExtractEndpointResponse<Paths, T>, Error>,\n 'queryKey' | 'queryFn'\n >\n | undefined\n ),\n ];\n\n const queryKey = buildQueryKey(endpoint, config);\n\n const memoizedOptions = useMemo(\n () => ({\n queryKey,\n queryFn: () =>\n fetcher(\n endpoint as Parameters<typeof fetcher>[0],\n config as Parameters<typeof fetcher>[1],\n ),\n ...queryOptions,\n }),\n [\n queryKey.join(','),\n endpoint,\n JSON.stringify(config),\n JSON.stringify(queryOptions),\n ],\n );\n\n return useQuery<ExtractEndpointResponse<Paths, T>, Error>(\n memoizedOptions,\n );\n },\n\n useMutation: <T extends MutationEndpoint<Paths>>(\n endpoint: T,\n mutationOptions?: Omit<\n UseMutationOptions<\n ExtractEndpointResponse<Paths, T>,\n Error,\n FilteredRequestConfig<Paths, T>\n >,\n 'mutationFn'\n >,\n ) => {\n const memoizedOptions = useMemo(\n () => ({\n mutationFn: (config: FilteredRequestConfig<Paths, T>) =>\n fetcher(\n endpoint as Parameters<typeof fetcher>[0],\n config as Parameters<typeof fetcher>[1],\n ),\n ...mutationOptions,\n }),\n [endpoint, JSON.stringify(mutationOptions)],\n );\n\n return useMutation<\n ExtractEndpointResponse<Paths, T>,\n Error,\n FilteredRequestConfig<Paths, T>\n >(memoizedOptions);\n },\n\n buildQueryKey,\n };\n}\n"],"mappings":";;;;;;;;AAmBA,SAAS,cACPA,UACAC,QACW;CACX,MAAMC,MAAiB,CAAC,QAAS;AAEjC,KAAI,UAAU,YAAY,UAAU,OAAO,OACzC,KAAI,KAAK,EAAE,QAAQ,OAAO,OAAQ,EAAC;AAGrC,KAAI,UAAU,WAAW,UAAU,OAAO,MACxC,KAAI,KAAK,EAAE,OAAO,OAAO,MAAO,EAAC;AAGnC,QAAO;AACR;;;;;;;;;;;;;;;;AA0FD,SAAgB,oBACdC,SACAC,UAAsC,CAAE,GAClB;AACtB,QAAO;EACL,UAAU,CACRJ,UACA,GAAG,SACA;GAEH,MAAM,CAAC,QAAQ,aAAa,GAAG;GAW/B,MAAM,WAAW,cAAc,UAAU,OAAO;GAEhD,MAAM,kBAAkB,mBACtB,OAAO;IACL;IACA,SAAS,MACP,QACE,UACA,OACD;IACH,GAAG;GACJ,IACD;IACE,SAAS,KAAK,IAAI;IAClB;IACA,KAAK,UAAU,OAAO;IACtB,KAAK,UAAU,aAAa;GAC7B,EACF;AAED,UAAO,qCACL,gBACD;EACF;EAED,aAAa,CACXA,UACAK,oBAQG;GACH,MAAM,kBAAkB,mBACtB,OAAO;IACL,YAAY,CAACC,WACX,QACE,UACA,OACD;IACH,GAAG;GACJ,IACD,CAAC,UAAU,KAAK,UAAU,gBAAgB,AAAC,EAC5C;AAED,UAAO,wCAIL,gBAAgB;EACnB;EAED;CACD;AACF"}
1
+ {"version":3,"file":"endpoint-hooks.cjs","names":["endpoint: T","config?: FilteredRequestConfig<Paths, T>","key: unknown[]","fetcher: TypedApiFunction<Paths>","options: CreateEndpointHooksOptions","mutationOptions?: Omit<\n UseMutationOptions<\n ExtractEndpointResponse<Paths, T>,\n Error,\n FilteredRequestConfig<Paths, T>\n >,\n 'mutationFn'\n >","config: FilteredRequestConfig<Paths, T>"],"sources":["../src/endpoint-hooks.ts"],"sourcesContent":["import type {\n QueryClient,\n UseMutationOptions,\n UseQueryOptions,\n} from '@tanstack/react-query';\nimport { useMutation, useQuery } from '@tanstack/react-query';\nimport { useMemo } from 'react';\nimport type {\n ExtractEndpointResponse,\n FilteredRequestConfig,\n IsConfigRequired,\n MutationEndpoint,\n QueryEndpoint,\n TypedApiFunction,\n} from './types';\n\n/**\n * Build query key from endpoint and config\n */\nfunction buildQueryKey<Paths, T extends QueryEndpoint<Paths>>(\n endpoint: T,\n config?: FilteredRequestConfig<Paths, T>,\n): unknown[] {\n const key: unknown[] = [endpoint];\n\n if (config && 'params' in config && config.params) {\n key.push({ params: config.params });\n }\n\n if (config && 'query' in config && config.query) {\n key.push({ query: config.query });\n }\n\n return key;\n}\n\n/**\n * Options for creating endpoint-based hooks\n */\nexport interface CreateEndpointHooksOptions {\n queryClient?: QueryClient;\n}\n\n/**\n * Hook options type that conditionally requires config\n */\ntype UseQueryArgs<Paths, T extends QueryEndpoint<Paths>> = IsConfigRequired<\n Paths,\n T\n> extends true\n ? [\n config: FilteredRequestConfig<Paths, T>,\n options?: Omit<\n UseQueryOptions<ExtractEndpointResponse<Paths, T>, Error>,\n 'queryKey' | 'queryFn'\n >,\n ]\n : [\n config?: FilteredRequestConfig<Paths, T>,\n options?: Omit<\n UseQueryOptions<ExtractEndpointResponse<Paths, T>, Error>,\n 'queryKey' | 'queryFn'\n >,\n ];\n\n/**\n * Endpoint-based React Query hooks\n */\nexport interface EndpointHooks<Paths> {\n /**\n * Use query hook for GET endpoints.\n * Config is required when endpoint has path params.\n */\n useQuery: <T extends QueryEndpoint<Paths>>(\n endpoint: T,\n ...args: UseQueryArgs<Paths, T>\n ) => ReturnType<typeof useQuery<ExtractEndpointResponse<Paths, T>, Error>>;\n\n /**\n * Use mutation hook for POST, PUT, PATCH, DELETE endpoints.\n * Config with params/body is passed to mutate().\n */\n useMutation: <T extends MutationEndpoint<Paths>>(\n endpoint: T,\n options?: Omit<\n UseMutationOptions<\n ExtractEndpointResponse<Paths, T>,\n Error,\n FilteredRequestConfig<Paths, T>\n >,\n 'mutationFn'\n >,\n ) => ReturnType<\n typeof useMutation<\n ExtractEndpointResponse<Paths, T>,\n Error,\n FilteredRequestConfig<Paths, T>\n >\n >;\n\n /**\n * Build a query key for manual cache operations\n */\n buildQueryKey: <T extends QueryEndpoint<Paths>>(\n endpoint: T,\n config?: FilteredRequestConfig<Paths, T>,\n ) => unknown[];\n}\n\n/**\n * Create endpoint-based React Query hooks from a typed fetcher.\n *\n * @example\n * ```typescript\n * const fetcher = createAuthAwareFetcher<paths>({ ... });\n * const hooks = createEndpointHooks<paths>(fetcher);\n *\n * // In a component\n * const { data } = hooks.useQuery('GET /users/{id}', { params: { id: '123' } });\n *\n * const mutation = hooks.useMutation('POST /users');\n * await mutation.mutateAsync({ body: { name: 'John' } });\n * ```\n */\nexport function createEndpointHooks<Paths>(\n fetcher: TypedApiFunction<Paths>,\n options: CreateEndpointHooksOptions = {},\n): EndpointHooks<Paths> {\n return {\n useQuery: <T extends QueryEndpoint<Paths>>(\n endpoint: T,\n ...args: UseQueryArgs<Paths, T>\n ) => {\n // Parse args - config is first, options is second\n const [config, queryOptions] = args as [\n FilteredRequestConfig<Paths, T> | undefined,\n (\n | Omit<\n UseQueryOptions<ExtractEndpointResponse<Paths, T>, Error>,\n 'queryKey' | 'queryFn'\n >\n | undefined\n ),\n ];\n\n const queryKey = buildQueryKey(endpoint, config);\n\n const memoizedOptions = useMemo(\n () => ({\n queryKey,\n queryFn: () =>\n // Type assertion needed due to complex conditional types\n (\n fetcher as (\n endpoint: T,\n config?: unknown,\n ) => Promise<ExtractEndpointResponse<Paths, T>>\n )(endpoint, config),\n ...queryOptions,\n }),\n [\n queryKey.join(','),\n endpoint,\n JSON.stringify(config),\n JSON.stringify(queryOptions),\n ],\n );\n\n return useQuery<ExtractEndpointResponse<Paths, T>, Error>(\n memoizedOptions,\n );\n },\n\n useMutation: <T extends MutationEndpoint<Paths>>(\n endpoint: T,\n mutationOptions?: Omit<\n UseMutationOptions<\n ExtractEndpointResponse<Paths, T>,\n Error,\n FilteredRequestConfig<Paths, T>\n >,\n 'mutationFn'\n >,\n ) => {\n const memoizedOptions = useMemo(\n () => ({\n mutationFn: (config: FilteredRequestConfig<Paths, T>) =>\n // Type assertion needed due to complex conditional types\n (\n fetcher as (\n endpoint: T,\n config?: unknown,\n ) => Promise<ExtractEndpointResponse<Paths, T>>\n )(endpoint, config),\n ...mutationOptions,\n }),\n [endpoint, JSON.stringify(mutationOptions)],\n );\n\n return useMutation<\n ExtractEndpointResponse<Paths, T>,\n Error,\n FilteredRequestConfig<Paths, T>\n >(memoizedOptions);\n },\n\n buildQueryKey,\n };\n}\n"],"mappings":";;;;;;;;AAmBA,SAAS,cACPA,UACAC,QACW;CACX,MAAMC,MAAiB,CAAC,QAAS;AAEjC,KAAI,UAAU,YAAY,UAAU,OAAO,OACzC,KAAI,KAAK,EAAE,QAAQ,OAAO,OAAQ,EAAC;AAGrC,KAAI,UAAU,WAAW,UAAU,OAAO,MACxC,KAAI,KAAK,EAAE,OAAO,OAAO,MAAO,EAAC;AAGnC,QAAO;AACR;;;;;;;;;;;;;;;;AA0FD,SAAgB,oBACdC,SACAC,UAAsC,CAAE,GAClB;AACtB,QAAO;EACL,UAAU,CACRJ,UACA,GAAG,SACA;GAEH,MAAM,CAAC,QAAQ,aAAa,GAAG;GAW/B,MAAM,WAAW,cAAc,UAAU,OAAO;GAEhD,MAAM,kBAAkB,mBACtB,OAAO;IACL;IACA,SAAS,MAEP,AACE,QAIA,UAAU,OAAO;IACrB,GAAG;GACJ,IACD;IACE,SAAS,KAAK,IAAI;IAClB;IACA,KAAK,UAAU,OAAO;IACtB,KAAK,UAAU,aAAa;GAC7B,EACF;AAED,UAAO,qCACL,gBACD;EACF;EAED,aAAa,CACXA,UACAK,oBAQG;GACH,MAAM,kBAAkB,mBACtB,OAAO;IACL,YAAY,CAACC,WAEX,AACE,QAIA,UAAU,OAAO;IACrB,GAAG;GACJ,IACD,CAAC,UAAU,KAAK,UAAU,gBAAgB,AAAC,EAC5C;AAED,UAAO,wCAIL,gBAAgB;EACnB;EAED;CACD;AACF"}
@@ -1,4 +1,4 @@
1
- import { ExtractEndpointResponse, FilteredRequestConfig, IsConfigRequired, MutationEndpoint, QueryEndpoint, TypedApiFunction } from "./types-D4OSWveN.cjs";
1
+ import { ExtractEndpointResponse, FilteredRequestConfig, IsConfigRequired, MutationEndpoint, QueryEndpoint, TypedApiFunction } from "./types-vutATyWv.cjs";
2
2
  import { QueryClient, UseMutationOptions, UseQueryOptions, useMutation, useQuery } from "@tanstack/react-query";
3
3
 
4
4
  //#region src/endpoint-hooks.d.ts
@@ -0,0 +1 @@
1
+ {"version":3,"file":"endpoint-hooks.d.cts","names":[],"sources":["../src/endpoint-hooks.ts"],"sourcesContent":[],"mappings":";;;;;;AAuCA;AAEC;AAKgB,UAPA,0BAAA,CAOA;EAAA,WAAgC,CAAA,EANjC,WAMiC;;;;;KAA5C,YAK+B,CAAA,KAAA,EAAA,UALD,aAKC,CALa,KAKb,CAAA,CAAA,GALuB,gBAKvB,CAJlC,KAIkC,EAHlC,CAGkC,CAAA,SAAA,IAAA,GAAA,CAAK,MAAE,EAA7B,qBAA6B,CAAP,KAAO,EAAA,CAAA,CAAA,EAAC,OAA9B,GACE,IADF,CAEN,eAFM,CAEU,uBAFV,CAEkC,KAFlC,EAEyC,CAFzC,CAAA,EAE6C,KAF7C,CAAA,EAAA,UAAA,GAAA,SAAA,CAAA,CAAqB,GAAA,CAEkB,MAAE,GAKxC,qBALwC,CAKlB,KALkB,EAKX,CALW,CAAA,EAAC,OAAhC,GAMR,IANQ,CAOhB,eAPgB,CAOA,uBAPA,CAOwB,KAPxB,EAO+B,CAP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,CAAA,EAuClC,aAvCkC,CAuCpB,KAvCoB,CAAA"}
@@ -1,4 +1,4 @@
1
- import { ExtractEndpointResponse, FilteredRequestConfig, IsConfigRequired, MutationEndpoint, QueryEndpoint, TypedApiFunction } from "./types-Cdv1XAWr.mjs";
1
+ import { ExtractEndpointResponse, FilteredRequestConfig, IsConfigRequired, MutationEndpoint, QueryEndpoint, TypedApiFunction } from "./types-FxummKaL.mjs";
2
2
  import { QueryClient, UseMutationOptions, UseQueryOptions, useMutation, useQuery } from "@tanstack/react-query";
3
3
 
4
4
  //#region src/endpoint-hooks.d.ts
@@ -0,0 +1 @@
1
+ {"version":3,"file":"endpoint-hooks.d.mts","names":[],"sources":["../src/endpoint-hooks.ts"],"sourcesContent":[],"mappings":";;;;;;AAuCA;AAEC;AAKgB,UAPA,0BAAA,CAOA;EAAA,WAAgC,CAAA,EANjC,WAMiC;;;;;KAA5C,YAK+B,CAAA,KAAA,EAAA,UALD,aAKC,CALa,KAKb,CAAA,CAAA,GALuB,gBAKvB,CAJlC,KAIkC,EAHlC,CAGkC,CAAA,SAAA,IAAA,GAAA,CAAK,MAAE,EAA7B,qBAA6B,CAAP,KAAO,EAAA,CAAA,CAAA,EAAC,OAA9B,GACE,IADF,CAEN,eAFM,CAEU,uBAFV,CAEkC,KAFlC,EAEyC,CAFzC,CAAA,EAE6C,KAF7C,CAAA,EAAA,UAAA,GAAA,SAAA,CAAA,CAAqB,GAAA,CAEkB,MAAE,GAKxC,qBALwC,CAKlB,KALkB,EAKX,CALW,CAAA,EAAC,OAAhC,GAMR,IANQ,CAOhB,eAPgB,CAOA,uBAPA,CAOwB,KAPxB,EAO+B,CAP/B,CAAA,EAOmC,KAPnC,CAAA,EAAA,UAAA,GAAA,SAAA,CAAA,CAAuB;;;;AAKH,UAU3B,aAV2B,CAAA,KAAA,CAAA,CAAA;EAAC;;;;EAEE,QAAY,EAAA,CAAA,UAapC,aAboC,CAatB,KAbsB,CAAA,CAAA,CAAA,QAAA,EAc7C,CAd6C,EAAA,GAAA,IAAA,EAe9C,YAf8C,CAejC,KAfiC,EAe1B,CAf0B,CAAA,EAAA,GAgBpD,UAhBoD,CAAA,OAgBlC,QAhBkC,CAgBzB,uBAhByB,CAgBD,KAhBC,EAgBM,CAhBN,CAAA,EAgBU,KAhBV,CAAA,CAAA;EAAK;;AAD5C;AASpB;EAA8B,WAAA,EAAA,CAAA,UAcJ,gBAdI,CAca,KAdb,CAAA,CAAA,CAAA,QAAA,EAehB,CAfgB,EAAA,OAAA,CAAA,EAgBhB,IAhBgB,CAiBxB,kBAjBwB,CAkBtB,uBAlBsB,CAkBE,KAlBF,EAkBS,CAlBT,CAAA,EAmBtB,KAnBsB,EAoBtB,qBApBsB,CAoBA,KApBA,EAoBO,CApBP,CAAA,CAAA,EAAA,YAAA,CAAA,EAAA,GAwBvB,UAxBuB,CAAA,OAyBnB,WAzBmB,CA0BxB,uBA1BwB,CA0BA,KA1BA,EA0BO,CA1BP,CAAA,EA2BxB,KA3BwB,EA4BxB,qBA5BwB,CA4BF,KA5BE,EA4BK,CA5BL,CAAA,CAAA,CAAA;EAAA;;;EAMf,aACW,EAAA,CAAA,UA4BE,aA5BF,CA4BgB,KA5BhB,CAAA,CAAA,CAAA,QAAA,EA6BZ,CA7BY,EAAA,MAAA,CAAA,EA8Bb,qBA9Ba,CA8BS,KA9BT,EA8BgB,CA9BhB,CAAA,EAAA,GAAA,OAAA,EAAA;;;;;;;;;;;;;;;;;AAaW,iBAoCrB,mBApCqB,CAAA,KAAA,CAAA,CAAA,OAAA,EAqC1B,gBArC0B,CAqCT,KArCS,CAAA,EAAA,OAAA,CAAA,EAsC1B,0BAtC0B,CAAA,EAuClC,aAvCkC,CAuCpB,KAvCoB,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"endpoint-hooks.mjs","names":["endpoint: T","config?: FilteredRequestConfig<Paths, T>","key: unknown[]","fetcher: TypedApiFunction<Paths>","options: CreateEndpointHooksOptions","mutationOptions?: Omit<\n UseMutationOptions<\n ExtractEndpointResponse<Paths, T>,\n Error,\n FilteredRequestConfig<Paths, T>\n >,\n 'mutationFn'\n >","config: FilteredRequestConfig<Paths, T>"],"sources":["../src/endpoint-hooks.ts"],"sourcesContent":["import type {\n QueryClient,\n UseMutationOptions,\n UseQueryOptions,\n} from '@tanstack/react-query';\nimport { useMutation, useQuery } from '@tanstack/react-query';\nimport { useMemo } from 'react';\nimport type {\n ExtractEndpointResponse,\n FilteredRequestConfig,\n IsConfigRequired,\n MutationEndpoint,\n QueryEndpoint,\n TypedApiFunction,\n} from './types';\n\n/**\n * Build query key from endpoint and config\n */\nfunction buildQueryKey<Paths, T extends QueryEndpoint<Paths>>(\n endpoint: T,\n config?: FilteredRequestConfig<Paths, T>,\n): unknown[] {\n const key: unknown[] = [endpoint];\n\n if (config && 'params' in config && config.params) {\n key.push({ params: config.params });\n }\n\n if (config && 'query' in config && config.query) {\n key.push({ query: config.query });\n }\n\n return key;\n}\n\n/**\n * Options for creating endpoint-based hooks\n */\nexport interface CreateEndpointHooksOptions {\n queryClient?: QueryClient;\n}\n\n/**\n * Hook options type that conditionally requires config\n */\ntype UseQueryArgs<Paths, T extends QueryEndpoint<Paths>> = IsConfigRequired<\n Paths,\n T\n> extends true\n ? [\n config: FilteredRequestConfig<Paths, T>,\n options?: Omit<\n UseQueryOptions<ExtractEndpointResponse<Paths, T>, Error>,\n 'queryKey' | 'queryFn'\n >,\n ]\n : [\n config?: FilteredRequestConfig<Paths, T>,\n options?: Omit<\n UseQueryOptions<ExtractEndpointResponse<Paths, T>, Error>,\n 'queryKey' | 'queryFn'\n >,\n ];\n\n/**\n * Endpoint-based React Query hooks\n */\nexport interface EndpointHooks<Paths> {\n /**\n * Use query hook for GET endpoints.\n * Config is required when endpoint has path params.\n */\n useQuery: <T extends QueryEndpoint<Paths>>(\n endpoint: T,\n ...args: UseQueryArgs<Paths, T>\n ) => ReturnType<typeof useQuery<ExtractEndpointResponse<Paths, T>, Error>>;\n\n /**\n * Use mutation hook for POST, PUT, PATCH, DELETE endpoints.\n * Config with params/body is passed to mutate().\n */\n useMutation: <T extends MutationEndpoint<Paths>>(\n endpoint: T,\n options?: Omit<\n UseMutationOptions<\n ExtractEndpointResponse<Paths, T>,\n Error,\n FilteredRequestConfig<Paths, T>\n >,\n 'mutationFn'\n >,\n ) => ReturnType<\n typeof useMutation<\n ExtractEndpointResponse<Paths, T>,\n Error,\n FilteredRequestConfig<Paths, T>\n >\n >;\n\n /**\n * Build a query key for manual cache operations\n */\n buildQueryKey: <T extends QueryEndpoint<Paths>>(\n endpoint: T,\n config?: FilteredRequestConfig<Paths, T>,\n ) => unknown[];\n}\n\n/**\n * Create endpoint-based React Query hooks from a typed fetcher.\n *\n * @example\n * ```typescript\n * const fetcher = createAuthAwareFetcher<paths>({ ... });\n * const hooks = createEndpointHooks<paths>(fetcher);\n *\n * // In a component\n * const { data } = hooks.useQuery('GET /users/{id}', { params: { id: '123' } });\n *\n * const mutation = hooks.useMutation('POST /users');\n * await mutation.mutateAsync({ body: { name: 'John' } });\n * ```\n */\nexport function createEndpointHooks<Paths>(\n fetcher: TypedApiFunction<Paths>,\n options: CreateEndpointHooksOptions = {},\n): EndpointHooks<Paths> {\n return {\n useQuery: <T extends QueryEndpoint<Paths>>(\n endpoint: T,\n ...args: UseQueryArgs<Paths, T>\n ) => {\n // Parse args - config is first, options is second\n const [config, queryOptions] = args as [\n FilteredRequestConfig<Paths, T> | undefined,\n (\n | Omit<\n UseQueryOptions<ExtractEndpointResponse<Paths, T>, Error>,\n 'queryKey' | 'queryFn'\n >\n | undefined\n ),\n ];\n\n const queryKey = buildQueryKey(endpoint, config);\n\n const memoizedOptions = useMemo(\n () => ({\n queryKey,\n queryFn: () =>\n fetcher(\n endpoint as Parameters<typeof fetcher>[0],\n config as Parameters<typeof fetcher>[1],\n ),\n ...queryOptions,\n }),\n [\n queryKey.join(','),\n endpoint,\n JSON.stringify(config),\n JSON.stringify(queryOptions),\n ],\n );\n\n return useQuery<ExtractEndpointResponse<Paths, T>, Error>(\n memoizedOptions,\n );\n },\n\n useMutation: <T extends MutationEndpoint<Paths>>(\n endpoint: T,\n mutationOptions?: Omit<\n UseMutationOptions<\n ExtractEndpointResponse<Paths, T>,\n Error,\n FilteredRequestConfig<Paths, T>\n >,\n 'mutationFn'\n >,\n ) => {\n const memoizedOptions = useMemo(\n () => ({\n mutationFn: (config: FilteredRequestConfig<Paths, T>) =>\n fetcher(\n endpoint as Parameters<typeof fetcher>[0],\n config as Parameters<typeof fetcher>[1],\n ),\n ...mutationOptions,\n }),\n [endpoint, JSON.stringify(mutationOptions)],\n );\n\n return useMutation<\n ExtractEndpointResponse<Paths, T>,\n Error,\n FilteredRequestConfig<Paths, T>\n >(memoizedOptions);\n },\n\n buildQueryKey,\n };\n}\n"],"mappings":";;;;;;;AAmBA,SAAS,cACPA,UACAC,QACW;CACX,MAAMC,MAAiB,CAAC,QAAS;AAEjC,KAAI,UAAU,YAAY,UAAU,OAAO,OACzC,KAAI,KAAK,EAAE,QAAQ,OAAO,OAAQ,EAAC;AAGrC,KAAI,UAAU,WAAW,UAAU,OAAO,MACxC,KAAI,KAAK,EAAE,OAAO,OAAO,MAAO,EAAC;AAGnC,QAAO;AACR;;;;;;;;;;;;;;;;AA0FD,SAAgB,oBACdC,SACAC,UAAsC,CAAE,GAClB;AACtB,QAAO;EACL,UAAU,CACRJ,UACA,GAAG,SACA;GAEH,MAAM,CAAC,QAAQ,aAAa,GAAG;GAW/B,MAAM,WAAW,cAAc,UAAU,OAAO;GAEhD,MAAM,kBAAkB,QACtB,OAAO;IACL;IACA,SAAS,MACP,QACE,UACA,OACD;IACH,GAAG;GACJ,IACD;IACE,SAAS,KAAK,IAAI;IAClB;IACA,KAAK,UAAU,OAAO;IACtB,KAAK,UAAU,aAAa;GAC7B,EACF;AAED,UAAO,SACL,gBACD;EACF;EAED,aAAa,CACXA,UACAK,oBAQG;GACH,MAAM,kBAAkB,QACtB,OAAO;IACL,YAAY,CAACC,WACX,QACE,UACA,OACD;IACH,GAAG;GACJ,IACD,CAAC,UAAU,KAAK,UAAU,gBAAgB,AAAC,EAC5C;AAED,UAAO,YAIL,gBAAgB;EACnB;EAED;CACD;AACF"}
1
+ {"version":3,"file":"endpoint-hooks.mjs","names":["endpoint: T","config?: FilteredRequestConfig<Paths, T>","key: unknown[]","fetcher: TypedApiFunction<Paths>","options: CreateEndpointHooksOptions","mutationOptions?: Omit<\n UseMutationOptions<\n ExtractEndpointResponse<Paths, T>,\n Error,\n FilteredRequestConfig<Paths, T>\n >,\n 'mutationFn'\n >","config: FilteredRequestConfig<Paths, T>"],"sources":["../src/endpoint-hooks.ts"],"sourcesContent":["import type {\n QueryClient,\n UseMutationOptions,\n UseQueryOptions,\n} from '@tanstack/react-query';\nimport { useMutation, useQuery } from '@tanstack/react-query';\nimport { useMemo } from 'react';\nimport type {\n ExtractEndpointResponse,\n FilteredRequestConfig,\n IsConfigRequired,\n MutationEndpoint,\n QueryEndpoint,\n TypedApiFunction,\n} from './types';\n\n/**\n * Build query key from endpoint and config\n */\nfunction buildQueryKey<Paths, T extends QueryEndpoint<Paths>>(\n endpoint: T,\n config?: FilteredRequestConfig<Paths, T>,\n): unknown[] {\n const key: unknown[] = [endpoint];\n\n if (config && 'params' in config && config.params) {\n key.push({ params: config.params });\n }\n\n if (config && 'query' in config && config.query) {\n key.push({ query: config.query });\n }\n\n return key;\n}\n\n/**\n * Options for creating endpoint-based hooks\n */\nexport interface CreateEndpointHooksOptions {\n queryClient?: QueryClient;\n}\n\n/**\n * Hook options type that conditionally requires config\n */\ntype UseQueryArgs<Paths, T extends QueryEndpoint<Paths>> = IsConfigRequired<\n Paths,\n T\n> extends true\n ? [\n config: FilteredRequestConfig<Paths, T>,\n options?: Omit<\n UseQueryOptions<ExtractEndpointResponse<Paths, T>, Error>,\n 'queryKey' | 'queryFn'\n >,\n ]\n : [\n config?: FilteredRequestConfig<Paths, T>,\n options?: Omit<\n UseQueryOptions<ExtractEndpointResponse<Paths, T>, Error>,\n 'queryKey' | 'queryFn'\n >,\n ];\n\n/**\n * Endpoint-based React Query hooks\n */\nexport interface EndpointHooks<Paths> {\n /**\n * Use query hook for GET endpoints.\n * Config is required when endpoint has path params.\n */\n useQuery: <T extends QueryEndpoint<Paths>>(\n endpoint: T,\n ...args: UseQueryArgs<Paths, T>\n ) => ReturnType<typeof useQuery<ExtractEndpointResponse<Paths, T>, Error>>;\n\n /**\n * Use mutation hook for POST, PUT, PATCH, DELETE endpoints.\n * Config with params/body is passed to mutate().\n */\n useMutation: <T extends MutationEndpoint<Paths>>(\n endpoint: T,\n options?: Omit<\n UseMutationOptions<\n ExtractEndpointResponse<Paths, T>,\n Error,\n FilteredRequestConfig<Paths, T>\n >,\n 'mutationFn'\n >,\n ) => ReturnType<\n typeof useMutation<\n ExtractEndpointResponse<Paths, T>,\n Error,\n FilteredRequestConfig<Paths, T>\n >\n >;\n\n /**\n * Build a query key for manual cache operations\n */\n buildQueryKey: <T extends QueryEndpoint<Paths>>(\n endpoint: T,\n config?: FilteredRequestConfig<Paths, T>,\n ) => unknown[];\n}\n\n/**\n * Create endpoint-based React Query hooks from a typed fetcher.\n *\n * @example\n * ```typescript\n * const fetcher = createAuthAwareFetcher<paths>({ ... });\n * const hooks = createEndpointHooks<paths>(fetcher);\n *\n * // In a component\n * const { data } = hooks.useQuery('GET /users/{id}', { params: { id: '123' } });\n *\n * const mutation = hooks.useMutation('POST /users');\n * await mutation.mutateAsync({ body: { name: 'John' } });\n * ```\n */\nexport function createEndpointHooks<Paths>(\n fetcher: TypedApiFunction<Paths>,\n options: CreateEndpointHooksOptions = {},\n): EndpointHooks<Paths> {\n return {\n useQuery: <T extends QueryEndpoint<Paths>>(\n endpoint: T,\n ...args: UseQueryArgs<Paths, T>\n ) => {\n // Parse args - config is first, options is second\n const [config, queryOptions] = args as [\n FilteredRequestConfig<Paths, T> | undefined,\n (\n | Omit<\n UseQueryOptions<ExtractEndpointResponse<Paths, T>, Error>,\n 'queryKey' | 'queryFn'\n >\n | undefined\n ),\n ];\n\n const queryKey = buildQueryKey(endpoint, config);\n\n const memoizedOptions = useMemo(\n () => ({\n queryKey,\n queryFn: () =>\n // Type assertion needed due to complex conditional types\n (\n fetcher as (\n endpoint: T,\n config?: unknown,\n ) => Promise<ExtractEndpointResponse<Paths, T>>\n )(endpoint, config),\n ...queryOptions,\n }),\n [\n queryKey.join(','),\n endpoint,\n JSON.stringify(config),\n JSON.stringify(queryOptions),\n ],\n );\n\n return useQuery<ExtractEndpointResponse<Paths, T>, Error>(\n memoizedOptions,\n );\n },\n\n useMutation: <T extends MutationEndpoint<Paths>>(\n endpoint: T,\n mutationOptions?: Omit<\n UseMutationOptions<\n ExtractEndpointResponse<Paths, T>,\n Error,\n FilteredRequestConfig<Paths, T>\n >,\n 'mutationFn'\n >,\n ) => {\n const memoizedOptions = useMemo(\n () => ({\n mutationFn: (config: FilteredRequestConfig<Paths, T>) =>\n // Type assertion needed due to complex conditional types\n (\n fetcher as (\n endpoint: T,\n config?: unknown,\n ) => Promise<ExtractEndpointResponse<Paths, T>>\n )(endpoint, config),\n ...mutationOptions,\n }),\n [endpoint, JSON.stringify(mutationOptions)],\n );\n\n return useMutation<\n ExtractEndpointResponse<Paths, T>,\n Error,\n FilteredRequestConfig<Paths, T>\n >(memoizedOptions);\n },\n\n buildQueryKey,\n };\n}\n"],"mappings":";;;;;;;AAmBA,SAAS,cACPA,UACAC,QACW;CACX,MAAMC,MAAiB,CAAC,QAAS;AAEjC,KAAI,UAAU,YAAY,UAAU,OAAO,OACzC,KAAI,KAAK,EAAE,QAAQ,OAAO,OAAQ,EAAC;AAGrC,KAAI,UAAU,WAAW,UAAU,OAAO,MACxC,KAAI,KAAK,EAAE,OAAO,OAAO,MAAO,EAAC;AAGnC,QAAO;AACR;;;;;;;;;;;;;;;;AA0FD,SAAgB,oBACdC,SACAC,UAAsC,CAAE,GAClB;AACtB,QAAO;EACL,UAAU,CACRJ,UACA,GAAG,SACA;GAEH,MAAM,CAAC,QAAQ,aAAa,GAAG;GAW/B,MAAM,WAAW,cAAc,UAAU,OAAO;GAEhD,MAAM,kBAAkB,QACtB,OAAO;IACL;IACA,SAAS,MAEP,AACE,QAIA,UAAU,OAAO;IACrB,GAAG;GACJ,IACD;IACE,SAAS,KAAK,IAAI;IAClB;IACA,KAAK,UAAU,OAAO;IACtB,KAAK,UAAU,aAAa;GAC7B,EACF;AAED,UAAO,SACL,gBACD;EACF;EAED,aAAa,CACXA,UACAK,oBAQG;GACH,MAAM,kBAAkB,QACtB,OAAO;IACL,YAAY,CAACC,WAEX,AACE,QAIA,UAAU,OAAO;IACrB,GAAG;GACJ,IACD,CAAC,UAAU,KAAK,UAAU,gBAAgB,AAAC,EAC5C;AAED,UAAO,YAIL,gBAAgB;EACnB;EAED;CACD;AACF"}
@@ -71,7 +71,7 @@ var TypedFetcher = class TypedFetcher {
71
71
  const [method, ...routeParts] = endpoint.split(" ");
72
72
  const route = routeParts.join(" ");
73
73
  return {
74
- method: method.toLowerCase(),
74
+ method: method?.toLowerCase() ?? "",
75
75
  route
76
76
  };
77
77
  }
@@ -83,4 +83,4 @@ function createTypedFetcher(options) {
83
83
 
84
84
  //#endregion
85
85
  export { TypedFetcher, createTypedFetcher };
86
- //# sourceMappingURL=fetcher-DLDD_7Sa.mjs.map
86
+ //# sourceMappingURL=fetcher-5fnBE7Dk.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"fetcher-DLDD_7Sa.mjs","names":["fn?: FetchFn","options: FetcherOptions","endpoint: T","config?: FilteredRequestConfig<Paths, T>","prefix: string","value: unknown","requestConfig: RequestInit","options?: FetcherOptions"],"sources":["../src/fetcher.ts"],"sourcesContent":["import type {\n EndpointString,\n ExtractEndpointResponse,\n FetcherOptions,\n FilteredRequestConfig,\n ParseEndpoint,\n TypedEndpoint,\n} from './types';\n\nexport type { FetcherOptions } from './types';\n\nexport class TypedFetcher<Paths> {\n private baseURL: string;\n private defaultHeaders: Record<string, string>;\n private options: FetcherOptions;\n private fetchFn: FetchFn;\n\n static getFetchFn(fn?: FetchFn): FetchFn {\n if (fn) {\n return fn;\n }\n\n if (typeof window !== 'undefined' && typeof window.fetch === 'function') {\n return window.fetch.bind(window);\n }\n\n if (\n typeof globalThis !== 'undefined' &&\n typeof globalThis.fetch === 'function'\n ) {\n return globalThis.fetch.bind(globalThis);\n }\n\n throw new Error('No fetch implementation found');\n }\n\n constructor(options: FetcherOptions = {}) {\n this.baseURL = options.baseURL || '';\n this.defaultHeaders = options.headers || {};\n this.options = options;\n this.fetchFn = TypedFetcher.getFetchFn(options.fetch);\n }\n\n async request<T extends TypedEndpoint<Paths>>(\n endpoint: T,\n config?: FilteredRequestConfig<Paths, T>,\n ): Promise<ExtractEndpointResponse<Paths, T>> {\n const { method, route } = this.parseEndpoint(endpoint);\n\n // Replace path parameters\n let url = route;\n if (config && 'params' in config && config.params) {\n Object.entries(config.params as Record<string, unknown>).forEach(\n ([key, value]) => {\n url = url.replace(`{${key}}`, encodeURIComponent(String(value)));\n },\n );\n }\n\n // Add query parameters\n if (config && 'query' in config && config.query) {\n const queryParams = new URLSearchParams();\n\n // Recursive function to handle nested objects and arrays\n const appendQueryParam = (prefix: string, value: unknown) => {\n if (value === undefined || value === null) {\n return;\n }\n\n if (Array.isArray(value)) {\n // Handle arrays by appending multiple values with the same key\n value.forEach((item) => {\n queryParams.append(prefix, String(item));\n });\n } else if (typeof value === 'object') {\n // For objects, recursively flatten into dot notation\n Object.entries(value as Record<string, unknown>).forEach(\n ([subKey, subValue]) => {\n appendQueryParam(`${prefix}.${subKey}`, subValue);\n },\n );\n } else {\n queryParams.append(prefix, String(value));\n }\n };\n\n // Process all query parameters\n Object.entries(config.query as Record<string, unknown>).forEach(\n ([key, value]) => {\n appendQueryParam(key, value);\n },\n );\n\n const queryString = queryParams.toString();\n if (queryString) {\n url += `?${queryString}`;\n }\n }\n\n // Build request configuration\n let requestConfig: RequestInit = {\n method: method.toUpperCase(),\n headers: {\n ...this.defaultHeaders,\n ...((config && 'headers' in config && config.headers) || {}),\n },\n };\n\n // Add body if present\n if (config && 'body' in config && config.body) {\n requestConfig.body = JSON.stringify(config.body);\n requestConfig.headers = {\n ...requestConfig.headers,\n 'Content-Type': 'application/json',\n };\n }\n\n // Apply request interceptor\n if (this.options.onRequest) {\n requestConfig = await this.options.onRequest(requestConfig);\n }\n\n try {\n // Make the request\n let response = await this.fetchFn(`${this.baseURL}${url}`, requestConfig);\n\n // Apply response interceptor\n if (this.options.onResponse) {\n response = await this.options.onResponse(response);\n }\n\n // Handle errors\n if (!response.ok) {\n throw response;\n }\n\n // Handle empty responses (204 No Content, etc.)\n if (\n response.status === 204 ||\n response.headers.get('content-length') === '0'\n ) {\n return undefined as ExtractEndpointResponse<Paths, T>;\n }\n\n // Parse JSON response\n const data = await response.json();\n return data as ExtractEndpointResponse<Paths, T>;\n } catch (error) {\n // Apply error handler\n if (this.options.onError) {\n // @ts-ignore\n await this.options.onError(error);\n }\n throw error;\n }\n }\n\n private parseEndpoint<T extends EndpointString>(\n endpoint: T,\n ): ParseEndpoint<T> {\n const [method, ...routeParts] = endpoint.split(' ');\n const route = routeParts.join(' ');\n return { method: method.toLowerCase(), route } as ParseEndpoint<T>;\n }\n}\n\nexport function createTypedFetcher<Paths>(options?: FetcherOptions) {\n const fetcher = new TypedFetcher<Paths>(options);\n return <T extends TypedEndpoint<Paths>>(\n endpoint: T,\n config?: FilteredRequestConfig<Paths, T>,\n ) => fetcher.request(endpoint, config);\n}\n\nexport type FetchFn = typeof fetch;\n"],"mappings":";AAWA,IAAa,eAAb,MAAa,aAAoB;CAC/B,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;CAER,OAAO,WAAWA,IAAuB;AACvC,MAAI,GACF,QAAO;AAGT,aAAW,WAAW,sBAAsB,OAAO,UAAU,WAC3D,QAAO,OAAO,MAAM,KAAK,OAAO;AAGlC,aACS,eAAe,sBACf,WAAW,UAAU,WAE5B,QAAO,WAAW,MAAM,KAAK,WAAW;AAG1C,QAAM,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Aa,UAAU,OAAO,WAAY,CAAE;GAC5D;EACF;AAGD,MAAI,UAAU,UAAU,UAAU,OAAO,MAAM;AAC7C,iBAAc,OAAO,KAAK,UAAU,OAAO,KAAK;AAChD,iBAAc,UAAU;IACtB,GAAG,cAAc;IACjB,gBAAgB;GACjB;EACF;AAGD,MAAI,KAAK,QAAQ,UACf,iBAAgB,MAAM,KAAK,QAAQ,UAAU,cAAc;AAG7D,MAAI;GAEF,IAAI,WAAW,MAAM,KAAK,SAAS,EAAE,KAAK,QAAQ,EAAE,IAAI,GAAG,cAAc;AAGzE,OAAI,KAAK,QAAQ,WACf,YAAW,MAAM,KAAK,QAAQ,WAAW,SAAS;AAIpD,QAAK,SAAS,GACZ,OAAM;AAIR,OACE,SAAS,WAAW,OACpB,SAAS,QAAQ,IAAI,iBAAiB,KAAK,IAE3C;GAIF,MAAM,OAAO,MAAM,SAAS,MAAM;AAClC,UAAO;EACR,SAAQ,OAAO;AAEd,OAAI,KAAK,QAAQ,QAEf,OAAM,KAAK,QAAQ,QAAQ,MAAM;AAEnC,SAAM;EACP;CACF;CAED,AAAQ,cACNJ,UACkB;EAClB,MAAM,CAAC,QAAQ,GAAG,WAAW,GAAG,SAAS,MAAM,IAAI;EACnD,MAAM,QAAQ,WAAW,KAAK,IAAI;AAClC,SAAO;GAAE,QAAQ,OAAO,aAAa;GAAE;EAAO;CAC/C;AACF;AAED,SAAgB,mBAA0BK,SAA0B;CAClE,MAAM,UAAU,IAAI,aAAoB;AACxC,QAAO,CACLL,UACAC,WACG,QAAQ,QAAQ,UAAU,OAAO;AACvC"}
1
+ {"version":3,"file":"fetcher-5fnBE7Dk.mjs","names":["fn?: FetchFn","options: FetcherOptions","endpoint: T","config?: FilteredRequestConfig<Paths, T>","prefix: string","value: unknown","requestConfig: RequestInit","options?: FetcherOptions"],"sources":["../src/fetcher.ts"],"sourcesContent":["import type {\n EndpointString,\n ExtractEndpointResponse,\n FetcherOptions,\n FilteredRequestConfig,\n ParseEndpoint,\n TypedEndpoint,\n} from './types';\n\nexport type { FetcherOptions } from './types';\n\nexport class TypedFetcher<Paths> {\n private baseURL: string;\n private defaultHeaders: Record<string, string>;\n private options: FetcherOptions;\n private fetchFn: FetchFn;\n\n static getFetchFn(fn?: FetchFn): FetchFn {\n if (fn) {\n return fn;\n }\n\n if (typeof window !== 'undefined' && typeof window.fetch === 'function') {\n return window.fetch.bind(window);\n }\n\n if (\n typeof globalThis !== 'undefined' &&\n typeof globalThis.fetch === 'function'\n ) {\n return globalThis.fetch.bind(globalThis);\n }\n\n throw new Error('No fetch implementation found');\n }\n\n constructor(options: FetcherOptions = {}) {\n this.baseURL = options.baseURL || '';\n this.defaultHeaders = options.headers || {};\n this.options = options;\n this.fetchFn = TypedFetcher.getFetchFn(options.fetch);\n }\n\n async request<T extends TypedEndpoint<Paths>>(\n endpoint: T,\n config?: FilteredRequestConfig<Paths, T>,\n ): Promise<ExtractEndpointResponse<Paths, T>> {\n const { method, route } = this.parseEndpoint(endpoint);\n\n // Replace path parameters\n let url = route;\n if (config && 'params' in config && config.params) {\n Object.entries(config.params as Record<string, unknown>).forEach(\n ([key, value]) => {\n url = url.replace(`{${key}}`, encodeURIComponent(String(value)));\n },\n );\n }\n\n // Add query parameters\n if (config && 'query' in config && config.query) {\n const queryParams = new URLSearchParams();\n\n // Recursive function to handle nested objects and arrays\n const appendQueryParam = (prefix: string, value: unknown) => {\n if (value === undefined || value === null) {\n return;\n }\n\n if (Array.isArray(value)) {\n // Handle arrays by appending multiple values with the same key\n value.forEach((item) => {\n queryParams.append(prefix, String(item));\n });\n } else if (typeof value === 'object') {\n // For objects, recursively flatten into dot notation\n Object.entries(value as Record<string, unknown>).forEach(\n ([subKey, subValue]) => {\n appendQueryParam(`${prefix}.${subKey}`, subValue);\n },\n );\n } else {\n queryParams.append(prefix, String(value));\n }\n };\n\n // Process all query parameters\n Object.entries(config.query as Record<string, unknown>).forEach(\n ([key, value]) => {\n appendQueryParam(key, value);\n },\n );\n\n const queryString = queryParams.toString();\n if (queryString) {\n url += `?${queryString}`;\n }\n }\n\n // Build request configuration\n let requestConfig: RequestInit = {\n method: method.toUpperCase(),\n headers: {\n ...this.defaultHeaders,\n ...((config && 'headers' in config && config.headers) || {}),\n },\n };\n\n // Add body if present\n if (config && 'body' in config && config.body) {\n requestConfig.body = JSON.stringify(config.body);\n requestConfig.headers = {\n ...requestConfig.headers,\n 'Content-Type': 'application/json',\n };\n }\n\n // Apply request interceptor\n if (this.options.onRequest) {\n requestConfig = await this.options.onRequest(requestConfig);\n }\n\n try {\n // Make the request\n let response = await this.fetchFn(`${this.baseURL}${url}`, requestConfig);\n\n // Apply response interceptor\n if (this.options.onResponse) {\n response = await this.options.onResponse(response);\n }\n\n // Handle errors\n if (!response.ok) {\n throw response;\n }\n\n // Handle empty responses (204 No Content, etc.)\n if (\n response.status === 204 ||\n response.headers.get('content-length') === '0'\n ) {\n return undefined as ExtractEndpointResponse<Paths, T>;\n }\n\n // Parse JSON response\n const data = await response.json();\n return data as ExtractEndpointResponse<Paths, T>;\n } catch (error) {\n // Apply error handler\n if (this.options.onError) {\n // @ts-ignore\n await this.options.onError(error);\n }\n throw error;\n }\n }\n\n private parseEndpoint<T extends EndpointString>(\n endpoint: T,\n ): ParseEndpoint<T> {\n const [method, ...routeParts] = endpoint.split(' ');\n const route = routeParts.join(' ');\n return { method: method?.toLowerCase() ?? '', route } as ParseEndpoint<T>;\n }\n}\n\nexport function createTypedFetcher<Paths>(options?: FetcherOptions) {\n const fetcher = new TypedFetcher<Paths>(options);\n return <T extends TypedEndpoint<Paths>>(\n endpoint: T,\n config?: FilteredRequestConfig<Paths, T>,\n ) => fetcher.request(endpoint, config);\n}\n\nexport type FetchFn = typeof fetch;\n"],"mappings":";AAWA,IAAa,eAAb,MAAa,aAAoB;CAC/B,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;CAER,OAAO,WAAWA,IAAuB;AACvC,MAAI,GACF,QAAO;AAGT,aAAW,WAAW,sBAAsB,O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75
- method: method.toLowerCase(),
75
+ method: method?.toLowerCase() ?? "",
76
76
  route
77
77
  };
78
78
  }
@@ -95,4 +95,4 @@ Object.defineProperty(exports, 'createTypedFetcher', {
95
95
  return createTypedFetcher;
96
96
  }
97
97
  });
98
- //# sourceMappingURL=fetcher-KdwHgdAl.cjs.map
98
+ //# sourceMappingURL=fetcher-CgLEaIAC.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"fetcher-KdwHgdAl.cjs","names":["fn?: FetchFn","options: FetcherOptions","endpoint: T","config?: FilteredRequestConfig<Paths, T>","prefix: string","value: unknown","requestConfig: RequestInit","options?: FetcherOptions"],"sources":["../src/fetcher.ts"],"sourcesContent":["import type {\n EndpointString,\n ExtractEndpointResponse,\n FetcherOptions,\n FilteredRequestConfig,\n ParseEndpoint,\n TypedEndpoint,\n} from './types';\n\nexport type { FetcherOptions } from './types';\n\nexport class TypedFetcher<Paths> {\n private baseURL: string;\n private defaultHeaders: Record<string, string>;\n private options: FetcherOptions;\n private fetchFn: FetchFn;\n\n static getFetchFn(fn?: FetchFn): FetchFn {\n if (fn) {\n return fn;\n }\n\n if (typeof window !== 'undefined' && typeof window.fetch === 'function') {\n return window.fetch.bind(window);\n }\n\n if (\n typeof globalThis !== 'undefined' &&\n typeof globalThis.fetch === 'function'\n ) {\n return globalThis.fetch.bind(globalThis);\n }\n\n throw new Error('No fetch implementation found');\n }\n\n constructor(options: FetcherOptions = {}) {\n this.baseURL = options.baseURL || '';\n this.defaultHeaders = options.headers || {};\n this.options = options;\n this.fetchFn = TypedFetcher.getFetchFn(options.fetch);\n }\n\n async request<T extends TypedEndpoint<Paths>>(\n endpoint: T,\n config?: FilteredRequestConfig<Paths, T>,\n ): Promise<ExtractEndpointResponse<Paths, T>> {\n const { method, route } = this.parseEndpoint(endpoint);\n\n // Replace path parameters\n let url = route;\n if (config && 'params' in config && config.params) {\n Object.entries(config.params as Record<string, unknown>).forEach(\n ([key, value]) => {\n url = url.replace(`{${key}}`, encodeURIComponent(String(value)));\n },\n );\n }\n\n // Add query parameters\n if (config && 'query' in config && config.query) {\n const queryParams = new URLSearchParams();\n\n // Recursive function to handle nested objects and arrays\n const appendQueryParam = (prefix: string, value: unknown) => {\n if (value === undefined || value === null) {\n return;\n }\n\n if (Array.isArray(value)) {\n // Handle arrays by appending multiple values with the same key\n value.forEach((item) => {\n queryParams.append(prefix, String(item));\n });\n } else if (typeof value === 'object') {\n // For objects, recursively flatten into dot notation\n Object.entries(value as Record<string, unknown>).forEach(\n ([subKey, subValue]) => {\n appendQueryParam(`${prefix}.${subKey}`, subValue);\n },\n );\n } else {\n queryParams.append(prefix, String(value));\n }\n };\n\n // Process all query parameters\n Object.entries(config.query as Record<string, unknown>).forEach(\n ([key, value]) => {\n appendQueryParam(key, value);\n },\n );\n\n const queryString = queryParams.toString();\n if (queryString) {\n url += `?${queryString}`;\n }\n }\n\n // Build request configuration\n let requestConfig: RequestInit = {\n method: method.toUpperCase(),\n headers: {\n ...this.defaultHeaders,\n ...((config && 'headers' in config && config.headers) || {}),\n },\n };\n\n // Add body if present\n if (config && 'body' in config && config.body) {\n requestConfig.body = JSON.stringify(config.body);\n requestConfig.headers = {\n ...requestConfig.headers,\n 'Content-Type': 'application/json',\n };\n }\n\n // Apply request interceptor\n if (this.options.onRequest) {\n requestConfig = await this.options.onRequest(requestConfig);\n }\n\n try {\n // Make the request\n let response = await this.fetchFn(`${this.baseURL}${url}`, requestConfig);\n\n // Apply response interceptor\n if (this.options.onResponse) {\n response = await this.options.onResponse(response);\n }\n\n // Handle errors\n if (!response.ok) {\n throw response;\n }\n\n // Handle empty responses (204 No Content, etc.)\n if (\n response.status === 204 ||\n response.headers.get('content-length') === '0'\n ) {\n return undefined as ExtractEndpointResponse<Paths, T>;\n }\n\n // Parse JSON response\n const data = await response.json();\n return data as ExtractEndpointResponse<Paths, T>;\n } catch (error) {\n // Apply error handler\n if (this.options.onError) {\n // @ts-ignore\n await this.options.onError(error);\n }\n throw error;\n }\n }\n\n private parseEndpoint<T extends EndpointString>(\n endpoint: T,\n ): ParseEndpoint<T> {\n const [method, ...routeParts] = endpoint.split(' ');\n const route = routeParts.join(' ');\n return { method: method.toLowerCase(), route } as ParseEndpoint<T>;\n }\n}\n\nexport function createTypedFetcher<Paths>(options?: FetcherOptions) {\n const fetcher = new TypedFetcher<Paths>(options);\n return <T extends TypedEndpoint<Paths>>(\n endpoint: T,\n config?: FilteredRequestConfig<Paths, T>,\n ) => fetcher.request(endpoint, config);\n}\n\nexport type FetchFn = typeof fetch;\n"],"mappings":";;AAWA,IAAa,eAAb,MAAa,aAAoB;CAC/B,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;CAER,OAAO,WAAWA,IAAuB;AACvC,MAAI,GACF,QAAO;AAGT,aAAW,WAAW,sBAAsB,OAAO,UAAU,WAC3D,QAAO,OAAO,MAAM,KAAK,OAAO;AAGlC,aACS,eAAe,sBACf,WAAW,UAAU,WAE5B,QAAO,WAAW,MAAM,KAAK,WAAW;AAG1C,QAAM,IAAI,MAAM;CACjB;CAED,YAAYC,UAA0B,CAAE,GAAE;AACxC,OAAK,UAAU,QAAQ,WAAW;AAClC,OAAK,iBAAiB,QAAQ,WAAW,CAAE;AAC3C,OAAK,UAAU;AACf,OAAK,UAAU,aAAa,WAAW,QAAQ,MAAM;CACtD;CAED,MAAM,QACJC,UACAC,QAC4C;EAC5C,MAAM,EAAE,QAAQ,OAAO,GAAG,KAAK,cAAc,SAAS;EAGtD,IAAI,MAAM;AACV,MAAI,UAAU,YAAY,UAAU,OAAO,OACzC,QAAO,QAAQ,OAAO,OAAkC,CAAC,QACvD,CAAC,CAAC,KAAK,MAAM,KAAK;AAChB,SAAM,IAAI,SAAS,GAAG,IAAI,IAAI,mBAAmB,OAAO,MAAM,CAAC,CAAC;EACjE,EACF;AAIH,MAAI,UAAU,WAAW,UAAU,OAAO,OAAO;GAC/C,MAAM,cAAc,IAAI;GAGxB,MAAM,mBAAmB,CAACC,QAAgBC,UAAmB;AA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AK,QAAQ,QAEf,OAAM,KAAK,QAAQ,QAAQ,MAAM;AAEnC,SAAM;EACP;CACF;CAED,AAAQ,cACNJ,UACkB;EAClB,MAAM,CAAC,QAAQ,GAAG,WAAW,GAAG,SAAS,MAAM,IAAI;EACnD,MAAM,QAAQ,WAAW,KAAK,IAAI;AAClC,SAAO;GAAE,QAAQ,OAAO,aAAa;GAAE;EAAO;CAC/C;AACF;AAED,SAAgB,mBAA0BK,SAA0B;CAClE,MAAM,UAAU,IAAI,aAAoB;AACxC,QAAO,CACLL,UACAC,WACG,QAAQ,QAAQ,UAAU,OAAO;AACvC"}
1
+ {"version":3,"file":"fetcher-CgLEaIAC.cjs","names":["fn?: FetchFn","options: FetcherOptions","endpoint: T","config?: FilteredRequestConfig<Paths, T>","prefix: string","value: unknown","requestConfig: RequestInit","options?: FetcherOptions"],"sources":["../src/fetcher.ts"],"sourcesContent":["import type {\n EndpointString,\n ExtractEndpointResponse,\n FetcherOptions,\n FilteredRequestConfig,\n ParseEndpoint,\n TypedEndpoint,\n} from './types';\n\nexport type { FetcherOptions } from './types';\n\nexport class TypedFetcher<Paths> {\n private baseURL: string;\n private defaultHeaders: Record<string, string>;\n private options: FetcherOptions;\n private fetchFn: FetchFn;\n\n static getFetchFn(fn?: FetchFn): FetchFn {\n if (fn) {\n return fn;\n }\n\n if (typeof window !== 'undefined' && typeof window.fetch === 'function') {\n return window.fetch.bind(window);\n }\n\n if (\n typeof globalThis !== 'undefined' &&\n typeof globalThis.fetch === 'function'\n ) {\n return globalThis.fetch.bind(globalThis);\n }\n\n throw new Error('No fetch implementation found');\n }\n\n constructor(options: FetcherOptions = {}) {\n this.baseURL = options.baseURL || '';\n this.defaultHeaders = options.headers || {};\n this.options = options;\n this.fetchFn = TypedFetcher.getFetchFn(options.fetch);\n }\n\n async request<T extends TypedEndpoint<Paths>>(\n endpoint: T,\n config?: FilteredRequestConfig<Paths, T>,\n ): Promise<ExtractEndpointResponse<Paths, T>> {\n const { method, route } = this.parseEndpoint(endpoint);\n\n // Replace path parameters\n let url = route;\n if (config && 'params' in config && config.params) {\n Object.entries(config.params as Record<string, unknown>).forEach(\n ([key, value]) => {\n url = url.replace(`{${key}}`, encodeURIComponent(String(value)));\n },\n );\n }\n\n // Add query parameters\n if (config && 'query' in config && config.query) {\n const queryParams = new URLSearchParams();\n\n // Recursive function to handle nested objects and arrays\n const appendQueryParam = (prefix: string, value: unknown) => {\n if (value === undefined || value === null) {\n return;\n }\n\n if (Array.isArray(value)) {\n // Handle arrays by appending multiple values with the same key\n value.forEach((item) => {\n queryParams.append(prefix, String(item));\n });\n } else if (typeof value === 'object') {\n // For objects, recursively flatten into dot notation\n Object.entries(value as Record<string, unknown>).forEach(\n ([subKey, subValue]) => {\n appendQueryParam(`${prefix}.${subKey}`, subValue);\n },\n );\n } else {\n queryParams.append(prefix, String(value));\n }\n };\n\n // Process all query parameters\n Object.entries(config.query as Record<string, unknown>).forEach(\n ([key, value]) => {\n appendQueryParam(key, value);\n },\n );\n\n const queryString = queryParams.toString();\n if (queryString) {\n url += `?${queryString}`;\n }\n }\n\n // Build request configuration\n let requestConfig: RequestInit = {\n method: method.toUpperCase(),\n headers: {\n ...this.defaultHeaders,\n ...((config && 'headers' in config && config.headers) || {}),\n },\n };\n\n // Add body if present\n if (config && 'body' in config && config.body) {\n requestConfig.body = JSON.stringify(config.body);\n requestConfig.headers = {\n ...requestConfig.headers,\n 'Content-Type': 'application/json',\n };\n }\n\n // Apply request interceptor\n if (this.options.onRequest) {\n requestConfig = await this.options.onRequest(requestConfig);\n }\n\n try {\n // Make the request\n let response = await this.fetchFn(`${this.baseURL}${url}`, requestConfig);\n\n // Apply response interceptor\n if (this.options.onResponse) {\n response = await this.options.onResponse(response);\n }\n\n // Handle errors\n if (!response.ok) {\n throw response;\n }\n\n // Handle empty responses (204 No Content, etc.)\n if (\n response.status === 204 ||\n response.headers.get('content-length') === '0'\n ) {\n return undefined as ExtractEndpointResponse<Paths, T>;\n }\n\n // Parse JSON response\n const data = await response.json();\n return data as ExtractEndpointResponse<Paths, T>;\n } catch (error) {\n // Apply error handler\n if (this.options.onError) {\n // @ts-ignore\n await this.options.onError(error);\n }\n throw error;\n }\n }\n\n private parseEndpoint<T extends EndpointString>(\n endpoint: T,\n ): ParseEndpoint<T> {\n const [method, ...routeParts] = endpoint.split(' ');\n const route = routeParts.join(' ');\n return { method: method?.toLowerCase() ?? '', route } as ParseEndpoint<T>;\n }\n}\n\nexport function createTypedFetcher<Paths>(options?: FetcherOptions) {\n const fetcher = new TypedFetcher<Paths>(options);\n return <T extends TypedEndpoint<Paths>>(\n endpoint: T,\n config?: FilteredRequestConfig<Paths, T>,\n ) => fetcher.request(endpoint, config);\n}\n\nexport type FetchFn = typeof fetch;\n"],"mappings":";;AAWA,IAAa,eAAb,MAAa,aAAoB;CAC/B,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;CAER,OAAO,WAAWA,IAAuB;AACvC,MAAI,GACF,QAAO;AAGT,aAAW,WAAW,sBAAsB,OAAO,UAAU,WAC3D,QAAO,OAAO,MAAM,KAAK,OAAO;AAGlC,aACS,eAAe,sBACf,WAAW,UAAU,WAE5B,QAAO,WAAW,MAAM,KAAK,WAAW;AAG1C,QAAM,IAAI,MAAM;CACjB;CAED,YAAYC,UAA0B,CAAE,GAAE;AACxC,OAAK,UAAU,QAAQ,WAAW;AAClC,OAAK,iBAAiB,QAAQ,WAAW,CAAE;AAC3C,OAAK,UAAU;AACf,OAAK,UAAU,aAAa,WAAW,QAAQ,MAAM;CACtD;CAED,MAAM,QACJC,UACAC,QAC4C;EAC5C,MAAM,EAAE,QAAQ,OAAO,GAAG,KAAK,cAAc,SAAS;EAGtD,IAAI,MAAM;AACV,MAAI,UAAU,YAAY,UAAU,OAAO,OACzC,QAAO,QAAQ,OAAO,OAAkC,CAAC,QACvD,CAAC,CAAC,KAAK,MAAM,KAAK;AAChB,SAAM,IAAI,SAAS,GAAG,IAAI,IAAI,mBAAmB,OAAO,MAAM,C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,WAAW,OACpB,SAAS,QAAQ,IAAI,iBAAiB,KAAK,IAE3C;GAIF,MAAM,OAAO,MAAM,SAAS,MAAM;AAClC,UAAO;EACR,SAAQ,OAAO;AAEd,OAAI,KAAK,QAAQ,QAEf,OAAM,KAAK,QAAQ,QAAQ,MAAM;AAEnC,SAAM;EACP;CACF;CAED,AAAQ,cACNJ,UACkB;EAClB,MAAM,CAAC,QAAQ,GAAG,WAAW,GAAG,SAAS,MAAM,IAAI;EACnD,MAAM,QAAQ,WAAW,KAAK,IAAI;AAClC,SAAO;GAAE,QAAQ,QAAQ,aAAa,IAAI;GAAI;EAAO;CACtD;AACF;AAED,SAAgB,mBAA0BK,SAA0B;CAClE,MAAM,UAAU,IAAI,aAAoB;AACxC,QAAO,CACLL,UACAC,WACG,QAAQ,QAAQ,UAAU,OAAO;AACvC"}
package/dist/fetcher.cjs CHANGED
@@ -1,4 +1,4 @@
1
- const require_fetcher = require('./fetcher-KdwHgdAl.cjs');
1
+ const require_fetcher = require('./fetcher-CgLEaIAC.cjs');
2
2
 
3
3
  exports.TypedFetcher = require_fetcher.TypedFetcher;
4
4
  exports.createTypedFetcher = require_fetcher.createTypedFetcher;
@@ -1,4 +1,4 @@
1
- import { ExtractEndpointResponse, FetcherOptions, FilteredRequestConfig, TypedEndpoint } from "./types-D4OSWveN.cjs";
1
+ import { ExtractEndpointResponse, FetcherOptions, FilteredRequestConfig, TypedEndpoint } from "./types-vutATyWv.cjs";
2
2
 
3
3
  //#region src/fetcher.d.ts
4
4
  declare class TypedFetcher<Paths> {
@@ -13,6 +13,8 @@ declare class TypedFetcher<Paths> {
13
13
  }
14
14
  declare function createTypedFetcher<Paths>(options?: FetcherOptions): <T extends TypedEndpoint<Paths>>(endpoint: T, config?: FilteredRequestConfig<Paths, T>) => Promise<ExtractEndpointResponse<Paths, T>>;
15
15
  type FetchFn = typeof fetch;
16
+ //# sourceMappingURL=fetcher.d.ts.map
17
+
16
18
  //#endregion
17
19
  export { FetchFn, FetcherOptions, TypedFetcher, createTypedFetcher };
18
20
  //# sourceMappingURL=fetcher.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetcher.d.cts","names":[],"sources":["../src/fetcher.ts"],"sourcesContent":[],"mappings":";;;cAWa;EAAA,QAAA,OAAY;EAAA,QAAA,cAAA;EAAA,QAMA,OAAA;EAAO,QAAG,OAAA;EAAO,OAmBnB,UAAA,CAAA,EAAA,CAAA,EAnBE,OAmBF,CAAA,EAnBY,OAmBZ;EAAmB,WAOF,CAAA,OAAA,CAAA,EAPjB,cAOiB;EAAK,OAAnB,CAAA,UAAA,aAAA,CAAc,KAAd,CAAA,CAAA,CAAA,QAAA,EACZ,CADY,EAAA,MAAA,CAAA,EAEb,qBAFa,CAES,KAFT,EAEgB,CAFhB,CAAA,CAAA,EAGrB,OAHqB,CAGb,uBAHa,CAGW,KAHX,EAGkB,CAHlB,CAAA,CAAA;EAAa,QACzB,aAAA;;AAC4B,iBAyH1B,kBAzH0B,CAAA,KAAA,CAAA,CAAA,OAAA,CAAA,EAyHU,cAzHV,CAAA,EAAA,CAAA,UA2HtB,aA3HsB,CA2HR,KA3HQ,CAAA,CAAA,CAAA,QAAA,EA4H5B,CA5H4B,EAAA,MAAA,CAAA,EA6H7B,qBA7H6B,CA6HP,KA7HO,EA6HA,CA7HA,CAAA,EAAA,GA6HE,OA7HF,CA6HE,uBA7HF,CA6HE,KA7HF,EA6HE,CA7HF,CAAA,CAAA;AAA7B,KAiID,OAAA,GAjIC,OAiIgB,KAjIhB"}
@@ -1,4 +1,4 @@
1
- import { ExtractEndpointResponse, FetcherOptions, FilteredRequestConfig, TypedEndpoint } from "./types-Cdv1XAWr.mjs";
1
+ import { ExtractEndpointResponse, FetcherOptions, FilteredRequestConfig, TypedEndpoint } from "./types-FxummKaL.mjs";
2
2
 
3
3
  //#region src/fetcher.d.ts
4
4
  declare class TypedFetcher<Paths> {
@@ -13,6 +13,8 @@ declare class TypedFetcher<Paths> {
13
13
  }
14
14
  declare function createTypedFetcher<Paths>(options?: FetcherOptions): <T extends TypedEndpoint<Paths>>(endpoint: T, config?: FilteredRequestConfig<Paths, T>) => Promise<ExtractEndpointResponse<Paths, T>>;
15
15
  type FetchFn = typeof fetch;
16
+ //# sourceMappingURL=fetcher.d.ts.map
17
+
16
18
  //#endregion
17
19
  export { FetchFn, FetcherOptions, TypedFetcher, createTypedFetcher };
18
20
  //# sourceMappingURL=fetcher.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetcher.d.mts","names":[],"sources":["../src/fetcher.ts"],"sourcesContent":[],"mappings":";;;cAWa;EAAA,QAAA,OAAY;EAAA,QAAA,cAAA;EAAA,QAMA,OAAA;EAAO,QAAG,OAAA;EAAO,OAmBnB,UAAA,CAAA,EAAA,CAAA,EAnBE,OAmBF,CAAA,EAnBY,OAmBZ;EAAmB,WAOF,CAAA,OAAA,CAAA,EAPjB,cAOiB;EAAK,OAAnB,CAAA,UAAA,aAAA,CAAc,KAAd,CAAA,CAAA,CAAA,QAAA,EACZ,CADY,EAAA,MAAA,CAAA,EAEb,qBAFa,CAES,KAFT,EAEgB,CAFhB,CAAA,CAAA,EAGrB,OAHqB,CAGb,uBAHa,CAGW,KAHX,EAGkB,CAHlB,CAAA,CAAA;EAAa,QACzB,aAAA;;AAC4B,iBAyH1B,kBAzH0B,CAAA,KAAA,CAAA,CAAA,OAAA,CAAA,EAyHU,cAzHV,CAAA,EAAA,CAAA,UA2HtB,aA3HsB,CA2HR,KA3HQ,CAAA,CAAA,CAAA,QAAA,EA4H5B,CA5H4B,EAAA,MAAA,CAAA,EA6H7B,qBA7H6B,CA6HP,KA7HO,EA6HA,CA7HA,CAAA,EAAA,GA6HE,OA7HF,CA6HE,uBA7HF,CA6HE,KA7HF,EA6HE,CA7HF,CAAA,CAAA;AAA7B,KAiID,OAAA,GAjIC,OAiIgB,KAjIhB"}
package/dist/fetcher.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import { TypedFetcher, createTypedFetcher } from "./fetcher-DLDD_7Sa.mjs";
1
+ import { TypedFetcher, createTypedFetcher } from "./fetcher-5fnBE7Dk.mjs";
2
2
 
3
3
  export { TypedFetcher, createTypedFetcher };
@@ -0,0 +1 @@
1
+ {"version":3,"file":"infer.d.cts","names":[],"sources":["../src/infer.ts"],"sourcesContent":[],"mappings":";;;;;;;;;AAM8D;;KAMzD,eACH,CAAA,eAAA,MAAA,CAAA,GAAA,MAAA,SAAA,GAAA,MAAA,IAAA,KAAA,MAAA,IAAA,KAAA,KAAA,EAAA,GAAA,QACY,KAAA,GAAA,MAAA,EAAK,GAAc,eAAgB,CAAA,IAAA,CAAA,GAAA,CAAA,CAAA;;AAAD;AAAA;KAM3C,eAAe,CAAA,UAAW,UAAX,CAAA,GAAyB,SAAzB,CAAmC,CAAnC,CAAA;;;;AAAkC,KAKjD,oBALiD,CAAA,eAAA,MAAA,CAAA,GAMpD,eANoD,CAMpC,MANoC,CAAA,SAMpB,MANoB,CAAA,MAAA,EAAA,KAAA,CAAA,GAAA,CAAA,CAAA,GAAA;EAKjD,UAAA,EAAA;IAAoB,IAAA,EAKT,eALS,CAKO,MALP,CAAA;EAAA,CAAA;CACD;;;;AAIO,KAO1B,wBAP0B,CAAA,eAOc,eAPd,CAAA,GAOiC,MAPjC,SAAA;EAO1B,KAAA,EAAA,KAAA,EAAA;CAAwB,GAAA;EAAA,UAAgB,EAAA;IAAmB,KAAA,EAKjD,mBALiD,CAK7B,CAL6B,CAAA;EAAM,CAAA;CAKlC,GAAA,CAAA,CAAA;AAAF;AAAA;;KAQ7B,cACY,CAAA,eAAA,eAAA,EAAA,gBACC,gBADD,GAAA,SAAA,CAAA,GAEb,wBAFa,CAEY,MAFZ,CAAA,GAAA;EAAe,WACd,CAAA,EAEF,MAFE,SAAA;IACW,IAAA,EAAA,KAAA,EAAA;EAAM,CAAA,GAA/B;IACY,OAAA,EAAA;MAGkC,kBAAA,EAApB,mBAAoB,CAAA,CAAA,CAAA;IAApB,CAAA;EAAmB,CAA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AK7B,CAL6B,CAAA;EAAM,CAAA;CAKlC,GAAA,CAAA,CAAA;AAAF;AAAA;;KAQ7B,cACY,CAAA,eAAA,eAAA,EAAA,gBACC,gBADD,GAAA,SAAA,CAAA,GAEb,wBAFa,CAEY,MAFZ,CAAA,GAAA;EAAe,WACd,CAAA,EAEF,MAFE,SAAA;IACW,IAAA,EAAA,KAAA,EAAA;EAAM,CAAA,GAA/B;IACY,OAAA,EAAA;MAGkC,kBAAA,EAApB,mBAAoB,CAAA,CAAA,CAAA;IAApB,CAAA;EAAmB,CAAA,GAMlC,KAAA;EAAO,SAAS,EAAA;IAEqB,GAAA,EAAA;MAApB,OAAA,EAFjB,OAEiB,SAFD,gBAEC,GAAA;QAAmB,kBAAA,EAAnB,mBAAmB,CAAC,OAAD,CAAA;MA+BvC,CAAA,GAAA,KAAA;IAAwB,CAAA;EAAA,CAAA;CAAO;;;;;;;;;AAYc;AA2CzD;;;;;;;;;;;;;;AAQoB;KA/DR,8BAA8B,UAAU;iBAWtC,SAAS,qBAAqB,kBAC5B,gBAAgB,WAAW,eAAe,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA2CtD,kDACV,2DACI,yBAAyB;;IACvB;SACW;IACT,aAAa;;;SACF,KAAK;;SACL;IACb,aAAa"}
@@ -1,5 +1,5 @@
1
1
  const require_chunk = require('./chunk-CUT6urMc.cjs');
2
- const require_fetcher = require('./fetcher-KdwHgdAl.cjs');
2
+ const require_fetcher = require('./fetcher-CgLEaIAC.cjs');
3
3
  const __tanstack_react_query = require_chunk.__toESM(require("@tanstack/react-query"));
4
4
 
5
5
  //#region src/openapi-hooks.ts
@@ -7,10 +7,8 @@ function createOpenAPIHooks(options = {}) {
7
7
  const { operations,...fetcherOptions } = options;
8
8
  const fetcher = require_fetcher.createTypedFetcher(fetcherOptions);
9
9
  function buildEndpoint(operationId) {
10
- if (operations && operations[operationId]) {
11
- const op = operations[operationId];
12
- return `${op.method.toUpperCase()} ${op.path}`;
13
- }
10
+ const op = operations?.[operationId];
11
+ if (op) return `${op.method.toUpperCase()} ${op.path}`;
14
12
  return operationId;
15
13
  }
16
14
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"openapi-hooks.cjs","names":["options: FetcherOptions & { operations?: OperationRegistry }","operationId: OpId","config?: RemoveNever<OperationParams<Paths, OpId>>","options?: Omit<\n UseQueryOptions<OperationResponse<Paths, OpId>, Error>,\n 'queryKey' | 'queryFn'\n >","options","options?: Omit<\n UseMutationOptions<\n OperationResponse<Paths, OpId>,\n Error,\n RemoveNever<OperationParams<Paths, OpId>>\n >,\n 'mutationFn'\n >"],"sources":["../src/openapi-hooks.ts"],"sourcesContent":["import type {\n UseMutationOptions,\n UseQueryOptions,\n} from '@tanstack/react-query';\nimport { useMutation, useQuery } from '@tanstack/react-query';\nimport { createTypedFetcher } from './fetcher';\nimport type { FetcherOptions } from './types';\n\n// Simplified type helpers for OpenAPI paths\ntype HttpMethods = 'get' | 'post' | 'put' | 'patch' | 'delete';\n\n// Extract all operations from paths\ntype AllOperations<Paths> = {\n [Path in keyof Paths]: {\n [Method in keyof Paths[Path] & HttpMethods]: Paths[Path][Method] extends {\n operationId: infer OpId;\n }\n ? OpId extends string\n ? {\n operationId: OpId;\n path: Path;\n method: Method;\n spec: Paths[Path][Method] & {\n _pathParams?: Paths[Path] extends {\n parameters: { path: infer P };\n }\n ? P\n : never;\n };\n }\n : never\n : never;\n }[keyof Paths[Path] & HttpMethods];\n}[keyof Paths];\n\n// Create operation map\ntype OperationMap<Paths> = {\n [Op in AllOperations<Paths> as Op extends {\n operationId: infer Id extends string;\n }\n ? Id\n : never]: Op;\n};\n\n// Get operation IDs\ntype OperationId<Paths> = keyof OperationMap<Paths>;\n\n// Get operations by method\ntype OperationsByMethod<Paths, Method extends HttpMethods> = {\n [K in OperationId<Paths>]: OperationMap<Paths>[K] extends { method: Method }\n ? K\n : never;\n}[OperationId<Paths>];\n\n// Extract parameter types\ntype OperationParams<\n Paths,\n OpId extends OperationId<Paths>,\n> = OperationMap<Paths>[OpId] extends {\n path: infer Path extends keyof Paths;\n spec: infer Spec;\n}\n ? {\n params?: Paths[Path] extends { parameters: { path: infer P } }\n ? P\n : Spec extends { parameters: { path: infer P } }\n ? P\n : never;\n query?: Spec extends { parameters: { query?: infer Q } } ? Q : never;\n body?: Spec extends {\n requestBody: { content: { 'application/json': infer Body } };\n }\n ? Body\n : Spec extends {\n requestBody: {\n required: true;\n content: { 'application/json': infer Body };\n };\n }\n ? Body\n : never;\n }\n : never;\n\n// Extract response type\ntype OperationResponse<\n Paths,\n OpId extends OperationId<Paths>,\n> = OperationMap<Paths>[OpId] extends { spec: infer Spec }\n ? Spec extends {\n responses: { 200: { content: { 'application/json': infer R } } };\n }\n ? R\n : Spec extends {\n responses: { 201: { content: { 'application/json': infer R } } };\n }\n ? R\n : Spec extends { responses: { 204: any } }\n ? void\n : unknown\n : never;\n\n// Remove never properties\ntype RemoveNever<T> = Pick<\n T,\n {\n [K in keyof T]: T[K] extends never ? never : K;\n }[keyof T]\n>;\n\n// Check if type is empty\ntype IsEmpty<T> = keyof T extends never ? true : false;\n\n// Runtime operation registry (would be generated)\ninterface OperationRegistry {\n [operationId: string]: {\n path: string;\n method: string;\n };\n}\n\nexport function createOpenAPIHooks<Paths>(\n options: FetcherOptions & { operations?: OperationRegistry } = {},\n) {\n const { operations, ...fetcherOptions } = options;\n const fetcher = createTypedFetcher<Paths>(fetcherOptions);\n\n function buildEndpoint<OpId extends OperationId<Paths>>(\n operationId: OpId,\n ): string {\n // Runtime lookup from registry\n if (operations && operations[operationId as string]) {\n const op = operations[operationId as string];\n return `${op.method.toUpperCase()} ${op.path}`;\n }\n // Fallback for compile-time only usage\n return operationId as string;\n }\n\n return {\n useQuery: <OpId extends OperationsByMethod<Paths, 'get'>>(\n operationId: OpId,\n config?: RemoveNever<OperationParams<Paths, OpId>>,\n options?: Omit<\n UseQueryOptions<OperationResponse<Paths, OpId>, Error>,\n 'queryKey' | 'queryFn'\n >,\n ) => {\n const endpoint = buildEndpoint(operationId);\n const queryKey = [operationId, ...(config ? [config] : [])];\n\n return useQuery<OperationResponse<Paths, OpId>, Error>({\n queryKey,\n queryFn: async () => {\n const response = await fetcher(endpoint as any, config as any);\n return response as OperationResponse<Paths, OpId>;\n },\n ...options,\n });\n },\n\n useMutation: <\n OpId extends Exclude<\n OperationId<Paths>,\n OperationsByMethod<Paths, 'get'>\n >,\n >(\n operationId: OpId,\n options?: Omit<\n UseMutationOptions<\n OperationResponse<Paths, OpId>,\n Error,\n RemoveNever<OperationParams<Paths, OpId>>\n >,\n 'mutationFn'\n >,\n ) => {\n const endpoint = buildEndpoint(operationId);\n\n return useMutation<\n OperationResponse<Paths, OpId>,\n Error,\n RemoveNever<OperationParams<Paths, OpId>>\n >({\n mutationFn: async (variables) => {\n const response = await fetcher(endpoint as any, variables as any);\n return response as OperationResponse<Paths, OpId>;\n },\n ...options,\n });\n },\n };\n}\n"],"mappings":";;;;;AAyHA,SAAgB,mBACdA,UAA+D,CAAE,GACjE;CACA,MAAM,EAAE,WAAY,GAAG,gBAAgB,GAAG;CAC1C,MAAM,UAAU,mCAA0B,eAAe;CAEzD,SAAS,cACPC,aACQ;AAER,MAAI,cAAc,WAAW,cAAwB;GACnD,MAAM,KAAK,WAAW;AACtB,WAAQ,EAAE,GAAG,OAAO,aAAa,CAAC,GAAG,GAAG,KAAK;EAC9C;AAED,SAAO;CACR;AAED,QAAO;EACL,UAAU,CACRA,aACAC,QACAC,cAIG;GACH,MAAM,WAAW,cAAc,YAAY;GAC3C,MAAM,WAAW,CAAC,aAAa,GAAI,SAAS,CAAC,MAAO,IAAG,CAAE,CAAE;AAE3D,UAAO,qCAAgD;IACrD;IACA,SAAS,YAAY;KACnB,MAAM,WAAW,MAAM,QAAQ,UAAiB,OAAc;AAC9D,YAAO;IACR;IACD,GAAGC;GACJ,EAAC;EACH;EAED,aAAa,CAMXH,aACAI,cAQG;GACH,MAAM,WAAW,cAAc,YAAY;AAE3C,UAAO,wCAIL;IACA,YAAY,OAAO,cAAc;KAC/B,MAAM,WAAW,MAAM,QAAQ,UAAiB,UAAiB;AACjE,YAAO;IACR;IACD,GAAGD;GACJ,EAAC;EACH;CACF;AACF"}
1
+ {"version":3,"file":"openapi-hooks.cjs","names":["options: FetcherOptions & { operations?: OperationRegistry }","operationId: OpId","config?: RemoveNever<OperationParams<Paths, OpId>>","options?: Omit<\n UseQueryOptions<OperationResponse<Paths, OpId>, Error>,\n 'queryKey' | 'queryFn'\n >","options","options?: Omit<\n UseMutationOptions<\n OperationResponse<Paths, OpId>,\n Error,\n RemoveNever<OperationParams<Paths, OpId>>\n >,\n 'mutationFn'\n >"],"sources":["../src/openapi-hooks.ts"],"sourcesContent":["import type {\n UseMutationOptions,\n UseQueryOptions,\n} from '@tanstack/react-query';\nimport { useMutation, useQuery } from '@tanstack/react-query';\nimport { createTypedFetcher } from './fetcher';\nimport type { FetcherOptions } from './types';\n\n// Simplified type helpers for OpenAPI paths\ntype HttpMethods = 'get' | 'post' | 'put' | 'patch' | 'delete';\n\n// Extract all operations from paths\ntype AllOperations<Paths> = {\n [Path in keyof Paths]: {\n [Method in keyof Paths[Path] & HttpMethods]: Paths[Path][Method] extends {\n operationId: infer OpId;\n }\n ? OpId extends string\n ? {\n operationId: OpId;\n path: Path;\n method: Method;\n spec: Paths[Path][Method] & {\n _pathParams?: Paths[Path] extends {\n parameters: { path: infer P };\n }\n ? P\n : never;\n };\n }\n : never\n : never;\n }[keyof Paths[Path] & HttpMethods];\n}[keyof Paths];\n\n// Create operation map\ntype OperationMap<Paths> = {\n [Op in AllOperations<Paths> as Op extends {\n operationId: infer Id extends string;\n }\n ? Id\n : never]: Op;\n};\n\n// Get operation IDs\ntype OperationId<Paths> = keyof OperationMap<Paths>;\n\n// Get operations by method\ntype OperationsByMethod<Paths, Method extends HttpMethods> = {\n [K in OperationId<Paths>]: OperationMap<Paths>[K] extends { method: Method }\n ? K\n : never;\n}[OperationId<Paths>];\n\n// Extract parameter types\ntype OperationParams<\n Paths,\n OpId extends OperationId<Paths>,\n> = OperationMap<Paths>[OpId] extends {\n path: infer Path extends keyof Paths;\n spec: infer Spec;\n}\n ? {\n params?: Paths[Path] extends { parameters: { path: infer P } }\n ? P\n : Spec extends { parameters: { path: infer P } }\n ? P\n : never;\n query?: Spec extends { parameters?: { query?: infer Q } } ? Q : never;\n body?: Spec extends {\n requestBody: { content: { 'application/json': infer Body } };\n }\n ? Body\n : Spec extends {\n requestBody: {\n required: true;\n content: { 'application/json': infer Body };\n };\n }\n ? Body\n : never;\n }\n : never;\n\n// Extract response type\ntype OperationResponse<\n Paths,\n OpId extends OperationId<Paths>,\n> = OperationMap<Paths>[OpId] extends { spec: infer Spec }\n ? Spec extends {\n responses: { 200: { content: { 'application/json': infer R } } };\n }\n ? R\n : Spec extends {\n responses: { 201: { content: { 'application/json': infer R } } };\n }\n ? R\n : Spec extends { responses: { 204: any } }\n ? void\n : unknown\n : never;\n\n// Remove never properties\ntype RemoveNever<T> = Pick<\n T,\n {\n [K in keyof T]: T[K] extends never ? never : K;\n }[keyof T]\n>;\n\n// Check if type is empty\ntype IsEmpty<T> = keyof T extends never ? true : false;\n\n// Runtime operation registry (would be generated)\ninterface OperationRegistry {\n [operationId: string]: {\n path: string;\n method: string;\n };\n}\n\nexport function createOpenAPIHooks<Paths>(\n options: FetcherOptions & { operations?: OperationRegistry } = {},\n) {\n const { operations, ...fetcherOptions } = options;\n const fetcher = createTypedFetcher<Paths>(fetcherOptions);\n\n function buildEndpoint<OpId extends OperationId<Paths>>(\n operationId: OpId,\n ): string {\n // Runtime lookup from registry\n const op = operations?.[operationId as string];\n if (op) {\n return `${op.method.toUpperCase()} ${op.path}`;\n }\n // Fallback for compile-time only usage\n return operationId as string;\n }\n\n return {\n useQuery: <OpId extends OperationsByMethod<Paths, 'get'>>(\n operationId: OpId,\n config?: RemoveNever<OperationParams<Paths, OpId>>,\n options?: Omit<\n UseQueryOptions<OperationResponse<Paths, OpId>, Error>,\n 'queryKey' | 'queryFn'\n >,\n ) => {\n const endpoint = buildEndpoint(operationId);\n const queryKey = [operationId, ...(config ? [config] : [])];\n\n return useQuery<OperationResponse<Paths, OpId>, Error>({\n queryKey,\n queryFn: async () => {\n const response = await fetcher(endpoint as any, config as any);\n return response as OperationResponse<Paths, OpId>;\n },\n ...options,\n });\n },\n\n useMutation: <\n OpId extends Exclude<\n OperationId<Paths>,\n OperationsByMethod<Paths, 'get'>\n >,\n >(\n operationId: OpId,\n options?: Omit<\n UseMutationOptions<\n OperationResponse<Paths, OpId>,\n Error,\n RemoveNever<OperationParams<Paths, OpId>>\n >,\n 'mutationFn'\n >,\n ) => {\n const endpoint = buildEndpoint(operationId);\n\n return useMutation<\n OperationResponse<Paths, OpId>,\n Error,\n RemoveNever<OperationParams<Paths, OpId>>\n >({\n mutationFn: async (variables) => {\n const response = await fetcher(endpoint as any, variables as any);\n return response as OperationResponse<Paths, OpId>;\n },\n ...options,\n });\n },\n };\n}\n"],"mappings":";;;;;AAyHA,SAAgB,mBACdA,UAA+D,CAAE,GACjE;CACA,MAAM,EAAE,WAAY,GAAG,gBAAgB,GAAG;CAC1C,MAAM,UAAU,mCAA0B,eAAe;CAEzD,SAAS,cACPC,aACQ;EAER,MAAM,KAAK,aAAa;AACxB,MAAI,GACF,SAAQ,EAAE,GAAG,OAAO,aAAa,CAAC,GAAG,GAAG,KAAK;AAG/C,SAAO;CACR;AAED,QAAO;EACL,UAAU,CACRA,aACAC,QACAC,cAIG;GACH,MAAM,WAAW,cAAc,YAAY;GAC3C,MAAM,WAAW,CAAC,aAAa,GAAI,SAAS,CAAC,MAAO,IAAG,CAAE,CAAE;AAE3D,UAAO,qCAAgD;IACrD;IACA,SAAS,YAAY;KACnB,MAAM,WAAW,MAAM,QAAQ,UAAiB,OAAc;AAC9D,YAAO;IACR;IACD,GAAGC;GACJ,EAAC;EACH;EAED,aAAa,CAMXH,aACAI,cAQG;GACH,MAAM,WAAW,cAAc,YAAY;AAE3C,UAAO,wCAIL;IACA,YAAY,OAAO,cAAc;KAC/B,MAAM,WAAW,MAAM,QAAQ,UAAiB,UAAiB;AACjE,YAAO;IACR;IACD,GAAGD;GACJ,EAAC;EACH;CACF;AACF"}
@@ -1,4 +1,4 @@
1
- import { FetcherOptions } from "./types-D4OSWveN.cjs";
1
+ import { FetcherOptions } from "./types-vutATyWv.cjs";
2
2
  import * as _tanstack_react_query0 from "@tanstack/react-query";
3
3
  import { UseMutationOptions, UseQueryOptions } from "@tanstack/react-query";
4
4
 
@@ -39,7 +39,7 @@ type OperationParams<Paths, OpId extends OperationId<Paths>> = OperationMap<Path
39
39
  };
40
40
  } ? P : never;
41
41
  query?: Spec extends {
42
- parameters: {
42
+ parameters?: {
43
43
  query?: infer Q;
44
44
  };
45
45
  } ? Q : never;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openapi-hooks.d.cts","names":[],"sources":["../src/openapi-hooks.ts"],"sourcesContent":[],"mappings":";;;;;KASK,WAAA;KAGA,wCACY,qBAJD,MAKK,KALL,CAKW,IALX,CAAA,GAKmB,WALnB,GAKiC,KALjC,CAKuC,IALvC,CAAA,CAK6C,MAL7C,CAAA,SAAA;EAGX,WAAa,EAAA,KAAA,KAAA;AAAA,CAAA,GAKV,IALU,SAAA,MAAA,GAAA;EACD,WAAA,EAMQ,IANR;EACI,IAAA,EAMH,IANG;EAAM,MAAA,EAOP,MAPO;EAAQ,IAAA,EAQjB,KARiB,CAQX,IARW,CAAA,CAQL,MARK,CAAA,GAAA;IAAc,WAAA,CAAA,EASrB,KATqB,CASf,IATe,CAAA,SAAA;MAAM,UAAA,EAAA;QAAM,IAAA,EAAA,KAAA,EAAA;MAGrD,CAAA;IAEiB,CAAA,GAOP,CAPO,GAAA,KAAA;EACP,CAAA;AACE,CAAA,GAAA,KAAA,GAAA,KAAA,EAAM,CAAA,MAWhB,KAVQ,CAUF,IAVE,CAAA,GAUM,WAVN,CAAA,EAAK,CAAA,MAWf,KAXgB,CAAA;KAcnB,YA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A;CAAA"}
@@ -1,5 +1,5 @@
1
- import { FetcherOptions } from "./types-Cdv1XAWr.mjs";
2
- import * as _tanstack_react_query0 from "@tanstack/react-query";
1
+ import { FetcherOptions } from "./types-FxummKaL.mjs";
2
+ import * as _tanstack_react_query8 from "@tanstack/react-query";
3
3
  import { UseMutationOptions, UseQueryOptions } from "@tanstack/react-query";
4
4
 
5
5
  //#region src/openapi-hooks.d.ts
@@ -39,7 +39,7 @@ type OperationParams<Paths, OpId extends OperationId<Paths>> = OperationMap<Path
39
39
  };
40
40
  } ? P : never;
41
41
  query?: Spec extends {
42
- parameters: {
42
+ parameters?: {
43
43
  query?: infer Q;
44
44
  };
45
45
  } ? Q : never;
@@ -91,8 +91,8 @@ interface OperationRegistry {
91
91
  declare function createOpenAPIHooks<Paths>(options?: FetcherOptions & {
92
92
  operations?: OperationRegistry;
93
93
  }): {
94
- useQuery: <OpId extends OperationsByMethod<Paths, "get">>(operationId: OpId, config?: RemoveNever<OperationParams<Paths, OpId>>, options?: Omit<UseQueryOptions<OperationResponse<Paths, OpId>, Error>, "queryKey" | "queryFn">) => _tanstack_react_query0.UseQueryResult<_tanstack_react_query0.NoInfer<OperationResponse<Paths, OpId>>, Error>;
95
- useMutation: <OpId extends Exclude<OperationId<Paths>, OperationsByMethod<Paths, "get">>>(operationId: OpId, options?: Omit<UseMutationOptions<OperationResponse<Paths, OpId>, Error, RemoveNever<OperationParams<Paths, OpId>>>, "mutationFn">) => _tanstack_react_query0.UseMutationResult<OperationResponse<Paths, OpId>, Error, RemoveNever<OperationParams<Paths, OpId>>, unknown>;
94
+ useQuery: <OpId extends OperationsByMethod<Paths, "get">>(operationId: OpId, config?: RemoveNever<OperationParams<Paths, OpId>>, options?: Omit<UseQueryOptions<OperationResponse<Paths, OpId>, Error>, "queryKey" | "queryFn">) => _tanstack_react_query8.UseQueryResult<_tanstack_react_query8.NoInfer<OperationResponse<Paths, OpId>>, Error>;
95
+ useMutation: <OpId extends Exclude<OperationId<Paths>, OperationsByMethod<Paths, "get">>>(operationId: OpId, options?: Omit<UseMutationOptions<OperationResponse<Paths, OpId>, Error, RemoveNever<OperationParams<Paths, OpId>>>, "mutationFn">) => _tanstack_react_query8.UseMutationResult<OperationResponse<Paths, OpId>, Error, RemoveNever<OperationParams<Paths, OpId>>, unknown>;
96
96
  };
97
97
  //#endregion
98
98
  export { createOpenAPIHooks };