Skip to content

Commit

Permalink
Merge pull request #20 from pagopa/IP-84--enforce-strict-to-true
Browse files Browse the repository at this point in the history
[#IP-84] Change strict configuration to true
  • Loading branch information
gquadrati committed Apr 13, 2021
2 parents a319dd8 + b2819af commit 6cf783c
Show file tree
Hide file tree
Showing 25 changed files with 108 additions and 126 deletions.
6 changes: 1 addition & 5 deletions HandleNHCreateOrUpdateInstallationCallActivity/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ import {
getActivityBody
} from "./handler";

export {
ActivityBodyImpl,
ActivityInput,
ActivityResultSuccess
} from "./handler";
export { ActivityInput, ActivityResultSuccess } from "./handler";
export const activityName = "HandleNHCreateOrUpdateInstallationCallActivity";

const activityFunctionHandler = createActivity(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@ import { IOrchestrationFunctionContext } from "durable-functions/lib/src/iorches
import {
CallableActivity,
failureActivity,
failureInvalidInput,
OrchestratorActivityFailure,
OrchestratorFailure,
OrchestratorInvalidInputFailure,
OrchestratorSuccess,
OrchestratorUnhandledFailure
} from "../../utils/durable/orchestrators";
import { ActivityBodyImpl as CreateOrUpdateActivityBody } from "../../HandleNHCreateOrUpdateInstallationCallActivity";
import { ActivityInput as CreateOrUpdateActivityInput } from "../../HandleNHCreateOrUpdateInstallationCallActivity";

const aFiscalCodeHash = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" as NonEmptyString;
const aPushChannel =
Expand Down Expand Up @@ -64,7 +63,7 @@ const aNotificationHubConfig = NotificationHubConfig.decode({
});

type CallableCreateOrUpdateActivity = CallableActivity<
CreateOrUpdateActivityBody // FIXME: the editor marks it as type error, but tests compile correctly
CreateOrUpdateActivityInput // FIXME: the editor marks it as type error, but tests compile correctly
>;
const mockCreateOrUpdateActivity = jest.fn<
ReturnType<CallableCreateOrUpdateActivity>,
Expand Down
4 changes: 2 additions & 2 deletions HandleNHCreateOrUpdateInstallationCallOrchestrator/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as t from "io-ts";
import * as o from "../utils/durable/orchestrators";

import { CreateOrUpdateInstallationMessage } from "../generated/notifications/CreateOrUpdateInstallationMessage";
import { ActivityBodyImpl as CreateOrUpdateActivityBodyImpl } from "../HandleNHCreateOrUpdateInstallationCallActivity";
import { ActivityInput as CreateOrUpdateActivityInput } from "../HandleNHCreateOrUpdateInstallationCallActivity";
import { NotificationHubConfig } from "../utils/notificationhubServicePartition";

export const OrchestratorName =
Expand All @@ -21,7 +21,7 @@ export type NhCreateOrUpdateInstallationOrchestratorCallInput = t.TypeOf<
>;

interface IHandlerParams {
createOrUpdateActivity: o.CallableActivity<CreateOrUpdateActivityBodyImpl>;
createOrUpdateActivity: o.CallableActivity<CreateOrUpdateActivityInput>;
notificationHubConfig: NotificationHubConfig;
}

Expand Down
16 changes: 9 additions & 7 deletions HandleNHCreateOrUpdateInstallationCallOrchestrator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,22 @@ import { getConfigOrThrow } from "../utils/config";
import { getHandler } from "./handler";

import {
ActivityBodyImpl as CreateOrUpdateActivityBodyImpl,
ActivityInput as CreateOrUpdateActivityInput,
activityName as CreateOrUpdateActivityName,
ActivityResultSuccess as CreateOrUpdateActivityResultSuccess
} from "../HandleNHCreateOrUpdateInstallationCallActivity";
import { getNHLegacyConfig } from "../utils/notificationhubServicePartition";

const config = getConfigOrThrow();

const createOrUpdateActivity = o.callableActivity<
CreateOrUpdateActivityBodyImpl
>(CreateOrUpdateActivityName, CreateOrUpdateActivityResultSuccess, {
...new df.RetryOptions(5000, config.RETRY_ATTEMPT_NUMBER),
backoffCoefficient: 1.5
});
const createOrUpdateActivity = o.callableActivity<CreateOrUpdateActivityInput>(
CreateOrUpdateActivityName,
CreateOrUpdateActivityResultSuccess,
{
...new df.RetryOptions(5000, config.RETRY_ATTEMPT_NUMBER),
backoffCoefficient: 1.5
}
);

const notificationHubConfig = getNHLegacyConfig(config);

Expand Down
7 changes: 4 additions & 3 deletions HandleNHDeleteInstallationCallActivity/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,16 @@ export const ActivityInput = t.interface({
// Activity Result
export { ActivityResultSuccess } from "../utils/durable/activities";

export type ActivityBodyImpl = ActivityBody<ActivityInput>;

/**
* For each Notification Hub Message of type "Delete" calls related Notification Hub service
*/

export const getActivityBody = (
buildNHService: (nhConfig: NotificationHubConfig) => NotificationHubService
): ActivityBodyImpl => ({ input, logger }) => {
): ActivityBody<ActivityInput, ActivityResultSuccess> => ({
input,
logger
}) => {
logger.info(`INSTALLATION_ID=${input.installationId}`);
const nhService = buildNHService(input.notificationHubConfig);

Expand Down
9 changes: 2 additions & 7 deletions HandleNHDeleteInstallationCallActivity/index.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
import { createActivity } from "../utils/durable/activities";
import { buildNHService } from "../utils/notificationhubServicePartition";
import {
ActivityBodyImpl,
ActivityInput,
ActivityResultSuccess,
getActivityBody
} from "./handler";

export {
ActivityBodyImpl,
ActivityInput,
ActivityResultSuccess
} from "./handler";
export { ActivityInput, ActivityResultSuccess } from "./handler";
export const activityName = "HandleNHDeleteInstallationCallActivity";

const activityFunctionHandler = createActivity<ActivityBodyImpl>(
const activityFunctionHandler = createActivity<ActivityInput>(
activityName,
ActivityInput,
ActivityResultSuccess,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { KindEnum as DeleteKind } from "../../generated/notifications/DeleteInst

import { DeleteInstallationMessage } from "../../generated/notifications/DeleteInstallationMessage";
import {
ActivityBodyImpl,
ActivityInput as NHCallServiceActivityInput,
ActivityName
} from "../../HandleNHDeleteInstallationCallActivity/handler";
Expand All @@ -25,7 +24,7 @@ import {
success as orchestratorSuccess
} from "../../utils/durable/orchestrators";

import { ActivityBodyImpl as DeleteInstallationActivityBody } from "../../HandleNHDeleteInstallationCallActivity";
import { ActivityInput as DeleteInstallationActivityInput } from "../../HandleNHDeleteInstallationCallActivity";
import { IOrchestrationFunctionContext } from "durable-functions/lib/src/iorchestrationfunctioncontext";
import { NotificationHubConfig } from "../../utils/notificationhubServicePartition";
import { readableReport } from "italia-ts-commons/lib/reporters";
Expand Down Expand Up @@ -57,7 +56,7 @@ const aNotificationHubConfig = NotificationHubConfig.decode({
});

const deleteInstallationActivity = o.callableActivity<
DeleteInstallationActivityBody
DeleteInstallationActivityInput
>(ActivityName, ActivityResultSuccess, retryOptions);

const mockGetInput = jest.fn<unknown, []>(() => nhCallOrchestratorInput);
Expand Down
4 changes: 2 additions & 2 deletions HandleNHDeleteInstallationCallOrchestrator/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as t from "io-ts";

import { DeleteInstallationMessage } from "../generated/notifications/DeleteInstallationMessage";

import { ActivityBodyImpl as DeleteInstallationActivityBodyImpl } from "../HandleNHDeleteInstallationCallActivity";
import { ActivityInput as DeleteInstallationActivityInput } from "../HandleNHDeleteInstallationCallActivity";

import * as o from "../utils/durable/orchestrators";
import { NotificationHubConfig } from "../utils/notificationhubServicePartition";
Expand All @@ -23,7 +23,7 @@ export const OrchestratorCallInput = t.interface({

interface IHandlerParams {
deleteInstallationActivity: o.CallableActivity<
DeleteInstallationActivityBodyImpl
DeleteInstallationActivityInput
>;
legacyNotificationHubConfig: NotificationHubConfig;
}
Expand Down
4 changes: 2 additions & 2 deletions HandleNHDeleteInstallationCallOrchestrator/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as df from "durable-functions";
import {
ActivityBodyImpl as DeleteInstallationActivityBodyImpl,
ActivityInput as DeleteInstallationActivityInput,
activityName as DeleteInstallationActivityName,
ActivityResultSuccess as DeleteInstallationActivityResultSuccess
} from "../HandleNHDeleteInstallationCallActivity";
Expand All @@ -12,7 +12,7 @@ import { getHandler } from "./handler";
const config = getConfigOrThrow();

const deleteInstallationActivity = o.callableActivity<
DeleteInstallationActivityBodyImpl
DeleteInstallationActivityInput
>(DeleteInstallationActivityName, DeleteInstallationActivityResultSuccess, {
...new df.RetryOptions(5000, config.RETRY_ATTEMPT_NUMBER),
backoffCoefficient: 1.5
Expand Down
6 changes: 0 additions & 6 deletions HandleNHNotificationCallActivity/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ export type HandleNHNotificationCallActivityInput = t.TypeOf<
typeof HandleNHNotificationCallActivityInput
>;

const assertNever = (x: never): never => {
throw new Error(`Unexpected object: ${toString(x)}`);
};

/**
* For each Notification Hub Message calls related Notification Hub service
*/
Expand Down Expand Up @@ -104,8 +100,6 @@ export const getCallNHServiceActivityHandler = (
return failActivity(logger)(e.message);
}
);
default:
assertNever(message);
}
})
.fold<ActivityResult>(identity, success)
Expand Down
11 changes: 4 additions & 7 deletions HandleNHNotifyMessageCallActivity/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,17 @@ export type ActivityInput = t.TypeOf<typeof ActivityInput>;
// Activity Result
export { ActivityResultSuccess } from "../utils/durable/activities";

// ActivityBody
export type ActivityBodyImpl = ActivityBody<
ActivityInput,
ActivityResultSuccess
>;

/**
* For each Notification Hub Message of type "Delete" calls related Notification Hub service
*/

export const getActivityBody = (
telemetryClient: TelemetryClient,
buildNHService: (nhConfig: NotificationHubConfig) => NotificationHubService
): ActivityBodyImpl => ({ input, logger }) => {
): ActivityBody<ActivityInput, ActivityResultSuccess> => ({
input,
logger
}) => {
logger.info(`INSTALLATION_ID=${input.message.installationId}`);
const nhService = buildNHService(input.notificationHubConfig);
return notify(nhService, input.message.installationId, input.message.payload)
Expand Down
6 changes: 1 addition & 5 deletions HandleNHNotifyMessageCallActivity/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ import {
getActivityBody
} from "./handler";

export {
ActivityBodyImpl,
ActivityInput,
ActivityResultSuccess
} from "./handler";
export { ActivityInput, ActivityResultSuccess } from "./handler";
export const activityName = "HandleNHNotifyMessageCallActivity";

const config = getConfigOrThrow();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { KindEnum as NotifyMessageKind } from "../../generated/notifications/Not
import { NotifyMessage } from "../../generated/notifications/NotifyMessage";

import {
ActivityInput,
ActivityInput as NHCallServiceActivityInput,
ActivityBodyImpl as NotifyMessageActivityBodyImpl,
ActivityResultSuccess as NotifyMessageActivityResultSuccess
} from "../../HandleNHNotifyMessageCallActivity/handler";

Expand Down Expand Up @@ -53,7 +53,7 @@ const retryOptions = {
backoffCoefficient: 1.5
};

const notifyMessageActivity = callableActivity<NotifyMessageActivityBodyImpl>(
const notifyMessageActivity = callableActivity<ActivityInput>(
"HandleNHNotifyMessageCallActivity",
NotifyMessageActivityResultSuccess,
retryOptions
Expand Down
10 changes: 8 additions & 2 deletions HandleNHNotifyMessageCallOrchestrator/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import * as t from "io-ts";

import { Task } from "durable-functions/lib/src/classes";

import { ActivityBodyImpl as NotifyMessageActivityBodyImpl } from "../HandleNHNotifyMessageCallActivity";
import {
ActivityInput as NotifyMessageActivityInput,
ActivityResultSuccess as NotifyMessageActivityResultSuccess
} from "../HandleNHNotifyMessageCallActivity";

import { NotifyMessage } from "../generated/notifications/NotifyMessage";

Expand All @@ -29,7 +32,10 @@ export type NhNotifyMessageOrchestratorCallInput = t.TypeOf<
>;

interface IHandlerParams {
notifyMessageActivity: CallableActivity<NotifyMessageActivityBodyImpl>;
notifyMessageActivity: CallableActivity<
NotifyMessageActivityInput,
NotifyMessageActivityResultSuccess
>;
legacyNotificationHubConfig: NotificationHubConfig;
}

Expand Down
4 changes: 2 additions & 2 deletions HandleNHNotifyMessageCallOrchestrator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import { getNHLegacyConfig } from "../utils/notificationhubServicePartition";
import { getHandler } from "./handler";

import {
ActivityBodyImpl as NotifyMessageActivityBodyImpl,
ActivityInput as NotifyMessageActivityInput,
activityName as NotifyMessageActivityName,
ActivityResultSuccess as NotifyMessageActivityResultSuccess
} from "../HandleNHNotifyMessageCallActivity";

const config = getConfigOrThrow();
const legacyNotificationHubConfig = getNHLegacyConfig(config);

const notifyMessageActivity = callableActivity<NotifyMessageActivityBodyImpl>(
const notifyMessageActivity = callableActivity<NotifyMessageActivityInput>(
NotifyMessageActivityName,
NotifyMessageActivityResultSuccess,
{
Expand Down
4 changes: 2 additions & 2 deletions __mocks__/env-config.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { IConfig } from "../utils/config";
export const envConfig: IConfig = {
isProduction: false,
APPINSIGHTS_INSTRUMENTATIONKEY: "Idontknow" as NonEmptyString,
APPINSIGHTS_SAMPLING_PERCENTAGE: ("20" as undefined) as IntegerFromString,
APPINSIGHTS_SAMPLING_PERCENTAGE: ("20" as unknown) as IntegerFromString,

RETRY_ATTEMPT_NUMBER: ("1" as undefined) as IntegerFromString,
RETRY_ATTEMPT_NUMBER: ("1" as unknown) as IntegerFromString,

AzureWebJobsStorage: "Endpoint=sb://host.docker.internal:30000;SharedAccessKeyName=DefaultFullSharedAccessSignature;SharedAccessKey=foobar" as NonEmptyString,
AZURE_NH_ENDPOINT: "Endpoint=sb://host.docker.internal:30000;SharedAccessKeyName=DefaultFullSharedAccessSignature;SharedAccessKey=foobar" as NonEmptyString,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"jest": "^24.8.0",
"jest-mock-express": "^0.1.1",
"modclean": "^3.0.0-beta.1",
"nock": "^13.0.5",
"nock": "^13.0.11",
"npm-run-all": "^4.1.5",
"oval": "^1.0.0",
"prettier": "^1.18.2",
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"outDir": "dist",
"module": "commonjs",
"moduleResolution": "node",
"strict": false,
"strict": true,
"sourceMap": true,
"resolveJsonModule": true,
"skipLibCheck": true
Expand Down
12 changes: 7 additions & 5 deletions utils/__tests__/notification.keepalive.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// tslint:disable-next-line: no-object-mutation
process.env = {
const env = {
...process.env,
AZURE_NH_ENDPOINT:
"Endpoint=sb://127.0.0.1:30000;SharedAccessKeyName=DefaultFullSharedAccessSignature;SharedAccessKey=foobar",
Expand All @@ -12,15 +11,18 @@ process.env = {
FETCH_KEEPALIVE_TIMEOUT: "60000"
};

// keepalive settings are red straight from the environment :(
process.env = env; // tslint:disable-line: no-object-mutation

import { NonEmptyString } from "italia-ts-commons/lib/strings";
import * as nock from "nock";
import { ExtendedNotificationHubService, notify } from "../notification";

describe("NotificationHubService", () => {
it("should use agentkeepalive when calling notification hub", async () => {
const notificationHubService = new ExtendedNotificationHubService(
process.env.AZURE_NH_HUB_NAME,
process.env.AZURE_NH_ENDPOINT
env.AZURE_NH_HUB_NAME,
env.AZURE_NH_ENDPOINT
);

const responseSpy = jest.fn();
Expand All @@ -38,7 +40,7 @@ describe("NotificationHubService", () => {
title: "beef"
}).run();
expect(responseSpy).toHaveBeenCalledWith(
parseInt(process.env.FETCH_KEEPALIVE_MAX_SOCKETS, 10)
parseInt(env.FETCH_KEEPALIVE_MAX_SOCKETS, 10)
);
});
});
Loading

0 comments on commit 6cf783c

Please sign in to comment.