{
  "info": {
    "name": "hub-control — Partner API (Registrasi)",
    "_postman_id": "c2d3e4f5-0000-4000-8000-partnerapi01",
    "description": "Koleksi untuk PARTNER: mendaftarkan tenant via HMAC.\n\nLangkah:\n1. Isi variable: base_url, api_key, api_secret (dari admin hub-control).\n2. Jalankan 'Register' — pre-request script membuat tanda tangan HMAC otomatis.\n\n'Cek Subdomain' = cek ketersediaan alamat {subdomain}.hub.xpanca.com sebelum Register (field 'subdomain', unik).",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "variable": [
    {
      "key": "base_url",
      "value": "http://localhost:3099"
    },
    {
      "key": "api_key",
      "value": ""
    },
    {
      "key": "api_secret",
      "value": ""
    }
  ],
  "item": [
    {
      "name": "Cek Subdomain",
      "event": [
        {
          "listen": "prerequest",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const key = pm.variables.get('api_key');",
              "const secret = pm.variables.get('api_secret');",
              "if(!key || !secret){ throw new Error('Isi dulu variable api_key & api_secret.'); }",
              "const ts = Math.floor(Date.now()/1000).toString();",
              "// PATH ditandatangani TANPA query string; body kosong",
              "const str = ts + '\\n' + 'GET' + '\\n' + '/api/public/check-subdomain' + '\\n' + '';",
              "const sig = CryptoJS.HmacSHA256(str, secret).toString(CryptoJS.enc.Hex);",
              "pm.request.headers.upsert({key:'X-Api-Key', value:key});",
              "pm.request.headers.upsert({key:'X-Timestamp', value:ts});",
              "pm.request.headers.upsert({key:'X-Signature', value:sig});"
            ]
          }
        }
      ],
      "request": {
        "method": "GET",
        "header": [],
        "url": {
          "raw": "{{base_url}}/api/public/check-subdomain?name=menjala",
          "host": [
            "{{base_url}}"
          ],
          "path": [
            "api",
            "public",
            "check-subdomain"
          ],
          "query": [
            {
              "key": "name",
              "value": "menjala"
            }
          ]
        }
      }
    },
    {
      "name": "Register",
      "event": [
        {
          "listen": "prerequest",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const key = pm.variables.get('api_key');",
              "const secret = pm.variables.get('api_secret');",
              "if(!key || !secret){ throw new Error('Isi dulu variable api_key & api_secret (Environment ATAU Collection → Variables → Current value → Save).'); }",
              "const ts = Math.floor(Date.now()/1000).toString();",
              "const path = '/api/public/register';",
              "const body = pm.request.body && pm.request.body.raw ? pm.request.body.raw : '';",
              "const str = ts + '\\n' + 'POST' + '\\n' + path + '\\n' + body;",
              "const sig = CryptoJS.HmacSHA256(str, secret).toString(CryptoJS.enc.Hex);",
              "pm.request.headers.upsert({key:'X-Api-Key', value:key});",
              "pm.request.headers.upsert({key:'X-Timestamp', value:ts});",
              "pm.request.headers.upsert({key:'X-Signature', value:sig});"
            ]
          }
        }
      ],
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"email\": \"owner@toko.com\",\n  \"business_name\": \"Toko Budi\",\n  \"phone\": \"08123456789\",\n  \"full_name\": \"Budi\",\n  \"business_field\": \"Retail\",\n  \"address\": \"Bandung\",\n  \"subdomain\": \"tokobudi\"\n}"
        },
        "url": {
          "raw": "{{base_url}}/api/public/register",
          "host": [
            "{{base_url}}"
          ],
          "path": [
            "api",
            "public",
            "register"
          ]
        }
      }
    }
  ]
}