Skip to content

Commit

Permalink
[#IP-86] tslint to eslint migration
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Disaro committed Apr 9, 2021
1 parent 6ff5a11 commit a09b17f
Show file tree
Hide file tree
Showing 46 changed files with 186 additions and 8 deletions.
14 changes: 13 additions & 1 deletion CreateMessage/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@ import {
import { NonEmptyString } from "italia-ts-commons/lib/strings";
import { PromiseType } from "italia-ts-commons/lib/types";

// eslint-disable-next-line @typescript-eslint/naming-convention
const ApiNewMessageWithDefaults = t.intersection([
ApiNewMessage,
// eslint-disable-next-line @typescript-eslint/naming-convention
t.interface({ time_to_live: TimeToLiveSeconds })
]);
export type ApiNewMessageWithDefaults = t.TypeOf<
Expand All @@ -89,6 +91,7 @@ export type ApiNewMessageWithDefaults = t.TypeOf<
/**
* A request middleware that validates the Message payload.
*/
// eslint-disable-next-line @typescript-eslint/naming-convention
export const MessagePayloadMiddleware: IRequestMiddleware<
"IResponseErrorValidation",
ApiNewMessageWithDefaults
Expand Down Expand Up @@ -117,7 +120,7 @@ type ICreateMessageHandler = (
messagePayload: ApiNewMessageWithDefaults,
maybeFiscalCode: Option<FiscalCode>
) => Promise<
// eslint-disable-next-line sonar/max-union-size
// eslint-disable-next-line @typescript-eslint/ban-types
| IResponseSuccessRedirectToResource<Message, {}>
| IResponseErrorInternal
| IResponseErrorQuery
Expand Down Expand Up @@ -221,6 +224,7 @@ export const createMessageDocument = (
): TaskEither<
IResponseErrorInternal | IResponseErrorQuery,
NewMessageWithoutContent
// eslint-disable-next-line max-params
> => {
// create a new message from the payload
// this object contains only the message metadata, the content of the
Expand Down Expand Up @@ -299,6 +303,7 @@ export const forkOrchestrator = (
// queue the message to the created messages queue by setting
// the message to the output binding of this function
// eslint-disable-next-line functional/immutable-data
// eslint-disable-next-line extra-rules/no-commented-out-code
// context.bindings.createdMessage = createdMessageEventOrError.value;
const dfClient = getDfClient();
return tryCatch(
Expand All @@ -317,6 +322,7 @@ export const forkOrchestrator = (
*/
const redirectToNewMessage = (
newMessageWithoutContent: NewMessageWithoutContent
// eslint-disable-next-line @typescript-eslint/ban-types
): IResponseSuccessRedirectToResource<Message, {}> =>
ResponseSuccessRedirectToResource(
newMessageWithoutContent,
Expand All @@ -327,18 +333,21 @@ const redirectToNewMessage = (
/**
* Returns a type safe CreateMessage handler.
*/
// eslint-disable-next-line prefer-arrow/prefer-arrow-functions, @typescript-eslint/naming-convention
export function CreateMessageHandler(
telemetryClient: ReturnType<typeof initAppInsights>,
messageModel: MessageModel,
generateObjectId: ObjectIdGenerator
): ICreateMessageHandler {
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
return async (
context,
auth,
__,
userAttributes,
messagePayload,
maybeFiscalCodeInPath
// eslint-disable-next-line max-params
) => {
const maybeFiscalCodeInPayload = fromNullable(messagePayload.fiscal_code);

Expand Down Expand Up @@ -378,6 +387,7 @@ export function CreateMessageHandler(
properties: {
error: isSuccess ? undefined : r.kind,
hasDefaultEmail: Boolean(
// eslint-disable-next-line @typescript-eslint/prefer-optional-chain
messagePayload.default_addresses &&
messagePayload.default_addresses.email
).toString(),
Expand Down Expand Up @@ -464,6 +474,7 @@ export function CreateMessageHandler(
/**
* Wraps a CreateMessage handler inside an Express request handler.
*/
// eslint-disable-next-line prefer-arrow/prefer-arrow-functions, @typescript-eslint/naming-convention
export function CreateMessage(
telemetryClient: ReturnType<typeof initAppInsights>,
serviceModel: ServiceModel,
Expand Down Expand Up @@ -492,6 +503,7 @@ export function CreateMessage(
);
return wrapRequestHandler(
middlewaresWrap(
// eslint-disable-next-line @typescript-eslint/naming-convention, max-params
checkSourceIpForHandler(handler, (_, __, c, u, ___, ____) =>
ipTuple(c, u)
)
Expand Down
1 change: 1 addition & 0 deletions CreateMessage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ app.post(
const azureFunctionHandler = createAzureFunctionHandler(app);

// Binds the express app to an Azure Function handler
// eslint-disable-next-line prefer-arrow/prefer-arrow-functions
function httpStart(context: Context): void {
setAppContext(app, context);
withAppInsightsContext(context, () => azureFunctionHandler(context));
Expand Down
5 changes: 5 additions & 0 deletions CreateNotificationActivity/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const getEmailAddressFromProfile = (
/**
* Try to create (save) a new notification
*/
// eslint-disable-next-line prefer-arrow/prefer-arrow-functions
async function createNotification(
lNotificationModel: NotificationModel,
senderMetadata: CreatedMessageEventSenderMetadata,
Expand Down Expand Up @@ -73,6 +74,7 @@ async function createNotification(
};
}

// eslint-disable-next-line @typescript-eslint/naming-convention
export const CreateNotificationActivityInput = t.interface({
createdMessageEvent: CreatedMessageEvent,
storeMessageContentActivityResult: SuccessfulStoreMessageContentActivityResult
Expand All @@ -82,6 +84,7 @@ export type CreateNotificationActivityInput = t.TypeOf<
typeof CreateNotificationActivityInput
>;

// eslint-disable-next-line @typescript-eslint/naming-convention
const CreateNotificationActivitySomeResult = t.interface({
hasEmail: t.boolean,
hasWebhook: t.boolean,
Expand All @@ -93,6 +96,7 @@ type CreateNotificationActivitySomeResult = t.TypeOf<
typeof CreateNotificationActivitySomeResult
>;

// eslint-disable-next-line @typescript-eslint/naming-convention
const CreateNotificationActivityNoneResult = t.interface({
kind: t.literal("none")
});
Expand All @@ -101,6 +105,7 @@ type CreateNotificationActivityNoneResult = t.TypeOf<
typeof CreateNotificationActivityNoneResult
>;

// eslint-disable-next-line @typescript-eslint/naming-convention
export const CreateNotificationActivityResult = t.taggedUnion("kind", [
CreateNotificationActivitySomeResult,
CreateNotificationActivityNoneResult
Expand Down
13 changes: 13 additions & 0 deletions CreateService/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,11 @@ const createSubscriptionTask = (
() =>
apiClient.createSubscription({
body: {
// eslint-disable-next-line @typescript-eslint/naming-convention
product_name: productName
},
email: userEmail,
// eslint-disable-next-line @typescript-eslint/naming-convention
subscription_id: subscriptionId
}),
200
Expand All @@ -123,17 +125,22 @@ const createServiceTask = (
subscriptionId: NonEmptyString,
sandboxFiscalCode: FiscalCode,
adb2cTokenName: NonEmptyString
// eslint-disable-next-line max-params
): TaskEither<ErrorResponses, Service> =>
withApiRequestWrapper(
logger,
() =>
apiClient.createService({
body: {
...servicePayload,
// eslint-disable-next-line @typescript-eslint/naming-convention
authorized_recipients: [sandboxFiscalCode],
// eslint-disable-next-line @typescript-eslint/naming-convention
service_id: subscriptionId,
// eslint-disable-next-line @typescript-eslint/naming-convention
service_metadata: {
...servicePayload.service_metadata,
// eslint-disable-next-line @typescript-eslint/naming-convention
token_name: adb2cTokenName
}
}
Expand All @@ -144,13 +151,15 @@ const createServiceTask = (
/**
* Handles requests for create a service by a Service Payload.
*/
// eslint-disable-next-line prefer-arrow/prefer-arrow-functions, @typescript-eslint/naming-convention
export function CreateServiceHandler(
telemetryClient: ReturnType<typeof initAppInsights>,
apiClient: APIClient,
generateObjectId: ObjectIdGenerator,
productName: NonEmptyString,
sandboxFiscalCode: NonEmptyString
): ICreateServiceHandler {
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type, @typescript-eslint/naming-convention
return (context, __, ___, userAttributes, servicePayload) => {
const subscriptionId = generateObjectId();
context.log.info(
Expand Down Expand Up @@ -187,7 +196,9 @@ export function CreateServiceHandler(
});
return ResponseSuccessJson({
...service,
// eslint-disable-next-line @typescript-eslint/naming-convention
primary_key: subscription.primary_key,
// eslint-disable-next-line @typescript-eslint/naming-convention
secondary_key: subscription.secondary_key
});
})
Expand All @@ -201,6 +212,7 @@ export function CreateServiceHandler(
/**
* Wraps a CreateService handler inside an Express request handler.
*/
// eslint-disable-next-line prefer-arrow/prefer-arrow-functions, @typescript-eslint/naming-convention
export function CreateService(
telemetryClient: ReturnType<typeof initAppInsights>,
serviceModel: ServiceModel,
Expand All @@ -224,6 +236,7 @@ export function CreateService(
);
return wrapRequestHandler(
middlewaresWrap(
// eslint-disable-next-line @typescript-eslint/naming-convention
checkSourceIpForHandler(handler, (_, __, c, u, ___) => ipTuple(c, u))
)
);
Expand Down
1 change: 1 addition & 0 deletions CreateService/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ app.post(
const azureFunctionHandler = createAzureFunctionHandler(app);

// Binds the express app to an Azure Function handler
// eslint-disable-next-line prefer-arrow/prefer-arrow-functions
function httpStart(context: Context): void {
setAppContext(app, context);
azureFunctionHandler(context);
Expand Down
3 changes: 2 additions & 1 deletion CreatedMessageOrchestrator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { MessageProcessingEventNames, trackMessageProcessing } from "./utils";
* See https://docs.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-checkpointing-and-replay
*
*/
// eslint-disable-next-line sonarjs/cognitive-complexity, sonar/sonar-max-lines-per-function
// eslint-disable-next-line sonarjs/cognitive-complexity, max-lines-per-function
function* handler(context: IOrchestrationFunctionContext): Generator<unknown> {
const input = context.df.getInput();

Expand Down Expand Up @@ -70,6 +70,7 @@ function* handler(context: IOrchestrationFunctionContext): Generator<unknown> {

context.log.verbose(`${logPrefix}|Starting`);

// eslint-disable-next-line extra-rules/no-commented-out-code
// TODO: customize + backoff
// see https://docs.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-error-handling#javascript-functions-2x-only-1
const retryOptions = new df.RetryOptions(5000, 10);
Expand Down
8 changes: 8 additions & 0 deletions CreatedMessageOrchestrator/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export type HandlerInputType<T> = T extends Function2<any, infer A, any>
? A
: never;

// eslint-disable-next-line @typescript-eslint/naming-convention
const MessageProcessingEvent = t.interface({
name: t.string,
properties: t.interface({
Expand Down Expand Up @@ -42,11 +43,18 @@ export const trackMessageProcessing = (
: null;

export enum MessageProcessingEventNames {
// eslint-disable-next-line @typescript-eslint/naming-convention
DECODE_INPUT = "api.messages.create.decodeinput",
// eslint-disable-next-line @typescript-eslint/naming-convention
STORE_MESSAGE_DECODE = "api.messages.create.storemessagedecode",
// eslint-disable-next-line @typescript-eslint/naming-convention
UPDATE_NOTIFICATION_STATUS = "api.messages.create.updatenotificationstatus",
// eslint-disable-next-line @typescript-eslint/naming-convention
NO_CHANNEL = "api.messages.create.nochannel",
// eslint-disable-next-line @typescript-eslint/naming-convention
EMAIL_SENT = "api.messages.create.emailsent",
// eslint-disable-next-line @typescript-eslint/naming-convention
WEBHOOK = "api.messages.create.webhook",
// eslint-disable-next-line @typescript-eslint/naming-convention
UPDATE_MESSAGE_STATUS = "api.messages.create.updatemessagestatus"
}
8 changes: 8 additions & 0 deletions EmailNotificationActivity/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ import { sendMail } from "@pagopa/io-functions-commons/dist/src/mailer";
import { generateDocumentHtml } from "./utils";

export interface INotificationDefaults {
// eslint-disable-next-line @typescript-eslint/naming-convention
readonly HTML_TO_TEXT_OPTIONS: HtmlToTextOptions;
// eslint-disable-next-line @typescript-eslint/naming-convention
readonly MAIL_FROM: NonEmptyString;
}

// eslint-disable-next-line @typescript-eslint/naming-convention
export const EmailNotificationActivityInput = t.interface({
notificationEvent: NotificationEvent
});
Expand All @@ -31,13 +34,16 @@ export type EmailNotificationActivityInput = t.TypeOf<
typeof EmailNotificationActivityInput
>;

// eslint-disable-next-line @typescript-eslint/naming-convention
export const EmailNotificationActivityResult = t.taggedUnion("kind", [
t.interface({
kind: t.literal("SUCCESS"),
// eslint-disable-next-line @typescript-eslint/naming-convention, sort-keys
result: t.keyof({ OK: null, EXPIRED: null })
}),
t.interface({
kind: t.literal("FAILURE"),
// eslint-disable-next-line @typescript-eslint/naming-convention
reason: t.keyof({ DECODE_ERROR: null })
})
]);
Expand Down Expand Up @@ -153,7 +159,9 @@ export const getEmailNotificationActivityHandler = (
await sendMail(lMailerTransporter, {
from: notificationDefaultParams.MAIL_FROM,
headers: {
// eslint-disable-next-line @typescript-eslint/naming-convention
"X-Italia-Messages-MessageId": message.id,
// eslint-disable-next-line @typescript-eslint/naming-convention
"X-Italia-Messages-NotificationId": notificationId
},
html: documentHtml,
Expand Down
2 changes: 2 additions & 0 deletions EmailNotificationActivity/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ const activityFunction: AzureFunction = getEmailNotificationActivityHandler(
mailerTransporter,
notificationModel,
{
// eslint-disable-next-line @typescript-eslint/naming-convention
HTML_TO_TEXT_OPTIONS,
// eslint-disable-next-line @typescript-eslint/naming-convention
MAIL_FROM
}
);
Expand Down
3 changes: 3 additions & 0 deletions EmailNotificationActivity/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Puoi anche disattivare l’inoltro dei messaggi via email per tutti i servizi, s
/**
* Generates the HTML for the email from the Markdown content and the subject
*/
// eslint-disable-next-line prefer-arrow/prefer-arrow-functions
export async function generateDocumentHtml(
subject: MessageSubject,
markdown: MessageBodyMarkdown,
Expand All @@ -43,6 +44,7 @@ export async function generateDocumentHtml(
// wrap the generated HTML into an email template
return defaultEmailTemplate(
subject, // title
// eslint-disable-next-line extra-rules/no-commented-out-code
"", // TODO: headline
senderMetadata.organizationName, // organization name
senderServiceName, // service name
Expand All @@ -56,6 +58,7 @@ export async function generateDocumentHtml(
/**
* Promise wrapper around Transporter#sendMail
*/
// eslint-disable-next-line prefer-arrow/prefer-arrow-functions
export async function sendMail(
transporter: NodeMailer.Transporter,
options: NodeMailer.SendMailOptions
Expand Down
4 changes: 3 additions & 1 deletion GetLimitedProfile/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ type IGetLimitedProfileHandler = (
userAttributes: IAzureUserAttributes,
fiscalCode: FiscalCode
) => Promise<
// eslint-disable-next-line sonar/max-union-size
| IResponseSuccessJson<LimitedProfile>
| IResponseErrorNotFound
| IResponseErrorQuery
Expand All @@ -67,9 +66,11 @@ type IGetLimitedProfileHandler = (
/**
* Returns a type safe GetLimitedProfile handler.
*/
// eslint-disable-next-line prefer-arrow/prefer-arrow-functions, @typescript-eslint/naming-convention
export function GetLimitedProfileHandler(
profileModel: ProfileModel
): IGetLimitedProfileHandler {
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
return async (auth, __, userAttributes, fiscalCode) => {
// Sandboxed accounts will receive 403
// if they're not authorized to send a messages to this fiscal code.
Expand Down Expand Up @@ -126,6 +127,7 @@ export function GetLimitedProfileHandler(
/**
* Wraps a GetLimitedProfile handler inside an Express request handler.
*/
// eslint-disable-next-line prefer-arrow/prefer-arrow-functions, @typescript-eslint/naming-convention
export function GetLimitedProfile(
serviceModel: ServiceModel,
profileModel: ProfileModel
Expand Down
1 change: 1 addition & 0 deletions GetLimitedProfile/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ app.get(
const azureFunctionHandler = createAzureFunctionHandler(app);

// Binds the express app to an Azure Function handler
// eslint-disable-next-line prefer-arrow/prefer-arrow-functions
function httpStart(context: Context): void {
setAppContext(app, context);
azureFunctionHandler(context);
Expand Down
Loading

0 comments on commit a09b17f

Please sign in to comment.