/** * Do not edit this file it is auto-generated by io-utils / gen-api-models. * See https://github.com/pagopa/io-utils */ /* tslint:disable */ import { RequestParams, TypeofApiCall, TypeofApiParams, createFetchRequestForApi, ReplaceRequestParams } from "italia-ts-commons/lib/requests"; import { identity } from "fp-ts/lib/function"; import { GetBPDCitizenT, GetBPDCitizenDefaultDecoder, GetBPDTransactionsT, GetBPDTransactionsDefaultDecoder, GetBPDPaymentInstrumentT, GetBPDPaymentInstrumentDefaultDecoder, GetBPDAwardsT, GetBPDAwardsDefaultDecoder } from "./requestTypes"; // This is a placeholder for undefined when dealing with object keys // Typescript doesn't perform well when narrowing a union type which includes string and undefined // (example: "foo" | "bar" | undefined) // We use this as a placeholder for type parameters indicating "no key" type __UNDEFINED_KEY = "_____"; export type ApiOperation = TypeofApiCall & TypeofApiCall & TypeofApiCall & TypeofApiCall; export type ParamKeys = keyof (TypeofApiParams & TypeofApiParams & TypeofApiParams & TypeofApiParams); /** * Defines an adapter for TypeofApiCall which omit one or more parameters in the signature * @param ApiT the type which defines the operation to expose * @param K the parameter to omit. undefined means no parameters will be omitted */ export type OmitApiCallParams< ApiT, K extends ParamKeys | __UNDEFINED_KEY = __UNDEFINED_KEY > = ( op: TypeofApiCall ) => K extends __UNDEFINED_KEY ? TypeofApiCall : TypeofApiCall, K>>>; /** * Defines an adapter for TypeofApiCall which omit one or more parameters in the signature * @param ApiT the type which defines the operation to expose * @param K the parameter to omit. undefined means no parameters will be omitted */ export type WithDefaultsT< K extends ParamKeys | __UNDEFINED_KEY = __UNDEFINED_KEY > = OmitApiCallParams< | GetBPDCitizenT | GetBPDTransactionsT | GetBPDPaymentInstrumentT | GetBPDAwardsT, K >; /** * Defines a collection of api operations * @param K name of the parameters that the Clients masks from the operations */ export type Client< K extends ParamKeys | __UNDEFINED_KEY = __UNDEFINED_KEY > = K extends __UNDEFINED_KEY ? { readonly GetBPDCitizen: TypeofApiCall; readonly GetBPDTransactions: TypeofApiCall; readonly GetBPDPaymentInstrument: TypeofApiCall; readonly GetBPDAwards: TypeofApiCall; } : { readonly GetBPDCitizen: TypeofApiCall< ReplaceRequestParams< GetBPDCitizenT, Omit, K> > >; readonly GetBPDTransactions: TypeofApiCall< ReplaceRequestParams< GetBPDTransactionsT, Omit, K> > >; readonly GetBPDPaymentInstrument: TypeofApiCall< ReplaceRequestParams< GetBPDPaymentInstrumentT, Omit, K> > >; readonly GetBPDAwards: TypeofApiCall< ReplaceRequestParams< GetBPDAwardsT, Omit, K> > >; }; /** * Create an instance of a client * @param params hash map of parameters thata define the client: * - baseUrl: the base url for every api call (required) * - fetchApi: an implementation of the fetch() web API, depending on the platform (required) * - basePath: optional path to be appended to the baseUrl * - withDefaults: optional adapter to be applied to every operation, to omit some paramenters * @returns a collection of api operations */ export function createClient(params: { baseUrl: string; // tslint:disable-next-line:no-any fetchApi: typeof fetch; withDefaults: WithDefaultsT; basePath?: string; }): Client; export function createClient(params: { baseUrl: string; // tslint:disable-next-line:no-any fetchApi: typeof fetch; withDefaults?: undefined; basePath?: string; }): Client; export function createClient({ baseUrl, // tslint:disable-next-line:no-any fetchApi, withDefaults, basePath = "/api/v1" }: { baseUrl: string; // tslint:disable-next-line:no-any fetchApi: typeof fetch; withDefaults?: WithDefaultsT; basePath?: string; }) { const options = { baseUrl, fetchApi }; const GetBPDCitizenT: ReplaceRequestParams< GetBPDCitizenT, RequestParams > = { method: "get", headers: ({ ["Bearer"]: Bearer, ["x-citizen-id"]: xCitizenId }: { Bearer: string; "x-citizen-id": string; }) => ({ Authorization: Bearer, "x-citizen-id": xCitizenId }), response_decoder: GetBPDCitizenDefaultDecoder(), url: ({}) => `${basePath}/bpd/citizen`, query: () => ({}) }; const GetBPDCitizen: TypeofApiCall = createFetchRequestForApi( GetBPDCitizenT, options ); const GetBPDTransactionsT: ReplaceRequestParams< GetBPDTransactionsT, RequestParams > = { method: "get", headers: ({ ["Bearer"]: Bearer, ["x-citizen-id"]: xCitizenId }: { Bearer: string; "x-citizen-id": string; }) => ({ Authorization: Bearer, "x-citizen-id": xCitizenId }), response_decoder: GetBPDTransactionsDefaultDecoder(), url: ({}) => `${basePath}/bpd/transactions`, query: () => ({}) }; const GetBPDTransactions: TypeofApiCall = createFetchRequestForApi( GetBPDTransactionsT, options ); const GetBPDPaymentInstrumentT: ReplaceRequestParams< GetBPDPaymentInstrumentT, RequestParams > = { method: "get", headers: ({ ["Bearer"]: Bearer, ["x-citizen-id"]: xCitizenId }: { Bearer: string; "x-citizen-id": string; }) => ({ Authorization: Bearer, "x-citizen-id": xCitizenId }), response_decoder: GetBPDPaymentInstrumentDefaultDecoder(), url: ({ ["hpan"]: hpan }) => `${basePath}/bpd/payment-instruments/${hpan}`, query: () => ({}) }; const GetBPDPaymentInstrument: TypeofApiCall = createFetchRequestForApi( GetBPDPaymentInstrumentT, options ); const GetBPDAwardsT: ReplaceRequestParams< GetBPDAwardsT, RequestParams > = { method: "get", headers: ({ ["Bearer"]: Bearer, ["x-citizen-id"]: xCitizenId }: { Bearer: string; "x-citizen-id": string; }) => ({ Authorization: Bearer, "x-citizen-id": xCitizenId }), response_decoder: GetBPDAwardsDefaultDecoder(), url: ({}) => `${basePath}/bpd/awards`, query: () => ({}) }; const GetBPDAwards: TypeofApiCall = createFetchRequestForApi( GetBPDAwardsT, options ); return { GetBPDCitizen: (withDefaults || identity)(GetBPDCitizen), GetBPDTransactions: (withDefaults || identity)(GetBPDTransactions), GetBPDPaymentInstrument: (withDefaults || identity)( GetBPDPaymentInstrument ), GetBPDAwards: (withDefaults || identity)(GetBPDAwards) }; }