Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function CreateMessage(
getCustomTelemetryClient: CustomTelemetryClientFactory,
serviceModel: ServiceModel,
messageModel: MessageModel
): express.RequestHandler {
const handler = CreateMessageHandler(
getCustomTelemetryClient,
messageModel,
ulidGenerator
);
const middlewaresWrap = withRequestMiddlewares(
// extract Azure Functions bindings
ContextMiddleware(),
// allow only users in the ApiMessageWrite and ApiMessageWriteLimited groups
AzureApiAuthMiddleware(
new Set([UserGroup.ApiMessageWrite, UserGroup.ApiLimitedMessageWrite])
),
// extracts the client IP from the request
ClientIpMiddleware,
// extracts custom user attributes from the request
AzureUserAttributesMiddleware(serviceModel),
// extracts the fiscal code from the request params
FiscalCodeMiddleware,
// extracts the create message payload from the request body
MessagePayloadMiddleware
);
return wrapRequestHandler(
middlewaresWrap(
checkSourceIpForHandler(handler, (_, __, c, u, ___, ____) =>
ipTuple(c, u)
)
export function GetService(serviceModel: ServiceModel): express.RequestHandler {
const handler = GetServiceHandler(serviceModel);
const azureUserAttributesMiddleware = AzureUserAttributesMiddleware(
serviceModel
);
const middlewaresWrap = withRequestMiddlewares(
AzureApiAuthMiddleware(new Set([UserGroup.ApiServiceRead])),
ClientIpMiddleware,
azureUserAttributesMiddleware,
requiredServiceIdMiddleware
);
return wrapRequestHandler(
middlewaresWrap(
checkSourceIpForHandler(handler, (_, c, u, __) => ipTuple(c, u))
)
);
}
export function CreateService(
serviceModel: ServiceModel
): express.RequestHandler {
const handler = CreateServiceHandler(serviceModel);
const azureUserAttributesMiddleware = AzureUserAttributesMiddleware(
serviceModel
);
const middlewaresWrap = withRequestMiddlewares(
AzureApiAuthMiddleware(new Set([UserGroup.ApiServiceWrite])),
ClientIpMiddleware,
azureUserAttributesMiddleware,
ServicePayloadMiddleware
);
return wrapRequestHandler(
middlewaresWrap(
checkSourceIpForHandler(handler, (_, c, u, __) => ipTuple(c, u))
)
);
}
export function GetProfile(
serviceModel: ServiceModel,
profileModel: ProfileModel
): express.RequestHandler {
const handler = GetProfileHandler(profileModel);
const azureUserAttributesMiddleware = AzureUserAttributesMiddleware(
serviceModel
);
const middlewaresWrap = withRequestMiddlewares(
AzureApiAuthMiddleware(
new Set([UserGroup.ApiLimitedProfileRead, UserGroup.ApiFullProfileRead])
),
ClientIpMiddleware,
azureUserAttributesMiddleware,
FiscalCodeMiddleware
);
return wrapRequestHandler(
middlewaresWrap(
checkSourceIpForHandler(handler, (_, c, u, __) => ipTuple(c, u))
)
);
}
export function GetServicesByRecipient(
serviceModel: ServiceModel,
senderServiceModel: SenderServiceModel
): express.RequestHandler {
const handler = GetServicesByRecipientHandler(senderServiceModel);
const azureUserAttributesMiddleware = AzureUserAttributesMiddleware(
serviceModel
);
const middlewaresWrap = withRequestMiddlewares(
AzureApiAuthMiddleware(new Set([UserGroup.ApiServiceByRecipientQuery])),
ClientIpMiddleware,
azureUserAttributesMiddleware,
RequiredParamMiddleware("fiscalcode", FiscalCode)
);
return wrapRequestHandler(
middlewaresWrap(
checkSourceIpForHandler(handler, (_, c, u, __) => ipTuple(c, u))
)
);
}
export function GetDebug(serviceModel: ServiceModel): express.RequestHandler {
const azureApiMiddleware = AzureApiAuthMiddleware(
new Set([UserGroup.ApiDebugRead])
);
const azureUserAttributesMiddleware = AzureUserAttributesMiddleware(
serviceModel
);
const middlewaresWrap = withRequestMiddlewares(
ExpressRequestMiddleware,
ClientIpMiddleware,
azureApiMiddleware,
azureUserAttributesMiddleware
);
return wrapRequestHandler(
middlewaresWrap(
checkSourceIpForHandler(getDebugHandler, (_, c, __, u) => ipTuple(c, u))
)
);
export function UpdateService(
serviceModel: ServiceModel
): express.RequestHandler {
const handler = UpdateServiceHandler(serviceModel);
const azureUserAttributesMiddleware = AzureUserAttributesMiddleware(
serviceModel
);
const middlewaresWrap = withRequestMiddlewares(
AzureApiAuthMiddleware(new Set([UserGroup.ApiServiceWrite])),
ClientIpMiddleware,
azureUserAttributesMiddleware,
requiredServiceIdMiddleware,
ServicePayloadMiddleware
);
return wrapRequestHandler(
middlewaresWrap(
checkSourceIpForHandler(handler, (_, c, u, __, ___) => ipTuple(c, u))
)
);
}
export function GetMessages(
serviceModel: ServiceModel,
messageModel: MessageModel
): express.RequestHandler {
const handler = GetMessagesHandler(messageModel);
const middlewaresWrap = withRequestMiddlewares(
AzureApiAuthMiddleware(new Set([UserGroup.ApiMessageList])),
ClientIpMiddleware,
AzureUserAttributesMiddleware(serviceModel),
FiscalCodeMiddleware
);
return wrapRequestHandler(
middlewaresWrap(
checkSourceIpForHandler(handler, (_, c, u, __) => ipTuple(c, u))
)
);
}
serviceModel: ServiceModel,
messageModel: MessageModel,
messageStatusModel: MessageStatusModel,
notificationModel: NotificationModel,
notificationStatusModel: NotificationStatusModel,
blobService: BlobService
): express.RequestHandler {
const handler = GetMessageHandler(
messageModel,
messageStatusModel,
notificationModel,
notificationStatusModel,
blobService
);
const middlewaresWrap = withRequestMiddlewares(
AzureApiAuthMiddleware(
new Set([UserGroup.ApiMessageRead, UserGroup.ApiMessageList])
),
ClientIpMiddleware,
AzureUserAttributesMiddleware(serviceModel),
FiscalCodeMiddleware,
RequiredParamMiddleware("id", NonEmptyString)
);
return wrapRequestHandler(
middlewaresWrap(
checkSourceIpForHandler(handler, (_, c, u, __, ___) => ipTuple(c, u))
)
);
}
export function UpsertProfile(
serviceModel: ServiceModel,
profileModel: ProfileModel
): express.RequestHandler {
const handler = UpsertProfileHandler(profileModel);
const azureUserAttributesMiddleware = AzureUserAttributesMiddleware(
serviceModel
);
const middlewaresWrap = withRequestMiddlewares(
ContextMiddleware(),
AzureApiAuthMiddleware(new Set([UserGroup.ApiProfileWrite])),
ClientIpMiddleware,
azureUserAttributesMiddleware,
FiscalCodeMiddleware,
ProfilePayloadMiddleware
);
return wrapRequestHandler(
middlewaresWrap(
checkSourceIpForHandler(handler, (_, __, c, u, ___, ____) =>
ipTuple(c, u)
)
)
);
}