@didomi/vega-sdk

中文文档
0.3.2发布于 2026/11/05MITTypeScriptCommonJS近 30 天下载 4406

Didomi SDK for Vega TV platform

原始使用文档
文档目录12 节
  1. Features
  2. Installation
  3. Peer Dependencies
  4. Usage
  5. Basic Integration
  6. Programmatically Interacting with the SDK
  7. API Reference
  8. Component Props
  9. Methods
  10. Events
  11. Implementation Example
  12. License

Didomi Vega SDK

A Vega SDK for integrating Didomi's Consent Management Platform (CMP) with Amazon's Vega platform. This SDK enables applications to manage user consent for data collection and processing in compliance with privacy regulations.

Features

  • Display consent notices and preference dialogs
  • Collect and manage user consent choices
  • Synchronize consent data with Didomi servers
  • Support for various privacy regulations (GDPR, CCPA, etc.)
  • Comprehensive event handling for user interactions

Installation

npm install @didomi/vega-sdk

Peer Dependencies

This SDK has 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-vega (^2.0.0)
  • @amazon-devices/webview

For WebView: Update your app's manifest.toml file to include required services

Usage

Basic Integration

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 application content */}
      <YourApp />
    </DidomiSDK>
  );
};

Programmatically Interacting with the SDK

After integrating the SDK, you can programmatically access its functionality through the ref:

// All SDK methods are accessible through the ref
const didomiSDK = didomiRef.current;

// Display UI elements
didomiSDK?.notice.show(); // Show consent notice
didomiSDK?.preferences.show('purposes'); // Show preferences UI

// 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

The DidomiSDK accepts the following required props:

PropTypeDescription
noticeIdstringID of the consent notice to display
didomiPublicApiKeystringYour Didomi public API key
sdkPathstring(Optional) Path to the Didomi SDK, defaults to 'https://sdk.privacy-center.org/'

Methods

The SDK exposes methods through a ref:

Promise-returning methods reject with an Error when the bridge or Web SDK call fails, when no response arrives within 30 seconds, or when the WebView reloads, fails, is reconfigured, or unmounts. Handle these rejections with try/catch.

Dependent-resource load events and errors do not cancel unrelated SDK calls. For Vega load events without frame metadata, cancellation requires a URL matching the configured page or the document identified by didomi.ready. Events with unknown URLs rely on the request timeout. WebView errors are still forwarded to onError.

syncUser() waits for the Web SDK synchronization to finish and preserves its statusApplied and syncError values. Its syncAcknowledged() callback belongs to that specific result and returns the underlying Web SDK callback's boolean result. Each attempt is forwarded independently, including retries after errors; the Web SDK handles duplicate events and normally returns false after the first acknowledgement. This boolean does not confirm HTTP delivery: the Web SDK sends the event asynchronously.

Results with statusApplied: false retain no WebView callback and their acknowledgement returns false. Each WebView retains at most 100 completed results that applied a status, evicting the oldest retained sync calls when that limit is reached. Acknowledging an evicted result, or one from a previous WebView page after a reload or reconfiguration, rejects with an Error.

MethodDescriptionParametersReturns
notice.show()Shows the consent noticeNonevoid
notice.hide()Hides the consent notice if visibleNonevoid
notice.isVisible()Checks if the notice is visibleNonePromise<boolean>
preferences.show(type)Shows the preferences UItype: 'information' | 'purposes' | 'vendor'void
preferences.hide()Closes the preferences dialog if openNonevoid
preferences.isVisible()Checks if the preferences dialog is openNonePromise<boolean>
reset()Resets the consent dataNonevoid

User Status

MethodDescriptionParametersReturns
getCurrentUserStatus()Gets detailed user consent statusNonePromise<CurrentUserStatus>
getUserStatus()Gets user consent statusNonePromise<any>
getPurposes()Gets available purposesNonePromise<any>
getVendors()Gets available vendorsNonePromise<any>

User Configuration

MethodDescriptionParametersReturns
setUser(config)Sets user informationconfig: UserConfigurationPromise<void>
clearUser()Clears user dataNonePromise<void>
setUserAgreeToAll()Sets consent to agree to allNonePromise<void>
setUserDisagreeToAll()Sets consent to disagree to allNonePromise<void>
setCurrentUserStatus(params)Updates user consent statusparams: SetUserStatusParamsPromise<boolean>
syncUser()Synchronizes user consent with serverNonePromise<SyncReadyEvent>
MethodDescriptionParametersReturns
isConsentRequired()Checks if consent is requiredNonePromise<boolean>
isUserConsentStatusPartial()Checks if user consent is partialNonePromise<boolean>
shouldConsentBeCollected()Checks if consent should be collectedNonePromise<boolean>
isRegulationApplied(name)Checks if a regulation appliesname: stringPromise<boolean>
getRequiredPurposeIds()Gets required purpose IDsNonePromise<string[]>
getRequiredVendorIds()Gets required vendor IDsNonePromise<string[]>

Events

The SDK provides callbacks for various events:

Ready Events

EventDescriptionCallback Parameter
onReadyCalled when the SDK is readyNone
EventDescriptionCallback Parameter
onConsentChangedCalled when user consent changesconsent: User consent data

UI Events

EventDescriptionCallback Parameter
onNoticeShownCalled when notice is shownNone
onNoticeHiddenCalled when notice is hiddenNone
onPreferencesShownCalled when preferences UI is shownNone
onPreferencesHiddenCalled when preferences UI is hiddenNone

User Interaction Events

EventDescriptionCallback Parameter
onNoticeBackdropclickCalled when notice backdrop is clickedNone
onNoticeClickAgreeCalled when user clicks agree on noticeNone
onNoticeClickDisagreeCalled when user clicks disagree on noticeNone
onNoticeClickMoreInfoCalled when user clicks more info on noticeNone
onPreferencesClickAgreeToAllCalled when user clicks agree to allNone
onPreferencesClickDisagreeToAllCalled when user clicks disagree to allNone
onPreferencesClickSaveChoicesCalled when user saves choicesNone

Error Events

EventDescriptionCallback Parameter
onErrorCalled when an error occurs in the underlying Didomi Web SDK or in the WebViewerror: DidomiError

The DidomiError payload is a discriminated union on the source field:

type DidomiError =
  | { source: 'api'; id?: string; reason?: string }
  | {
      source: 'webview';
      code?: number;
      description?: string;
      nativeEvent?: unknown;
    };
  • source: 'api' — forwarded from the Didomi Web SDK api.error event (HTTP failures while sending consents, events, metrics, etc.). id identifies the failed request, reason is one of request.failure or response.error.
  • source: 'webview' — emitted by the underlying WebView for load/runtime errors.

Implementation Example

Below is a simplified example showing how to implement the SDK and access its functionality:

import { DidomiSDK, DidomiSDKAPI } from '@didomi/vega-sdk';
import React, { useRef, useState } from 'react';
import { View } from 'react-native';

function App() {
  // Create ref to access SDK methods
  const didomiRef = useRef<DidomiSDKAPI>(null);

  // Example of event handling
  const handleReady = () => {
    // SDK is ready, you can now call methods
    console.log('SDK is ready');
  };

  // Example of handling consent changes
  const handleConsentChanged = (consent) => {
    console.log('Consent changed', consent);
    // Update application state or perform actions based on consent
  };

  return (
    <DidomiSDK
      noticeId="YOUR_NOTICE_ID"
      didomiPublicApiKey="YOUR_PUBLIC_API_KEY"
      ref={didomiRef}
      onReady={handleReady}
      onConsentChanged={handleConsentChanged}
    >
      <View>{/* Your application UI */}</View>
    </DidomiSDK>
  );
}

export default App;

License

Copyright © Didomi. All rights reserved.

版本与发布记录

@didomi/vega-sdk 共发布 8 个版本,首次发布于 2025/10/01;过去 12 个月发布了 7 个版本。

版本发布日期距今
0.3.2latest2026/11/056 天前
0.3.12026/10/1923 天前
0.3.02026/08/152 个月前
0.2.22026/06/254 个月前
0.2.12026/05/225 个月前
0.2.02026/05/066 个月前

关于 @didomi/vega-sdk 的常见问题

@didomi/vega-sdk 是什么?

Didomi SDK for Vega TV platform

如何安装 @didomi/vega-sdk?

在项目目录运行 npm install @didomi/vega-sdk,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(>=18.0.0 <20.0.0)、react-dom(>=18.0.0 <20.0.0)、react-native(>=0.72.0 <0.84.0)、@amazon-devices/webview(~4.0.2)、@amazon-devices/react-native-kepler(>=4.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@didomi/vega-sdk 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@didomi/vega-sdk 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@didomi/vega-sdk 可以商用吗?

@didomi/vega-sdk 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@didomi/vega-sdk 的下载量有多少?

根据 npm 官方下载统计,@didomi/vega-sdk 在 2026/10/12 – 2026/11/10 这 30 天内被下载 4,406 次,日均约 147 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@didomi/vega-sdk 还在维护吗?

最新版本 0.3.2 发布于 2026/11/05(6 天前);至今共发布 8 个版本,其中过去 12 个月发布了 7 个;首次发布于 2025/10/01。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。