{
  "info": {
    "name": "myzrok-orchestration - Custom Domains",
    "description": "Custom domain API of myzrok-orchestration (`/billing-accounts/{billingAccountId}/custom-domains`).\n\nProvisioning is asynchronous: create/delete/retry/reissue answer **202 Accepted** and the worker does the zrok and zrok-orchestration calls in the background. Poll **Get Custom Domain** to follow `status`:\nPROVISIONING \u2192 PENDING_VALIDATION (add the `cnames` records to DNS) \u2192 DEPLOYING \u2192 ACTIVE. Alternative outcomes: CERT_FAILED (use Reissue Certificate), FAILED (use Retry, see `lastError`), DELETING \u2192 gone.\n\nAuth: run **Login** first. It sets the `MYZROK_SESSION` cookie that `ZrokAuthenticationInterceptor` requires, and the caller must own `{{billingAccountId}}`. Non-GET requests carry the `X-Requested-With: myzrok-extension` CSRF header.\n\n`{{baseUrl}}` = scheme + host + port + `/myzrok-orchestration/v1`.",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "variable": [
    {
      "key": "baseUrl",
      "value": "http://localhost:8106/myzrok-orchestration/v1"
    },
    {
      "key": "zrokEmail",
      "value": "you@example.com"
    },
    {
      "key": "zrokPassword",
      "value": ""
    },
    {
      "key": "billingAccountId",
      "value": ""
    },
    {
      "key": "customDomainId",
      "value": ""
    },
    {
      "key": "domainName",
      "value": "share.example.com"
    },
    {
      "key": "frontendName",
      "value": "acme"
    }
  ],
  "item": [
    {
      "name": "Login",
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "X-Requested-With",
            "value": "myzrok-extension"
          },
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/session/login"
        },
        "description": "Creates the browser session (sets the MYZROK_SESSION cookie) from zrok credentials.",
        "body": {
          "mode": "raw",
          "raw": "{\n  \"email\": \"{{zrokEmail}}\",\n  \"password\": \"{{zrokPassword}}\"\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        }
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "pm.test('logged in', () => pm.response.to.have.status(200));"
            ]
          }
        }
      ]
    },
    {
      "name": "Happy path",
      "item": [
        {
          "name": "Create Custom Domain",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "X-Requested-With",
                "value": "myzrok-extension"
              },
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{baseUrl}}/billing-accounts/{{billingAccountId}}/custom-domains"
            },
            "description": "Queues provisioning. 409 when the plan's custom domain limit is reached or the domain name is in use.",
            "body": {
              "mode": "raw",
              "raw": "{\n  \"domainName\": \"{{domainName}}\",\n  \"frontendName\": \"{{frontendName}}\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('202 Accepted', () => pm.response.to.have.status(202));",
                  "const body = pm.response.json();",
                  "pm.collectionVariables.set('customDomainId', body.id);",
                  "pm.test('queued for provisioning', () => pm.expect(body.status).to.eql('PROVISIONING'));"
                ]
              }
            }
          ]
        },
        {
          "name": "Get Custom Domain",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/billing-accounts/{{billingAccountId}}/custom-domains/{{customDomainId}}"
            },
            "description": "Current state. Once PENDING_VALIDATION, `cnames` lists the DNS records to create."
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('200 OK', () => pm.response.to.have.status(200));",
                  "const body = pm.response.json();",
                  "pm.test('no internals leak', () => ['zitiIdentityCfg','zitiIdentityId','frontendToken','namespaceToken','leaseOwner'].forEach(k => pm.expect(body).to.not.have.property(k)));",
                  "console.log('status', body.status, 'certificate', body.certificateStatus, 'cnames', JSON.stringify(body.cnames));"
                ]
              }
            }
          ]
        },
        {
          "name": "List Custom Domains",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/billing-accounts/{{billingAccountId}}/custom-domains"
            },
            "description": "All live custom domains of the billing account, oldest first."
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('200 OK', () => pm.response.to.have.status(200));"
                ]
              }
            }
          ]
        }
      ]
    },
    {
      "name": "Alternative flows",
      "item": [
        {
          "name": "Retry Failed Custom Domain",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "X-Requested-With",
                "value": "myzrok-extension"
              }
            ],
            "url": {
              "raw": "{{baseUrl}}/billing-accounts/{{billingAccountId}}/custom-domains/{{customDomainId}}/retry"
            },
            "description": "Resumes a FAILED domain from the step that failed. 409 in any other status."
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('202 or 409', () => pm.expect(pm.response.code).to.be.oneOf([202, 409]));"
                ]
              }
            }
          ]
        },
        {
          "name": "Reissue Certificate",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "X-Requested-With",
                "value": "myzrok-extension"
              }
            ],
            "url": {
              "raw": "{{baseUrl}}/billing-accounts/{{billingAccountId}}/custom-domains/{{customDomainId}}/reissue-cert"
            },
            "description": "For CERT_FAILED: reissues the certificate and restarts DNS validation. 409 in any other status."
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('202 or 409', () => pm.expect(pm.response.code).to.be.oneOf([202, 409]));"
                ]
              }
            }
          ]
        },
        {
          "name": "Create Custom Domain - Invalid Domain Name",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "X-Requested-With",
                "value": "myzrok-extension"
              },
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{baseUrl}}/billing-accounts/{{billingAccountId}}/custom-domains"
            },
            "description": "Rejected by validation with 400.",
            "body": {
              "mode": "raw",
              "raw": "{\n  \"domainName\": \"not a domain\",\n  \"frontendName\": \"{{frontendName}}\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('400 Bad Request', () => pm.response.to.have.status(400));"
                ]
              }
            }
          ]
        },
        {
          "name": "Create Custom Domain - Duplicate Name",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "X-Requested-With",
                "value": "myzrok-extension"
              },
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{baseUrl}}/billing-accounts/{{billingAccountId}}/custom-domains"
            },
            "description": "Run after Create: the same domain name is refused with 409 while the first one is live.",
            "body": {
              "mode": "raw",
              "raw": "{\n  \"domainName\": \"{{domainName}}\",\n  \"frontendName\": \"{{frontendName}}\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('409 Conflict', () => pm.response.to.have.status(409));"
                ]
              }
            }
          ]
        },
        {
          "name": "Get Custom Domain - Not Found",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/billing-accounts/{{billingAccountId}}/custom-domains/00000000-0000-0000-0000-000000000000"
            },
            "description": "Unknown id: 404."
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('404 Not Found', () => pm.response.to.have.status(404));"
                ]
              }
            }
          ]
        }
      ]
    },
    {
      "name": "Delete Custom Domain",
      "request": {
        "method": "DELETE",
        "header": [
          {
            "key": "X-Requested-With",
            "value": "myzrok-extension"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/billing-accounts/{{billingAccountId}}/custom-domains/{{customDomainId}}"
        },
        "description": "Queues teardown of everything the domain created (zrok grant, stack, mapping, namespace, frontend, identity). Idempotent."
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "pm.test('202 Accepted', () => pm.response.to.have.status(202));"
            ]
          }
        }
      ]
    }
  ]
}