/** * Do not edit this file it is auto-generated by io-utils / gen-api-models. * See https://github.com/pagopa/io-utils */ /* eslint-disable */ import { withoutUndefinedValues } from "@pagopa/ts-commons/lib/types"; import { RequestParams, TypeofApiCall, TypeofApiParams, createFetchRequestForApi, ReplaceRequestParams } from "@pagopa/ts-commons/lib/requests"; import { identity } from "fp-ts/lib/function"; import { GetMessagesByUserT, getMessagesByUserDefaultDecoder, GetMessageT, getMessageDefaultDecoder, UpsertMessageStatusAttributesT, upsertMessageStatusAttributesDefaultDecoder, GetRCConfigurationT, getRCConfigurationDefaultDecoder } 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< | GetMessagesByUserT | GetMessageT | UpsertMessageStatusAttributesT | GetRCConfigurationT, 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 getMessagesByUser: TypeofApiCall; readonly getMessage: TypeofApiCall; readonly upsertMessageStatusAttributes: TypeofApiCall< UpsertMessageStatusAttributesT >; readonly getRCConfiguration: TypeofApiCall; } : { readonly getMessagesByUser: TypeofApiCall< ReplaceRequestParams< GetMessagesByUserT, Omit, K> > >; readonly getMessage: TypeofApiCall< ReplaceRequestParams, K>> >; readonly upsertMessageStatusAttributes: TypeofApiCall< ReplaceRequestParams< UpsertMessageStatusAttributesT, Omit, K> > >; readonly getRCConfiguration: TypeofApiCall< ReplaceRequestParams< GetRCConfigurationT, 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; // eslint-disable-next-line @typescript-eslint/no-explicit-any fetchApi: typeof fetch; withDefaults: WithDefaultsT; basePath?: string; }): Client; export function createClient(params: { baseUrl: string; // eslint-disable-next-line @typescript-eslint/no-explicit-any fetchApi: typeof fetch; withDefaults?: undefined; basePath?: string; }): Client; export function createClient({ baseUrl, // eslint-disable-next-line @typescript-eslint/no-explicit-any fetchApi, withDefaults, basePath = "/api/v1" }: { baseUrl: string; // eslint-disable-next-line @typescript-eslint/no-explicit-any fetchApi: typeof fetch; withDefaults?: WithDefaultsT; basePath?: string; }) { const options = { baseUrl, fetchApi }; const getMessagesByUserT: ReplaceRequestParams< GetMessagesByUserT, RequestParams > = { method: "get", headers: ({ ["SubscriptionKey"]: SubscriptionKey }: { SubscriptionKey: string; }) => ({ "X-Functions-Key": SubscriptionKey }), response_decoder: getMessagesByUserDefaultDecoder(), url: ({ ["fiscal_code"]: fiscalCode }) => `${basePath}/messages/${fiscalCode}`, query: ({ ["page_size"]: pageSize, ["maximum_id"]: maximumId, ["minimum_id"]: minimumId, ["enrich_result_data"]: enrichResultData, ["archived"]: archived }) => withoutUndefinedValues({ ["page_size"]: pageSize, ["maximum_id"]: maximumId, ["minimum_id"]: minimumId, ["enrich_result_data"]: enrichResultData, ["archived"]: archived }) }; const getMessagesByUser: TypeofApiCall = createFetchRequestForApi( getMessagesByUserT, options ); const getMessageT: ReplaceRequestParams< GetMessageT, RequestParams > = { method: "get", headers: ({ ["SubscriptionKey"]: SubscriptionKey }: { SubscriptionKey: string; }) => ({ "X-Functions-Key": SubscriptionKey }), response_decoder: getMessageDefaultDecoder(), url: ({ ["fiscal_code"]: fiscalCode, ["id"]: id }) => `${basePath}/messages/${fiscalCode}/${id}`, query: ({ ["public_message"]: publicMessage }) => withoutUndefinedValues({ ["public_message"]: publicMessage }) }; const getMessage: TypeofApiCall = createFetchRequestForApi( getMessageT, options ); const upsertMessageStatusAttributesT: ReplaceRequestParams< UpsertMessageStatusAttributesT, RequestParams > = { method: "put", headers: ({ ["SubscriptionKey"]: SubscriptionKey }: { SubscriptionKey: string; }) => ({ "X-Functions-Key": SubscriptionKey, "Content-Type": "application/json" }), response_decoder: upsertMessageStatusAttributesDefaultDecoder(), url: ({ ["fiscal_code"]: fiscalCode, ["id"]: id }) => `${basePath}/messages/${fiscalCode}/${id}/message-status`, body: ({ ["body"]: body }) => JSON.stringify(body), query: () => withoutUndefinedValues({}) }; const upsertMessageStatusAttributes: TypeofApiCall = createFetchRequestForApi( upsertMessageStatusAttributesT, options ); const getRCConfigurationT: ReplaceRequestParams< GetRCConfigurationT, RequestParams > = { method: "get", headers: ({ ["SubscriptionKey"]: SubscriptionKey }: { SubscriptionKey: string; }) => ({ "X-Functions-Key": SubscriptionKey }), response_decoder: getRCConfigurationDefaultDecoder(), url: ({ ["id"]: id }) => `${basePath}/remote-contents/configurations/${id}`, query: () => withoutUndefinedValues({}) }; const getRCConfiguration: TypeofApiCall = createFetchRequestForApi( getRCConfigurationT, options ); return { getMessagesByUser: (withDefaults || identity)(getMessagesByUser), getMessage: (withDefaults || identity)(getMessage), upsertMessageStatusAttributes: (withDefaults || identity)( upsertMessageStatusAttributes ), getRCConfiguration: (withDefaults || identity)(getRCConfiguration) }; }