@ptkl/sdk 0.9.9 → 0.9.10

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/dist/index.cjs.js CHANGED
@@ -19180,11 +19180,7 @@ class Apps extends PlatformBaseClient {
19180
19180
  }
19181
19181
  async upload(formData) {
19182
19182
  return await this.client.post(`/v3/system/gateway/app-service/${this.appType}/upload`, formData, {
19183
- timeout: 60000,
19184
- headers: {
19185
- // set form data headers
19186
- 'Content-Type': 'multipart/form-data'
19187
- }
19183
+ timeout: 60000
19188
19184
  });
19189
19185
  }
19190
19186
  }
@@ -19643,15 +19639,38 @@ class IntegrationsBaseClient extends BaseClient {
19643
19639
  *
19644
19640
  * The DMS class includes powerful data conversion capabilities that allow you to:
19645
19641
  * - Convert between JSON, CSV, and Excel (.xlsx) formats
19642
+ * - Handle structured data with header, items, and footer sections
19643
+ * - Auto-detect structured patterns in JSON arrays
19646
19644
  * - Validate data format integrity
19647
19645
  * - Analyze data structure and metadata
19648
19646
  * - Handle large datasets with memory-efficient processing
19649
19647
  *
19650
19648
  * ### Supported Formats
19651
- * - **JSON**: Array of objects (recommended for tabular data)
19652
- * - **CSV**: Comma-separated values with headers
19649
+ * - **JSON**: Array of objects (recommended for tabular data) or structured objects
19650
+ * - **CSV**: Comma-separated values with headers and optional comments
19653
19651
  * - **Excel**: .xlsx format with optional sheet specification
19654
19652
  *
19653
+ * ### Structured Data Support
19654
+ * When converting from JSON, the API supports:
19655
+ *
19656
+ * **Explicit Structure**: JSON with dedicated sections
19657
+ * ```json
19658
+ * {
19659
+ * "header": { "content": { "title": "Report" } },
19660
+ * "items": [{ "name": "Data" }],
19661
+ * "footer": { "content": { "total": 100 } }
19662
+ * }
19663
+ * ```
19664
+ *
19665
+ * **Auto-Detection**: Mixed arrays with metadata and summary objects
19666
+ * ```json
19667
+ * [
19668
+ * { "metadata": "Header info" },
19669
+ * { "name": "John", "age": 30 },
19670
+ * { "summary": "Footer info" }
19671
+ * ]
19672
+ * ```
19673
+ *
19655
19674
  * ### Error Handling
19656
19675
  * All conversion methods may throw errors with code 3003 for conversion failures.
19657
19676
  * Always wrap calls in try-catch blocks for production use.
@@ -19667,15 +19686,20 @@ class IntegrationsBaseClient extends BaseClient {
19667
19686
  *
19668
19687
  * const libraryRef = 'your-library-uuid';
19669
19688
  *
19670
- * // Convert JSON to CSV
19671
- * const jsonData = [
19672
- * { name: "John", age: 30 },
19673
- * { name: "Jane", age: 25 }
19674
- * ];
19689
+ * // Convert structured JSON to CSV with comments
19690
+ * const structuredData = {
19691
+ * header: { content: { title: "Sales Report" } },
19692
+ * items: [{ product: "Widget", sales: 100 }],
19693
+ * footer: { content: { total: 100 } }
19694
+ * };
19675
19695
  *
19676
19696
  * try {
19677
- * const csvResult = await dms.jsonToCsv(libraryRef, jsonData);
19678
- * console.log(csvResult.data); // CSV string
19697
+ * const csvResult = await dms.convertData(libraryRef, structuredData, {
19698
+ * from: 'json',
19699
+ * to: 'csv',
19700
+ * header_as_comment: true
19701
+ * });
19702
+ * console.log(csvResult.data); // CSV with header as comments
19679
19703
  * } catch (error) {
19680
19704
  * console.error('Conversion failed:', error.message);
19681
19705
  * }
@@ -19777,18 +19801,16 @@ class DMS extends IntegrationsBaseClient {
19777
19801
  return await this.request("POST", `media/library/${lib}/dirs`, { data });
19778
19802
  }
19779
19803
  async fillPdf(lib, data) {
19780
- const { input_html, input_path, output_path, output_pdf = false, output_type, output_file_name, data: templateData, form_data, forms } = data;
19804
+ const { input_path, output_path, output_pdf = false, output_type, output_file_name, form_data, forms } = data;
19781
19805
  const responseType = output_pdf ? 'arraybuffer' : 'json';
19782
19806
  const contentType = output_pdf ? 'application/pdf' : 'application/json';
19783
19807
  return this.request('POST', `media/library/${lib}/pdf/fill`, {
19784
19808
  data: {
19785
- input_html,
19786
19809
  input_path,
19787
19810
  output_path,
19788
19811
  output_pdf,
19789
19812
  output_type,
19790
19813
  output_file_name,
19791
- data: templateData,
19792
19814
  form_data,
19793
19815
  forms
19794
19816
  },
@@ -19809,9 +19831,13 @@ class DMS extends IntegrationsBaseClient {
19809
19831
  /**
19810
19832
  * Convert data between different formats (JSON, CSV, Excel)
19811
19833
  *
19834
+ * Supports structured data when converting from JSON format with:
19835
+ * - Explicit structure: JSON with `header`, `items`, and `footer` properties
19836
+ * - Auto-detection: Mixed JSON arrays with metadata objects and summary rows
19837
+ *
19812
19838
  * @param lib - Library reference UUID
19813
19839
  * @param data - Raw data to convert
19814
- * @param params - Conversion parameters
19840
+ * @param params - Conversion parameters including structured data options
19815
19841
  * @returns Promise resolving to converted data
19816
19842
  *
19817
19843
  * @example
@@ -19828,6 +19854,32 @@ class DMS extends IntegrationsBaseClient {
19828
19854
  * });
19829
19855
  * console.log(csvResult.data); // CSV string
19830
19856
  *
19857
+ * // Convert structured JSON with header as comments
19858
+ * const structuredData = {
19859
+ * header: {
19860
+ * content: {
19861
+ * report_title: "Monthly Sales Report",
19862
+ * generated_by: "Sales System"
19863
+ * }
19864
+ * },
19865
+ * items: [
19866
+ * { product: "Widget A", sales: 100 },
19867
+ * { product: "Widget B", sales: 150 }
19868
+ * ],
19869
+ * footer: {
19870
+ * content: {
19871
+ * total_sales: 250
19872
+ * }
19873
+ * }
19874
+ * };
19875
+ *
19876
+ * const csvWithComments = await dms.convertData(libraryRef, structuredData, {
19877
+ * from: 'json',
19878
+ * to: 'csv',
19879
+ * header_as_comment: true,
19880
+ * separator_rows: 2
19881
+ * });
19882
+ *
19831
19883
  * // Convert JSON to Excel with custom sheet name
19832
19884
  * const excelResult = await dms.convertData(libraryRef, jsonData, {
19833
19885
  * from: 'json',
@@ -19838,11 +19890,21 @@ class DMS extends IntegrationsBaseClient {
19838
19890
  * ```
19839
19891
  */
19840
19892
  async convertData(lib, data, params) {
19841
- const { from, to, sheet_name } = params;
19893
+ const { from, to, sheet_name, include_header, include_footer, header_as_comment, footer_as_comment, separator_rows } = params;
19842
19894
  const queryParams = { from, to };
19843
- if (sheet_name) {
19895
+ // Add optional parameters if provided
19896
+ if (sheet_name)
19844
19897
  queryParams.sheet_name = sheet_name;
19845
- }
19898
+ if (include_header !== undefined)
19899
+ queryParams.include_header = include_header;
19900
+ if (include_footer !== undefined)
19901
+ queryParams.include_footer = include_footer;
19902
+ if (header_as_comment !== undefined)
19903
+ queryParams.header_as_comment = header_as_comment;
19904
+ if (footer_as_comment !== undefined)
19905
+ queryParams.footer_as_comment = footer_as_comment;
19906
+ if (separator_rows !== undefined)
19907
+ queryParams.separator_rows = separator_rows;
19846
19908
  // Determine content type based on target format
19847
19909
  let responseType = 'text';
19848
19910
  if (to === 'json') {
@@ -19948,12 +20010,17 @@ class DMS extends IntegrationsBaseClient {
19948
20010
  /**
19949
20011
  * Convert JSON data to CSV format
19950
20012
  *
20013
+ * This method supports both regular JSON arrays and structured data with auto-detection:
20014
+ * - Regular arrays are converted directly to CSV
20015
+ * - Structured data (with metadata objects) is automatically detected and formatted
20016
+ *
19951
20017
  * @param lib - Library reference UUID
19952
- * @param jsonData - JSON data (array of objects recommended for tabular data)
20018
+ * @param jsonData - JSON data (array of objects or structured data)
19953
20019
  * @returns Promise resolving to CSV string
19954
20020
  *
19955
20021
  * @example
19956
20022
  * ```typescript
20023
+ * // Regular JSON to CSV
19957
20024
  * const jsonData = [
19958
20025
  * { name: "John Doe", age: 30, email: "john@example.com" },
19959
20026
  * { name: "Jane Smith", age: 25, email: "jane@example.com" }
@@ -19965,6 +20032,17 @@ class DMS extends IntegrationsBaseClient {
19965
20032
  * // name,age,email
19966
20033
  * // John Doe,30,john@example.com
19967
20034
  * // Jane Smith,25,jane@example.com
20035
+ *
20036
+ * // Structured JSON with auto-detection
20037
+ * const structuredData = [
20038
+ * { metadata: "EMPLOYEE REPORT\nGenerated: 2025-10-08" },
20039
+ * { name: "John Doe", age: 30, position: "Developer" },
20040
+ * { name: "Jane Smith", age: 25, position: "Designer" },
20041
+ * { name: "Total Employees:", age: null, position: "2 people" }
20042
+ * ];
20043
+ *
20044
+ * const structuredCsv = await dms.jsonToCsv(libraryRef, structuredData);
20045
+ * // Auto-detects header, items, and footer sections
19968
20046
  * ```
19969
20047
  */
19970
20048
  async jsonToCsv(lib, jsonData) {
@@ -19979,13 +20057,17 @@ class DMS extends IntegrationsBaseClient {
19979
20057
  /**
19980
20058
  * Convert JSON data to Excel (.xlsx) format
19981
20059
  *
20060
+ * Supports both regular JSON arrays and structured data patterns.
20061
+ * Excel files are always generated with .xlsx extension.
20062
+ *
19982
20063
  * @param lib - Library reference UUID
19983
- * @param jsonData - JSON data (array of objects recommended for tabular data)
20064
+ * @param jsonData - JSON data (array of objects or structured data)
19984
20065
  * @param options - Optional conversion options
19985
20066
  * @returns Promise resolving to Excel file as Blob
19986
20067
  *
19987
20068
  * @example
19988
20069
  * ```typescript
20070
+ * // Regular JSON to Excel
19989
20071
  * const jsonData = [
19990
20072
  * { name: "John Doe", age: 30, email: "john@example.com" },
19991
20073
  * { name: "Jane Smith", age: 25, email: "jane@example.com" }
@@ -20000,11 +20082,20 @@ class DMS extends IntegrationsBaseClient {
20000
20082
  * sheet_name: 'Customer Data'
20001
20083
  * });
20002
20084
  *
20085
+ * // Structured data with explicit sections
20086
+ * const structuredData = {
20087
+ * header: { content: { title: "Monthly Report" } },
20088
+ * items: [{ product: "Widget A", sales: 100 }],
20089
+ * footer: { content: { total_sales: 100 } }
20090
+ * };
20091
+ *
20092
+ * const structuredExcel = await dms.jsonToExcel(libraryRef, structuredData);
20093
+ *
20003
20094
  * // Create download link
20004
- * const url = URL.createObjectURL(excelWithOptions.data);
20095
+ * const url = URL.createObjectURL(structuredExcel.data);
20005
20096
  * const link = document.createElement('a');
20006
20097
  * link.href = url;
20007
- * link.download = 'data.xlsx';
20098
+ * link.download = 'report.xlsx'; // Always .xlsx extension
20008
20099
  * link.click();
20009
20100
  * ```
20010
20101
  */
@@ -20178,7 +20269,7 @@ class DMS extends IntegrationsBaseClient {
20178
20269
  async request(method, endpoint, params) {
20179
20270
  return await this.client.request({
20180
20271
  method: method,
20181
- url: `/v2/dms/${endpoint}`,
20272
+ url: `/v2/${endpoint}`,
20182
20273
  ...params
20183
20274
  });
20184
20275
  }
@@ -20252,7 +20343,7 @@ class Integrations extends IntegrationsBaseClient {
20252
20343
  this.integrations = {
20253
20344
  'protokol-invoicing': new Invoicing().setClient(this.client),
20254
20345
  'protokol-vpfr': new VPFR().setClient(this.client),
20255
- 'protokol-media': new DMS().setClient(this.client),
20346
+ 'protokol-dms': new DMS().setClient(this.client),
20256
20347
  'serbia-utilities': new SerbiaUtil().setClient(this.client),
20257
20348
  'protokol-payments': new Payments().setClient(this.client),
20258
20349
  };
@@ -20261,7 +20352,7 @@ class Integrations extends IntegrationsBaseClient {
20261
20352
  return this.getInterfaceOf('serbia-utilities');
20262
20353
  }
20263
20354
  getDMS() {
20264
- return this.getInterfaceOf('protokol-media');
20355
+ return this.getInterfaceOf('protokol-dms');
20265
20356
  }
20266
20357
  getVPFR() {
20267
20358
  return this.getInterfaceOf('protokol-vpfr');
@@ -20290,12 +20381,12 @@ exports.APIUser = APIUser;
20290
20381
  exports.Apps = Apps;
20291
20382
  exports.Component = Component;
20292
20383
  exports.ComponentUtils = ComponentUtils;
20384
+ exports.DMS = DMS;
20293
20385
  exports.Forge = Forge;
20294
20386
  exports.Functions = Functions;
20295
20387
  exports.Integration = Integrations;
20296
20388
  exports.Integrations = Integrations;
20297
20389
  exports.Invoicing = Invoicing;
20298
- exports.Media = DMS;
20299
20390
  exports.Payments = Payments;
20300
20391
  exports.Ratchet = Ratchet;
20301
20392
  exports.Roles = Roles;
package/dist/index.esm.js CHANGED
@@ -211,11 +211,7 @@ class Apps extends PlatformBaseClient {
211
211
  }
212
212
  async upload(formData) {
213
213
  return await this.client.post(`/v3/system/gateway/app-service/${this.appType}/upload`, formData, {
214
- timeout: 60000,
215
- headers: {
216
- // set form data headers
217
- 'Content-Type': 'multipart/form-data'
218
- }
214
+ timeout: 60000
219
215
  });
220
216
  }
221
217
  }
@@ -674,15 +670,38 @@ class IntegrationsBaseClient extends BaseClient {
674
670
  *
675
671
  * The DMS class includes powerful data conversion capabilities that allow you to:
676
672
  * - Convert between JSON, CSV, and Excel (.xlsx) formats
673
+ * - Handle structured data with header, items, and footer sections
674
+ * - Auto-detect structured patterns in JSON arrays
677
675
  * - Validate data format integrity
678
676
  * - Analyze data structure and metadata
679
677
  * - Handle large datasets with memory-efficient processing
680
678
  *
681
679
  * ### Supported Formats
682
- * - **JSON**: Array of objects (recommended for tabular data)
683
- * - **CSV**: Comma-separated values with headers
680
+ * - **JSON**: Array of objects (recommended for tabular data) or structured objects
681
+ * - **CSV**: Comma-separated values with headers and optional comments
684
682
  * - **Excel**: .xlsx format with optional sheet specification
685
683
  *
684
+ * ### Structured Data Support
685
+ * When converting from JSON, the API supports:
686
+ *
687
+ * **Explicit Structure**: JSON with dedicated sections
688
+ * ```json
689
+ * {
690
+ * "header": { "content": { "title": "Report" } },
691
+ * "items": [{ "name": "Data" }],
692
+ * "footer": { "content": { "total": 100 } }
693
+ * }
694
+ * ```
695
+ *
696
+ * **Auto-Detection**: Mixed arrays with metadata and summary objects
697
+ * ```json
698
+ * [
699
+ * { "metadata": "Header info" },
700
+ * { "name": "John", "age": 30 },
701
+ * { "summary": "Footer info" }
702
+ * ]
703
+ * ```
704
+ *
686
705
  * ### Error Handling
687
706
  * All conversion methods may throw errors with code 3003 for conversion failures.
688
707
  * Always wrap calls in try-catch blocks for production use.
@@ -698,15 +717,20 @@ class IntegrationsBaseClient extends BaseClient {
698
717
  *
699
718
  * const libraryRef = 'your-library-uuid';
700
719
  *
701
- * // Convert JSON to CSV
702
- * const jsonData = [
703
- * { name: "John", age: 30 },
704
- * { name: "Jane", age: 25 }
705
- * ];
720
+ * // Convert structured JSON to CSV with comments
721
+ * const structuredData = {
722
+ * header: { content: { title: "Sales Report" } },
723
+ * items: [{ product: "Widget", sales: 100 }],
724
+ * footer: { content: { total: 100 } }
725
+ * };
706
726
  *
707
727
  * try {
708
- * const csvResult = await dms.jsonToCsv(libraryRef, jsonData);
709
- * console.log(csvResult.data); // CSV string
728
+ * const csvResult = await dms.convertData(libraryRef, structuredData, {
729
+ * from: 'json',
730
+ * to: 'csv',
731
+ * header_as_comment: true
732
+ * });
733
+ * console.log(csvResult.data); // CSV with header as comments
710
734
  * } catch (error) {
711
735
  * console.error('Conversion failed:', error.message);
712
736
  * }
@@ -808,18 +832,16 @@ class DMS extends IntegrationsBaseClient {
808
832
  return await this.request("POST", `media/library/${lib}/dirs`, { data });
809
833
  }
810
834
  async fillPdf(lib, data) {
811
- const { input_html, input_path, output_path, output_pdf = false, output_type, output_file_name, data: templateData, form_data, forms } = data;
835
+ const { input_path, output_path, output_pdf = false, output_type, output_file_name, form_data, forms } = data;
812
836
  const responseType = output_pdf ? 'arraybuffer' : 'json';
813
837
  const contentType = output_pdf ? 'application/pdf' : 'application/json';
814
838
  return this.request('POST', `media/library/${lib}/pdf/fill`, {
815
839
  data: {
816
- input_html,
817
840
  input_path,
818
841
  output_path,
819
842
  output_pdf,
820
843
  output_type,
821
844
  output_file_name,
822
- data: templateData,
823
845
  form_data,
824
846
  forms
825
847
  },
@@ -840,9 +862,13 @@ class DMS extends IntegrationsBaseClient {
840
862
  /**
841
863
  * Convert data between different formats (JSON, CSV, Excel)
842
864
  *
865
+ * Supports structured data when converting from JSON format with:
866
+ * - Explicit structure: JSON with `header`, `items`, and `footer` properties
867
+ * - Auto-detection: Mixed JSON arrays with metadata objects and summary rows
868
+ *
843
869
  * @param lib - Library reference UUID
844
870
  * @param data - Raw data to convert
845
- * @param params - Conversion parameters
871
+ * @param params - Conversion parameters including structured data options
846
872
  * @returns Promise resolving to converted data
847
873
  *
848
874
  * @example
@@ -859,6 +885,32 @@ class DMS extends IntegrationsBaseClient {
859
885
  * });
860
886
  * console.log(csvResult.data); // CSV string
861
887
  *
888
+ * // Convert structured JSON with header as comments
889
+ * const structuredData = {
890
+ * header: {
891
+ * content: {
892
+ * report_title: "Monthly Sales Report",
893
+ * generated_by: "Sales System"
894
+ * }
895
+ * },
896
+ * items: [
897
+ * { product: "Widget A", sales: 100 },
898
+ * { product: "Widget B", sales: 150 }
899
+ * ],
900
+ * footer: {
901
+ * content: {
902
+ * total_sales: 250
903
+ * }
904
+ * }
905
+ * };
906
+ *
907
+ * const csvWithComments = await dms.convertData(libraryRef, structuredData, {
908
+ * from: 'json',
909
+ * to: 'csv',
910
+ * header_as_comment: true,
911
+ * separator_rows: 2
912
+ * });
913
+ *
862
914
  * // Convert JSON to Excel with custom sheet name
863
915
  * const excelResult = await dms.convertData(libraryRef, jsonData, {
864
916
  * from: 'json',
@@ -869,11 +921,21 @@ class DMS extends IntegrationsBaseClient {
869
921
  * ```
870
922
  */
871
923
  async convertData(lib, data, params) {
872
- const { from, to, sheet_name } = params;
924
+ const { from, to, sheet_name, include_header, include_footer, header_as_comment, footer_as_comment, separator_rows } = params;
873
925
  const queryParams = { from, to };
874
- if (sheet_name) {
926
+ // Add optional parameters if provided
927
+ if (sheet_name)
875
928
  queryParams.sheet_name = sheet_name;
876
- }
929
+ if (include_header !== undefined)
930
+ queryParams.include_header = include_header;
931
+ if (include_footer !== undefined)
932
+ queryParams.include_footer = include_footer;
933
+ if (header_as_comment !== undefined)
934
+ queryParams.header_as_comment = header_as_comment;
935
+ if (footer_as_comment !== undefined)
936
+ queryParams.footer_as_comment = footer_as_comment;
937
+ if (separator_rows !== undefined)
938
+ queryParams.separator_rows = separator_rows;
877
939
  // Determine content type based on target format
878
940
  let responseType = 'text';
879
941
  if (to === 'json') {
@@ -979,12 +1041,17 @@ class DMS extends IntegrationsBaseClient {
979
1041
  /**
980
1042
  * Convert JSON data to CSV format
981
1043
  *
1044
+ * This method supports both regular JSON arrays and structured data with auto-detection:
1045
+ * - Regular arrays are converted directly to CSV
1046
+ * - Structured data (with metadata objects) is automatically detected and formatted
1047
+ *
982
1048
  * @param lib - Library reference UUID
983
- * @param jsonData - JSON data (array of objects recommended for tabular data)
1049
+ * @param jsonData - JSON data (array of objects or structured data)
984
1050
  * @returns Promise resolving to CSV string
985
1051
  *
986
1052
  * @example
987
1053
  * ```typescript
1054
+ * // Regular JSON to CSV
988
1055
  * const jsonData = [
989
1056
  * { name: "John Doe", age: 30, email: "john@example.com" },
990
1057
  * { name: "Jane Smith", age: 25, email: "jane@example.com" }
@@ -996,6 +1063,17 @@ class DMS extends IntegrationsBaseClient {
996
1063
  * // name,age,email
997
1064
  * // John Doe,30,john@example.com
998
1065
  * // Jane Smith,25,jane@example.com
1066
+ *
1067
+ * // Structured JSON with auto-detection
1068
+ * const structuredData = [
1069
+ * { metadata: "EMPLOYEE REPORT\nGenerated: 2025-10-08" },
1070
+ * { name: "John Doe", age: 30, position: "Developer" },
1071
+ * { name: "Jane Smith", age: 25, position: "Designer" },
1072
+ * { name: "Total Employees:", age: null, position: "2 people" }
1073
+ * ];
1074
+ *
1075
+ * const structuredCsv = await dms.jsonToCsv(libraryRef, structuredData);
1076
+ * // Auto-detects header, items, and footer sections
999
1077
  * ```
1000
1078
  */
1001
1079
  async jsonToCsv(lib, jsonData) {
@@ -1010,13 +1088,17 @@ class DMS extends IntegrationsBaseClient {
1010
1088
  /**
1011
1089
  * Convert JSON data to Excel (.xlsx) format
1012
1090
  *
1091
+ * Supports both regular JSON arrays and structured data patterns.
1092
+ * Excel files are always generated with .xlsx extension.
1093
+ *
1013
1094
  * @param lib - Library reference UUID
1014
- * @param jsonData - JSON data (array of objects recommended for tabular data)
1095
+ * @param jsonData - JSON data (array of objects or structured data)
1015
1096
  * @param options - Optional conversion options
1016
1097
  * @returns Promise resolving to Excel file as Blob
1017
1098
  *
1018
1099
  * @example
1019
1100
  * ```typescript
1101
+ * // Regular JSON to Excel
1020
1102
  * const jsonData = [
1021
1103
  * { name: "John Doe", age: 30, email: "john@example.com" },
1022
1104
  * { name: "Jane Smith", age: 25, email: "jane@example.com" }
@@ -1031,11 +1113,20 @@ class DMS extends IntegrationsBaseClient {
1031
1113
  * sheet_name: 'Customer Data'
1032
1114
  * });
1033
1115
  *
1116
+ * // Structured data with explicit sections
1117
+ * const structuredData = {
1118
+ * header: { content: { title: "Monthly Report" } },
1119
+ * items: [{ product: "Widget A", sales: 100 }],
1120
+ * footer: { content: { total_sales: 100 } }
1121
+ * };
1122
+ *
1123
+ * const structuredExcel = await dms.jsonToExcel(libraryRef, structuredData);
1124
+ *
1034
1125
  * // Create download link
1035
- * const url = URL.createObjectURL(excelWithOptions.data);
1126
+ * const url = URL.createObjectURL(structuredExcel.data);
1036
1127
  * const link = document.createElement('a');
1037
1128
  * link.href = url;
1038
- * link.download = 'data.xlsx';
1129
+ * link.download = 'report.xlsx'; // Always .xlsx extension
1039
1130
  * link.click();
1040
1131
  * ```
1041
1132
  */
@@ -1209,7 +1300,7 @@ class DMS extends IntegrationsBaseClient {
1209
1300
  async request(method, endpoint, params) {
1210
1301
  return await this.client.request({
1211
1302
  method: method,
1212
- url: `/v2/dms/${endpoint}`,
1303
+ url: `/v2/${endpoint}`,
1213
1304
  ...params
1214
1305
  });
1215
1306
  }
@@ -1283,7 +1374,7 @@ class Integrations extends IntegrationsBaseClient {
1283
1374
  this.integrations = {
1284
1375
  'protokol-invoicing': new Invoicing().setClient(this.client),
1285
1376
  'protokol-vpfr': new VPFR().setClient(this.client),
1286
- 'protokol-media': new DMS().setClient(this.client),
1377
+ 'protokol-dms': new DMS().setClient(this.client),
1287
1378
  'serbia-utilities': new SerbiaUtil().setClient(this.client),
1288
1379
  'protokol-payments': new Payments().setClient(this.client),
1289
1380
  };
@@ -1292,7 +1383,7 @@ class Integrations extends IntegrationsBaseClient {
1292
1383
  return this.getInterfaceOf('serbia-utilities');
1293
1384
  }
1294
1385
  getDMS() {
1295
- return this.getInterfaceOf('protokol-media');
1386
+ return this.getInterfaceOf('protokol-dms');
1296
1387
  }
1297
1388
  getVPFR() {
1298
1389
  return this.getInterfaceOf('protokol-vpfr');
@@ -1317,4 +1408,4 @@ class Integrations extends IntegrationsBaseClient {
1317
1408
  }
1318
1409
  }
1319
1410
 
1320
- export { APIUser, Apps, Component, ComponentUtils, Forge, Functions, Integrations as Integration, Integrations, Invoicing, DMS as Media, Payments, Ratchet, Roles, Sandbox, SerbiaUtil, System, Thunder, Users as User, VPFR, Workflow, Platform as default };
1411
+ export { APIUser, Apps, Component, ComponentUtils, DMS, Forge, Functions, Integrations as Integration, Integrations, Invoicing, Payments, Ratchet, Roles, Sandbox, SerbiaUtil, System, Thunder, Users as User, VPFR, Workflow, Platform as default };
@@ -212,11 +212,7 @@ var ProtokolSDK09 = (function (exports, axios) {
212
212
  }
213
213
  async upload(formData) {
214
214
  return await this.client.post(`/v3/system/gateway/app-service/${this.appType}/upload`, formData, {
215
- timeout: 60000,
216
- headers: {
217
- // set form data headers
218
- 'Content-Type': 'multipart/form-data'
219
- }
215
+ timeout: 60000
220
216
  });
221
217
  }
222
218
  }
@@ -675,15 +671,38 @@ var ProtokolSDK09 = (function (exports, axios) {
675
671
  *
676
672
  * The DMS class includes powerful data conversion capabilities that allow you to:
677
673
  * - Convert between JSON, CSV, and Excel (.xlsx) formats
674
+ * - Handle structured data with header, items, and footer sections
675
+ * - Auto-detect structured patterns in JSON arrays
678
676
  * - Validate data format integrity
679
677
  * - Analyze data structure and metadata
680
678
  * - Handle large datasets with memory-efficient processing
681
679
  *
682
680
  * ### Supported Formats
683
- * - **JSON**: Array of objects (recommended for tabular data)
684
- * - **CSV**: Comma-separated values with headers
681
+ * - **JSON**: Array of objects (recommended for tabular data) or structured objects
682
+ * - **CSV**: Comma-separated values with headers and optional comments
685
683
  * - **Excel**: .xlsx format with optional sheet specification
686
684
  *
685
+ * ### Structured Data Support
686
+ * When converting from JSON, the API supports:
687
+ *
688
+ * **Explicit Structure**: JSON with dedicated sections
689
+ * ```json
690
+ * {
691
+ * "header": { "content": { "title": "Report" } },
692
+ * "items": [{ "name": "Data" }],
693
+ * "footer": { "content": { "total": 100 } }
694
+ * }
695
+ * ```
696
+ *
697
+ * **Auto-Detection**: Mixed arrays with metadata and summary objects
698
+ * ```json
699
+ * [
700
+ * { "metadata": "Header info" },
701
+ * { "name": "John", "age": 30 },
702
+ * { "summary": "Footer info" }
703
+ * ]
704
+ * ```
705
+ *
687
706
  * ### Error Handling
688
707
  * All conversion methods may throw errors with code 3003 for conversion failures.
689
708
  * Always wrap calls in try-catch blocks for production use.
@@ -699,15 +718,20 @@ var ProtokolSDK09 = (function (exports, axios) {
699
718
  *
700
719
  * const libraryRef = 'your-library-uuid';
701
720
  *
702
- * // Convert JSON to CSV
703
- * const jsonData = [
704
- * { name: "John", age: 30 },
705
- * { name: "Jane", age: 25 }
706
- * ];
721
+ * // Convert structured JSON to CSV with comments
722
+ * const structuredData = {
723
+ * header: { content: { title: "Sales Report" } },
724
+ * items: [{ product: "Widget", sales: 100 }],
725
+ * footer: { content: { total: 100 } }
726
+ * };
707
727
  *
708
728
  * try {
709
- * const csvResult = await dms.jsonToCsv(libraryRef, jsonData);
710
- * console.log(csvResult.data); // CSV string
729
+ * const csvResult = await dms.convertData(libraryRef, structuredData, {
730
+ * from: 'json',
731
+ * to: 'csv',
732
+ * header_as_comment: true
733
+ * });
734
+ * console.log(csvResult.data); // CSV with header as comments
711
735
  * } catch (error) {
712
736
  * console.error('Conversion failed:', error.message);
713
737
  * }
@@ -809,18 +833,16 @@ var ProtokolSDK09 = (function (exports, axios) {
809
833
  return await this.request("POST", `media/library/${lib}/dirs`, { data });
810
834
  }
811
835
  async fillPdf(lib, data) {
812
- const { input_html, input_path, output_path, output_pdf = false, output_type, output_file_name, data: templateData, form_data, forms } = data;
836
+ const { input_path, output_path, output_pdf = false, output_type, output_file_name, form_data, forms } = data;
813
837
  const responseType = output_pdf ? 'arraybuffer' : 'json';
814
838
  const contentType = output_pdf ? 'application/pdf' : 'application/json';
815
839
  return this.request('POST', `media/library/${lib}/pdf/fill`, {
816
840
  data: {
817
- input_html,
818
841
  input_path,
819
842
  output_path,
820
843
  output_pdf,
821
844
  output_type,
822
845
  output_file_name,
823
- data: templateData,
824
846
  form_data,
825
847
  forms
826
848
  },
@@ -841,9 +863,13 @@ var ProtokolSDK09 = (function (exports, axios) {
841
863
  /**
842
864
  * Convert data between different formats (JSON, CSV, Excel)
843
865
  *
866
+ * Supports structured data when converting from JSON format with:
867
+ * - Explicit structure: JSON with `header`, `items`, and `footer` properties
868
+ * - Auto-detection: Mixed JSON arrays with metadata objects and summary rows
869
+ *
844
870
  * @param lib - Library reference UUID
845
871
  * @param data - Raw data to convert
846
- * @param params - Conversion parameters
872
+ * @param params - Conversion parameters including structured data options
847
873
  * @returns Promise resolving to converted data
848
874
  *
849
875
  * @example
@@ -860,6 +886,32 @@ var ProtokolSDK09 = (function (exports, axios) {
860
886
  * });
861
887
  * console.log(csvResult.data); // CSV string
862
888
  *
889
+ * // Convert structured JSON with header as comments
890
+ * const structuredData = {
891
+ * header: {
892
+ * content: {
893
+ * report_title: "Monthly Sales Report",
894
+ * generated_by: "Sales System"
895
+ * }
896
+ * },
897
+ * items: [
898
+ * { product: "Widget A", sales: 100 },
899
+ * { product: "Widget B", sales: 150 }
900
+ * ],
901
+ * footer: {
902
+ * content: {
903
+ * total_sales: 250
904
+ * }
905
+ * }
906
+ * };
907
+ *
908
+ * const csvWithComments = await dms.convertData(libraryRef, structuredData, {
909
+ * from: 'json',
910
+ * to: 'csv',
911
+ * header_as_comment: true,
912
+ * separator_rows: 2
913
+ * });
914
+ *
863
915
  * // Convert JSON to Excel with custom sheet name
864
916
  * const excelResult = await dms.convertData(libraryRef, jsonData, {
865
917
  * from: 'json',
@@ -870,11 +922,21 @@ var ProtokolSDK09 = (function (exports, axios) {
870
922
  * ```
871
923
  */
872
924
  async convertData(lib, data, params) {
873
- const { from, to, sheet_name } = params;
925
+ const { from, to, sheet_name, include_header, include_footer, header_as_comment, footer_as_comment, separator_rows } = params;
874
926
  const queryParams = { from, to };
875
- if (sheet_name) {
927
+ // Add optional parameters if provided
928
+ if (sheet_name)
876
929
  queryParams.sheet_name = sheet_name;
877
- }
930
+ if (include_header !== undefined)
931
+ queryParams.include_header = include_header;
932
+ if (include_footer !== undefined)
933
+ queryParams.include_footer = include_footer;
934
+ if (header_as_comment !== undefined)
935
+ queryParams.header_as_comment = header_as_comment;
936
+ if (footer_as_comment !== undefined)
937
+ queryParams.footer_as_comment = footer_as_comment;
938
+ if (separator_rows !== undefined)
939
+ queryParams.separator_rows = separator_rows;
878
940
  // Determine content type based on target format
879
941
  let responseType = 'text';
880
942
  if (to === 'json') {
@@ -980,12 +1042,17 @@ var ProtokolSDK09 = (function (exports, axios) {
980
1042
  /**
981
1043
  * Convert JSON data to CSV format
982
1044
  *
1045
+ * This method supports both regular JSON arrays and structured data with auto-detection:
1046
+ * - Regular arrays are converted directly to CSV
1047
+ * - Structured data (with metadata objects) is automatically detected and formatted
1048
+ *
983
1049
  * @param lib - Library reference UUID
984
- * @param jsonData - JSON data (array of objects recommended for tabular data)
1050
+ * @param jsonData - JSON data (array of objects or structured data)
985
1051
  * @returns Promise resolving to CSV string
986
1052
  *
987
1053
  * @example
988
1054
  * ```typescript
1055
+ * // Regular JSON to CSV
989
1056
  * const jsonData = [
990
1057
  * { name: "John Doe", age: 30, email: "john@example.com" },
991
1058
  * { name: "Jane Smith", age: 25, email: "jane@example.com" }
@@ -997,6 +1064,17 @@ var ProtokolSDK09 = (function (exports, axios) {
997
1064
  * // name,age,email
998
1065
  * // John Doe,30,john@example.com
999
1066
  * // Jane Smith,25,jane@example.com
1067
+ *
1068
+ * // Structured JSON with auto-detection
1069
+ * const structuredData = [
1070
+ * { metadata: "EMPLOYEE REPORT\nGenerated: 2025-10-08" },
1071
+ * { name: "John Doe", age: 30, position: "Developer" },
1072
+ * { name: "Jane Smith", age: 25, position: "Designer" },
1073
+ * { name: "Total Employees:", age: null, position: "2 people" }
1074
+ * ];
1075
+ *
1076
+ * const structuredCsv = await dms.jsonToCsv(libraryRef, structuredData);
1077
+ * // Auto-detects header, items, and footer sections
1000
1078
  * ```
1001
1079
  */
1002
1080
  async jsonToCsv(lib, jsonData) {
@@ -1011,13 +1089,17 @@ var ProtokolSDK09 = (function (exports, axios) {
1011
1089
  /**
1012
1090
  * Convert JSON data to Excel (.xlsx) format
1013
1091
  *
1092
+ * Supports both regular JSON arrays and structured data patterns.
1093
+ * Excel files are always generated with .xlsx extension.
1094
+ *
1014
1095
  * @param lib - Library reference UUID
1015
- * @param jsonData - JSON data (array of objects recommended for tabular data)
1096
+ * @param jsonData - JSON data (array of objects or structured data)
1016
1097
  * @param options - Optional conversion options
1017
1098
  * @returns Promise resolving to Excel file as Blob
1018
1099
  *
1019
1100
  * @example
1020
1101
  * ```typescript
1102
+ * // Regular JSON to Excel
1021
1103
  * const jsonData = [
1022
1104
  * { name: "John Doe", age: 30, email: "john@example.com" },
1023
1105
  * { name: "Jane Smith", age: 25, email: "jane@example.com" }
@@ -1032,11 +1114,20 @@ var ProtokolSDK09 = (function (exports, axios) {
1032
1114
  * sheet_name: 'Customer Data'
1033
1115
  * });
1034
1116
  *
1117
+ * // Structured data with explicit sections
1118
+ * const structuredData = {
1119
+ * header: { content: { title: "Monthly Report" } },
1120
+ * items: [{ product: "Widget A", sales: 100 }],
1121
+ * footer: { content: { total_sales: 100 } }
1122
+ * };
1123
+ *
1124
+ * const structuredExcel = await dms.jsonToExcel(libraryRef, structuredData);
1125
+ *
1035
1126
  * // Create download link
1036
- * const url = URL.createObjectURL(excelWithOptions.data);
1127
+ * const url = URL.createObjectURL(structuredExcel.data);
1037
1128
  * const link = document.createElement('a');
1038
1129
  * link.href = url;
1039
- * link.download = 'data.xlsx';
1130
+ * link.download = 'report.xlsx'; // Always .xlsx extension
1040
1131
  * link.click();
1041
1132
  * ```
1042
1133
  */
@@ -1210,7 +1301,7 @@ var ProtokolSDK09 = (function (exports, axios) {
1210
1301
  async request(method, endpoint, params) {
1211
1302
  return await this.client.request({
1212
1303
  method: method,
1213
- url: `/v2/dms/${endpoint}`,
1304
+ url: `/v2/${endpoint}`,
1214
1305
  ...params
1215
1306
  });
1216
1307
  }
@@ -1284,7 +1375,7 @@ var ProtokolSDK09 = (function (exports, axios) {
1284
1375
  this.integrations = {
1285
1376
  'protokol-invoicing': new Invoicing().setClient(this.client),
1286
1377
  'protokol-vpfr': new VPFR().setClient(this.client),
1287
- 'protokol-media': new DMS().setClient(this.client),
1378
+ 'protokol-dms': new DMS().setClient(this.client),
1288
1379
  'serbia-utilities': new SerbiaUtil().setClient(this.client),
1289
1380
  'protokol-payments': new Payments().setClient(this.client),
1290
1381
  };
@@ -1293,7 +1384,7 @@ var ProtokolSDK09 = (function (exports, axios) {
1293
1384
  return this.getInterfaceOf('serbia-utilities');
1294
1385
  }
1295
1386
  getDMS() {
1296
- return this.getInterfaceOf('protokol-media');
1387
+ return this.getInterfaceOf('protokol-dms');
1297
1388
  }
1298
1389
  getVPFR() {
1299
1390
  return this.getInterfaceOf('protokol-vpfr');
@@ -1322,12 +1413,12 @@ var ProtokolSDK09 = (function (exports, axios) {
1322
1413
  exports.Apps = Apps;
1323
1414
  exports.Component = Component;
1324
1415
  exports.ComponentUtils = ComponentUtils;
1416
+ exports.DMS = DMS;
1325
1417
  exports.Forge = Forge;
1326
1418
  exports.Functions = Functions;
1327
1419
  exports.Integration = Integrations;
1328
1420
  exports.Integrations = Integrations;
1329
1421
  exports.Invoicing = Invoicing;
1330
- exports.Media = DMS;
1331
1422
  exports.Payments = Payments;
1332
1423
  exports.Ratchet = Ratchet;
1333
1424
  exports.Roles = Roles;
package/dist/monaco.d.ts CHANGED
@@ -1,3 +1,31 @@
1
+ declare module "@ptkl/sdk" {
2
+ import Platform from './api/platform';
3
+ export { default as Component } from './api/component';
4
+ export { default as Integration } from './api/integrations';
5
+ export { default as Ratchet } from './api/ratchet';
6
+ export { default as Sandbox } from './api/sandbox';
7
+ export { default as System } from './api/system';
8
+ export { default as User } from './api/users';
9
+ export { default as Functions } from './api/functions';
10
+ export { default as APIUser } from './api/apiUser';
11
+ export { default as Roles } from './api/roles';
12
+ export { default as Apps } from './api/apps';
13
+ export { default as Workflow } from './api/workflow';
14
+ export { default as ComponentUtils } from './api/componentUtils';
15
+ export { default as Thunder } from './api/thunder';
16
+ export { default as Forge } from './api/forge';
17
+ export { default as Integrations } from './api/integrations';
18
+ export { default as Payments } from './api/integrations/payments';
19
+ export { default as Invoicing } from './api/integrations/invoicing';
20
+ export { default as DMS } from './api/integrations/dms';
21
+ export { default as SerbiaUtil } from './api/integrations/serbiaUtil';
22
+ export { default as VPFR } from './api/integrations/vpfr';
23
+ export type * from './types/component';
24
+ export type * from './types/integrations';
25
+ export type * from './types/users';
26
+ export default Platform;
27
+
28
+ }
1
29
 
2
30
  // Type definitions
3
31
  declare type FindParams = {
@@ -111,17 +139,106 @@ declare type PDFFormStructure = {
111
139
  declare type PDFOutputType = 'pdf' | 'base64' | 'file';
112
140
 
113
141
  declare type PDFFillOptions = {
114
- input_html?: string;
115
142
  input_path?: string;
116
143
  output_path?: string;
117
144
  output_pdf?: boolean;
118
145
  output_type?: PDFOutputType;
119
146
  output_file_name?: string;
120
- data?: Record<string, any>;
121
147
  form_data?: Record<string, any>;
122
148
  forms?: PDFFormStructure[] | any;
123
149
  };
124
150
 
151
+ declare type HTML2PDFOptions = {
152
+ input_html?: string;
153
+ input_path?: string;
154
+ output_path?: string;
155
+ output_pdf?: boolean;
156
+ output_type?: PDFOutputType;
157
+ output_file_name?: string;
158
+ data?: Record<string, any>;
159
+ };
160
+
161
+ /**
162
+ * Supported data formats for conversion operations
163
+ */
164
+ declare type DataFormat = 'json' | 'csv' | 'excel' | 'xlsx';
165
+
166
+ /**
167
+ * Parameters for data conversion between formats
168
+ */
169
+ declare type DataConversionParams = {
170
+ /** Source format */
171
+ from: DataFormat;
172
+ /** Target format */
173
+ to: DataFormat;
174
+ /** Optional Excel sheet name (defaults to "Sheet1") */
175
+ sheet_name?: string;
176
+ /** Include header section in output (default: true) */
177
+ include_header?: boolean;
178
+ /** Include footer section in output (default: true) */
179
+ include_footer?: boolean;
180
+ /** Render header as comments in CSV (default: false) */
181
+ header_as_comment?: boolean;
182
+ /** Render footer as comments in CSV (default: false) */
183
+ footer_as_comment?: boolean;
184
+ /** Empty rows between sections (default: 1) */
185
+ separator_rows?: number;
186
+ };
187
+
188
+ /**
189
+ * Parameters for data format validation
190
+ */
191
+ declare type DataValidationParams = {
192
+ /** Format to validate against */
193
+ format: DataFormat;
194
+ };
195
+
196
+ /**
197
+ * Parameters for data analysis and information extraction
198
+ */
199
+ declare type DataInfoParams = {
200
+ /** Format of the data to analyze */
201
+ format: DataFormat;
202
+ };
203
+
204
+ /**
205
+ * Information about analyzed data structure and content
206
+ */
207
+ declare type DataInfo = {
208
+ /** Detected or specified format */
209
+ format: string;
210
+ /** Size of data in bytes */
211
+ size_bytes: number;
212
+ /** Number of records/rows */
213
+ record_count: number;
214
+ /** Number of fields/columns */
215
+ field_count: number;
216
+ /** Array of field/column names */
217
+ fields: string[];
218
+ /** Library reference UUID */
219
+ library_ref: string;
220
+ };
221
+
222
+ /**
223
+ * Result of data format validation
224
+ */
225
+ declare type DataValidationResult = {
226
+ /** Whether the data is valid for the specified format */
227
+ valid: boolean;
228
+ /** Validation message (success or error details) */
229
+ message: string;
230
+ /** Library reference UUID */
231
+ library_ref: string;
232
+ };
233
+
234
+ /**
235
+ * Optional parameters for data conversion operations
236
+ */
237
+ declare type ConversionOptions = {
238
+ /** Excel sheet name for read/write operations (defaults to "Sheet1") */
239
+ sheet_name?: string;
240
+ };
241
+
125
242
  declare interface UserModel {
126
243
  uuid: string;
127
244
  name: string;
@@ -215,11 +332,20 @@ declare class DMSConstructor extends IntegrationsBaseClientConstructor {
215
332
  getMedia(lib: string, key: string, encoding: string): Promise<any>;
216
333
  download(lib: string, key: string): Promise<any>;
217
334
  getExifData(lib: string, key: string): Promise<any>;
218
- html2pdf(lib: string, data: any): Promise<any>;
335
+ html2pdf(lib: string, data: HTML2PDFOptions): Promise<any>;
219
336
  createDir(lib: string, path: string): Promise<any>;
220
337
  deleteDir(lib: string, path: string): Promise<any>;
221
338
  dirs(lib: string, data: string): Promise<any>;
222
339
  fillPdf(lib: string, data: PDFFillOptions): Promise<any>;
340
+ convertData(lib: string, data: any, params: DataConversionParams): Promise<any>;
341
+ getDataInfo(lib: string, data: any, params: DataInfoParams): Promise<any>;
342
+ validateData(lib: string, data: any, params: DataValidationParams): Promise<any>;
343
+ jsonToCsv(lib: string, jsonData: any): Promise<any>;
344
+ jsonToExcel(lib: string, jsonData: any, options?: ConversionOptions): Promise<any>;
345
+ csvToJson(lib: string, csvData: string): Promise<any>;
346
+ csvToExcel(lib: string, csvData: string, options?: ConversionOptions): Promise<any>;
347
+ excelToJson(lib: string, excelData: Blob | ArrayBuffer, options?: ConversionOptions): Promise<any>;
348
+ excelToCsv(lib: string, excelData: Blob | ArrayBuffer, options?: ConversionOptions): Promise<any>;
223
349
  request(method: string, endpoint: string, params?: any): Promise<any>;
224
350
  requestv1(method: string, endpoint: string, params?: any): Promise<any>;
225
351
  }
@@ -393,6 +519,7 @@ declare class VPFRConstructor extends IntegrationsBaseClientConstructor {
393
519
  declare class WorkflowConstructor extends PlatformBaseClientConstructor {
394
520
  constructor();
395
521
  trigger(id: string, event: string, data: any): Promise<any>;
522
+ publish(event: string, data: any): Promise<any>;
396
523
  }
397
524
 
398
525
  interface ProtokolSDK {
@@ -411,7 +538,7 @@ interface ProtokolSDK {
411
538
  Integrations: typeof IntegrationsConstructor;
412
539
  Payments: typeof PaymentsConstructor;
413
540
  Invoicing: typeof InvoicingConstructor;
414
- Media: typeof MediaConstructor;
541
+ DMS: typeof DMSConstructor;
415
542
  SerbiaUtil: typeof SerbiaUtilConstructor;
416
543
  VPFR: typeof VPFRConstructor;
417
544
  }
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ptkl/sdk",
3
- "version": "0.9.8",
3
+ "version": "0.9.10",
4
4
  "scripts": {
5
5
  "build": "rollup -c",
6
6
  "build:monaco": "npm run build && node scripts/generate-monaco-types.cjs",
@@ -1,6 +1,6 @@
1
1
  import IntegrationsBaseClient from "../integrationsBaseClient";
2
2
  import { AxiosResponse } from "axios";
3
- import { PDFFillOptions, DataConversionParams, DataValidationParams, DataInfoParams, DataInfo, DataValidationResult, ConversionOptions } from "../../types/integrations";
3
+ import { PDFFillOptions, DataConversionParams, DataValidationParams, DataInfoParams, DataInfo, DataValidationResult, ConversionOptions, HTML2PDFOptions } from "../../types/integrations";
4
4
  /**
5
5
  * Document Management System (DMS) API client
6
6
  *
@@ -14,15 +14,38 @@ import { PDFFillOptions, DataConversionParams, DataValidationParams, DataInfoPar
14
14
  *
15
15
  * The DMS class includes powerful data conversion capabilities that allow you to:
16
16
  * - Convert between JSON, CSV, and Excel (.xlsx) formats
17
+ * - Handle structured data with header, items, and footer sections
18
+ * - Auto-detect structured patterns in JSON arrays
17
19
  * - Validate data format integrity
18
20
  * - Analyze data structure and metadata
19
21
  * - Handle large datasets with memory-efficient processing
20
22
  *
21
23
  * ### Supported Formats
22
- * - **JSON**: Array of objects (recommended for tabular data)
23
- * - **CSV**: Comma-separated values with headers
24
+ * - **JSON**: Array of objects (recommended for tabular data) or structured objects
25
+ * - **CSV**: Comma-separated values with headers and optional comments
24
26
  * - **Excel**: .xlsx format with optional sheet specification
25
27
  *
28
+ * ### Structured Data Support
29
+ * When converting from JSON, the API supports:
30
+ *
31
+ * **Explicit Structure**: JSON with dedicated sections
32
+ * ```json
33
+ * {
34
+ * "header": { "content": { "title": "Report" } },
35
+ * "items": [{ "name": "Data" }],
36
+ * "footer": { "content": { "total": 100 } }
37
+ * }
38
+ * ```
39
+ *
40
+ * **Auto-Detection**: Mixed arrays with metadata and summary objects
41
+ * ```json
42
+ * [
43
+ * { "metadata": "Header info" },
44
+ * { "name": "John", "age": 30 },
45
+ * { "summary": "Footer info" }
46
+ * ]
47
+ * ```
48
+ *
26
49
  * ### Error Handling
27
50
  * All conversion methods may throw errors with code 3003 for conversion failures.
28
51
  * Always wrap calls in try-catch blocks for production use.
@@ -38,15 +61,20 @@ import { PDFFillOptions, DataConversionParams, DataValidationParams, DataInfoPar
38
61
  *
39
62
  * const libraryRef = 'your-library-uuid';
40
63
  *
41
- * // Convert JSON to CSV
42
- * const jsonData = [
43
- * { name: "John", age: 30 },
44
- * { name: "Jane", age: 25 }
45
- * ];
64
+ * // Convert structured JSON to CSV with comments
65
+ * const structuredData = {
66
+ * header: { content: { title: "Sales Report" } },
67
+ * items: [{ product: "Widget", sales: 100 }],
68
+ * footer: { content: { total: 100 } }
69
+ * };
46
70
  *
47
71
  * try {
48
- * const csvResult = await dms.jsonToCsv(libraryRef, jsonData);
49
- * console.log(csvResult.data); // CSV string
72
+ * const csvResult = await dms.convertData(libraryRef, structuredData, {
73
+ * from: 'json',
74
+ * to: 'csv',
75
+ * header_as_comment: true
76
+ * });
77
+ * console.log(csvResult.data); // CSV with header as comments
50
78
  * } catch (error) {
51
79
  * console.error('Conversion failed:', error.message);
52
80
  * }
@@ -61,7 +89,7 @@ export default class DMS extends IntegrationsBaseClient {
61
89
  getMedia(lib: string, key: string, encoding: string): Promise<AxiosResponse<any, any>>;
62
90
  download(lib: string, key: string): Promise<AxiosResponse<any, any>>;
63
91
  getExifData(lib: string, key: string): Promise<AxiosResponse<any, any>>;
64
- html2pdf(lib: string, data: any): Promise<AxiosResponse<any, any>>;
92
+ html2pdf(lib: string, data: HTML2PDFOptions): Promise<AxiosResponse<any, any>>;
65
93
  createDir(lib: string, path: string): Promise<AxiosResponse<any, any>>;
66
94
  deleteDir(lib: string, path: string): Promise<AxiosResponse<any, any>>;
67
95
  dirs(lib: string, data: string): Promise<AxiosResponse<any, any>>;
@@ -69,9 +97,13 @@ export default class DMS extends IntegrationsBaseClient {
69
97
  /**
70
98
  * Convert data between different formats (JSON, CSV, Excel)
71
99
  *
100
+ * Supports structured data when converting from JSON format with:
101
+ * - Explicit structure: JSON with `header`, `items`, and `footer` properties
102
+ * - Auto-detection: Mixed JSON arrays with metadata objects and summary rows
103
+ *
72
104
  * @param lib - Library reference UUID
73
105
  * @param data - Raw data to convert
74
- * @param params - Conversion parameters
106
+ * @param params - Conversion parameters including structured data options
75
107
  * @returns Promise resolving to converted data
76
108
  *
77
109
  * @example
@@ -88,6 +120,32 @@ export default class DMS extends IntegrationsBaseClient {
88
120
  * });
89
121
  * console.log(csvResult.data); // CSV string
90
122
  *
123
+ * // Convert structured JSON with header as comments
124
+ * const structuredData = {
125
+ * header: {
126
+ * content: {
127
+ * report_title: "Monthly Sales Report",
128
+ * generated_by: "Sales System"
129
+ * }
130
+ * },
131
+ * items: [
132
+ * { product: "Widget A", sales: 100 },
133
+ * { product: "Widget B", sales: 150 }
134
+ * ],
135
+ * footer: {
136
+ * content: {
137
+ * total_sales: 250
138
+ * }
139
+ * }
140
+ * };
141
+ *
142
+ * const csvWithComments = await dms.convertData(libraryRef, structuredData, {
143
+ * from: 'json',
144
+ * to: 'csv',
145
+ * header_as_comment: true,
146
+ * separator_rows: 2
147
+ * });
148
+ *
91
149
  * // Convert JSON to Excel with custom sheet name
92
150
  * const excelResult = await dms.convertData(libraryRef, jsonData, {
93
151
  * from: 'json',
@@ -168,12 +226,17 @@ export default class DMS extends IntegrationsBaseClient {
168
226
  /**
169
227
  * Convert JSON data to CSV format
170
228
  *
229
+ * This method supports both regular JSON arrays and structured data with auto-detection:
230
+ * - Regular arrays are converted directly to CSV
231
+ * - Structured data (with metadata objects) is automatically detected and formatted
232
+ *
171
233
  * @param lib - Library reference UUID
172
- * @param jsonData - JSON data (array of objects recommended for tabular data)
234
+ * @param jsonData - JSON data (array of objects or structured data)
173
235
  * @returns Promise resolving to CSV string
174
236
  *
175
237
  * @example
176
238
  * ```typescript
239
+ * // Regular JSON to CSV
177
240
  * const jsonData = [
178
241
  * { name: "John Doe", age: 30, email: "john@example.com" },
179
242
  * { name: "Jane Smith", age: 25, email: "jane@example.com" }
@@ -185,19 +248,34 @@ export default class DMS extends IntegrationsBaseClient {
185
248
  * // name,age,email
186
249
  * // John Doe,30,john@example.com
187
250
  * // Jane Smith,25,jane@example.com
251
+ *
252
+ * // Structured JSON with auto-detection
253
+ * const structuredData = [
254
+ * { metadata: "EMPLOYEE REPORT\nGenerated: 2025-10-08" },
255
+ * { name: "John Doe", age: 30, position: "Developer" },
256
+ * { name: "Jane Smith", age: 25, position: "Designer" },
257
+ * { name: "Total Employees:", age: null, position: "2 people" }
258
+ * ];
259
+ *
260
+ * const structuredCsv = await dms.jsonToCsv(libraryRef, structuredData);
261
+ * // Auto-detects header, items, and footer sections
188
262
  * ```
189
263
  */
190
264
  jsonToCsv(lib: string, jsonData: any): Promise<AxiosResponse<string>>;
191
265
  /**
192
266
  * Convert JSON data to Excel (.xlsx) format
193
267
  *
268
+ * Supports both regular JSON arrays and structured data patterns.
269
+ * Excel files are always generated with .xlsx extension.
270
+ *
194
271
  * @param lib - Library reference UUID
195
- * @param jsonData - JSON data (array of objects recommended for tabular data)
272
+ * @param jsonData - JSON data (array of objects or structured data)
196
273
  * @param options - Optional conversion options
197
274
  * @returns Promise resolving to Excel file as Blob
198
275
  *
199
276
  * @example
200
277
  * ```typescript
278
+ * // Regular JSON to Excel
201
279
  * const jsonData = [
202
280
  * { name: "John Doe", age: 30, email: "john@example.com" },
203
281
  * { name: "Jane Smith", age: 25, email: "jane@example.com" }
@@ -212,11 +290,20 @@ export default class DMS extends IntegrationsBaseClient {
212
290
  * sheet_name: 'Customer Data'
213
291
  * });
214
292
  *
293
+ * // Structured data with explicit sections
294
+ * const structuredData = {
295
+ * header: { content: { title: "Monthly Report" } },
296
+ * items: [{ product: "Widget A", sales: 100 }],
297
+ * footer: { content: { total_sales: 100 } }
298
+ * };
299
+ *
300
+ * const structuredExcel = await dms.jsonToExcel(libraryRef, structuredData);
301
+ *
215
302
  * // Create download link
216
- * const url = URL.createObjectURL(excelWithOptions.data);
303
+ * const url = URL.createObjectURL(structuredExcel.data);
217
304
  * const link = document.createElement('a');
218
305
  * link.href = url;
219
- * link.download = 'data.xlsx';
306
+ * link.download = 'report.xlsx'; // Always .xlsx extension
220
307
  * link.click();
221
308
  * ```
222
309
  */
@@ -16,7 +16,7 @@ export { default as Forge } from './api/forge';
16
16
  export { default as Integrations } from './api/integrations';
17
17
  export { default as Payments } from './api/integrations/payments';
18
18
  export { default as Invoicing } from './api/integrations/invoicing';
19
- export { default as Media } from './api/integrations/dms';
19
+ export { default as DMS } from './api/integrations/dms';
20
20
  export { default as SerbiaUtil } from './api/integrations/serbiaUtil';
21
21
  export { default as VPFR } from './api/integrations/vpfr';
22
22
  export type * from './types/component';
@@ -42,16 +42,23 @@ export type PDFFormStructure = {
42
42
  };
43
43
  export type PDFOutputType = 'pdf' | 'base64' | 'file';
44
44
  export type PDFFillOptions = {
45
- input_html?: string;
46
45
  input_path?: string;
47
46
  output_path?: string;
48
47
  output_pdf?: boolean;
49
48
  output_type?: PDFOutputType;
50
49
  output_file_name?: string;
51
- data?: Record<string, any>;
52
50
  form_data?: Record<string, any>;
53
51
  forms?: PDFFormStructure[] | any;
54
52
  };
53
+ export type HTML2PDFOptions = {
54
+ input_html?: string;
55
+ input_path?: string;
56
+ output_path?: string;
57
+ output_pdf?: boolean;
58
+ output_type?: PDFOutputType;
59
+ output_file_name?: string;
60
+ data?: Record<string, any>;
61
+ };
55
62
  /**
56
63
  * Supported data formats for conversion operations
57
64
  */
@@ -66,6 +73,16 @@ export type DataConversionParams = {
66
73
  to: DataFormat;
67
74
  /** Optional Excel sheet name (defaults to "Sheet1") */
68
75
  sheet_name?: string;
76
+ /** Include header section in output (default: true) */
77
+ include_header?: boolean;
78
+ /** Include footer section in output (default: true) */
79
+ include_footer?: boolean;
80
+ /** Render header as comments in CSV (default: false) */
81
+ header_as_comment?: boolean;
82
+ /** Render footer as comments in CSV (default: false) */
83
+ footer_as_comment?: boolean;
84
+ /** Empty rows between sections (default: 1) */
85
+ separator_rows?: number;
69
86
  };
70
87
  /**
71
88
  * Parameters for data format validation
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ptkl/sdk",
3
- "version": "0.9.9",
3
+ "version": "0.9.10",
4
4
  "scripts": {
5
5
  "build": "rollup -c",
6
6
  "build:monaco": "npm run build && node scripts/generate-monaco-types.cjs",