# Setup

#### Installation

```bash
npm install @didomi/vega-sdk
```

#### Peer Dependencies

This SDK requires the following peer dependencies:

* `react` (>=18.0.0 <=18.2.0)
* `react-dom` (>=18.0.0 <=18.2.0)
* `react-native` (^0.72.0)
* `@amazon-devices/react-native-kepler` (^2.0.0)
* `@amazon-devices/webview`

> **Note:** For **WebView support**, update your app’s `manifest.toml` file to include the required Vega services.\
> Please refer to <https://developer.amazon.com/docs/vega/0.21/set-up-webview.html>

### Basic Integration

```tsx
import { DidomiSDK, DidomiSDKAPI } from '@didomi/vega-sdk';
import React, { useRef } from 'react';

const MyApp = () => {
  const didomiRef = useRef<DidomiSDKAPI>(null);

  return (
    <DidomiSDK
      noticeId="YOUR_NOTICE_ID"
      didomiPublicApiKey="YOUR_PUBLIC_API_KEY"
      ref={didomiRef}
      onReady={() => console.log('Didomi SDK is ready')}
      onConsentChanged={(consent) => console.log('Consent changed:', consent)}
    >
      {/* Your app content */}
      <YourApp />
    </DidomiSDK>
  );
};
```

***

### Programmatic Usage

All SDK functionality is exposed through the component `ref`:

```tsx
const didomiSDK = didomiRef.current;

// Display UI
didomiSDK?.notice.show();                  // Show consent notice
didomiSDK?.preferences.show('purposes');   // Show preferences dialog, the parameter is optional, and "vendors" can also be set to display the associated layer.

// Query SDK state
const isConsentRequired = await didomiSDK?.isConsentRequired();

// Manage user consent
const userStatus = await didomiSDK?.getCurrentUserStatus();
await didomiSDK?.setUserAgreeToAll();
await didomiSDK?.setCurrentUserStatus({
  purposes: { /* purpose status */ },
  vendors: { /* vendor status */ },
});
```

***

### API Reference

#### Component Props

| Prop                 | Type                     | Description                                                                      |
| -------------------- | ------------------------ | -------------------------------------------------------------------------------- |
| `noticeId`           | string                   | ID of the consent notice to display                                              |
| `didomiPublicApiKey` | string                   | Your Didomi **public API key**                                                   |
| `sdkPath`            | string                   | (Optional) Path to the Didomi SDK, defaults to `https://sdk.privacy-center.org/` |
| `onReady`            | `() => void`             | Fired when the SDK is initialized and ready.                                     |
| `onConsentChanged`   | `(consent: any) => void` | Fired whenever the user’s consent status changes.                                |

Other events are available as props, please refer to [Events](/cmp/mobile-sdk/vega-os/reference/events.md) for more details.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developers.didomi.io/cmp/mobile-sdk/vega-os/setup.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
