{
	"info": {
		"_postman_id": "e2e28f53-9e9f-4208-a7f0-7617e1b6c47d",
		"name": "Fivaldi Customer API",
		"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
	},
	"item": [
		{
			"name": "ping",
			"request": {
				"method": "GET",
				"header": [
					{
						"key": "Content-Type",
						"name": "Content-Type",
						"type": "text",
						"value": "application/json"
					}
				],
				"url": {
					"raw": "https://api.fivaldi.net/customer/api/ping",
					"protocol": "https",
					"host": [
						"api",
						"fivaldi",
						"net"
					],
					"path": [
						"customer",
						"api",
						"ping"
					]
				}
			},
			"response": []
		}
	],
	"event": [
		{
			"listen": "prerequest",
			"script": {
				"type": "text/javascript",
				"exec": [
					"const LF = '\\u000a';",
					"",
					"pm.request.headers.add({key: 'X-Fivaldi-Partner', value: pm.variables.get('partnerId')});",
					"",
					"let bodyMD5 = '';",
					"let contentType = '';",
					"",
					"if (request.data.length > 0) {",
					"    bodyMD5 = CryptoJS.MD5(request.data);",
					"    contentType = request.headers['content-type'];",
					"}",
					"",
					"let time = Math.floor(new Date().getTime() / 1000).toString();",
					"pm.request.headers.add({key: 'X-Fivaldi-Timestamp', value: time});",
					"",
					"let stringToSign = request.method + LF +",
					"                bodyMD5 + LF +",
					"                contentType + LF;",
					"                ",
					"let headers = pm.request.headers.all();",
					"",
					"headers.sort(function (a, b) {",
					"    return a.key.toLowerCase().localeCompare(b.key.toLowerCase());",
					"}).forEach(function(header) {",
					"    if (header.key.startsWith('X-Fivaldi')) {",
					"        let key = header.key.trim().toLowerCase();",
					"        let value = header.value;",
					"        ",
					"        if (typeof value === 'string') {",
					"            value = value.trim();",
					"        }",
					"        ",
					"        stringToSign += key + ':' + value + LF;",
					"    }",
					"});",
					"",
					"let url = request.url.replace('http://', '').replace('https://', '');",
					"let path = '';",
					"let queryStr = '';",
					"",
					"if (url.includes('?')) {",
					"    path = url.substring(url.indexOf('/'), url.indexOf('?'));",
					"    queryStr = LF + encodeURI(url.substring(url.indexOf('?') +1));",
					"} else {",
					"    path = url.substring(url.indexOf('/'));",
					"}",
					"",
					"stringToSign += path + queryStr;",
					"console.log(stringToSign);",
					"",
					"stringToSign = CryptoJS.enc.Utf8.parse(stringToSign);",
					"let key = CryptoJS.enc.Utf8.parse(pm.variables.get('partnerSecret'));",
					"",
					"let hash = CryptoJS.HmacSHA256(stringToSign, key);",
					"let signature = 'Fivaldi ' + CryptoJS.enc.Base64.stringify(hash);",
					"pm.request.headers.add({key: 'Authorization', value: signature});"
				]
			}
		},
		{
			"listen": "test",
			"script": {
				"type": "text/javascript",
				"exec": [
					""
				]
			}
		}
	],
	"variable": [
		{
			"key": "partnerId",
			"value": ""
		},
		{
			"key": "partnerSecret",
			"value": ""
		}
	]
}