{
	"info": {
		"_postman_id": "e0b8ca78-c5fe-431e-ab34-4205e87f47fe",
		"name": "PDMX - Mobile Identity API v1",
		"description": "_**Círculo de Crédito**_ - Mobile Identity v1 API postman collection.",
		"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
		"_exporter_id": "21352240"
	},
	"item": [
		{
			"name": "New Aggregation",
			"event": [
				{
					"listen": "prerequest",
					"script": {
						"exec": [
							"var uuidGenerator = require('uuid');",
							"var uuid = uuidGenerator.v4();",
							"pm.collectionVariables.set(\"uuid\", uuid);",
							"",
							"function doHttpSig() {",
							"    var navigator = {}; ",
							"    var window = {};",
							"",
							"    eval(pm.environment.get(\"jsrsasign-js\"));",
							"    var privateKey = pm.environment.get(\"private-key\").trim().replace(/[\\x00-\\x1F\\x7F-\\x9F]/g, \"\");",
							"    ",
							"    var strBody = pm.variables.replaceIn(pm.request.body.raw)",
							"    ",
							"    console.log(\"[DEBUG ] requestId: \" + uuid);",
							"    console.log(\"[DEBUG ] private-key: \" + privateKey);",
							"    console.log(\"[DEBUG ] request-body: \" + strBody);",
							"",
							"    var sig = new KJUR.crypto.Signature({\"alg\": \"SHA256withECDSA\", \"prov\": \"cryptojs/jsrsa\"});",
							"    sig.init({d: privateKey, curve: \"secp384r1\"});",
							"    sig.updateString(strBody);",
							"",
							"    var signature = sig.sign();",
							"",
							"    console.log(\"[DEBUG] Signature ECDSA: \" + signature);",
							"    pm.collectionVariables.set(\"x-signature\", signature);",
							"    pm.request.body.update(strBody);",
							"}",
							"",
							"if (!pm.environment.has(\"jsrsasign-js\") || pm.environment.get(\"jsrsasign-js\")===\"\") {",
							"",
							"    console.log(\"La biblioteca jsrasign aún no se ha descargado. Descargando ahora.\");",
							"    pm.sendRequest({",
							"        url: \"https://cdnjs.cloudflare.com/ajax/libs/jsrsasign/8.0.12/jsrsasign-all-min.js\",",
							"        method: \"GET\",",
							"        body: {}",
							"    }, function (err, res) {",
							"        pm.environment.set(\"jsrsasign-js\", res.text());",
							"        doHttpSig();",
							"    });",
							"",
							"} else {",
							"    doHttpSig();",
							"}",
							"",
							"function generateUUIDv1() {",
							"    var time = new Date().getTime();",
							"    var uuid = 'xxxxxxxx-xxxx-1xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {",
							"        const r = (time + Math.random() * 16) % 16 | 0;",
							"        time = Math.floor(time/16);",
							"        return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16);",
							"    });",
							"",
							"    var staticNode = \"a38b-00b0d068b224\";",
							"",
							"    return (uuid.slice(0, -17) + staticNode);",
							"}"
						],
						"type": "text/javascript",
						"packages": {}
					}
				}
			],
			"request": {
				"method": "POST",
				"header": [
					{
						"key": "username",
						"value": "{{username}}",
						"type": "text"
					},
					{
						"key": "password",
						"value": "{{password}}",
						"type": "text"
					},
					{
						"key": "x-api-key",
						"value": "{{x-api-key}}",
						"type": "text"
					},
					{
						"key": "x-signature",
						"value": "{{x-signature}}",
						"type": "text"
					},
					{
						"key": "Content-Type",
						"value": "application/json",
						"type": "text"
					}
				],
				"body": {
					"mode": "raw",
					"raw": "{\n  \"requestId\": \"{{uuid}}\",\n  \"subscriptionId\": \"\",\n  \"customer\": {\n    \"phoneNumber\": \"\",\n    \"termsAcceptedAt\": \"\"\n  },\n  \"settings\": {\n    \"phone\": true,\n    \"socialNetworks\": true\n  }\n}",
					"options": {
						"raw": {
							"language": "json"
						}
					}
				},
				"url": {
					"raw": "{{url}}/v1/telco/aggregations",
					"host": [
						"{{url}}"
					],
					"path": [
						"v1",
						"telco",
						"aggregations"
					]
				}
			},
			"response": []
		},
		{
			"name": "Get Aggregation",
			"event": [
				{
					"listen": "prerequest",
					"script": {
						"exec": [
							"function doHttpSig() {",
							"    var navigator = {};",
							"    var window = {};",
							"",
							"    eval(pm.environment.get(\"jsrsasign-js\"));",
							"    var privateKey = pm.environment.get(\"private-key\").trim().replace(/[\\x00-\\x1F\\x7F-\\x9F]/g, \"\");",
							"",
							"    var pathUrl = pm.request.url.getPath();",
							"",
							"    console.log(\"[DEBUG] private-key: \" + privateKey);",
							"    console.log(\"[DEBUG] request-url: \" + pathUrl);",
							"",
							"    var sig = new KJUR.crypto.Signature({\"alg\": \"SHA256withECDSA\", \"prov\": \"cryptojs/jsrsa\"});",
							"    sig.init({d: privateKey, curve: \"secp384r1\"});",
							"    sig.updateString(pathUrl);",
							"",
							"    var signature = sig.sign();",
							"",
							"    console.log(\"[DEBUG] Signature ECDSA: \" + signature);",
							"    pm.collectionVariables.set(\"x-signature\", signature);",
							"}",
							"",
							"if (!pm.environment.has(\"jsrsasign-js\") || pm.environment.get(\"jsrsasign-js\")===\"\") {",
							"",
							"    console.log(\"La biblioteca jsrasign aún no se ha descargado. Descargando ahora.\");",
							"    pm.sendRequest({",
							"        url: \"https://cdnjs.cloudflare.com/ajax/libs/jsrsasign/8.0.12/jsrsasign-all-min.js\",",
							"        method: \"GET\",",
							"        body: {}",
							"    }, function (err, res) {",
							"        pm.environment.set(\"jsrsasign-js\", res.text());",
							"        doHttpSig();",
							"    });",
							"",
							"} else {",
							"    doHttpSig();",
							"}"
						],
						"type": "text/javascript",
						"packages": {}
					}
				}
			],
			"request": {
				"method": "GET",
				"header": [
					{
						"key": "username",
						"value": "{{username}}",
						"type": "text"
					},
					{
						"key": "password",
						"value": "{{password}}",
						"type": "text"
					},
					{
						"key": "x-api-key",
						"value": "{{x-api-key}}",
						"type": "text"
					},
					{
						"key": "x-signature",
						"value": "{{x-signature}}",
						"type": "text"
					}
				],
				"url": {
					"raw": "{{url}}/v1/telco/aggregations/{id}",
					"host": [
						"{{url}}"
					],
					"path": [
						"v1",
						"telco",
						"aggregations",
						"{id}"
					]
				}
			},
			"response": []
		}
	],
	"event": [
		{
			"listen": "prerequest",
			"script": {
				"type": "text/javascript",
				"exec": [
					""
				]
			}
		},
		{
			"listen": "test",
			"script": {
				"type": "text/javascript",
				"exec": [
					""
				]
			}
		}
	],
	"variable": [
		{
			"key": "x-signature",
			"value": "",
			"type": "string"
		},
		{
			"key": "uuid",
			"value": "",
			"type": "string"
		},
		{
			"key": "date-time",
			"value": "",
			"type": "string"
		},
		{
			"key": "url",
			"value": "",
			"type": "string"
		}
	]
}