@adyen/kyc-components
Version:
This guide assumes that you have already an account with Adyen. A legalEntity needs to be created, and you need to have a `legalEntityId` to instatiate a Component.
30 lines (29 loc) • 1.87 kB
TypeScript
import type { UseMutationOptions, UseQueryOptions } from '@tanstack/preact-query';
type MandatoryQueryArgs = 'queryKey' | 'queryFn';
type MandatoryMutationArgs = 'mutationFn';
/**
* useQuery params we do NOT want in our options.
* <ResponseType> is the type of the Response received,
* <SelectedType> is the type returned by the select function (defaults to ResponseType)
* provide the generic to QueryOptions and nowhere else, it will be infered
*/
export type QueryOptions<ResponseType, SelectedType = ResponseType, ErrorType = Error> = Omit<UseQueryOptions<ResponseType, ErrorType, SelectedType>, MandatoryQueryArgs>;
/**
* useMutation params we do NOT want in our options.
*/
export type MutationOptions<ResponseType = unknown, ErrorType = Error, VariablesType = void, ContextType = unknown> = Omit<UseMutationOptions<ResponseType, ErrorType, VariablesType, ContextType>, MandatoryMutationArgs>;
type StripSlashV1Slash<T extends string> = T extends `/v1/${infer Endpoint}` ? Endpoint : T;
type StripGetParams<T extends string> = T extends `${infer Endpoint}?${string}` ? Endpoint : T;
type OptionalGetParams = `?${string}` | '';
type VariablesFromCurlyBraces<T extends string> = T extends `${infer Head}{${string}}${infer Tail}` ? `${Head}${string}${EndpointFromPaths<Tail>}${OptionalGetParams}` : T;
/**
* Creates a string union of all possible endpoints, by taking as generic the
* paths interface which we have in openApi contract.d.ts files, with variables included
*
* Used to type endpoint strings accross the codebase (api calls, mocks, etc.)
* It's recommended to narrow it down to one specific endpoint from the union, with Extract
* Strips `/v1/` from the beginning and anything after `?` (query params) at the end
*
*/
export type EndpointFromPaths<T extends string> = StripSlashV1Slash<StripGetParams<VariablesFromCurlyBraces<T>>>;
export {};