Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const returnedMessage:
| MessageResponseWithContent
| MessageResponseWithoutContent = {
message,
notification: notificationStatuses.toUndefined(),
// we do not return the status date-time
status: maybeMessageStatus
.map(messageStatus => messageStatus.status)
// when the message has been received but a MessageStatus
// does not exist yet, the message is considered to be
// in the ACCEPTED state (not yet stored in the inbox)
.getOrElse(MessageStatusValueEnum.ACCEPTED)
};
return ResponseSuccessJson(returnedMessage);
};
}
const getDebugHandler: GetDebug = (request, _, auth, userAttributes) => {
return Promise.resolve(
ResponseSuccessJson({
auth: {
...auth,
// must convert the Set to an Array
// see https://stackoverflow.com/questions/31190885/json-stringify-a-set
groups: Array.from(auth.groups.values())
},
body: request.body,
headers: request.headers,
params: request.params,
user: userAttributes
})
);
};
return async (auth, _, userAttributes, fiscalCode) => {
const errorOrMaybeProfile = await profileModel.findOneProfileByFiscalCode(
fiscalCode
);
if (isRight(errorOrMaybeProfile)) {
const maybeProfile = errorOrMaybeProfile.value;
if (isSome(maybeProfile)) {
const profile = maybeProfile.value;
if (auth.groups.has(UserGroup.ApiFullProfileRead)) {
// if the client is a trusted application we return the
// extended profile
return ResponseSuccessJson(toExtendedProfile(profile));
} else {
// or else, we return a limited profile
return ResponseSuccessJson(
toLimitedProfile(
profile,
isSenderAllowed(
profile.blockedInboxOrChannels,
userAttributes.service.serviceId
)
)
);
}
} else {
return ResponseErrorNotFound(
"Profile not found",
"The profile you requested was not found in the system."
);
}
} else {
return wrapRequestHandler(() =>
Promise.resolve(ResponseSuccessJson(apiSpecs))
);
service => ResponseSuccessJson(retrievedServiceToPublic(service))
)
): Promise | IResponseErrorQuery> {
const profile: Profile = {
acceptedTosVersion: profileModelPayload.accepted_tos_version,
blockedInboxOrChannels: profileModelPayload.blocked_inbox_or_channels,
email: profileModelPayload.email,
fiscalCode,
isInboxEnabled: profileModelPayload.is_inbox_enabled,
isWebhookEnabled: profileModelPayload.is_webhook_enabled,
preferredLanguages: profileModelPayload.preferred_languages
};
const errorOrProfile = await profileModel.create(profile, profile.fiscalCode);
const errorOrProfileAsPublicExtendedProfile = errorOrProfile.map(
toExtendedProfile
);
if (isRight(errorOrProfileAsPublicExtendedProfile)) {
return ResponseSuccessJson(errorOrProfileAsPublicExtendedProfile.value);
} else {
return ResponseErrorQuery(
"Error while creating a new profile",
errorOrProfileAsPublicExtendedProfile.value
);
}
}
createdService =>
ResponseSuccessJson(retrievedServiceToPublic(createdService))
);
return new Promise(resolve => {
const info: IResponseInfo = {
status: "OK"
};
resolve(ResponseSuccessJson(info));
});
};
p => ResponseSuccessJson(toExtendedProfile(p))
);