@zayne-labs/callapi-plugins 4.0.27 → 4.0.28

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 (2) hide show
  1. package/dist/index.d.ts +56 -34
  2. package/package.json +3 -3
package/dist/index.d.ts CHANGED
@@ -10,7 +10,7 @@ declare const fallBackRouteSchemaKey = "@default";
10
10
  type FallBackRouteSchemaKey = typeof fallBackRouteSchemaKey;
11
11
  //#endregion
12
12
  //#endregion
13
- //#region ../callapi/dist/index-HHFgKKcn.d.ts
13
+ //#region ../callapi/dist/index-j55-O6zR.d.ts
14
14
  //#region src/types/type-helpers.d.ts
15
15
  type AnyString = string & NonNullable<unknown>;
16
16
  type AnyNumber = number & NonNullable<unknown>;
@@ -293,7 +293,7 @@ type DedupeOptions = {
293
293
  //#endregion
294
294
  //#region src/middlewares.d.ts
295
295
  type FetchImpl = UnmaskType<(input: string | Request | URL, init?: RequestInit) => Promise<Response>>;
296
- interface Middlewares {
296
+ interface Middlewares<TCallApiContext$1 extends CallApiContext = DefaultCallApiContext> {
297
297
  /**
298
298
  * Wraps the fetch implementation to intercept requests at the network layer.
299
299
  *
@@ -325,7 +325,7 @@ interface Middlewares {
325
325
  * }
326
326
  * ```
327
327
  */
328
- fetchMiddleware?: (context: RequestContext & {
328
+ fetchMiddleware?: (context: RequestContext<TCallApiContext$1> & {
329
329
  fetchImpl: FetchImpl;
330
330
  }) => FetchImpl;
331
331
  }
@@ -853,6 +853,7 @@ type CallApiContext = {
853
853
  Meta?: DefaultMetaObject;
854
854
  ResultMode?: ResultModeType;
855
855
  };
856
+ type GetMergedCallApiContext<TFullCallApiContext extends CallApiContext, TOverrideCallApiContext extends CallApiContext> = Omit<TFullCallApiContext, keyof TOverrideCallApiContext> & TOverrideCallApiContext;
856
857
  type FetchSpecificKeysUnion = Exclude<(typeof fetchSpecificKeys)[number], "body" | "headers" | "method">;
857
858
  type ModifiedRequestInit = RequestInit & {
858
859
  duplex?: "half";
@@ -875,9 +876,9 @@ type CallApiRequestOptions = Prettify<{
875
876
  type CallApiRequestOptionsForHooks = Omit<CallApiRequestOptions, "headers"> & {
876
877
  headers: Record<string, string | undefined>;
877
878
  };
878
- type SharedExtraOptions<TCallApiContext$1 extends CallApiContext = DefaultCallApiContext, TData$1 = DefaultDataType, TErrorData$1 = DefaultDataType, TResultMode$1 extends ResultModeType = ResultModeType, TThrowOnError$1 extends ThrowOnErrorUnion = DefaultThrowOnError, TResponseType$1 extends ResponseTypeType = ResponseTypeType, TPluginArray$1 extends CallApiPlugin[] = DefaultPluginArray, TComputedPluginOptions = InferPluginOptions<TPluginArray$1> & TCallApiContext$1["InferredPluginOptions"], TComputedInferredPluginOptions extends Pick<Required<CallApiContext>, "InferredPluginOptions"> = {
879
- InferredPluginOptions: TComputedPluginOptions;
880
- }> = DedupeOptions & HookConfigOptions & HooksOrHooksArray<TComputedInferredPluginOptions, TData$1, TErrorData$1> & Middlewares & Partial<TComputedInferredPluginOptions["InferredPluginOptions"]> & ResultModeOption<TErrorData$1, TResultMode$1> & RetryOptions<TErrorData$1> & ThrowOnErrorOption<TErrorData$1, TThrowOnError$1> & URLOptions & {
879
+ type SharedExtraOptions<TCallApiContext$1 extends CallApiContext = DefaultCallApiContext, TData$1 = DefaultDataType, TErrorData$1 = DefaultDataType, TResultMode$1 extends ResultModeType = ResultModeType, TThrowOnError$1 extends ThrowOnErrorUnion = DefaultThrowOnError, TResponseType$1 extends ResponseTypeType = ResponseTypeType, TPluginArray$1 extends CallApiPlugin[] = DefaultPluginArray, TComputedMergedPluginOptions = Partial<InferPluginOptions<TPluginArray$1> & TCallApiContext$1["InferredPluginOptions"]>> = DedupeOptions & HookConfigOptions & HooksOrHooksArray<GetMergedCallApiContext<TCallApiContext$1, {
880
+ InferredPluginOptions: TComputedMergedPluginOptions;
881
+ }>> & Middlewares & ResultModeOption<TErrorData$1, TResultMode$1> & RetryOptions<TErrorData$1> & TComputedMergedPluginOptions & ThrowOnErrorOption<TErrorData$1, TThrowOnError$1> & URLOptions & {
881
882
  /**
882
883
  * Automatically add an Authorization header value.
883
884
  *
@@ -1424,7 +1425,7 @@ declare global {
1424
1425
  }
1425
1426
  //#endregion
1426
1427
  //#region src/hooks.d.ts
1427
- interface Hooks<TCallApiContext$1 extends Pick<CallApiContext, "Data" | "ErrorData" | "InferredPluginOptions" | "Meta"> = DefaultCallApiContext, TData$1 = TCallApiContext$1["Data"], TErrorData$1 = TCallApiContext$1["ErrorData"]> {
1428
+ interface Hooks<TCallApiContext$1 extends CallApiContext = DefaultCallApiContext> {
1428
1429
  /**
1429
1430
  * Hook called when any error occurs within the request/response lifecycle.
1430
1431
  *
@@ -1435,7 +1436,7 @@ interface Hooks<TCallApiContext$1 extends Pick<CallApiContext, "Data" | "ErrorDa
1435
1436
  * @param context - Error context containing error details, request info, and response (if available)
1436
1437
  * @returns Promise or void - Hook can be async or sync
1437
1438
  */
1438
- onError?: (context: ErrorContext<TCallApiContext$1, TErrorData$1>) => Awaitable<unknown>;
1439
+ onError?: (context: ErrorContext<TCallApiContext$1>) => Awaitable<unknown>;
1439
1440
  /**
1440
1441
  * Hook called before the HTTP request is sent and before any internal processing of the request object begins.
1441
1442
  *
@@ -1487,7 +1488,7 @@ interface Hooks<TCallApiContext$1 extends Pick<CallApiContext, "Data" | "ErrorDa
1487
1488
  * @returns Promise or void - Hook can be async or sync
1488
1489
  *
1489
1490
  */
1490
- onResponse?: (context: ResponseContext<TCallApiContext$1, TData$1, TErrorData$1>) => Awaitable<unknown>;
1491
+ onResponse?: (context: ResponseContext<TCallApiContext$1>) => Awaitable<unknown>;
1491
1492
  /**
1492
1493
  * Hook called when an HTTP error response (4xx, 5xx) is received from the API.
1493
1494
  *
@@ -1498,7 +1499,7 @@ interface Hooks<TCallApiContext$1 extends Pick<CallApiContext, "Data" | "ErrorDa
1498
1499
  * @param context - Response error context with HTTP error details and response
1499
1500
  * @returns Promise or void - Hook can be async or sync
1500
1501
  */
1501
- onResponseError?: (context: ResponseErrorContext<TCallApiContext$1, TErrorData$1>) => Awaitable<unknown>;
1502
+ onResponseError?: (context: ResponseErrorContext<TCallApiContext$1>) => Awaitable<unknown>;
1502
1503
  /**
1503
1504
  * Hook called during download stream progress tracking.
1504
1505
  *
@@ -1522,7 +1523,7 @@ interface Hooks<TCallApiContext$1 extends Pick<CallApiContext, "Data" | "ErrorDa
1522
1523
  * @returns Promise or void - Hook can be async or sync
1523
1524
  *
1524
1525
  */
1525
- onRetry?: (response: RetryContext<TCallApiContext$1, TErrorData$1>) => Awaitable<unknown>;
1526
+ onRetry?: (response: RetryContext<TCallApiContext$1>) => Awaitable<unknown>;
1526
1527
  /**
1527
1528
  * Hook called when a successful response (2xx status) is received from the API.
1528
1529
  *
@@ -1534,7 +1535,7 @@ interface Hooks<TCallApiContext$1 extends Pick<CallApiContext, "Data" | "ErrorDa
1534
1535
  * @returns Promise or void - Hook can be async or sync
1535
1536
  *
1536
1537
  */
1537
- onSuccess?: (context: SuccessContext<TCallApiContext$1, TData$1>) => Awaitable<unknown>;
1538
+ onSuccess?: (context: SuccessContext<TCallApiContext$1>) => Awaitable<unknown>;
1538
1539
  /**
1539
1540
  * Hook called when a validation error occurs.
1540
1541
  *
@@ -1548,7 +1549,7 @@ interface Hooks<TCallApiContext$1 extends Pick<CallApiContext, "Data" | "ErrorDa
1548
1549
  */
1549
1550
  onValidationError?: (context: ValidationErrorContext<TCallApiContext$1>) => Awaitable<unknown>;
1550
1551
  }
1551
- type HooksOrHooksArray<TCallApiContext$1 extends CallApiContext = DefaultCallApiContext, TData$1 = TCallApiContext$1["Data"], TErrorData$1 = TCallApiContext$1["ErrorData"]> = { [Key in keyof Hooks<TCallApiContext$1, TData$1, TErrorData$1>]: Hooks<TCallApiContext$1, TData$1, TErrorData$1>[Key] | Array<Hooks<TCallApiContext$1, TData$1, TErrorData$1>[Key]> };
1552
+ type HooksOrHooksArray<TCallApiContext$1 extends CallApiContext = DefaultCallApiContext> = { [Key in keyof Hooks<TCallApiContext$1>]: Hooks<TCallApiContext$1>[Key] | Array<Hooks<TCallApiContext$1>[Key]> };
1552
1553
  interface HookConfigOptions {
1553
1554
  /**
1554
1555
  * Controls the execution mode of all composed hooks (main + plugin hooks).
@@ -1598,28 +1599,28 @@ type ValidationErrorContext<TCallApiContext$1 extends Pick<CallApiContext, "Infe
1598
1599
  error: PossibleValidationError;
1599
1600
  response: Response | null;
1600
1601
  }>;
1601
- type SuccessContext<TCallApiContext$1 extends Pick<CallApiContext, "Data" | "InferredPluginOptions" | "Meta"> = DefaultCallApiContext, TData$1 = TCallApiContext$1["Data"]> = UnmaskType<RequestContext<TCallApiContext$1> & {
1602
- data: NoInfer<TData$1>;
1602
+ type SuccessContext<TCallApiContext$1 extends Pick<CallApiContext, "Data" | "InferredPluginOptions" | "Meta"> = DefaultCallApiContext> = UnmaskType<RequestContext<TCallApiContext$1> & {
1603
+ data: NoInfer<TCallApiContext$1["Data"]>;
1603
1604
  response: Response;
1604
1605
  }>;
1605
- type ResponseContext<TCallApiContext$1 extends Pick<CallApiContext, "Data" | "ErrorData" | "InferredPluginOptions" | "Meta"> = DefaultCallApiContext, TData$1 = TCallApiContext$1["Data"], TErrorData$1 = TCallApiContext$1["ErrorData"]> = UnmaskType<RequestContext<TCallApiContext$1> & (Prettify<CallApiResultSuccessVariant<TData$1>> | Prettify<Extract<CallApiResultErrorVariant<TErrorData$1>, {
1606
- error: PossibleHTTPError<TErrorData$1>;
1606
+ type ResponseContext<TCallApiContext$1 extends Pick<CallApiContext, "Data" | "ErrorData" | "InferredPluginOptions" | "Meta"> = DefaultCallApiContext> = UnmaskType<RequestContext<TCallApiContext$1> & (Prettify<CallApiResultSuccessVariant<TCallApiContext$1["Data"]>> | Prettify<Extract<CallApiResultErrorVariant<TCallApiContext$1["ErrorData"]>, {
1607
+ error: PossibleHTTPError<TCallApiContext$1["ErrorData"]>;
1607
1608
  }>>)>;
1608
1609
  type RequestErrorContext<TCallApiContext$1 extends Pick<CallApiContext, "InferredPluginOptions" | "Meta"> = DefaultCallApiContext> = RequestContext<TCallApiContext$1> & {
1609
1610
  error: PossibleJavaScriptError;
1610
1611
  response: null;
1611
1612
  };
1612
- type ErrorContext<TCallApiContext$1 extends Pick<CallApiContext, "ErrorData" | "InferredPluginOptions" | "Meta"> = DefaultCallApiContext, TErrorData$1 = TCallApiContext$1["ErrorData"]> = UnmaskType<RequestContext<TCallApiContext$1> & ({
1613
- error: PossibleHTTPError<TErrorData$1>;
1613
+ type ErrorContext<TCallApiContext$1 extends Pick<CallApiContext, "ErrorData" | "InferredPluginOptions" | "Meta"> = DefaultCallApiContext> = UnmaskType<RequestContext<TCallApiContext$1> & ({
1614
+ error: PossibleHTTPError<TCallApiContext$1["ErrorData"]>;
1614
1615
  response: Response;
1615
1616
  } | {
1616
1617
  error: PossibleJavaScriptOrValidationError;
1617
1618
  response: Response | null;
1618
1619
  })>;
1619
- type ResponseErrorContext<TCallApiContext$1 extends Pick<CallApiContext, "ErrorData" | "InferredPluginOptions" | "Meta"> = DefaultCallApiContext, TErrorData$1 = TCallApiContext$1["ErrorData"]> = UnmaskType<Extract<ErrorContext<TCallApiContext$1, TErrorData$1>, {
1620
- error: PossibleHTTPError<TErrorData$1>;
1620
+ type ResponseErrorContext<TCallApiContext$1 extends Pick<CallApiContext, "ErrorData" | "InferredPluginOptions" | "Meta"> = DefaultCallApiContext> = UnmaskType<Extract<ErrorContext<TCallApiContext$1>, {
1621
+ error: PossibleHTTPError<TCallApiContext$1["ErrorData"]>;
1621
1622
  }> & RequestContext<TCallApiContext$1>>;
1622
- type RetryContext<TCallApiContext$1 extends Pick<CallApiContext, "ErrorData" | "InferredPluginOptions" | "Meta"> = DefaultCallApiContext, TErrorData$1 = TCallApiContext$1["ErrorData"]> = UnmaskType<ErrorContext<TCallApiContext$1, TErrorData$1> & {
1623
+ type RetryContext<TCallApiContext$1 extends Pick<CallApiContext, "ErrorData" | "InferredPluginOptions" | "Meta"> = DefaultCallApiContext> = UnmaskType<ErrorContext<TCallApiContext$1> & {
1623
1624
  retryAttemptCount: number;
1624
1625
  }>;
1625
1626
  type RequestStreamContext<TCallApiContext$1 extends Pick<CallApiContext, "InferredPluginOptions" | "Meta"> = DefaultCallApiContext> = UnmaskType<RequestContext<TCallApiContext$1> & {
@@ -1635,12 +1636,15 @@ type ResponseStreamContext<TCallApiContext$1 extends Pick<CallApiContext, "Infer
1635
1636
  type PluginSetupContext<TCallApiContext$1 extends CallApiContext = DefaultCallApiContext> = RequestContext<TCallApiContext$1> & {
1636
1637
  initURL: string;
1637
1638
  };
1638
- type PluginInitResult = Partial<Omit<PluginSetupContext, "initURL" | "request"> & {
1639
+ type PluginInitResult<TCallApiContext$1 extends CallApiContext = DefaultCallApiContext> = Partial<Omit<PluginSetupContext<TCallApiContext$1>, "initURL" | "request"> & {
1639
1640
  initURL: InitURLOrURLObject;
1640
1641
  request: CallApiRequestOptions;
1641
1642
  }>;
1642
- type PluginHooks<TCallApiContext$1 extends CallApiContext = DefaultCallApiContext, TData$1 = (unknown extends TCallApiContext$1["Data"] ? never : TCallApiContext$1["Data"]), TErrorData$1 = (unknown extends TCallApiContext$1["ErrorData"] ? never : TCallApiContext$1["ErrorData"])> = HooksOrHooksArray<TCallApiContext$1, TData$1, TErrorData$1>;
1643
- interface CallApiPlugin {
1643
+ type PluginHooks<TCallApiContext$1 extends CallApiContext = DefaultCallApiContext> = HooksOrHooksArray<GetMergedCallApiContext<TCallApiContext$1, {
1644
+ Data: DefaultDataType extends TCallApiContext$1["Data"] ? never : TCallApiContext$1["Data"];
1645
+ ErrorData: DefaultDataType extends TCallApiContext$1["ErrorData"] ? never : TCallApiContext$1["ErrorData"];
1646
+ }>>;
1647
+ interface CallApiPlugin<TCallApiContext$1 extends CallApiContext = DefaultCallApiContext> {
1644
1648
  /**
1645
1649
  * Defines additional options that can be passed to callApi
1646
1650
  */
@@ -1652,7 +1656,7 @@ interface CallApiPlugin {
1652
1656
  /**
1653
1657
  * Hooks for the plugin
1654
1658
  */
1655
- hooks?: PluginHooks | ((context: PluginSetupContext) => Awaitable<PluginHooks>);
1659
+ hooks?: PluginHooks<TCallApiContext$1> | ((context: PluginSetupContext<TCallApiContext$1>) => Awaitable<PluginHooks<TCallApiContext$1>>);
1656
1660
  /**
1657
1661
  * A unique id for the plugin
1658
1662
  */
@@ -1660,7 +1664,7 @@ interface CallApiPlugin {
1660
1664
  /**
1661
1665
  * Middlewares that for the plugin
1662
1666
  */
1663
- middlewares?: Middlewares | ((context: PluginSetupContext) => Awaitable<Middlewares>);
1667
+ middlewares?: Middlewares<TCallApiContext$1> | ((context: PluginSetupContext<TCallApiContext$1>) => Awaitable<Middlewares<TCallApiContext$1>>);
1664
1668
  /**
1665
1669
  * A name for the plugin
1666
1670
  */
@@ -1672,7 +1676,7 @@ interface CallApiPlugin {
1672
1676
  /**
1673
1677
  * A function that will be called when the plugin is initialized. This will be called before the any of the other internal functions.
1674
1678
  */
1675
- setup?: (context: PluginSetupContext) => Awaitable<PluginInitResult> | Awaitable<void>;
1679
+ setup?: (context: PluginSetupContext<TCallApiContext$1>) => Awaitable<PluginInitResult<TCallApiContext$1>> | Awaitable<void>;
1676
1680
  /**
1677
1681
  * A version for the plugin
1678
1682
  */
@@ -1812,12 +1816,21 @@ declare const loggerPlugin: (options?: LoggerOptions) => {
1812
1816
  name: "Logger";
1813
1817
  version: "1.1.0";
1814
1818
  hooks: {
1815
- onRequest: (ctx: RequestContext<DefaultCallApiContext>) => void;
1816
- onRequestError: (ctx: RequestContext<DefaultCallApiContext> & {
1819
+ onRequest: (ctx: RequestContext<Omit<DefaultCallApiContext, "Data" | "ErrorData"> & {
1820
+ Data: never;
1821
+ ErrorData: never;
1822
+ }>) => void;
1823
+ onRequestError: (ctx: RequestContext<Omit<DefaultCallApiContext, "Data" | "ErrorData"> & {
1824
+ Data: never;
1825
+ ErrorData: never;
1826
+ }> & {
1817
1827
  error: PossibleJavaScriptError;
1818
1828
  response: null;
1819
1829
  }) => void;
1820
- onResponseError: (ctx: RequestContext<DefaultCallApiContext> & {
1830
+ onResponseError: (ctx: RequestContext<Omit<DefaultCallApiContext, "Data" | "ErrorData"> & {
1831
+ Data: never;
1832
+ ErrorData: never;
1833
+ }> & {
1821
1834
  error: {
1822
1835
  errorData: never;
1823
1836
  message: string;
@@ -1826,7 +1839,10 @@ declare const loggerPlugin: (options?: LoggerOptions) => {
1826
1839
  };
1827
1840
  response: Response;
1828
1841
  }) => void;
1829
- onRetry: (ctx: (RequestContext<DefaultCallApiContext> & ({
1842
+ onRetry: (ctx: (RequestContext<Omit<DefaultCallApiContext, "Data" | "ErrorData"> & {
1843
+ Data: never;
1844
+ ErrorData: never;
1845
+ }> & ({
1830
1846
  error: PossibleJavaScriptOrValidationError;
1831
1847
  response: Response | null;
1832
1848
  } | {
@@ -1840,11 +1856,17 @@ declare const loggerPlugin: (options?: LoggerOptions) => {
1840
1856
  })) & {
1841
1857
  retryAttemptCount: number;
1842
1858
  }) => void;
1843
- onSuccess: (ctx: RequestContext<DefaultCallApiContext> & {
1859
+ onSuccess: (ctx: RequestContext<Omit<DefaultCallApiContext, "Data" | "ErrorData"> & {
1860
+ Data: never;
1861
+ ErrorData: never;
1862
+ }> & {
1844
1863
  data: never;
1845
1864
  response: Response;
1846
1865
  }) => void;
1847
- onValidationError: (ctx: RequestContext<DefaultCallApiContext> & {
1866
+ onValidationError: (ctx: RequestContext<Omit<DefaultCallApiContext, "Data" | "ErrorData"> & {
1867
+ Data: never;
1868
+ ErrorData: never;
1869
+ }> & {
1848
1870
  error: PossibleValidationError;
1849
1871
  response: Response | null;
1850
1872
  }) => void;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@zayne-labs/callapi-plugins",
3
3
  "type": "module",
4
- "version": "4.0.27",
4
+ "version": "4.0.28",
5
5
  "description": "A collection of plugins for callapi",
6
6
  "author": "Ryan Zayne",
7
7
  "license": "MIT",
@@ -21,7 +21,7 @@
21
21
  "peerDependencies": {
22
22
  "@zayne-labs/toolkit-type-helpers": ">=0.11.17",
23
23
  "consola": "3.x.x",
24
- "@zayne-labs/callapi": "1.11.27"
24
+ "@zayne-labs/callapi": "1.11.28"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@arethetypeswrong/cli": "0.18.2",
@@ -38,7 +38,7 @@
38
38
  "tsdown": "0.15.9",
39
39
  "typescript": "5.9.3",
40
40
  "vitest": "^4.0.14",
41
- "@zayne-labs/callapi": "1.11.27"
41
+ "@zayne-labs/callapi": "1.11.28"
42
42
  },
43
43
  "publishConfig": {
44
44
  "access": "public",