Once `cmp.js` has loaded, the API lives on `window.LightningCMP`. Before it loads,
use the queue-safe `lightning('method', args)` dispatcher (see
[Quickstart](/quickstart/#lightning-vs-lightningcmp)).

## Methods

| Method               | Signature                             | Purpose                                                                                                         |
| -------------------- | ------------------------------------- | --------------------------------------------------------------------------------------------------------------- |
| `init`               | `init(config)`                        | Boot the CMP. See the [Config reference](/api/config-reference/). Idempotent — calling twice is a no-op.        |
| `openPreferences`    | `(): void`                            | Open the preferences modal, e.g. from a footer "Cookie settings" link.                                          |
| `getConsent`         | `(): ConsentState \| null`            | Current consent state, or `null` before init.                                                                   |
| `onConsentChange`    | `(fn) => () => void`                  | Subscribe to changes; returns an unsubscribe function.                                                          |
| `acceptAll`          | `(): void`                            | Grant all categories.                                                                                           |
| `rejectAll`          | `(): void`                            | Withhold all optional categories.                                                                               |
| `reset`              | `(): void`                            | Clear the stored decision and re-show the banner.                                                               |
| `renderCookieList`   | `(target, options?) => Promise<void>` | Paint the categorised cookie inventory into a page element. See [Cookie declaration](/api/cookie-declaration/). |
| `debug`              | `(): DebugReport \| null`             | Console snapshot: consent, Consent Mode signals, gated-script table.                                            |
| `audit`              | `(): Promise<AuditReport \| null>`    | Behavioural self-audit of cookies/requests actually observed.                                                   |
| `defineBridge`       | `(id, factory) => void`               | Register a [custom bridge](/integrations/custom-bridges/).                                                      |
| `version`            | `string`                              | The build version.                                                                                              |
| `BRIDGE_API_VERSION` | `number`                              | Custom-bridge contract version.                                                                                 |

## Example

```js
// React to consent from app code.
const off = LightningCMP.onConsentChange((state) => {
  if (state.choices.statistics) startAnalytics();
});

// Later, from a settings screen:
LightningCMP.openPreferences();
```

:::note[More detail coming]
Per-method detail and return types are being migrated from `docs/INSTALL.md` §
_“The JavaScript API.”_ See also [Verifying](/guides/verifying/) for `debug()` and
`audit()`.
:::