diff --git a/package.json b/package.json index 4d622b82..27464022 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,7 @@ "dependencies": { "@azure/cosmos": "^3.11.5", "@pagopa/io-functions-commons": "^20.6.6", - "@pagopa/ts-commons": "^9.4.1", + "@pagopa/ts-commons": "^9.6.0", "applicationinsights": "^1.7.4", "azure-storage": "^2.10.4", "cors": "^2.8.4", diff --git a/utils/config.ts b/utils/config.ts index f8b000d7..5fb9e5f1 100644 --- a/utils/config.ts +++ b/utils/config.ts @@ -8,10 +8,13 @@ import { ServiceId } from "@pagopa/io-functions-commons/dist/generated/definitions/ServiceId"; import { MailerConfig } from "@pagopa/io-functions-commons/dist/src/mailer"; import { fromNullable } from "fp-ts/lib/Option"; +import { fromNullable as fromNullableE } from "fp-ts/lib/Either"; import * as t from "io-ts"; import { readableReport } from "italia-ts-commons/lib/reporters"; import { NonEmptyString } from "italia-ts-commons/lib/strings"; -import { UTCISODateFromString } from "@pagopa/ts-commons/lib/dates"; +import { DateFromTimestamp } from "@pagopa/ts-commons/lib/dates"; +import { NumberFromString } from "@pagopa/ts-commons/lib/numbers"; +import { identity } from "fp-ts/lib/function"; import { CommaSeparatedListOf } from "./comma-separated-list"; // global app configuration @@ -34,7 +37,7 @@ export const IConfig = t.intersection([ IO_FUNCTIONS_ADMIN_BASE_URL: NonEmptyString, MESSAGE_CONTAINER_NAME: NonEmptyString, - OPT_OUT_EMAIL_SWITCH_DATE: UTCISODateFromString, + OPT_OUT_EMAIL_SWITCH_DATE: DateFromTimestamp, QueueStorageConnection: NonEmptyString, @@ -53,7 +56,7 @@ export const IConfig = t.intersection([ MailerConfig ]); -const DEFAULT_OPT_OUT_EMAIL_SWITCH_DATE = "1970-01-01T00:00:00Z"; +const DEFAULT_OPT_OUT_EMAIL_SWITCH_DATE = 1625781600000; // No need to re-evaluate this object for each call const errorOrConfig: t.Validation = IConfig.decode({ @@ -69,9 +72,15 @@ const errorOrConfig: t.Validation = IConfig.decode({ ) .map(_ => _.toLowerCase() === "true") .getOrElse(false), - OPT_OUT_EMAIL_SWITCH_DATE: fromNullable( + OPT_OUT_EMAIL_SWITCH_DATE: fromNullableE(DEFAULT_OPT_OUT_EMAIL_SWITCH_DATE)( process.env.OPT_OUT_EMAIL_SWITCH_DATE - ).getOrElse(DEFAULT_OPT_OUT_EMAIL_SWITCH_DATE), + ) + .chain(_ => + NumberFromString.decode(_).mapLeft( + () => DEFAULT_OPT_OUT_EMAIL_SWITCH_DATE + ) + ) + .fold(identity, identity), isProduction: process.env.NODE_ENV === "production" }); diff --git a/yarn.lock b/yarn.lock index 10099754..00c0ad8e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -669,24 +669,24 @@ node-fetch "^2.6.0" validator "^10.1.0" -"@pagopa/ts-commons@^9.4.1": - version "9.4.1" - resolved "https://registry.yarnpkg.com/@pagopa/ts-commons/-/ts-commons-9.4.1.tgz#cc2c1c08c84fb6fa55a99c506227b8c2dcc69c01" - integrity sha512-wA/eInP9l0vPovR4+50vpVxHdUr/el0xUrJ0LoRJv6qAErS9NzGIDwyg4ZjW6SHxDGzN4PpIFSb0QFki27wswg== +"@pagopa/ts-commons@^9.5.1": + version "9.5.1" + resolved "https://registry.yarnpkg.com/@pagopa/ts-commons/-/ts-commons-9.5.1.tgz#a1285589265560a1a96b4d389da2e37f9209ec58" + integrity sha512-Eqozj079y/oyLZwh6I/WBWsUKJ6rFOj5wGTXaYmVffxFHWXstQiSqw5S6cFAKK5/LA9lL9ro+zk3+lUKi+/Fow== dependencies: abort-controller "^3.0.0" - agentkeepalive "^4.1.2" - applicationinsights "^1.7.4" + agentkeepalive "^4.1.4" + applicationinsights "^1.8.10" fp-ts "1.17.4" io-ts "1.8.5" - json-set-map "^1.0.2" + json-set-map "^1.1.2" node-fetch "^2.6.0" validator "^10.1.0" -"@pagopa/ts-commons@^9.5.1": - version "9.5.1" - resolved "https://registry.yarnpkg.com/@pagopa/ts-commons/-/ts-commons-9.5.1.tgz#a1285589265560a1a96b4d389da2e37f9209ec58" - integrity sha512-Eqozj079y/oyLZwh6I/WBWsUKJ6rFOj5wGTXaYmVffxFHWXstQiSqw5S6cFAKK5/LA9lL9ro+zk3+lUKi+/Fow== +"@pagopa/ts-commons@^9.6.0": + version "9.6.0" + resolved "https://registry.yarnpkg.com/@pagopa/ts-commons/-/ts-commons-9.6.0.tgz#dbc837e8afa0aa66ab174d49757321a9fe18e416" + integrity sha512-GrXz6qFtBeRPS7reVxLEze6OvHUNMlCp4Ksbqwijl8xdkXD9ETCgU+9nKjGSPS6fOz2pUIOuIcts72HX7wlGmA== dependencies: abort-controller "^3.0.0" agentkeepalive "^4.1.4"