datax-sdk 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,61 @@
1
+ # datax-sdk
2
+
3
+ Official Node.js/TypeScript SDK for the [DataX API](https://github.com/rohitbborude-eaton/convertor-apis) — transform CSV, JSON, XLSX, and PDF with a single function call.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install datax-sdk
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```typescript
14
+ import { DataX } from 'datax-sdk';
15
+
16
+ const client = new DataX('dk_live_YOUR_API_KEY', 'https://your-api-url.com');
17
+
18
+ // CSV → JSON
19
+ const result = await client.csvToJson('name,age\nRohit,28\nPriya,25');
20
+ console.log(result.data);
21
+ // [{ name: "Rohit", age: 28 }, { name: "Priya", age: 25 }]
22
+
23
+ // JSON → CSV
24
+ const csv = await client.jsonToCsv([
25
+ { name: 'Rohit', age: 28 },
26
+ { name: 'Priya', age: 25 },
27
+ ]);
28
+ console.log(csv.data);
29
+ // "name,age\nRohit,28\nPriya,25"
30
+ ```
31
+
32
+ ## All Methods
33
+
34
+ | Method | Input | Output | Plan |
35
+ |--------|-------|--------|------|
36
+ | `csvToJson(csv, opts?)` | CSV string | JSON array | Free |
37
+ | `jsonToCsv(data)` | JSON array | CSV string | Free |
38
+ | `xlsxToJson(base64, opts?)` | Base64 XLSX | JSON array | Free |
39
+ | `jsonToXlsx(data, sheet?)` | JSON array | Base64 XLSX | Starter+ |
40
+ | `csvToXlsx(csv, sheet?)` | CSV string | Base64 XLSX | Starter+ |
41
+ | `jsonToPdf(data, title?)` | JSON array | Base64 PDF | Pro+ |
42
+ | `csvToPdf(csv, title?)` | CSV string | Base64 PDF | Pro+ |
43
+
44
+ ### File Uploads
45
+
46
+ ```typescript
47
+ const file = new Blob([csvContent], { type: 'text/csv' });
48
+ const result = await client.uploadCsvToJson(file);
49
+ ```
50
+
51
+ ### Async Jobs
52
+
53
+ ```typescript
54
+ const job = await client.createJob('csv-to-json');
55
+ // Poll for completion
56
+ const status = await client.getJob(job.jobId);
57
+ ```
58
+
59
+ ## License
60
+
61
+ MIT
@@ -0,0 +1,65 @@
1
+ export type CsvToJsonOptions = {
2
+ header?: boolean;
3
+ delimiter?: 'auto' | ',' | ';' | 'tab';
4
+ inferTypes?: boolean;
5
+ };
6
+ export type JsonToCsvOptions = Record<string, never>;
7
+ export type XlsxToJsonOptions = {
8
+ sheet?: string;
9
+ header?: boolean;
10
+ inferTypes?: boolean;
11
+ };
12
+ export type TransformResult<T = any> = {
13
+ data: T;
14
+ meta: Record<string, any>;
15
+ };
16
+ export type PaginatedResult<T = any> = {
17
+ data: T[];
18
+ meta: {
19
+ page: number;
20
+ limit: number;
21
+ total: number;
22
+ totalPages: number;
23
+ };
24
+ };
25
+ export type JobStatus = {
26
+ id: string;
27
+ type: string;
28
+ status: 'queued' | 'processing' | 'completed' | 'failed';
29
+ outputBlobUrl?: string;
30
+ downloadUrl?: string;
31
+ error?: string;
32
+ createdAt: string;
33
+ updatedAt: string;
34
+ };
35
+ export type WebhookEndpoint = {
36
+ id: string;
37
+ url: string;
38
+ events: string[];
39
+ secret?: string;
40
+ active: boolean;
41
+ createdAt: string;
42
+ };
43
+ export declare class DataX {
44
+ private apiKey;
45
+ private baseUrl;
46
+ constructor(apiKey: string, baseUrl?: string);
47
+ private request;
48
+ csvToJson(csv: string, opts?: CsvToJsonOptions): Promise<TransformResult<Record<string, any>[]>>;
49
+ jsonToCsv(data: Record<string, any>[]): Promise<TransformResult<string>>;
50
+ xlsxToJson(base64: string, opts?: XlsxToJsonOptions): Promise<TransformResult<Record<string, any>[]>>;
51
+ jsonToXlsx(data: Record<string, any>[], sheetName?: string): Promise<TransformResult<string>>;
52
+ csvToXlsx(csv: string, sheetName?: string): Promise<TransformResult<string>>;
53
+ jsonToPdf(data: Record<string, any>[], title?: string): Promise<TransformResult<string>>;
54
+ csvToPdf(csv: string, title?: string): Promise<TransformResult<string>>;
55
+ uploadCsvToJson(file: Blob): Promise<TransformResult<Record<string, any>[]>>;
56
+ uploadXlsxToJson(file: Blob): Promise<TransformResult<Record<string, any>[]>>;
57
+ private uploadFile;
58
+ createJob(type: string, options?: any): Promise<{
59
+ jobId: string;
60
+ status: string;
61
+ uploadUrl?: string;
62
+ }>;
63
+ getJob(jobId: string): Promise<JobStatus>;
64
+ listJobs(page?: number, limit?: number): Promise<PaginatedResult<JobStatus>>;
65
+ }
package/dist/index.js ADDED
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DataX = void 0;
4
+ class DataX {
5
+ constructor(apiKey, baseUrl = 'https://api.yourdomain.com') {
6
+ this.apiKey = apiKey;
7
+ this.baseUrl = baseUrl;
8
+ }
9
+ async request(path, body, method = 'POST') {
10
+ const res = await fetch(`${this.baseUrl}${path}`, {
11
+ method,
12
+ headers: {
13
+ 'Content-Type': 'application/json',
14
+ 'x-api-key': this.apiKey,
15
+ },
16
+ body: method !== 'GET' ? JSON.stringify(body) : undefined,
17
+ });
18
+ if (!res.ok) {
19
+ throw new Error(`DataX API ${res.status}: ${await res.text()}`);
20
+ }
21
+ return res.json();
22
+ }
23
+ // --- Transforms ---
24
+ async csvToJson(csv, opts = {}) {
25
+ return this.request('/v1/transform/csv-to-json', {
26
+ data: csv,
27
+ delimiter: opts.delimiter,
28
+ header: opts.header !== undefined ? String(opts.header) : undefined,
29
+ inferTypes: opts.inferTypes !== undefined ? String(opts.inferTypes) : undefined,
30
+ });
31
+ }
32
+ async jsonToCsv(data) {
33
+ return this.request('/v1/transform/json-to-csv', { data });
34
+ }
35
+ async xlsxToJson(base64, opts = {}) {
36
+ return this.request('/v1/transform/xlsx-to-json', {
37
+ data: base64,
38
+ sheet: opts.sheet,
39
+ header: opts.header !== undefined ? String(opts.header) : undefined,
40
+ inferTypes: opts.inferTypes !== undefined ? String(opts.inferTypes) : undefined,
41
+ });
42
+ }
43
+ async jsonToXlsx(data, sheetName) {
44
+ return this.request('/v1/transform/json-to-xlsx', { data, sheetName });
45
+ }
46
+ async csvToXlsx(csv, sheetName) {
47
+ return this.request('/v1/transform/csv-to-xlsx', { data: csv, sheetName });
48
+ }
49
+ async jsonToPdf(data, title) {
50
+ return this.request('/v1/transform/json-to-pdf', { data, title });
51
+ }
52
+ async csvToPdf(csv, title) {
53
+ return this.request('/v1/transform/csv-to-pdf', { data: csv, title });
54
+ }
55
+ // --- File upload transforms ---
56
+ async uploadCsvToJson(file) {
57
+ return this.uploadFile('/v1/upload/csv-to-json', file);
58
+ }
59
+ async uploadXlsxToJson(file) {
60
+ return this.uploadFile('/v1/upload/xlsx-to-json', file);
61
+ }
62
+ async uploadFile(path, file) {
63
+ const form = new FormData();
64
+ form.append('file', file);
65
+ const res = await fetch(`${this.baseUrl}${path}`, {
66
+ method: 'POST',
67
+ headers: { 'x-api-key': this.apiKey },
68
+ body: form,
69
+ });
70
+ if (!res.ok) {
71
+ throw new Error(`DataX API ${res.status}: ${await res.text()}`);
72
+ }
73
+ return res.json();
74
+ }
75
+ // --- Jobs ---
76
+ async createJob(type, options) {
77
+ return this.request('/v1/jobs', { type, options });
78
+ }
79
+ async getJob(jobId) {
80
+ const res = await fetch(`${this.baseUrl}/v1/jobs/${jobId}`, {
81
+ headers: { 'x-api-key': this.apiKey },
82
+ });
83
+ if (!res.ok) {
84
+ throw new Error(`DataX API ${res.status}: ${await res.text()}`);
85
+ }
86
+ return res.json();
87
+ }
88
+ async listJobs(page = 1, limit = 20) {
89
+ const res = await fetch(`${this.baseUrl}/v1/jobs?page=${page}&limit=${limit}`, { headers: { 'x-api-key': this.apiKey } });
90
+ if (!res.ok) {
91
+ throw new Error(`DataX API ${res.status}: ${await res.text()}`);
92
+ }
93
+ return res.json();
94
+ }
95
+ }
96
+ exports.DataX = DataX;
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "datax-sdk",
3
+ "version": "1.0.0",
4
+ "description": "Official SDK for the DataX API — CSV/JSON/XLSX/PDF transforms via REST",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": ["dist"],
8
+ "scripts": {
9
+ "build": "tsc",
10
+ "prepublishOnly": "npm run build"
11
+ },
12
+ "keywords": [
13
+ "csv", "json", "xlsx", "pdf", "transform", "convert",
14
+ "csv-to-json", "json-to-csv", "xlsx-to-json", "api", "datax"
15
+ ],
16
+ "author": "DataX",
17
+ "license": "MIT",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "https://github.com/rohitbborude-eaton/convertor-apis"
21
+ },
22
+ "homepage": "https://github.com/rohitbborude-eaton/convertor-apis#readme",
23
+ "engines": {
24
+ "node": ">=18.0.0"
25
+ }
26
+ }