Skip to content

Commit

Permalink
Merge pull request #14 from pagopa/io-core-ip-86-tslint2eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
Emanuele De Cupis committed Apr 15, 2021
2 parents 6cf783c + 02689b3 commit 45a490d
Show file tree
Hide file tree
Showing 31 changed files with 1,347 additions and 389 deletions.
24 changes: 24 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module.exports = {
"env": {
"browser": true,
"es6": true,
"node": true
},
"ignorePatterns": [
"node_modules",
"generated",
"**/__tests__/*",
"**/__mocks__/*",
"Dangerfile.*",
"*.d.ts"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "tsconfig.json",
"sourceType": "module"
},
"extends": [
"@pagopa/eslint-config/strong",
],
"rules": {}
}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,12 @@ generated
*.zip

*.js
!.eslintrc.js
!jest.config.js
!.release-it.js


azure-functions-core-tools

# Exclude ESLint cache file
.eslintcache
2 changes: 1 addition & 1 deletion Dangerfile.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// import custom DangerJS rules
// see http://danger.systems/js
// see https://github.com/teamdigitale/danger-plugin-digitalcitizenship/
// tslint:disable-next-line:prettier
// eslint-disable-next-line prettier/prettier
import checkDangers from "@pagopa/danger-custom-rules";

checkDangers();
1 change: 1 addition & 0 deletions HandleNHCreateOrUpdateInstallationCallActivity/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export type ActivityBodyImpl = ActivityBody<

export const getActivityBody = (
buildNHService: (nhConfig: NotificationHubConfig) => NotificationHubService
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
): ActivityBodyImpl => ({ input, logger }) => {
logger.info(`INSTALLATION_ID=${input.installationId}`);
const nhService = buildNHService(input.notificationHubConfig);
Expand Down
12 changes: 7 additions & 5 deletions HandleNHCreateOrUpdateInstallationCallOrchestrator/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,18 @@ export type NhCreateOrUpdateInstallationOrchestratorCallInput = t.TypeOf<
>;

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

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export const getHandler = ({
createOrUpdateActivity,
notificationHubConfig
}: IHandlerParams) => {
return o.createOrchestrator(
}: IHandlerParams) =>
o.createOrchestrator(
OrchestratorName,
NhCreateOrUpdateInstallationOrchestratorCallInput,
function*({
Expand All @@ -47,4 +50,3 @@ export const getHandler = ({
});
}
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
import * as o from "../utils/durable/orchestrators";

import { getConfigOrThrow } from "../utils/config";
import { getHandler } from "./handler";

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

const config = getConfigOrThrow();

Expand Down
1 change: 1 addition & 0 deletions HandleNHDeleteInstallationCallActivity/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export { ActivityResultSuccess } from "../utils/durable/activities";

export const getActivityBody = (
buildNHService: (nhConfig: NotificationHubConfig) => NotificationHubService
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
): ActivityBody<ActivityInput, ActivityResultSuccess> => ({
input,
logger
Expand Down
34 changes: 15 additions & 19 deletions HandleNHDeleteInstallationCallOrchestrator/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,25 @@ export const OrchestratorCallInput = t.interface({
});

interface IHandlerParams {
deleteInstallationActivity: o.CallableActivity<
readonly deleteInstallationActivity: o.CallableActivity<
DeleteInstallationActivityInput
>;
legacyNotificationHubConfig: NotificationHubConfig;
readonly legacyNotificationHubConfig: NotificationHubConfig;
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export const getHandler = ({
deleteInstallationActivity,
legacyNotificationHubConfig
}: IHandlerParams) => {
return o.createOrchestrator(
OrchestratorName,
OrchestratorCallInput,
function*({
context,
input: {
message: { installationId }
} /* , logger */
}): Generator<Task, void, Task> {
yield* deleteInstallationActivity(context, {
installationId,
notificationHubConfig: legacyNotificationHubConfig
});
}
);
};
}: IHandlerParams) =>
o.createOrchestrator(OrchestratorName, OrchestratorCallInput, function*({
context,
input: {
message: { installationId }
} /* , logger */
}): Generator<Task, void, Task> {
yield* deleteInstallationActivity(context, {
installationId,
notificationHubConfig: legacyNotificationHubConfig
});
});
3 changes: 1 addition & 2 deletions HandleNHNotificationCall/__tests__/handler.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// tslint:disable:no-any

/* eslint-disable @typescript-eslint/no-explicit-any */
import * as df from "durable-functions";
import { DurableOrchestrationClient } from "durable-functions/lib/src/durableorchestrationclient";
import { NonEmptyString } from "italia-ts-commons/lib/strings";
Expand Down
11 changes: 5 additions & 6 deletions HandleNHNotificationCallActivity/__tests__/handler.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* tslint:disable: no-any */
// tslint:disable-next-line: no-object-mutation
/* eslint-disable @typescript-eslint/no-explicit-any */
import { NonEmptyString } from "italia-ts-commons/lib/strings";
import { context as contextMock } from "../../__mocks__/durable-functions";
import { PlatformEnum } from "../../generated/backend/Platform";
Expand Down Expand Up @@ -94,7 +93,7 @@ describe("HandleNHNotificationCallActivity", () => {
const handler = getCallNHServiceActivityHandler(mockTelemetryClient);
const input = NHServiceActivityInput.encode({
message: aDeleteInStalltionMessage,
notificationHubConfig: aNHConfig
NotificationHubConfig: aNHConfig
});
expect.assertions(2);
await handler(contextMock as any, input);
Expand All @@ -106,7 +105,7 @@ describe("HandleNHNotificationCallActivity", () => {
const handler = getCallNHServiceActivityHandler(mockTelemetryClient);
const input = NHServiceActivityInput.encode({
message: aCreateOrUpdateInstallationMessage,
notificationHubConfig: aNHConfig
NotificationHubConfig: aNHConfig
});

expect.assertions(2);
Expand All @@ -122,7 +121,7 @@ describe("HandleNHNotificationCallActivity", () => {
const handler = getCallNHServiceActivityHandler(mockTelemetryClient);
const input = NHServiceActivityInput.encode({
message: aNotifyMessage,
notificationHubConfig: aNHConfig
NotificationHubConfig: aNHConfig
});
expect.assertions(2);
try {
Expand All @@ -136,7 +135,7 @@ describe("HandleNHNotificationCallActivity", () => {
it("should NOT trigger a retry if deleteInstallation fails", async () => {
const handler = getCallNHServiceActivityHandler(mockTelemetryClient);
const input = NHServiceActivityInput.encode({
notificationHubConfig: aNHConfig,
NotificationHubConfig: aNHConfig,
message: aDeleteInStalltionMessage
});
const res = await handler(contextMock as any, input);
Expand Down
107 changes: 68 additions & 39 deletions HandleNHNotificationCallActivity/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as t from "io-ts";

import { Context } from "@azure/functions";
import { identity, toString } from "fp-ts/lib/function";
import { fromEither, taskEither } from "fp-ts/lib/TaskEither";
import { fromEither, taskEither, TaskEither } from "fp-ts/lib/TaskEither";

import { readableReport } from "italia-ts-commons/lib/reporters";

Expand Down Expand Up @@ -34,7 +34,8 @@ import {
// Activity input
export const HandleNHNotificationCallActivityInput = t.interface({
message: NotificationMessage,
notificationHubConfig: NotificationHubConfig
// eslint-disable-next-line sort-keys
NotificationHubConfig
});

export type HandleNHNotificationCallActivityInput = t.TypeOf<
Expand All @@ -48,6 +49,7 @@ export const getCallNHServiceActivityHandler = (
// tslint:disable-next-line: no-unused-variable
telemetryClient: ReturnType<typeof initTelemetryClient>,
logPrefix = "NHCallServiceActivity"
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
) => async (context: Context, input: unknown) => {
const logger = createLogger(context, logPrefix);
return fromEither(HandleNHNotificationCallActivityInput.decode(input))
Expand All @@ -57,51 +59,78 @@ export const getCallNHServiceActivityHandler = (
readableReport(errs)
)
)
.chain<ActivityResultSuccess>(({ message, notificationHubConfig }) => {
context.log.info(
`${logPrefix}|${message.kind}|INSTALLATION_ID=${message.installationId}`
);
.chain<ActivityResultSuccess>(
({
message,
// eslint-disable-next-line @typescript-eslint/no-shadow
NotificationHubConfig
// eslint-disable-next-line @typescript-eslint/no-explicit-any
}): TaskEither<any, ActivityResultSuccess> => {
context.log.info(
`${logPrefix}|${message.kind}|INSTALLATION_ID=${message.installationId}`
);

const nhService = buildNHService(notificationHubConfig);
const nhService = buildNHService(NotificationHubConfig);

switch (message.kind) {
case CreateOrUpdateKind.CreateOrUpdateInstallation:
return createOrUpdateInstallation(
nhService,
message.installationId,
message.platform,
message.pushChannel,
message.tags
).mapLeft(e =>
retryActivity(logger, `${logPrefix}|ERROR=${toString(e)}`)
);
case NotifyKind.Notify:
return notify(nhService, message.installationId, message.payload)
.mapLeft(e =>
// eslint-disable-next-line default-case
switch (message.kind) {
case CreateOrUpdateKind.CreateOrUpdateInstallation:
return createOrUpdateInstallation(
nhService,
message.installationId,
message.platform,
message.pushChannel,
message.tags
).mapLeft(e =>
retryActivity(logger, `${logPrefix}|ERROR=${toString(e)}`)
)
.chainFirst(
taskEither.of(
telemetryClient.trackEvent({
name: "api.messages.notification.push.sent",
properties: {
isSuccess: "true",
messageId: message.payload.message_id
},
tagOverrides: { samplingEnabled: "false" }
})
)
);
case DeleteKind.DeleteInstallation:
return deleteInstallation(nhService, message.installationId).mapLeft(
e => {
case NotifyKind.Notify:
return notify(nhService, message.installationId, message.payload)
.mapLeft(e =>
retryActivity(logger, `${logPrefix}|ERROR=${toString(e)}`)
)
.chainFirst(
taskEither.of(
telemetryClient.trackEvent({
name: "api.messages.notification.push.sent",
properties: {
isSuccess: "true",
messageId: message.payload.message_id
},
tagOverrides: { samplingEnabled: "false" }
})
)
);
// eslint-disable-next-line sonarjs/no-duplicated-branches, no-duplicate-case
case NotifyKind.Notify:
return notify(nhService, message.installationId, message.payload)
.mapLeft(e =>
retryActivity(logger, `${logPrefix}|ERROR=${toString(e)}`)
)
.chainFirst(
taskEither.of(
telemetryClient.trackEvent({
name: "api.messages.notification.push.sent",
properties: {
isSuccess: "true",
messageId: message.payload.message_id
},
tagOverrides: { samplingEnabled: "false" }
})
)
);
case DeleteKind.DeleteInstallation:
return deleteInstallation(
nhService,
message.installationId
).mapLeft(e => {
// do not trigger a retry as delete may fail in case of 404
context.log.error(`${logPrefix}|ERROR=${toString(e)}`);
return failActivity(logger)(e.message);
}
);
});
}
}
})
)
.fold<ActivityResult>(identity, success)
.run();
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* tslint:disable:no-any */
// tslint:disable-next-line: no-object-mutation
/* eslint-disable @typescript-eslint/no-explicit-any */
import { NonEmptyString } from "italia-ts-commons/lib/strings";
import { context as contextMock } from "../../__mocks__/durable-functions";
import { PlatformEnum } from "../../generated/backend/Platform";
Expand Down Expand Up @@ -55,7 +54,7 @@ describe("HandleNHNotificationCallOrchestrator", () => {
retryOptions,
HandleNHNotificationCallActivityInput.encode({
message: aNotificationHubMessage,
notificationHubConfig: {
NotificationHubConfig: {
AZURE_NH_ENDPOINT: envConfig.AZURE_NH_ENDPOINT,
AZURE_NH_HUB_NAME: envConfig.AZURE_NH_HUB_NAME
}
Expand Down
2 changes: 1 addition & 1 deletion HandleNHNotificationCallOrchestrator/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const getHandler = (envConfig: IConfig) =>

const nhCallOrchestratorInput: HandleNHNotificationCallActivityInput = {
...errorOrNHCallOrchestratorInput.value,
notificationHubConfig: nhConfig
NotificationHubConfig: nhConfig
};

yield context.df.callActivityWithRetry(
Expand Down
5 changes: 1 addition & 4 deletions HandleNHNotifyMessageCallActivity/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ import { notify } from "../utils/notification";
import { NotifyMessage } from "../generated/notifications/NotifyMessage";
import { NotificationHubConfig } from "../utils/notificationhubServicePartition";

// message: t.string,
// message_id: t.string,
// title: t.string

// Activity input
export const ActivityInput = t.interface({
message: NotifyMessage,
Expand All @@ -37,6 +33,7 @@ export { ActivityResultSuccess } from "../utils/durable/activities";
export const getActivityBody = (
telemetryClient: TelemetryClient,
buildNHService: (nhConfig: NotificationHubConfig) => NotificationHubService
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
): ActivityBody<ActivityInput, ActivityResultSuccess> => ({
input,
logger
Expand Down
Loading

0 comments on commit 45a490d

Please sign in to comment.