Exact Online Premium - fixed handling plaintext payloads (#3637)

This commit is contained in:
Jos Smits 2024-09-03 14:59:17 +02:00 коммит произвёл GitHub
Родитель fe0f17eaf0
Коммит b987d1e05d
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
3 изменённых файлов: 17 добавлений и 8 удалений

Просмотреть файл

@ -519,6 +519,7 @@
}
},
"summary": "Get values",
"consumes": [ "text/plain", "application/json" ],
"description": "This loads the values from the trigger's Payload field in a format of choice.",
"operationId": "GetValues",
"parameters": [

Просмотреть файл

@ -29,8 +29,8 @@
"iconBrandColor": "#ff0000",
"scriptOperations": [],
"capabilities": [],
"policyTemplateInstances": [],
"publisher": "Exact Cloud Development Benelux",
"stackOwner": "Exact Cloud Development Benelux",
"policyTemplateInstances": []
"stackOwner": "Exact Cloud Development Benelux"
}
}

Просмотреть файл

@ -1,4 +1,4 @@
using Newtonsoft.Json;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Net;
using System.Net.Http.Headers;
@ -65,9 +65,17 @@ public class Script : ScriptBase
if (string.IsNullOrWhiteSpace(jsonText))
return ErrorMessage("Empty payload");
var obj = jsonText.AsJObject();
var token = JToken.Parse(jsonText);
if (token == null)
return ErrorMessage("Unable to read payload");
if (token.Type == JTokenType.String)
token = JToken.Parse(token.Value<string>());
if (token.Type != JTokenType.Object)
return ErrorMessage("Payload is not a valid json object");
var obj = token as JObject;
if (obj == null)
return ErrorMessage("Unable to parse payload");
return ErrorMessage("Unable to read json from payload");
if (string.IsNullOrWhiteSpace(key))
{
@ -93,7 +101,7 @@ public class Script : ScriptBase
};
if (string.IsNullOrWhiteSpace(emptyJson))
return ErrorMessage("Invalid value type", key);
return ErrorMessage($"Invalid value type: {key}");
var changes = obj.Property("Changes");
if (changes == null || changes.Value.Type != JTokenType.Array || changes.Value is not JArray)
@ -281,7 +289,7 @@ public class Script : ScriptBase
private static HttpResponseMessage CreateJsonResponse(JToken? token, HttpStatusCode statusCode = HttpStatusCode.OK)
=> CreateJsonResponse(token.GetString(), statusCode);
private static HttpResponseMessage ErrorMessage(string errorMessage, HttpStatusCode statusCode = HttpStatusCode.OK) => CreateJsonResponse($"{{\"error\":\"{errorMessage}\"}}", statusCode);
private static HttpResponseMessage ErrorMessage(string errorMessage, HttpStatusCode statusCode = HttpStatusCode.BadRequest) => CreateJsonResponse($"{{\"error\":\"{errorMessage}\"}}", statusCode);
private static HttpResponseMessage ErrorMessage(string errorMessage, string incomingMessage) => CreateJsonResponse($"{{\"error\":\"{errorMessage}\",\"message\":\"{incomingMessage}\"}}", HttpStatusCode.OK);
@ -503,7 +511,7 @@ public static class SchemaHelper
"sPurchaseVATCodeDescription","iQuotationMarkupType","bRecepientOfCommissions","sRemarks","iReminderFlowCategory","gReseller","sResellerCode","sResellerName",
"sSalesCurrency","sSalesCurrencyDescription","sSalesVATCode","sSalesVATCodeDescription","gSBICode","sSbiCodeDescription","gSbiCodeSector","gSbiCodeSubSector",
"sSearchCode","iSecurityLevel","iSendPurchaseOrderMethod","sSepaDDCreditorIdentifier","bSeparateInvPerProject","bSeparateInvPerSubscription","iShippingLeadDays",
"gShippingMethod","sShippingMethodCode","sShippingMethodDescription","iSource","dStartDate","sState","sStateDisplayValue","sStateName","sStatus","dStatusSince",/
"gShippingMethod","sShippingMethodCode","sShippingMethodDescription","iSource","dStartDate","sState","sStateDisplayValue","sStateName","sStatus","dStatusSince",
"sTaxReferenceNumber","sTradeName","sType","bUseTimeSpecification","sVATLiability","sVATNumber","sVatSystem","sWebsite","sWithholdingTaxDescription","sWithholdingTaxKey"
};