SDK v1.0

PDPA Platform SDK

A comprehensive JavaScript/TypeScript SDK for integrating PDPA compliance features into your application. Manage consent, cookie preferences, and data subject requests with ease.

Introduction

The PDPA Platform SDK provides a simple and type-safe way to integrate Thailand's Personal Data Protection Act compliance features into your web applications. Built with TypeScript, it offers full type safety and intelligent autocomplete for all API operations.

Type Safe

Full TypeScript support with end-to-end type safety using Eden Treaty.

Lightweight

Minimal footprint with tree-shaking support for optimal performance.

Easy Integration

Simple setup with minimal configuration required.

Installation

Install the SDK using your preferred package manager:

tsx

Quick Start

Get started in minutes by initializing the SDK with your API key:

Initialize SDK

Create a PDPA Platform client instance with your API credentials.

tsx

Getting Your API Key

Navigate to the API Keys section in your admin dashboard to generate a new API key for your application.

UI Components

For the fastest integration, use our pre-built UI components from @pdpa-platform/sdk/ui. These ready-to-use components handle all the logic and styling for you.

Cookie Banner Component

Drop-in cookie consent banner with full functionality.

tsx

Consent Form Component

Pre-built consent collection form with validation.

tsx

DSR Request Form

Data subject request submission form.

tsx

Consent Status Badge

Display current consent status for a user.

tsx

Available UI Components

CookieBanner — Cookie consent banner
ConsentForm — Consent collection form
DSRRequestForm — Data subject request form
ConsentBadge — Consent status indicator
ConsentToggle — Consent toggle switch
PrivacySettings — Full privacy settings panel
CookieTable — Display cookie inventory
ConsentLog — User consent history

Authentication

The SDK uses API keys for authentication. Include your API key in the initialization options:

Server-Side Usage

Use secret API keys in your backend code.

tsx

Client-Side Usage

Use public API keys in browser environments.

tsx

Security Best Practices

  • Never expose secret API keys in client-side code
  • Use environment variables to store API keys
  • Rotate API keys periodically for enhanced security

Data Subject Requests

Handle data subject requests (access, deletion, portability) in compliance with PDPA regulations. Automate workflows and track request status.

Submit a Request

Submit a new data subject request.

tsx

Check Request Status

Check the current status of a DSR.

tsx

List User Requests

Get all DSRs for a specific user.

tsx

Download Data Export

Download the data export for a portability request.

tsx

Webhooks

Receive real-time notifications for events in your PDPA Platform account. Set up webhooks to be notified when consent is updated, DSRs are submitted, or other events occur.

Configure Webhook Endpoint

Register a new webhook endpoint to receive events.

tsx

Verify Webhook Signature

Verify the webhook signature to ensure the request is authentic.

tsx

Webhook Events

EventDescription
consent.grantedUser has given consent for a purpose
consent.withdrawnUser has withdrawn consent
dsr.submittedNew data subject request received
dsr.completedDSR processing completed
cookie.preferences_updatedUser updated cookie preferences

Examples

Complete examples for common use cases:

Next.js API Route

Handle consent recording in a Next.js API route.

tsx

Express Middleware

Create middleware to check consent before processing requests.

tsx

Vue.js Composable

Create a Vue composable for cookie consent management.

tsx

Error Handling

The SDK throws typed errors that you can catch and handle appropriately:

Error Handling Example

Catch and handle different types of SDK errors.

tsx
Error ClassStatusDescription
ValidationError400Invalid request parameters
AuthenticationError401Invalid or missing API key
ForbiddenError403Insufficient permissions
NotFoundError404Resource not found
RateLimitError429Too many requests
PDPAError500Internal server error

Ready to integrate?

Get started with the PDPA Platform SDK today and ensure your application is fully compliant with Thailand's data protection regulations.