@ptkl/sdk 0.9.8 → 0.9.9

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.
@@ -1,19 +1,332 @@
1
1
  import IntegrationsBaseClient from "../integrationsBaseClient";
2
- import { PDFFillOptions } from "../../types/integrations";
2
+ import { AxiosResponse } from "axios";
3
+ import { PDFFillOptions, DataConversionParams, DataValidationParams, DataInfoParams, DataInfo, DataValidationResult, ConversionOptions } from "../../types/integrations";
4
+ /**
5
+ * Document Management System (DMS) API client
6
+ *
7
+ * Provides comprehensive document and media management capabilities including:
8
+ * - File upload, download, and management
9
+ * - PDF generation and form filling
10
+ * - Data conversion between JSON, CSV, and Excel formats
11
+ * - Media processing and EXIF data extraction
12
+ *
13
+ * ## Data Conversion Features
14
+ *
15
+ * The DMS class includes powerful data conversion capabilities that allow you to:
16
+ * - Convert between JSON, CSV, and Excel (.xlsx) formats
17
+ * - Validate data format integrity
18
+ * - Analyze data structure and metadata
19
+ * - Handle large datasets with memory-efficient processing
20
+ *
21
+ * ### Supported Formats
22
+ * - **JSON**: Array of objects (recommended for tabular data)
23
+ * - **CSV**: Comma-separated values with headers
24
+ * - **Excel**: .xlsx format with optional sheet specification
25
+ *
26
+ * ### Error Handling
27
+ * All conversion methods may throw errors with code 3003 for conversion failures.
28
+ * Always wrap calls in try-catch blocks for production use.
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * import { DMS } from 'protokol-sdk';
33
+ *
34
+ * const dms = new DMS({
35
+ * token: 'your-bearer-token',
36
+ * host: 'http://localhost:8086'
37
+ * });
38
+ *
39
+ * const libraryRef = 'your-library-uuid';
40
+ *
41
+ * // Convert JSON to CSV
42
+ * const jsonData = [
43
+ * { name: "John", age: 30 },
44
+ * { name: "Jane", age: 25 }
45
+ * ];
46
+ *
47
+ * try {
48
+ * const csvResult = await dms.jsonToCsv(libraryRef, jsonData);
49
+ * console.log(csvResult.data); // CSV string
50
+ * } catch (error) {
51
+ * console.error('Conversion failed:', error.message);
52
+ * }
53
+ * ```
54
+ */
3
55
  export default class DMS extends IntegrationsBaseClient {
4
- list(data: any): Promise<import("axios").AxiosResponse<any, any>>;
5
- libraries(): Promise<import("axios").AxiosResponse<any, any>>;
6
- upload(payload: any): Promise<import("axios").AxiosResponse<any, any> | undefined>;
7
- delete(data: any): Promise<import("axios").AxiosResponse<any, any>>;
8
- uploadBase64(data: any): Promise<import("axios").AxiosResponse<any, any>>;
9
- getMedia(lib: string, key: string, encoding: string): Promise<import("axios").AxiosResponse<any, any>>;
10
- download(lib: string, key: string): Promise<import("axios").AxiosResponse<any, any>>;
11
- getExifData(lib: string, key: string): Promise<import("axios").AxiosResponse<any, any>>;
12
- html2pdf(lib: string, data: any): Promise<import("axios").AxiosResponse<any, any>>;
13
- createDir(lib: string, path: string): Promise<import("axios").AxiosResponse<any, any>>;
14
- deleteDir(lib: string, path: string): Promise<import("axios").AxiosResponse<any, any>>;
15
- dirs(lib: string, data: string): Promise<import("axios").AxiosResponse<any, any>>;
16
- fillPdf(lib: string, data: PDFFillOptions): Promise<import("axios").AxiosResponse<any, any>>;
17
- request(method: string, endpoint: string, params?: any): Promise<import("axios").AxiosResponse<any, any>>;
18
- requestv1(method: string, endpoint: string, params?: any): Promise<import("axios").AxiosResponse<any, any>>;
56
+ list(data: any): Promise<AxiosResponse<any, any>>;
57
+ libraries(): Promise<AxiosResponse<any, any>>;
58
+ upload(payload: any): Promise<AxiosResponse<any, any> | undefined>;
59
+ delete(data: any): Promise<AxiosResponse<any, any>>;
60
+ uploadBase64(data: any): Promise<AxiosResponse<any, any>>;
61
+ getMedia(lib: string, key: string, encoding: string): Promise<AxiosResponse<any, any>>;
62
+ download(lib: string, key: string): Promise<AxiosResponse<any, any>>;
63
+ getExifData(lib: string, key: string): Promise<AxiosResponse<any, any>>;
64
+ html2pdf(lib: string, data: any): Promise<AxiosResponse<any, any>>;
65
+ createDir(lib: string, path: string): Promise<AxiosResponse<any, any>>;
66
+ deleteDir(lib: string, path: string): Promise<AxiosResponse<any, any>>;
67
+ dirs(lib: string, data: string): Promise<AxiosResponse<any, any>>;
68
+ fillPdf(lib: string, data: PDFFillOptions): Promise<AxiosResponse<any, any>>;
69
+ /**
70
+ * Convert data between different formats (JSON, CSV, Excel)
71
+ *
72
+ * @param lib - Library reference UUID
73
+ * @param data - Raw data to convert
74
+ * @param params - Conversion parameters
75
+ * @returns Promise resolving to converted data
76
+ *
77
+ * @example
78
+ * ```typescript
79
+ * // Convert JSON to CSV
80
+ * const jsonData = [
81
+ * { name: "John Doe", age: 30, email: "john@example.com" },
82
+ * { name: "Jane Smith", age: 25, email: "jane@example.com" }
83
+ * ];
84
+ *
85
+ * const csvResult = await dms.convertData(libraryRef, jsonData, {
86
+ * from: 'json',
87
+ * to: 'csv'
88
+ * });
89
+ * console.log(csvResult.data); // CSV string
90
+ *
91
+ * // Convert JSON to Excel with custom sheet name
92
+ * const excelResult = await dms.convertData(libraryRef, jsonData, {
93
+ * from: 'json',
94
+ * to: 'excel',
95
+ * sheet_name: 'Customer Data'
96
+ * });
97
+ * // excelResult.data is a Blob
98
+ * ```
99
+ */
100
+ convertData(lib: string, data: any, params: DataConversionParams): Promise<AxiosResponse<any>>;
101
+ /**
102
+ * Get information about data format and structure
103
+ *
104
+ * @param lib - Library reference UUID
105
+ * @param data - Raw data to analyze
106
+ * @param params - Analysis parameters
107
+ * @returns Promise resolving to data information
108
+ *
109
+ * @example
110
+ * ```typescript
111
+ * const jsonData = [
112
+ * { name: "John", age: 30, email: "john@example.com" },
113
+ * { name: "Jane", age: 25, email: "jane@example.com" }
114
+ * ];
115
+ *
116
+ * const dataInfo = await dms.getDataInfo(libraryRef, jsonData, {
117
+ * format: 'json'
118
+ * });
119
+ *
120
+ * console.log(dataInfo.data);
121
+ * // Output:
122
+ * // {
123
+ * // format: "json",
124
+ * // size_bytes: 245,
125
+ * // record_count: 2,
126
+ * // field_count: 3,
127
+ * // fields: ["name", "age", "email"],
128
+ * // library_ref: "98bee1cb-0f21-4582-a832-7c32b4b61831"
129
+ * // }
130
+ * ```
131
+ */
132
+ getDataInfo(lib: string, data: any, params: DataInfoParams): Promise<AxiosResponse<DataInfo>>;
133
+ /**
134
+ * Validate data format without performing conversion
135
+ *
136
+ * @param lib - Library reference UUID
137
+ * @param data - Raw data to validate
138
+ * @param params - Validation parameters
139
+ * @returns Promise resolving to validation result
140
+ *
141
+ * @example
142
+ * ```typescript
143
+ * const jsonData = [{ name: "John", age: 30 }];
144
+ *
145
+ * const validation = await dms.validateData(libraryRef, jsonData, {
146
+ * format: 'json'
147
+ * });
148
+ *
149
+ * console.log(validation.data);
150
+ * // Output:
151
+ * // {
152
+ * // valid: true,
153
+ * // message: "Data is valid JSON format",
154
+ * // library_ref: "98bee1cb-0f21-4582-a832-7c32b4b61831"
155
+ * // }
156
+ *
157
+ * // Handle invalid data
158
+ * try {
159
+ * const invalidValidation = await dms.validateData(libraryRef, "invalid json", {
160
+ * format: 'json'
161
+ * });
162
+ * } catch (error) {
163
+ * console.error('Validation failed:', error.response?.data?.message);
164
+ * }
165
+ * ```
166
+ */
167
+ validateData(lib: string, data: any, params: DataValidationParams): Promise<AxiosResponse<DataValidationResult>>;
168
+ /**
169
+ * Convert JSON data to CSV format
170
+ *
171
+ * @param lib - Library reference UUID
172
+ * @param jsonData - JSON data (array of objects recommended for tabular data)
173
+ * @returns Promise resolving to CSV string
174
+ *
175
+ * @example
176
+ * ```typescript
177
+ * const jsonData = [
178
+ * { name: "John Doe", age: 30, email: "john@example.com" },
179
+ * { name: "Jane Smith", age: 25, email: "jane@example.com" }
180
+ * ];
181
+ *
182
+ * const csvResponse = await dms.jsonToCsv(libraryRef, jsonData);
183
+ * console.log(csvResponse.data);
184
+ * // Output:
185
+ * // name,age,email
186
+ * // John Doe,30,john@example.com
187
+ * // Jane Smith,25,jane@example.com
188
+ * ```
189
+ */
190
+ jsonToCsv(lib: string, jsonData: any): Promise<AxiosResponse<string>>;
191
+ /**
192
+ * Convert JSON data to Excel (.xlsx) format
193
+ *
194
+ * @param lib - Library reference UUID
195
+ * @param jsonData - JSON data (array of objects recommended for tabular data)
196
+ * @param options - Optional conversion options
197
+ * @returns Promise resolving to Excel file as Blob
198
+ *
199
+ * @example
200
+ * ```typescript
201
+ * const jsonData = [
202
+ * { name: "John Doe", age: 30, email: "john@example.com" },
203
+ * { name: "Jane Smith", age: 25, email: "jane@example.com" }
204
+ * ];
205
+ *
206
+ * // Basic conversion
207
+ * const excelResponse = await dms.jsonToExcel(libraryRef, jsonData);
208
+ * const blob = excelResponse.data; // Blob for download
209
+ *
210
+ * // With custom sheet name
211
+ * const excelWithOptions = await dms.jsonToExcel(libraryRef, jsonData, {
212
+ * sheet_name: 'Customer Data'
213
+ * });
214
+ *
215
+ * // Create download link
216
+ * const url = URL.createObjectURL(excelWithOptions.data);
217
+ * const link = document.createElement('a');
218
+ * link.href = url;
219
+ * link.download = 'data.xlsx';
220
+ * link.click();
221
+ * ```
222
+ */
223
+ jsonToExcel(lib: string, jsonData: any, options?: ConversionOptions): Promise<AxiosResponse<Blob>>;
224
+ /**
225
+ * Convert CSV data to JSON format
226
+ *
227
+ * @param lib - Library reference UUID
228
+ * @param csvData - CSV data string (with headers in first row)
229
+ * @returns Promise resolving to JSON array
230
+ *
231
+ * @example
232
+ * ```typescript
233
+ * const csvString = `name,age,email
234
+ * John Doe,30,john@example.com
235
+ * Jane Smith,25,jane@example.com`;
236
+ *
237
+ * const jsonResponse = await dms.csvToJson(libraryRef, csvString);
238
+ * console.log(jsonResponse.data);
239
+ * // Output:
240
+ * // [
241
+ * // { name: "John Doe", age: "30", email: "john@example.com" },
242
+ * // { name: "Jane Smith", age: "25", email: "jane@example.com" }
243
+ * // ]
244
+ * ```
245
+ */
246
+ csvToJson(lib: string, csvData: string): Promise<AxiosResponse<any[]>>;
247
+ /**
248
+ * Convert CSV data to Excel (.xlsx) format
249
+ *
250
+ * @param lib - Library reference UUID
251
+ * @param csvData - CSV data string (with headers in first row)
252
+ * @param options - Optional conversion options
253
+ * @returns Promise resolving to Excel file as Blob
254
+ *
255
+ * @example
256
+ * ```typescript
257
+ * const csvString = `name,age,email
258
+ * John Doe,30,john@example.com
259
+ * Jane Smith,25,jane@example.com`;
260
+ *
261
+ * const excelResponse = await dms.csvToExcel(libraryRef, csvString, {
262
+ * sheet_name: 'Imported Data'
263
+ * });
264
+ *
265
+ * // Handle the Excel blob
266
+ * const blob = excelResponse.data;
267
+ * const url = URL.createObjectURL(blob);
268
+ * // Use url for download or further processing
269
+ * ```
270
+ */
271
+ csvToExcel(lib: string, csvData: string, options?: ConversionOptions): Promise<AxiosResponse<Blob>>;
272
+ /**
273
+ * Convert Excel (.xlsx) data to JSON format
274
+ *
275
+ * @param lib - Library reference UUID
276
+ * @param excelData - Excel file data as Blob or ArrayBuffer
277
+ * @param options - Optional conversion options
278
+ * @returns Promise resolving to JSON array
279
+ *
280
+ * @example
281
+ * ```typescript
282
+ * // From file input
283
+ * const fileInput = document.querySelector('input[type="file"]');
284
+ * const file = fileInput.files[0]; // Excel file
285
+ *
286
+ * const jsonResponse = await dms.excelToJson(libraryRef, file, {
287
+ * sheet_name: 'Sheet1' // optional, defaults to first sheet
288
+ * });
289
+ *
290
+ * console.log(jsonResponse.data);
291
+ * // Output: JSON array with data from Excel sheet
292
+ *
293
+ * // From ArrayBuffer
294
+ * const arrayBuffer = await file.arrayBuffer();
295
+ * const jsonFromBuffer = await dms.excelToJson(libraryRef, arrayBuffer);
296
+ * ```
297
+ */
298
+ excelToJson(lib: string, excelData: Blob | ArrayBuffer, options?: ConversionOptions): Promise<AxiosResponse<any[]>>;
299
+ /**
300
+ * Convert Excel (.xlsx) data to CSV format
301
+ *
302
+ * @param lib - Library reference UUID
303
+ * @param excelData - Excel file data as Blob or ArrayBuffer
304
+ * @param options - Optional conversion options
305
+ * @returns Promise resolving to CSV string
306
+ *
307
+ * @example
308
+ * ```typescript
309
+ * // From file input
310
+ * const fileInput = document.querySelector('input[type="file"]');
311
+ * const file = fileInput.files[0]; // Excel file
312
+ *
313
+ * const csvResponse = await dms.excelToCsv(libraryRef, file, {
314
+ * sheet_name: 'Data' // optional, defaults to first sheet
315
+ * });
316
+ *
317
+ * console.log(csvResponse.data);
318
+ * // Output: CSV string with data from Excel sheet
319
+ *
320
+ * // Save as CSV file
321
+ * const csvBlob = new Blob([csvResponse.data], { type: 'text/csv' });
322
+ * const url = URL.createObjectURL(csvBlob);
323
+ * const link = document.createElement('a');
324
+ * link.href = url;
325
+ * link.download = 'converted.csv';
326
+ * link.click();
327
+ * ```
328
+ */
329
+ excelToCsv(lib: string, excelData: Blob | ArrayBuffer, options?: ConversionOptions): Promise<AxiosResponse<string>>;
330
+ request(method: string, endpoint: string, params?: any): Promise<AxiosResponse<any, any>>;
331
+ requestv1(method: string, endpoint: string, params?: any): Promise<AxiosResponse<any, any>>;
19
332
  }
@@ -1,4 +1,5 @@
1
1
  import PlatformBaseClient from "./platformBaseClient";
2
2
  export default class Workflow extends PlatformBaseClient {
3
3
  trigger(id: string, event: string, data: any): Promise<import("axios").AxiosResponse<any, any>>;
4
+ publish(event: string, data: any): Promise<import("axios").AxiosResponse<any, any>>;
4
5
  }
@@ -52,3 +52,67 @@ export type PDFFillOptions = {
52
52
  form_data?: Record<string, any>;
53
53
  forms?: PDFFormStructure[] | any;
54
54
  };
55
+ /**
56
+ * Supported data formats for conversion operations
57
+ */
58
+ export type DataFormat = 'json' | 'csv' | 'excel' | 'xlsx';
59
+ /**
60
+ * Parameters for data conversion between formats
61
+ */
62
+ export type DataConversionParams = {
63
+ /** Source format */
64
+ from: DataFormat;
65
+ /** Target format */
66
+ to: DataFormat;
67
+ /** Optional Excel sheet name (defaults to "Sheet1") */
68
+ sheet_name?: string;
69
+ };
70
+ /**
71
+ * Parameters for data format validation
72
+ */
73
+ export type DataValidationParams = {
74
+ /** Format to validate against */
75
+ format: DataFormat;
76
+ };
77
+ /**
78
+ * Parameters for data analysis and information extraction
79
+ */
80
+ export type DataInfoParams = {
81
+ /** Format of the data to analyze */
82
+ format: DataFormat;
83
+ };
84
+ /**
85
+ * Information about analyzed data structure and content
86
+ */
87
+ export type DataInfo = {
88
+ /** Detected or specified format */
89
+ format: string;
90
+ /** Size of data in bytes */
91
+ size_bytes: number;
92
+ /** Number of records/rows */
93
+ record_count: number;
94
+ /** Number of fields/columns */
95
+ field_count: number;
96
+ /** Array of field/column names */
97
+ fields: string[];
98
+ /** Library reference UUID */
99
+ library_ref: string;
100
+ };
101
+ /**
102
+ * Result of data format validation
103
+ */
104
+ export type DataValidationResult = {
105
+ /** Whether the data is valid for the specified format */
106
+ valid: boolean;
107
+ /** Validation message (success or error details) */
108
+ message: string;
109
+ /** Library reference UUID */
110
+ library_ref: string;
111
+ };
112
+ /**
113
+ * Optional parameters for data conversion operations
114
+ */
115
+ export type ConversionOptions = {
116
+ /** Excel sheet name for read/write operations (defaults to "Sheet1") */
117
+ sheet_name?: string;
118
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ptkl/sdk",
3
- "version": "0.9.8",
3
+ "version": "0.9.9",
4
4
  "scripts": {
5
5
  "build": "rollup -c",
6
6
  "build:monaco": "npm run build && node scripts/generate-monaco-types.cjs",