224 lines
6.1 KiB
JSON
224 lines
6.1 KiB
JSON
{
|
|
"name": "Sales Data Import & Validation",
|
|
"nodes": [
|
|
{
|
|
"parameters": {
|
|
"httpMethod": "POST",
|
|
"path": "calculate-commissions",
|
|
"responseMode": "responseNode",
|
|
"options": {
|
|
"rawBody": false
|
|
}
|
|
},
|
|
"id": "Webhook-Node-1",
|
|
"name": "Webhook",
|
|
"type": "n8n-nodes-base.webhook",
|
|
"typeVersion": 1,
|
|
"position": [
|
|
100,
|
|
300
|
|
]
|
|
},
|
|
{
|
|
"parameters": {
|
|
"conditions": {
|
|
"string": [
|
|
{
|
|
"value1": "={{ $node[\"Webhook\"].json[\"headers\"][\"x-forwarded-uri\"] || \"\" }}",
|
|
"operation": "contains",
|
|
"value2": "webhook-test"
|
|
}
|
|
]
|
|
}
|
|
},
|
|
"id": "If-Node-1",
|
|
"name": "Is Test/Dev Mode?",
|
|
"type": "n8n-nodes-base.if",
|
|
"typeVersion": 1,
|
|
"position": [
|
|
300,
|
|
300
|
|
]
|
|
},
|
|
{
|
|
"parameters": {
|
|
"values": {
|
|
"string": [
|
|
{
|
|
"name": "appUrl",
|
|
"value": "https://special-hotel-dev.gaboggamer.online"
|
|
},
|
|
{
|
|
"name": "signature",
|
|
"value": "qUHuPqPjA65psdtwQU7zgp/DVkvd1xXk2WP/vzbnEdc="
|
|
}
|
|
]
|
|
},
|
|
"options": {}
|
|
},
|
|
"id": "Set-Dev-Env",
|
|
"name": "Set Dev Environment",
|
|
"type": "n8n-nodes-base.set",
|
|
"typeVersion": 1,
|
|
"position": [
|
|
500,
|
|
200
|
|
]
|
|
},
|
|
{
|
|
"parameters": {
|
|
"values": {
|
|
"string": [
|
|
{
|
|
"name": "appUrl",
|
|
"value": "https://special-hotel.gaboggamer.online"
|
|
},
|
|
{
|
|
"name": "signature",
|
|
"value": "Ecjb2s33tHJppNBDJ/DxXEjHWKow8bNWmsQrk1sQKyQ="
|
|
}
|
|
]
|
|
},
|
|
"options": {}
|
|
},
|
|
"id": "Set-Prod-Env",
|
|
"name": "Set Prod Environment",
|
|
"type": "n8n-nodes-base.set",
|
|
"typeVersion": 1,
|
|
"position": [
|
|
500,
|
|
400
|
|
]
|
|
},
|
|
{
|
|
"parameters": {
|
|
"jsCode": "// Process individual sales records and run standard deviation / anomaly checks\n// Output format matches batch-save API schema\nconst webhookNode = $node[\"Webhook\"];\nconst body = webhookNode ? webhookNode.json.body : {};\nconst sales = body.sales || [];\nconst idempotencyKey = body.idempotencyKey;\nconst uploaderId = body.uploaderId;\nconst appUrl = items[0].json.appUrl;\nconst signature = items[0].json.signature;\n\n// We will simulate anomaly detection:\n// Sales records deviating abnormally from standard amounts are marked or adjusted\nconst processedSales = sales.map(sale => {\n const isAnomaly = sale.amount > 1000000; // Example threshold (>1M)\n return {\n ...sale,\n isAnomaly,\n flaggedReason: isAnomaly ? 'Sales amount exceeds normal threshold limits (>1M)' : null\n };\n});\n\nreturn [{\n json: {\n idempotencyKey,\n uploaderId,\n sales: processedSales,\n appUrl,\n signature\n }\n}];"
|
|
},
|
|
"id": "Code-Node-1",
|
|
"name": "Data Validation & Anomaly Checks",
|
|
"type": "n8n-nodes-base.code",
|
|
"typeVersion": 1,
|
|
"position": [
|
|
750,
|
|
300
|
|
]
|
|
},
|
|
{
|
|
"parameters": {
|
|
"method": "POST",
|
|
"url": "={{$node[\"Data Validation & Anomaly Checks\"].json[\"appUrl\"]}}/api/sales/batch-save",
|
|
"sendHeaders": true,
|
|
"headerParameters": {
|
|
"parameters": [
|
|
{
|
|
"name": "Content-Type",
|
|
"value": "application/json"
|
|
},
|
|
{
|
|
"name": "x-n8n-signature",
|
|
"value": "={{$node[\"Data Validation & Anomaly Checks\"].json[\"signature\"]}}"
|
|
}
|
|
]
|
|
},
|
|
"sendBody": true,
|
|
"specifyBody": "json",
|
|
"jsonBody": "={{ { idempotencyKey: $node[\"Data Validation & Anomaly Checks\"].json[\"idempotencyKey\"], uploaderId: $node[\"Data Validation & Anomaly Checks\"].json[\"uploaderId\"], sales: $node[\"Data Validation & Anomaly Checks\"].json[\"sales\"] } }}",
|
|
"options": {}
|
|
},
|
|
"id": "Http-Request-1",
|
|
"name": "Callback batch-save",
|
|
"type": "n8n-nodes-base.httpRequest",
|
|
"typeVersion": 4,
|
|
"position": [
|
|
950,
|
|
300
|
|
]
|
|
},
|
|
{
|
|
"parameters": {
|
|
"respondWith": "json",
|
|
"responseBody": "={\n \"success\": true,\n \"code\": \"IMPORT_ACCEPTED\",\n \"metadata\": {\n \"idempotencyKey\": \"{{$node[\"Webhook\"].json[\"body\"][\"idempotencyKey\"]}}\",\n \"status\": \"PROCESSING\"\n }\n}"
|
|
},
|
|
"id": "Respond-To-Webhook",
|
|
"name": "Respond to Webhook",
|
|
"type": "n8n-nodes-base.respondToWebhook",
|
|
"typeVersion": 1,
|
|
"position": [
|
|
450,
|
|
550
|
|
]
|
|
}
|
|
],
|
|
"connections": {
|
|
"Webhook": {
|
|
"main": [
|
|
[
|
|
{
|
|
"node": "Is Test/Dev Mode?",
|
|
"type": "main",
|
|
"index": 0
|
|
},
|
|
{
|
|
"node": "Respond to Webhook",
|
|
"type": "main",
|
|
"index": 0
|
|
}
|
|
]
|
|
]
|
|
},
|
|
"Is Test/Dev Mode?": {
|
|
"main": [
|
|
[
|
|
{
|
|
"node": "Set Dev Environment",
|
|
"type": "main",
|
|
"index": 0
|
|
}
|
|
],
|
|
[
|
|
{
|
|
"node": "Set Prod Environment",
|
|
"type": "main",
|
|
"index": 0
|
|
}
|
|
]
|
|
]
|
|
},
|
|
"Set Dev Environment": {
|
|
"main": [
|
|
[
|
|
{
|
|
"node": "Data Validation & Anomaly Checks",
|
|
"type": "main",
|
|
"index": 0
|
|
}
|
|
]
|
|
]
|
|
},
|
|
"Set Prod Environment": {
|
|
"main": [
|
|
[
|
|
{
|
|
"node": "Data Validation & Anomaly Checks",
|
|
"type": "main",
|
|
"index": 0
|
|
}
|
|
]
|
|
]
|
|
},
|
|
"Data Validation & Anomaly Checks": {
|
|
"main": [
|
|
[
|
|
{
|
|
"node": "Callback batch-save",
|
|
"type": "main",
|
|
"index": 0
|
|
}
|
|
]
|
|
]
|
|
}
|
|
},
|
|
"active": true,
|
|
"settings": {},
|
|
"id": "sales-import-workflow"
|
|
}
|