# Config ID Refactor — Design

## Goal

Decouple the config lookup key from the NS API domain so one NS domain can have
multiple widget/SMS configurations (e.g. different queues, different SMS
numbers, different branding).

## Problem

Currently `domains.json` is keyed by the NS API domain (e.g. `pressone.net`),
which means one NS domain can only have one config. The domain key is used for
both the widget embed (`?domain=pressone.net`) and the webresponder lookup
(`AccountDomain`), conflating two different concepts.

## Solution

Replace the domain key with a free-format `id` of the form
`<api_domain>-<suffix>` (e.g. `pressone.net-sales`, `pressone.net-support`,
`pressone.net-sms`). All routes use `?id=` or body field `id` for lookup.
`api_domain` becomes an explicit field inside each config entry.

Nothing is in production so no backward compatibility is required.

## New `domains.json` schema

```json
{
  "pressone.net-sms": {
    "api_domain": "pressone.net",
    "user": "2000",
    "from_number": "19294873999",
    "message": "Our hours are Mon-Fri 9am-5pm. We are located at 123 Main St."
  },
  "pressone.net-sales": {
    "api_domain": "pressone.net",
    "queue": "9025@pressone.net",
    "branding": {
      "button_text": "Talk to Sales",
      "button_color": "#1a73e8",
      "company_name": "PressOne",
      "logo_url": ""
    }
  },
  "pressone.net-support": {
    "api_domain": "pressone.net",
    "queue": "9030@pressone.net",
    "branding": {
      "button_text": "Get Support",
      "button_color": "#e8341a",
      "company_name": "PressOne",
      "logo_url": ""
    }
  }
}
```

## Route changes

| Route | Old param | New param |
|-------|-----------|-----------|
| `GET /widget.js` | `?domain=pressone.net` | `?id=pressone.net-sales` |
| `POST /click-to-call` | body `{"domain": ...}` | body `{"id": ...}` |
| `GET/POST /webresponder` | looks up by `AccountDomain` header | looks up by `?id=` query param in URL |
| `POST /update-domain` | form field `domain` | form field `id` |

All routes look up config by the `id` key directly in `domains.json`. The
`AccountDomain` param sent by NS is no longer used for lookup — instead the NS
portal is configured to call the webresponder URL with `?id=pressone.net-sms`.

## Validation

`_DOMAIN_RE` already allows hyphens and dots so `pressone.net-sales` passes
validation without any regex change.

## Widget embed

```html
<!-- Sales queue -->
<script src="https://ns-scripts.pressone.net/widget.js?id=pressone.net-sales"></script>

<!-- Support queue -->
<script src="https://ns-scripts.pressone.net/widget.js?id=pressone.net-support"></script>
```

## NS webresponder URL

Configure in NS portal:
```
https://ns-scripts.pressone.net/webresponder?id=pressone.net-sms
```

## Zoho Form change

Rename one field: `domain` → `id`. All other fields and the webhook URL stay
the same.

## Testing

Update all existing tests to use `id` instead of `domain`. Add tests for the
new webresponder `?id=` lookup. No new test files needed.
