datax-sdk
v2.0.5
Published
Official SDK for the DataX API — CSV/JSON/XLSX/PDF/XML/YAML/Markdown transforms, batch processing, data masking, image conversion, and scheduled transforms
Maintainers
Readme
datax-sdk
Official Node.js/TypeScript SDK for the DataX API — transform CSV, JSON, XLSX, PDF, XML, YAML, Markdown, batch processing, data masking, image conversion, and scheduled transforms.
Install
npm install datax-sdkQuick Start
import { DataX } from 'datax-sdk';
const client = new DataX('dk_live_YOUR_API_KEY', 'https://datax-api-production.up.railway.app');
// CSV → JSON
const result = await client.csvToJson('name,age\nRohit,28\nPriya,25');
console.log(result.data);
// [{ name: "Rohit", age: 28 }, { name: "Priya", age: 25 }]All Methods
Core Transforms (Free)
| Method | Input | Output |
|--------|-------|--------|
| csvToJson(csv, opts?) | CSV string | JSON array |
| jsonToCsv(data) | JSON array | CSV string |
| xlsxToJson(base64, opts?) | Base64 XLSX | JSON array |
| jsonToXlsx(data, sheet?) | JSON array | Base64 XLSX |
| csvToXlsx(csv, sheet?) | CSV string | Base64 XLSX |
XML / YAML / Markdown (Free)
| Method | Input | Output |
|--------|-------|--------|
| xmlToJson(xml) | XML string | JSON object |
| jsonToXml(data, rootName?) | JSON object | XML string |
| yamlToJson(yaml) | YAML string | JSON object |
| jsonToYaml(data) | JSON object | YAML string |
| markdownToHtml(md) | Markdown string | HTML string |
PDF (Pro+)
| Method | Input | Output |
|--------|-------|--------|
| jsonToPdf(data, title?) | JSON array | Base64 PDF |
| csvToPdf(csv, title?) | CSV string | Base64 PDF |
| templatePdf(template, data, pageSize?, orientation?) | Handlebars template + data | Base64 PDF |
| pdfToJson(base64, opts?) | Base64 PDF | Text, pages array, or JSON rows |
pdfToJson options: mode ('text' | 'pages' | 'table'), delimiter (for table mode)
// Extract text from PDF
const text = await client.pdfToJson(base64Pdf, { mode: 'text' });
// → { data: "Full document text...", meta: { totalPages: 3, mode: "text" } }
// Extract tabular data from PDF
const table = await client.pdfToJson(base64Pdf, { mode: 'table' });
// → { data: [{ Name: "Rohit", Age: 28 }, ...], meta: { rows: 5, mode: "table" } }
// Get text per page
const pages = await client.pdfToJson(base64Pdf, { mode: 'pages' });
// → { data: ["Page 1 text", "Page 2 text"], meta: { pages: 2, mode: "pages" } }Data Utilities (Pro+)
| Method | Input | Output |
|--------|-------|--------|
| validateJson(data, schema) | JSON + JSON Schema | Validation result |
| queryJson(data, expression) | JSON + JMESPath expression | Query result |
| mergeCsvs(csvs) | Array of CSV strings | Merged CSV |
Batch Processing (Pro+)
const result = await client.batch([
{ type: 'csv-to-json', data: 'name,age\nRohit,28' },
{ type: 'json-to-yaml', data: { name: 'Priya', age: 25 } },
]);
console.log(result.meta); // { total: 2, succeeded: 2, failed: 0 }| Method | Input | Output |
|--------|-------|--------|
| batch(operations, continueOnError?) | Array of { type, data, options? } | Per-operation results |
Data Masking / Anonymization (Pro+)
Auto-detects PII (email, phone, SSN, credit cards, passwords, API keys) or mask specific fields.
// Auto-detect PII
const masked = await client.mask([
{ name: 'Rohit', email: '[email protected]', phone: '+919876543210' },
]);
// → { name: 'Rohit', email: 'r***@example.com', phone: '+9*********10' }
// Specific fields with strategy
const redacted = await client.mask(data, {
fields: ['email', 'ssn'],
strategy: 'redact', // 'redact' | 'hash' | 'partial'
});| Method | Input | Output |
|--------|-------|--------|
| mask(data, opts?) | JSON object/array | Masked data |
Strategies: partial (default — keeps first/last chars), redact (replaces with ***REDACTED***), hash (SHA-256 hash)
Image Conversion (Pro+)
Convert between PNG, JPEG, WebP, AVIF, TIFF with optional resize and quality control.
const result = await client.convertImage(base64Png, {
outputFormat: 'webp',
quality: 80,
width: 800,
});
console.log(result.meta); // { format: 'webp', width: 800, height: 600, sizeBytes: 24530 }| Method | Input | Output |
|--------|-------|--------|
| convertImage(base64, opts) | Base64 image | Base64 converted image |
Options: outputFormat (required), quality (1-100), width, height
Scheduled Transforms (Scale)
Create recurring cron-based transforms that run automatically.
// Create a schedule
const schedule = await client.createSchedule({
name: 'Daily sales report',
cron: '0 9 * * *',
transformType: 'csv-to-json',
transformInput: { data: 'name,age\nRohit,28' },
});
// Manage schedules
const all = await client.listSchedules();
const one = await client.getSchedule(schedule.id);
await client.pauseSchedule(schedule.id);
await client.resumeSchedule(schedule.id);
await client.deleteSchedule(schedule.id);| Method | Input | Output |
|--------|-------|--------|
| createSchedule(input) | Name, cron, type, input | Schedule object |
| listSchedules() | — | Schedule array |
| getSchedule(id) | Schedule ID | Schedule object |
| pauseSchedule(id) | Schedule ID | Schedule object |
| resumeSchedule(id) | Schedule ID | Schedule object |
| deleteSchedule(id) | Schedule ID | { message } |
File Uploads (Free)
const file = new Blob([csvContent], { type: 'text/csv' });
const result = await client.uploadCsvToJson(file);| Method | Input | Output |
|--------|-------|--------|
| uploadCsvToJson(file) | CSV Blob | JSON array |
| uploadXlsxToJson(file) | XLSX Blob | JSON array |
| uploadPdfToJson(file, opts?) | PDF Blob | Text, pages, or JSON rows |
Async Jobs
const job = await client.createJob('csv-to-json', { data: largeCsv });
const status = await client.getJob(job.jobId);
const jobs = await client.listJobs(1, 20);Plans
| Plan | Price | Features | |------|-------|----------| | Free | $0 | Core transforms, 100 req/month | | Starter | $5/mo | All free + XLSX export, 5,000 req/month | | Pro | $19/mo | All starter + PDF, batch, masking, image, 50,000 req/month | | Scale | $99/mo | Everything + scheduled transforms, 500,000 req/month |
License
MIT
