Skip to content

Commit

Permalink
Fixing lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Alessandro Atzeni committed Oct 16, 2024
1 parent aaeab65 commit b7c4b14
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 48 deletions.
2 changes: 1 addition & 1 deletion apps/io-wallet-message-func/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "io-wallet-message-func",
"version": "1.3.0",
"version": "1.0.0",
"private": true,
"scripts": {
"build": "tsup-node",
Expand Down
13 changes: 8 additions & 5 deletions apps/io-wallet-message-func/src/app/configs/azureConfig.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
import { pipe } from "fp-ts/function";
import { sequenceS } from "fp-ts/Apply";
import * as RE from "fp-ts/ReaderEither";
import { pipe } from "fp-ts/function";
import * as t from "io-ts";
import {
AzureCosmosConfig,
getAzureCosmosConfigFromEnvironment
getAzureCosmosConfigFromEnvironment,
} from "io-wallet-common/infra/azure/cosmos/config";

export const AzureConfig = t.type({
cosmos: AzureCosmosConfig
cosmos: AzureCosmosConfig,
});

export type AzureConfig = t.TypeOf<typeof AzureConfig>;

export const getAzureConfigFromEnvironment: RE.ReaderEither<NodeJS.ProcessEnv, Error, AzureConfig> = pipe(
export const getAzureConfigFromEnvironment: RE.ReaderEither<
NodeJS.ProcessEnv,
Error,
AzureConfig
> = pipe(
sequenceS(RE.Apply)({
cosmos: getAzureCosmosConfigFromEnvironment,
}),
//@ts-ignore
RE.map(({ cosmos }) => ({
cosmos: {
...cosmos,
Expand Down
37 changes: 20 additions & 17 deletions apps/io-wallet-message-func/src/app/configs/config.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
import { AzureConfig, getAzureConfigFromEnvironment } from "./azureConfig";
import { sequenceS } from "fp-ts/Apply";
import * as RE from "fp-ts/ReaderEither";
import * as t from "io-ts";
import { pipe } from "fp-ts/function";
import { sequenceS } from "fp-ts/Apply";
import { IoServiceConfig, getIoServiceConfigFromEnvironment } from "./ioServiceConfig";
import * as t from "io-ts";

import { AzureConfig, getAzureConfigFromEnvironment } from "./azureConfig";
import {
IoServiceConfig,
getIoServiceConfigFromEnvironment,
} from "./ioServiceConfig";

export const CosmosDbConfig = t.type({
ioService: IoServiceConfig,
azure: AzureConfig,
azure: AzureConfig,
ioService: IoServiceConfig,
});

export type AppConfig = t.TypeOf<typeof CosmosDbConfig>;

export const getAppConfigFromEnvironment: RE.ReaderEither<NodeJS.ProcessEnv, Error, AppConfig> =
pipe(
sequenceS(RE.Apply)({
azure: pipe(
getAzureConfigFromEnvironment
),
ioService: pipe(
getIoServiceConfigFromEnvironment
)
})
);
export const getAppConfigFromEnvironment: RE.ReaderEither<
NodeJS.ProcessEnv,
Error,
AppConfig
> = pipe(
sequenceS(RE.Apply)({
azure: pipe(getAzureConfigFromEnvironment),
ioService: pipe(getIoServiceConfigFromEnvironment),
}),
);
41 changes: 21 additions & 20 deletions apps/io-wallet-message-func/src/app/configs/ioServiceConfig.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
import * as t from "io-ts";
import { pipe } from "fp-ts/function";
import { sequenceS } from "fp-ts/Apply";
import { readFromEnvironment } from "io-wallet-common/infra/env";
import * as RE from "fp-ts/ReaderEither";
import { pipe } from "fp-ts/function";
import * as t from "io-ts";
import { readFromEnvironment } from "io-wallet-common/infra/env";

export const IoServiceConfig = t.type({
ioServiceBaseUrl: t.string,
ioServiceApiKey: t.string,
ioServiceRequestTimeout: t.number
ioServiceApiKey: t.string,
ioServiceBaseUrl: t.string,
ioServiceRequestTimeout: t.number,
});

export type IoServiceConfig = t.TypeOf<typeof IoServiceConfig>;

export const getIoServiceConfigFromEnvironment: RE.ReaderEither<NodeJS.ProcessEnv, Error, IoServiceConfig> =
pipe(
sequenceS(RE.Apply)({
ioServiceBaseUrl: readFromEnvironment("IoServiceBaseUrl"),
ioServiceApiKey: readFromEnvironment("IoServiceApiKey"),
ioServiceRequestTimeout: pipe(
readFromEnvironment("IoServiceRequestTimeout"),
RE.map(
(value) => Number.parseInt(value)
)
)
}),
);
export const getIoServiceConfigFromEnvironment: RE.ReaderEither<
NodeJS.ProcessEnv,
Error,
IoServiceConfig
> = pipe(
sequenceS(RE.Apply)({
ioServiceApiKey: readFromEnvironment("IoServiceApiKey"),
ioServiceBaseUrl: readFromEnvironment("IoServiceBaseUrl"),
ioServiceRequestTimeout: pipe(
readFromEnvironment("IoServiceRequestTimeout"),
RE.map((value) => Number.parseInt(value, 10)),
),
}),
);
5 changes: 2 additions & 3 deletions apps/io-wallet-message-func/src/app/main.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { HealthFunction } from "@/infra/azure/functions/health";
import { CosmosClient } from "@azure/cosmos";
import { app } from "@azure/functions";
import { DefaultAzureCredential } from "@azure/identity";
import * as E from "fp-ts/Either";
import { identity, pipe } from "fp-ts/function";

import { HealthFunction } from "../infra/azure/functions/health";
import { getAppConfigFromEnvironment } from "./configs/config";

const configOrError = pipe(
Expand All @@ -27,8 +28,6 @@ const cosmosClient = new CosmosClient({
endpoint: config.azure.cosmos.endpoint,
});

const database = cosmosClient.database(config.azure.cosmos.dbName);

app.http("healthCheck", {
authLevel: "anonymous",
handler: HealthFunction({ cosmosClient }),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { HealthHandler } from "@/infra/http/handlers/health";
import { httpAzureFunction } from "@pagopa/handler-kit-azure-func";

import { HealthHandler } from "../../http/handlers/health";

export const HealthFunction = httpAzureFunction(HealthHandler);
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import { HealthCheckError } from "io-wallet-common/error";
import { getCosmosHealth } from "io-wallet-common/infra/azure/cosmos/health-check";
import { logErrorAndReturnResponse } from "io-wallet-common/infra/http/error";

const getHealthCheck: RTE.ReaderTaskEither<{ cosmosClient: CosmosClient; }, Error, void> = ({ cosmosClient }) =>
const getHealthCheck: RTE.ReaderTaskEither<
{ cosmosClient: CosmosClient },
Error,
void
> = ({ cosmosClient }) =>
pipe(
[pipe({ cosmosClient }, getCosmosHealth)],
RA.wilt(T.ApplicativePar)(identity),
Expand Down

0 comments on commit b7c4b14

Please sign in to comment.