@tahanabavi/typefetch 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -1
- package/dist/index.d.mts +6 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +3972 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3984 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -27,7 +27,7 @@ yarn add @tahanabavi/typefetch
|
|
|
27
27
|
|
|
28
28
|
---
|
|
29
29
|
|
|
30
|
-
## What's New in v1.1.
|
|
30
|
+
## What's New in v1.1.1
|
|
31
31
|
|
|
32
32
|
### 🎯 Mock Data Support
|
|
33
33
|
|
|
@@ -48,6 +48,13 @@ yarn add @tahanabavi/typefetch
|
|
|
48
48
|
- Better Zod error wrapping and reporting
|
|
49
49
|
- Improved type safety for response wrappers
|
|
50
50
|
|
|
51
|
+
### 🔧 Token Provider System
|
|
52
|
+
|
|
53
|
+
- Dynamic token resolution: Tokens resolved at request time, not initialization
|
|
54
|
+
- Universal compatibility: Works seamlessly in both server and client environments
|
|
55
|
+
- Async token providers: Support for asynchronous token retrieval
|
|
56
|
+
- Multiple token sources: Flexible token sourcing from cookies, context, or external services
|
|
57
|
+
|
|
51
58
|
---
|
|
52
59
|
|
|
53
60
|
## Defining Contracts
|
package/dist/index.d.mts
CHANGED
|
@@ -29,6 +29,7 @@ type EndpointDefZ = EndpointDef<z.ZodTypeAny, z.ZodTypeAny>;
|
|
|
29
29
|
type EndpointMethods<M extends Record<string, EndpointDefZ>> = {
|
|
30
30
|
[K in keyof M]: (input: z.infer<M[K]["request"]>) => Promise<z.infer<M[K]["response"]>>;
|
|
31
31
|
};
|
|
32
|
+
type TokenProvider = () => string | Promise<string>;
|
|
32
33
|
|
|
33
34
|
declare class RichError extends Error implements ErrorLike {
|
|
34
35
|
status?: number;
|
|
@@ -49,10 +50,12 @@ declare class ApiClient<C extends Contracts, E extends ErrorLike = RichError> {
|
|
|
49
50
|
private useMockData;
|
|
50
51
|
private mockDelay;
|
|
51
52
|
private responseWrapper?;
|
|
53
|
+
private tokenProvider?;
|
|
52
54
|
private _modules;
|
|
53
55
|
constructor(config: {
|
|
54
56
|
baseUrl: string;
|
|
55
57
|
token?: string;
|
|
58
|
+
tokenProvider?: TokenProvider;
|
|
56
59
|
useMockData?: boolean;
|
|
57
60
|
mockDelay?: {
|
|
58
61
|
min: number;
|
|
@@ -69,6 +72,8 @@ declare class ApiClient<C extends Contracts, E extends ErrorLike = RichError> {
|
|
|
69
72
|
max: number;
|
|
70
73
|
}): void;
|
|
71
74
|
setResponseWrapper(wrapper: (successResponse: z.ZodTypeAny) => z.ZodTypeAny): void;
|
|
75
|
+
setTokenProvider(provider: TokenProvider): void;
|
|
76
|
+
getCurrentToken(): Promise<string | undefined>;
|
|
72
77
|
private request;
|
|
73
78
|
private handleMockRequest;
|
|
74
79
|
private getRandomDelay;
|
|
@@ -99,4 +104,4 @@ type CacheOptions = {
|
|
|
99
104
|
};
|
|
100
105
|
declare const cacheMiddleware: (options?: CacheOptions) => (ctx: MiddlewareContext, next: MiddlewareNext) => Promise<Response>;
|
|
101
106
|
|
|
102
|
-
export { ApiClient, type AuthOptions, type CacheOptions, type Contracts, type EndpointDef, type EndpointDefZ, type EndpointMethods, type ErrorLike, type LoggingOptions, type Middleware, type MiddlewareContext, type MiddlewareNext, type RetryOptions, RichError, authMiddleware, cacheMiddleware, loggingMiddleware, retryMiddleware };
|
|
107
|
+
export { ApiClient, type AuthOptions, type CacheOptions, type Contracts, type EndpointDef, type EndpointDefZ, type EndpointMethods, type ErrorLike, type LoggingOptions, type Middleware, type MiddlewareContext, type MiddlewareNext, type RetryOptions, RichError, type TokenProvider, authMiddleware, cacheMiddleware, loggingMiddleware, retryMiddleware };
|
package/dist/index.d.ts
CHANGED
|
@@ -29,6 +29,7 @@ type EndpointDefZ = EndpointDef<z.ZodTypeAny, z.ZodTypeAny>;
|
|
|
29
29
|
type EndpointMethods<M extends Record<string, EndpointDefZ>> = {
|
|
30
30
|
[K in keyof M]: (input: z.infer<M[K]["request"]>) => Promise<z.infer<M[K]["response"]>>;
|
|
31
31
|
};
|
|
32
|
+
type TokenProvider = () => string | Promise<string>;
|
|
32
33
|
|
|
33
34
|
declare class RichError extends Error implements ErrorLike {
|
|
34
35
|
status?: number;
|
|
@@ -49,10 +50,12 @@ declare class ApiClient<C extends Contracts, E extends ErrorLike = RichError> {
|
|
|
49
50
|
private useMockData;
|
|
50
51
|
private mockDelay;
|
|
51
52
|
private responseWrapper?;
|
|
53
|
+
private tokenProvider?;
|
|
52
54
|
private _modules;
|
|
53
55
|
constructor(config: {
|
|
54
56
|
baseUrl: string;
|
|
55
57
|
token?: string;
|
|
58
|
+
tokenProvider?: TokenProvider;
|
|
56
59
|
useMockData?: boolean;
|
|
57
60
|
mockDelay?: {
|
|
58
61
|
min: number;
|
|
@@ -69,6 +72,8 @@ declare class ApiClient<C extends Contracts, E extends ErrorLike = RichError> {
|
|
|
69
72
|
max: number;
|
|
70
73
|
}): void;
|
|
71
74
|
setResponseWrapper(wrapper: (successResponse: z.ZodTypeAny) => z.ZodTypeAny): void;
|
|
75
|
+
setTokenProvider(provider: TokenProvider): void;
|
|
76
|
+
getCurrentToken(): Promise<string | undefined>;
|
|
72
77
|
private request;
|
|
73
78
|
private handleMockRequest;
|
|
74
79
|
private getRandomDelay;
|
|
@@ -99,4 +104,4 @@ type CacheOptions = {
|
|
|
99
104
|
};
|
|
100
105
|
declare const cacheMiddleware: (options?: CacheOptions) => (ctx: MiddlewareContext, next: MiddlewareNext) => Promise<Response>;
|
|
101
106
|
|
|
102
|
-
export { ApiClient, type AuthOptions, type CacheOptions, type Contracts, type EndpointDef, type EndpointDefZ, type EndpointMethods, type ErrorLike, type LoggingOptions, type Middleware, type MiddlewareContext, type MiddlewareNext, type RetryOptions, RichError, authMiddleware, cacheMiddleware, loggingMiddleware, retryMiddleware };
|
|
107
|
+
export { ApiClient, type AuthOptions, type CacheOptions, type Contracts, type EndpointDef, type EndpointDefZ, type EndpointMethods, type ErrorLike, type LoggingOptions, type Middleware, type MiddlewareContext, type MiddlewareNext, type RetryOptions, RichError, type TokenProvider, authMiddleware, cacheMiddleware, loggingMiddleware, retryMiddleware };
|