# cmp-sdk

> consentmanager react native sdk

Latest version **2.7.0** (published 2024-09-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install cmp-sdk
pnpm add cmp-sdk
yarn add cmp-sdk
bun add cmp-sdk
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.7.0 |
| Published | 2024-09-06 |
| First published | 2024-07-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 99.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Skander Ben Abdelmalak |
| Maintainers | skanderphilipp |
| Keywords | react-native, ios, android |

## Links

- npm: https://www.npmjs.com/package/cmp-sdk
- Repository: https://github.com/iubenda/cm-sdk-react-native
- Homepage: https://github.com/iubenda/cm-sdk-react-native#readme
- Issues: https://github.com/iubenda/cm-sdk-react-native/issues
- npm.io page: https://npm.io/package/cmp-sdk

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 2.7.0 (latest) — 2024-09-06
- 2.6.2 — 2024-09-02
- 2.6.1 — 2024-07-29
- 2.6.0 — 2024-07-28

## README

# CMP SDK for React Native

CMP SDK is a React Native library that facilitates the management of user consent for data processing and storage. It is designed to help developers comply with various data protection regulations.

## Installation

```sh
npm install cmp-sdk
```

## Getting Started

### Linking (React Native 0.59 and below)

If you are using React Native 0.59 or below, you need to link the native modules manually:

```bash
react-native link cmp-sdk
```

## Usage

Import the `Consentmanager` from the `cmp-sdk` package in your code:

```jsx
import { Consentmanager } from 'cmp-sdk';
```

### Initializing the SDK

You can initialize the CMP SDK using either the direct configuration or a config object:

- **Direct Initialization:**
  ```jsx
  Consentmanager.createInstance('yourID', 'yourDomain', 'yourAppName', 'yourLanguage');
  ```

- **Initialization using Config Object:**
  ```jsx
  Consentmanager.createInstanceByConfig(yourConfigObject);
  ```

  ```jsx
import { CmpConfig, CmpScreenConfig, CmpIosPresentationStyle } from 'cmp-sdk/types';

const config = new CmpConfig({
  id: 'yourID',
  domain: 'yourDomain',
  appName: 'yourAppName',
  language: 'yourLanguage',
  screenConfig: CmpScreenConfig.FullScreen,
  iosPresentationStyle: CmpIosPresentationStyle.FullScreen,
});

Consentmanager.createInstanceByConfig(config);
  ```

### Managing Consent Layer

To manage the consent layer:

- **Open Consent Layer:**
  ```jsx
  Consentmanager.openConsentlayer();
  ```

### Event Handling

Add event listeners to handle various consent-related events:

```jsx
const removeListeners = Consentmanager.addEventListeners({
  onOpen: () => console.log('Consent layer opened'),
  onClose: () => console.log('Consent layer closed'),
  onNotOpened: () => console.log('Consent layer not opened'),
  onError: (type, message) => console.log(`Error: ${type}, Message: ${message}`),
  onButtonClicked: (buttonType) => console.log(`Button clicked: ${buttonType}`),
  onGoogleConsentUpdated: (consentMap) => console.log(`Google consent updated: ${JSON.stringify(consentMap)}`),
});

```

Remember to remove the event listeners when they are no longer needed:

```jsx
removeListeners();
```

### Consent Queries

You can check for vendor and purpose consents:

- **Check Vendor Consent:**
  ```jsx
  Consentmanager.hasVendor('vendorID').then((hasConsent) => {
    console.log('Has vendor consent: ', hasConsent);
  });
  ```

- **Check Purpose Consent:**
  ```jsx
  Consentmanager.hasPurpose('purposeID').then((hasConsent) => {
    console.log('Has purpose consent: ', hasConsent);
  });
  ```

### Resetting Consent

To reset the current consent settings:

```jsx
Consentmanager.reset();
```

### Exporting Consent String

Export the current consent string:

```jsx
Consentmanager.exportCmpString().then((cmpString) => {
  console.log('CMP String: ', cmpString);
});
```

## Additional Methods

The CMP SDK provides various methods to retrieve or manage consent data, such as:

- `getAllVendors()`
- `getAllPurposes()`
- `getEnabledVendors()`
- `getEnabledPurposes()`
- `getDisabledVendors()`
- `getDisabledPurposes()`
- `getUSPrivacyString()`
- `getGoogleACString()`

Refer to the SDK documentation for detailed information on these methods.

---

Remember to replace placeholders like 'yourID', 'yourDomain', etc., with actual values relevant to the users of your SDK. You can also expand each section with more detailed examples if needed.

## Jest mocks
When running jest, you can pass our mock
```js
jest.mock('cmp-sdk', () =>
  require('cmp-sdk/jest/mock'),
);
```

## Contributing

See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.

## License

MIT

---

Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)

---

---
_Source: https://npm.io/package/cmp-sdk · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
