@ptkl/sdk 0.9.8 → 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 +541 -21
- package/dist/index.esm.js +541 -21
- package/dist/index.iife.js +541 -21
- package/dist/monaco.d.ts +131 -4
- package/dist/package.json +1 -1
- package/dist/types/api/integrations/dms.d.ts +416 -16
- package/dist/types/api/workflow.d.ts +1 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/types/integrations.d.ts +83 -2
- package/package.json +1 -1
package/dist/index.iife.js
CHANGED
|
@@ -35,24 +35,23 @@ var ProtokolSDK09 = (function (exports, axios) {
|
|
|
35
35
|
*/
|
|
36
36
|
class PlatformBaseClient extends BaseClient {
|
|
37
37
|
constructor(options) {
|
|
38
|
-
var _a, _b;
|
|
38
|
+
var _a, _b, _c;
|
|
39
39
|
let { env = null, token = null, host = null, } = options !== null && options !== void 0 ? options : {};
|
|
40
40
|
let headers = {};
|
|
41
41
|
var project_uuid = null;
|
|
42
42
|
if (isBrowser) {
|
|
43
|
-
console.log("
|
|
43
|
+
console.log("PlatformBaseClient: running in browser context");
|
|
44
44
|
if (sessionStorage.getItem('protokol_context') == "forge") {
|
|
45
45
|
headers['X-Project-Env'] = (_a = sessionStorage.getItem('forge_app_env')) !== null && _a !== void 0 ? _a : "dev";
|
|
46
46
|
}
|
|
47
47
|
else {
|
|
48
|
-
|
|
49
|
-
headers['X-Project-Env'] = "dev";
|
|
48
|
+
headers['X-Project-Env'] = (_b = localStorage.getItem('current_env')) !== null && _b !== void 0 ? _b : "dev";
|
|
50
49
|
}
|
|
51
50
|
}
|
|
52
51
|
if (typeof window !== "undefined") {
|
|
53
52
|
// @ts-ignore
|
|
54
53
|
const __global_env__ = window === null || window === void 0 ? void 0 : window.__ENV_VARIABLES__;
|
|
55
|
-
host = (
|
|
54
|
+
host = (_c = __global_env__ === null || __global_env__ === void 0 ? void 0 : __global_env__.API_HOST) !== null && _c !== void 0 ? _c : host;
|
|
56
55
|
// @ts-ignore
|
|
57
56
|
env = env !== null && env !== void 0 ? env : __global_env__ === null || __global_env__ === void 0 ? void 0 : __global_env__.PROJECT_ENV;
|
|
58
57
|
token = token !== null && token !== void 0 ? token : __global_env__ === null || __global_env__ === void 0 ? void 0 : __global_env__.PROJECT_API_TOKEN;
|
|
@@ -213,11 +212,7 @@ var ProtokolSDK09 = (function (exports, axios) {
|
|
|
213
212
|
}
|
|
214
213
|
async upload(formData) {
|
|
215
214
|
return await this.client.post(`/v3/system/gateway/app-service/${this.appType}/upload`, formData, {
|
|
216
|
-
timeout: 60000
|
|
217
|
-
headers: {
|
|
218
|
-
// set form data headers
|
|
219
|
-
'Content-Type': 'multipart/form-data'
|
|
220
|
-
}
|
|
215
|
+
timeout: 60000
|
|
221
216
|
});
|
|
222
217
|
}
|
|
223
218
|
}
|
|
@@ -518,6 +513,9 @@ var ProtokolSDK09 = (function (exports, axios) {
|
|
|
518
513
|
async trigger(id, event, data) {
|
|
519
514
|
return await this.client.post(`/v1/project/workflow/workflow/${id}/event/${event}`, data);
|
|
520
515
|
}
|
|
516
|
+
async publish(event, data) {
|
|
517
|
+
return await this.client.post(`/v1/project/workflow/workflow/event/${event}`, data);
|
|
518
|
+
}
|
|
521
519
|
}
|
|
522
520
|
|
|
523
521
|
class Forge extends PlatformBaseClient {
|
|
@@ -617,7 +615,7 @@ var ProtokolSDK09 = (function (exports, axios) {
|
|
|
617
615
|
|
|
618
616
|
class IntegrationsBaseClient extends BaseClient {
|
|
619
617
|
constructor(options) {
|
|
620
|
-
var _a, _b;
|
|
618
|
+
var _a, _b, _c;
|
|
621
619
|
let { env = null, token, host, } = options !== null && options !== void 0 ? options : {};
|
|
622
620
|
let headers = {};
|
|
623
621
|
var project_uuid = null;
|
|
@@ -626,14 +624,13 @@ var ProtokolSDK09 = (function (exports, axios) {
|
|
|
626
624
|
headers['X-Project-Env'] = (_a = sessionStorage.getItem('forge_app_env')) !== null && _a !== void 0 ? _a : "dev";
|
|
627
625
|
}
|
|
628
626
|
else {
|
|
629
|
-
|
|
630
|
-
headers['X-Project-Env'] = "dev";
|
|
627
|
+
headers['X-Project-Env'] = (_b = localStorage.getItem('current_env')) !== null && _b !== void 0 ? _b : "dev";
|
|
631
628
|
}
|
|
632
629
|
}
|
|
633
630
|
if (typeof window !== "undefined") {
|
|
634
631
|
// @ts-ignore
|
|
635
632
|
const __global_env__ = window === null || window === void 0 ? void 0 : window.__ENV_VARIABLES__;
|
|
636
|
-
host = (
|
|
633
|
+
host = (_c = __global_env__.INTEGRATION_API) !== null && _c !== void 0 ? _c : host;
|
|
637
634
|
// @ts-ignore
|
|
638
635
|
token = token !== null && token !== void 0 ? token : __global_env__ === null || __global_env__ === void 0 ? void 0 : __global_env__.PROJECT_API_TOKEN;
|
|
639
636
|
// @ts-ignore
|
|
@@ -661,6 +658,85 @@ var ProtokolSDK09 = (function (exports, axios) {
|
|
|
661
658
|
}
|
|
662
659
|
}
|
|
663
660
|
|
|
661
|
+
/**
|
|
662
|
+
* Document Management System (DMS) API client
|
|
663
|
+
*
|
|
664
|
+
* Provides comprehensive document and media management capabilities including:
|
|
665
|
+
* - File upload, download, and management
|
|
666
|
+
* - PDF generation and form filling
|
|
667
|
+
* - Data conversion between JSON, CSV, and Excel formats
|
|
668
|
+
* - Media processing and EXIF data extraction
|
|
669
|
+
*
|
|
670
|
+
* ## Data Conversion Features
|
|
671
|
+
*
|
|
672
|
+
* The DMS class includes powerful data conversion capabilities that allow you to:
|
|
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
|
|
676
|
+
* - Validate data format integrity
|
|
677
|
+
* - Analyze data structure and metadata
|
|
678
|
+
* - Handle large datasets with memory-efficient processing
|
|
679
|
+
*
|
|
680
|
+
* ### Supported Formats
|
|
681
|
+
* - **JSON**: Array of objects (recommended for tabular data) or structured objects
|
|
682
|
+
* - **CSV**: Comma-separated values with headers and optional comments
|
|
683
|
+
* - **Excel**: .xlsx format with optional sheet specification
|
|
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
|
+
*
|
|
706
|
+
* ### Error Handling
|
|
707
|
+
* All conversion methods may throw errors with code 3003 for conversion failures.
|
|
708
|
+
* Always wrap calls in try-catch blocks for production use.
|
|
709
|
+
*
|
|
710
|
+
* @example
|
|
711
|
+
* ```typescript
|
|
712
|
+
* import { DMS } from 'protokol-sdk';
|
|
713
|
+
*
|
|
714
|
+
* const dms = new DMS({
|
|
715
|
+
* token: 'your-bearer-token',
|
|
716
|
+
* host: 'http://localhost:8086'
|
|
717
|
+
* });
|
|
718
|
+
*
|
|
719
|
+
* const libraryRef = 'your-library-uuid';
|
|
720
|
+
*
|
|
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
|
+
* };
|
|
727
|
+
*
|
|
728
|
+
* try {
|
|
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
|
|
735
|
+
* } catch (error) {
|
|
736
|
+
* console.error('Conversion failed:', error.message);
|
|
737
|
+
* }
|
|
738
|
+
* ```
|
|
739
|
+
*/
|
|
664
740
|
class DMS extends IntegrationsBaseClient {
|
|
665
741
|
async list(data) {
|
|
666
742
|
return this.request('POST', 'media/list', { data });
|
|
@@ -757,18 +833,16 @@ var ProtokolSDK09 = (function (exports, axios) {
|
|
|
757
833
|
return await this.request("POST", `media/library/${lib}/dirs`, { data });
|
|
758
834
|
}
|
|
759
835
|
async fillPdf(lib, data) {
|
|
760
|
-
const {
|
|
836
|
+
const { input_path, output_path, output_pdf = false, output_type, output_file_name, form_data, forms } = data;
|
|
761
837
|
const responseType = output_pdf ? 'arraybuffer' : 'json';
|
|
762
838
|
const contentType = output_pdf ? 'application/pdf' : 'application/json';
|
|
763
839
|
return this.request('POST', `media/library/${lib}/pdf/fill`, {
|
|
764
840
|
data: {
|
|
765
|
-
input_html,
|
|
766
841
|
input_path,
|
|
767
842
|
output_path,
|
|
768
843
|
output_pdf,
|
|
769
844
|
output_type,
|
|
770
845
|
output_file_name,
|
|
771
|
-
data: templateData,
|
|
772
846
|
form_data,
|
|
773
847
|
forms
|
|
774
848
|
},
|
|
@@ -778,10 +852,456 @@ var ProtokolSDK09 = (function (exports, axios) {
|
|
|
778
852
|
responseType
|
|
779
853
|
});
|
|
780
854
|
}
|
|
855
|
+
// ===================================================================
|
|
856
|
+
// Data Converter Methods
|
|
857
|
+
// ===================================================================
|
|
858
|
+
//
|
|
859
|
+
// The following methods provide comprehensive data conversion capabilities
|
|
860
|
+
// between JSON, CSV, and Excel formats, along with validation and analysis tools.
|
|
861
|
+
// All methods require a valid library reference UUID and return AxiosResponse objects.
|
|
862
|
+
//
|
|
863
|
+
/**
|
|
864
|
+
* Convert data between different formats (JSON, CSV, Excel)
|
|
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
|
+
*
|
|
870
|
+
* @param lib - Library reference UUID
|
|
871
|
+
* @param data - Raw data to convert
|
|
872
|
+
* @param params - Conversion parameters including structured data options
|
|
873
|
+
* @returns Promise resolving to converted data
|
|
874
|
+
*
|
|
875
|
+
* @example
|
|
876
|
+
* ```typescript
|
|
877
|
+
* // Convert JSON to CSV
|
|
878
|
+
* const jsonData = [
|
|
879
|
+
* { name: "John Doe", age: 30, email: "john@example.com" },
|
|
880
|
+
* { name: "Jane Smith", age: 25, email: "jane@example.com" }
|
|
881
|
+
* ];
|
|
882
|
+
*
|
|
883
|
+
* const csvResult = await dms.convertData(libraryRef, jsonData, {
|
|
884
|
+
* from: 'json',
|
|
885
|
+
* to: 'csv'
|
|
886
|
+
* });
|
|
887
|
+
* console.log(csvResult.data); // CSV string
|
|
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
|
+
*
|
|
915
|
+
* // Convert JSON to Excel with custom sheet name
|
|
916
|
+
* const excelResult = await dms.convertData(libraryRef, jsonData, {
|
|
917
|
+
* from: 'json',
|
|
918
|
+
* to: 'excel',
|
|
919
|
+
* sheet_name: 'Customer Data'
|
|
920
|
+
* });
|
|
921
|
+
* // excelResult.data is a Blob
|
|
922
|
+
* ```
|
|
923
|
+
*/
|
|
924
|
+
async convertData(lib, data, params) {
|
|
925
|
+
const { from, to, sheet_name, include_header, include_footer, header_as_comment, footer_as_comment, separator_rows } = params;
|
|
926
|
+
const queryParams = { from, to };
|
|
927
|
+
// Add optional parameters if provided
|
|
928
|
+
if (sheet_name)
|
|
929
|
+
queryParams.sheet_name = sheet_name;
|
|
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;
|
|
940
|
+
// Determine content type based on target format
|
|
941
|
+
let responseType = 'text';
|
|
942
|
+
if (to === 'json') {
|
|
943
|
+
responseType = 'json';
|
|
944
|
+
}
|
|
945
|
+
else if (to === 'excel' || to === 'xlsx') {
|
|
946
|
+
responseType = 'blob';
|
|
947
|
+
}
|
|
948
|
+
return this.request('POST', `media/library/${lib}/convert/data`, {
|
|
949
|
+
data,
|
|
950
|
+
params: queryParams,
|
|
951
|
+
responseType,
|
|
952
|
+
headers: {
|
|
953
|
+
'Content-Type': 'application/json'
|
|
954
|
+
}
|
|
955
|
+
});
|
|
956
|
+
}
|
|
957
|
+
/**
|
|
958
|
+
* Get information about data format and structure
|
|
959
|
+
*
|
|
960
|
+
* @param lib - Library reference UUID
|
|
961
|
+
* @param data - Raw data to analyze
|
|
962
|
+
* @param params - Analysis parameters
|
|
963
|
+
* @returns Promise resolving to data information
|
|
964
|
+
*
|
|
965
|
+
* @example
|
|
966
|
+
* ```typescript
|
|
967
|
+
* const jsonData = [
|
|
968
|
+
* { name: "John", age: 30, email: "john@example.com" },
|
|
969
|
+
* { name: "Jane", age: 25, email: "jane@example.com" }
|
|
970
|
+
* ];
|
|
971
|
+
*
|
|
972
|
+
* const dataInfo = await dms.getDataInfo(libraryRef, jsonData, {
|
|
973
|
+
* format: 'json'
|
|
974
|
+
* });
|
|
975
|
+
*
|
|
976
|
+
* console.log(dataInfo.data);
|
|
977
|
+
* // Output:
|
|
978
|
+
* // {
|
|
979
|
+
* // format: "json",
|
|
980
|
+
* // size_bytes: 245,
|
|
981
|
+
* // record_count: 2,
|
|
982
|
+
* // field_count: 3,
|
|
983
|
+
* // fields: ["name", "age", "email"],
|
|
984
|
+
* // library_ref: "98bee1cb-0f21-4582-a832-7c32b4b61831"
|
|
985
|
+
* // }
|
|
986
|
+
* ```
|
|
987
|
+
*/
|
|
988
|
+
async getDataInfo(lib, data, params) {
|
|
989
|
+
const { format } = params;
|
|
990
|
+
return this.request('POST', `media/library/${lib}/convert/info`, {
|
|
991
|
+
data,
|
|
992
|
+
params: { format },
|
|
993
|
+
headers: {
|
|
994
|
+
'Content-Type': 'application/json'
|
|
995
|
+
}
|
|
996
|
+
});
|
|
997
|
+
}
|
|
998
|
+
/**
|
|
999
|
+
* Validate data format without performing conversion
|
|
1000
|
+
*
|
|
1001
|
+
* @param lib - Library reference UUID
|
|
1002
|
+
* @param data - Raw data to validate
|
|
1003
|
+
* @param params - Validation parameters
|
|
1004
|
+
* @returns Promise resolving to validation result
|
|
1005
|
+
*
|
|
1006
|
+
* @example
|
|
1007
|
+
* ```typescript
|
|
1008
|
+
* const jsonData = [{ name: "John", age: 30 }];
|
|
1009
|
+
*
|
|
1010
|
+
* const validation = await dms.validateData(libraryRef, jsonData, {
|
|
1011
|
+
* format: 'json'
|
|
1012
|
+
* });
|
|
1013
|
+
*
|
|
1014
|
+
* console.log(validation.data);
|
|
1015
|
+
* // Output:
|
|
1016
|
+
* // {
|
|
1017
|
+
* // valid: true,
|
|
1018
|
+
* // message: "Data is valid JSON format",
|
|
1019
|
+
* // library_ref: "98bee1cb-0f21-4582-a832-7c32b4b61831"
|
|
1020
|
+
* // }
|
|
1021
|
+
*
|
|
1022
|
+
* // Handle invalid data
|
|
1023
|
+
* try {
|
|
1024
|
+
* const invalidValidation = await dms.validateData(libraryRef, "invalid json", {
|
|
1025
|
+
* format: 'json'
|
|
1026
|
+
* });
|
|
1027
|
+
* } catch (error) {
|
|
1028
|
+
* console.error('Validation failed:', error.response?.data?.message);
|
|
1029
|
+
* }
|
|
1030
|
+
* ```
|
|
1031
|
+
*/
|
|
1032
|
+
async validateData(lib, data, params) {
|
|
1033
|
+
const { format } = params;
|
|
1034
|
+
return this.request('POST', `media/library/${lib}/convert/validate`, {
|
|
1035
|
+
data,
|
|
1036
|
+
params: { format },
|
|
1037
|
+
headers: {
|
|
1038
|
+
'Content-Type': 'application/json'
|
|
1039
|
+
}
|
|
1040
|
+
});
|
|
1041
|
+
}
|
|
1042
|
+
/**
|
|
1043
|
+
* Convert JSON data to CSV format
|
|
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
|
+
*
|
|
1049
|
+
* @param lib - Library reference UUID
|
|
1050
|
+
* @param jsonData - JSON data (array of objects or structured data)
|
|
1051
|
+
* @returns Promise resolving to CSV string
|
|
1052
|
+
*
|
|
1053
|
+
* @example
|
|
1054
|
+
* ```typescript
|
|
1055
|
+
* // Regular JSON to CSV
|
|
1056
|
+
* const jsonData = [
|
|
1057
|
+
* { name: "John Doe", age: 30, email: "john@example.com" },
|
|
1058
|
+
* { name: "Jane Smith", age: 25, email: "jane@example.com" }
|
|
1059
|
+
* ];
|
|
1060
|
+
*
|
|
1061
|
+
* const csvResponse = await dms.jsonToCsv(libraryRef, jsonData);
|
|
1062
|
+
* console.log(csvResponse.data);
|
|
1063
|
+
* // Output:
|
|
1064
|
+
* // name,age,email
|
|
1065
|
+
* // John Doe,30,john@example.com
|
|
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
|
|
1078
|
+
* ```
|
|
1079
|
+
*/
|
|
1080
|
+
async jsonToCsv(lib, jsonData) {
|
|
1081
|
+
return this.request('POST', `media/library/${lib}/convert/json-to-csv`, {
|
|
1082
|
+
data: jsonData,
|
|
1083
|
+
responseType: 'text',
|
|
1084
|
+
headers: {
|
|
1085
|
+
'Content-Type': 'application/json'
|
|
1086
|
+
}
|
|
1087
|
+
});
|
|
1088
|
+
}
|
|
1089
|
+
/**
|
|
1090
|
+
* Convert JSON data to Excel (.xlsx) format
|
|
1091
|
+
*
|
|
1092
|
+
* Supports both regular JSON arrays and structured data patterns.
|
|
1093
|
+
* Excel files are always generated with .xlsx extension.
|
|
1094
|
+
*
|
|
1095
|
+
* @param lib - Library reference UUID
|
|
1096
|
+
* @param jsonData - JSON data (array of objects or structured data)
|
|
1097
|
+
* @param options - Optional conversion options
|
|
1098
|
+
* @returns Promise resolving to Excel file as Blob
|
|
1099
|
+
*
|
|
1100
|
+
* @example
|
|
1101
|
+
* ```typescript
|
|
1102
|
+
* // Regular JSON to Excel
|
|
1103
|
+
* const jsonData = [
|
|
1104
|
+
* { name: "John Doe", age: 30, email: "john@example.com" },
|
|
1105
|
+
* { name: "Jane Smith", age: 25, email: "jane@example.com" }
|
|
1106
|
+
* ];
|
|
1107
|
+
*
|
|
1108
|
+
* // Basic conversion
|
|
1109
|
+
* const excelResponse = await dms.jsonToExcel(libraryRef, jsonData);
|
|
1110
|
+
* const blob = excelResponse.data; // Blob for download
|
|
1111
|
+
*
|
|
1112
|
+
* // With custom sheet name
|
|
1113
|
+
* const excelWithOptions = await dms.jsonToExcel(libraryRef, jsonData, {
|
|
1114
|
+
* sheet_name: 'Customer Data'
|
|
1115
|
+
* });
|
|
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
|
+
*
|
|
1126
|
+
* // Create download link
|
|
1127
|
+
* const url = URL.createObjectURL(structuredExcel.data);
|
|
1128
|
+
* const link = document.createElement('a');
|
|
1129
|
+
* link.href = url;
|
|
1130
|
+
* link.download = 'report.xlsx'; // Always .xlsx extension
|
|
1131
|
+
* link.click();
|
|
1132
|
+
* ```
|
|
1133
|
+
*/
|
|
1134
|
+
async jsonToExcel(lib, jsonData, options) {
|
|
1135
|
+
const params = {};
|
|
1136
|
+
if (options === null || options === void 0 ? void 0 : options.sheet_name) {
|
|
1137
|
+
params.sheet_name = options.sheet_name;
|
|
1138
|
+
}
|
|
1139
|
+
return this.request('POST', `media/library/${lib}/convert/json-to-excel`, {
|
|
1140
|
+
data: jsonData,
|
|
1141
|
+
params,
|
|
1142
|
+
responseType: 'blob',
|
|
1143
|
+
headers: {
|
|
1144
|
+
'Content-Type': 'application/json'
|
|
1145
|
+
}
|
|
1146
|
+
});
|
|
1147
|
+
}
|
|
1148
|
+
/**
|
|
1149
|
+
* Convert CSV data to JSON format
|
|
1150
|
+
*
|
|
1151
|
+
* @param lib - Library reference UUID
|
|
1152
|
+
* @param csvData - CSV data string (with headers in first row)
|
|
1153
|
+
* @returns Promise resolving to JSON array
|
|
1154
|
+
*
|
|
1155
|
+
* @example
|
|
1156
|
+
* ```typescript
|
|
1157
|
+
* const csvString = `name,age,email
|
|
1158
|
+
* John Doe,30,john@example.com
|
|
1159
|
+
* Jane Smith,25,jane@example.com`;
|
|
1160
|
+
*
|
|
1161
|
+
* const jsonResponse = await dms.csvToJson(libraryRef, csvString);
|
|
1162
|
+
* console.log(jsonResponse.data);
|
|
1163
|
+
* // Output:
|
|
1164
|
+
* // [
|
|
1165
|
+
* // { name: "John Doe", age: "30", email: "john@example.com" },
|
|
1166
|
+
* // { name: "Jane Smith", age: "25", email: "jane@example.com" }
|
|
1167
|
+
* // ]
|
|
1168
|
+
* ```
|
|
1169
|
+
*/
|
|
1170
|
+
async csvToJson(lib, csvData) {
|
|
1171
|
+
return this.request('POST', `media/library/${lib}/convert/csv-to-json`, {
|
|
1172
|
+
data: csvData,
|
|
1173
|
+
responseType: 'json',
|
|
1174
|
+
headers: {
|
|
1175
|
+
'Content-Type': 'text/csv'
|
|
1176
|
+
}
|
|
1177
|
+
});
|
|
1178
|
+
}
|
|
1179
|
+
/**
|
|
1180
|
+
* Convert CSV data to Excel (.xlsx) format
|
|
1181
|
+
*
|
|
1182
|
+
* @param lib - Library reference UUID
|
|
1183
|
+
* @param csvData - CSV data string (with headers in first row)
|
|
1184
|
+
* @param options - Optional conversion options
|
|
1185
|
+
* @returns Promise resolving to Excel file as Blob
|
|
1186
|
+
*
|
|
1187
|
+
* @example
|
|
1188
|
+
* ```typescript
|
|
1189
|
+
* const csvString = `name,age,email
|
|
1190
|
+
* John Doe,30,john@example.com
|
|
1191
|
+
* Jane Smith,25,jane@example.com`;
|
|
1192
|
+
*
|
|
1193
|
+
* const excelResponse = await dms.csvToExcel(libraryRef, csvString, {
|
|
1194
|
+
* sheet_name: 'Imported Data'
|
|
1195
|
+
* });
|
|
1196
|
+
*
|
|
1197
|
+
* // Handle the Excel blob
|
|
1198
|
+
* const blob = excelResponse.data;
|
|
1199
|
+
* const url = URL.createObjectURL(blob);
|
|
1200
|
+
* // Use url for download or further processing
|
|
1201
|
+
* ```
|
|
1202
|
+
*/
|
|
1203
|
+
async csvToExcel(lib, csvData, options) {
|
|
1204
|
+
const params = {};
|
|
1205
|
+
if (options === null || options === void 0 ? void 0 : options.sheet_name) {
|
|
1206
|
+
params.sheet_name = options.sheet_name;
|
|
1207
|
+
}
|
|
1208
|
+
return this.request('POST', `media/library/${lib}/convert/csv-to-excel`, {
|
|
1209
|
+
data: csvData,
|
|
1210
|
+
params,
|
|
1211
|
+
responseType: 'blob',
|
|
1212
|
+
headers: {
|
|
1213
|
+
'Content-Type': 'text/csv'
|
|
1214
|
+
}
|
|
1215
|
+
});
|
|
1216
|
+
}
|
|
1217
|
+
/**
|
|
1218
|
+
* Convert Excel (.xlsx) data to JSON format
|
|
1219
|
+
*
|
|
1220
|
+
* @param lib - Library reference UUID
|
|
1221
|
+
* @param excelData - Excel file data as Blob or ArrayBuffer
|
|
1222
|
+
* @param options - Optional conversion options
|
|
1223
|
+
* @returns Promise resolving to JSON array
|
|
1224
|
+
*
|
|
1225
|
+
* @example
|
|
1226
|
+
* ```typescript
|
|
1227
|
+
* // From file input
|
|
1228
|
+
* const fileInput = document.querySelector('input[type="file"]');
|
|
1229
|
+
* const file = fileInput.files[0]; // Excel file
|
|
1230
|
+
*
|
|
1231
|
+
* const jsonResponse = await dms.excelToJson(libraryRef, file, {
|
|
1232
|
+
* sheet_name: 'Sheet1' // optional, defaults to first sheet
|
|
1233
|
+
* });
|
|
1234
|
+
*
|
|
1235
|
+
* console.log(jsonResponse.data);
|
|
1236
|
+
* // Output: JSON array with data from Excel sheet
|
|
1237
|
+
*
|
|
1238
|
+
* // From ArrayBuffer
|
|
1239
|
+
* const arrayBuffer = await file.arrayBuffer();
|
|
1240
|
+
* const jsonFromBuffer = await dms.excelToJson(libraryRef, arrayBuffer);
|
|
1241
|
+
* ```
|
|
1242
|
+
*/
|
|
1243
|
+
async excelToJson(lib, excelData, options) {
|
|
1244
|
+
const params = {};
|
|
1245
|
+
if (options === null || options === void 0 ? void 0 : options.sheet_name) {
|
|
1246
|
+
params.sheet_name = options.sheet_name;
|
|
1247
|
+
}
|
|
1248
|
+
return this.request('POST', `media/library/${lib}/convert/excel-to-json`, {
|
|
1249
|
+
data: excelData,
|
|
1250
|
+
params,
|
|
1251
|
+
responseType: 'json',
|
|
1252
|
+
headers: {
|
|
1253
|
+
'Content-Type': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
|
1254
|
+
}
|
|
1255
|
+
});
|
|
1256
|
+
}
|
|
1257
|
+
/**
|
|
1258
|
+
* Convert Excel (.xlsx) data to CSV format
|
|
1259
|
+
*
|
|
1260
|
+
* @param lib - Library reference UUID
|
|
1261
|
+
* @param excelData - Excel file data as Blob or ArrayBuffer
|
|
1262
|
+
* @param options - Optional conversion options
|
|
1263
|
+
* @returns Promise resolving to CSV string
|
|
1264
|
+
*
|
|
1265
|
+
* @example
|
|
1266
|
+
* ```typescript
|
|
1267
|
+
* // From file input
|
|
1268
|
+
* const fileInput = document.querySelector('input[type="file"]');
|
|
1269
|
+
* const file = fileInput.files[0]; // Excel file
|
|
1270
|
+
*
|
|
1271
|
+
* const csvResponse = await dms.excelToCsv(libraryRef, file, {
|
|
1272
|
+
* sheet_name: 'Data' // optional, defaults to first sheet
|
|
1273
|
+
* });
|
|
1274
|
+
*
|
|
1275
|
+
* console.log(csvResponse.data);
|
|
1276
|
+
* // Output: CSV string with data from Excel sheet
|
|
1277
|
+
*
|
|
1278
|
+
* // Save as CSV file
|
|
1279
|
+
* const csvBlob = new Blob([csvResponse.data], { type: 'text/csv' });
|
|
1280
|
+
* const url = URL.createObjectURL(csvBlob);
|
|
1281
|
+
* const link = document.createElement('a');
|
|
1282
|
+
* link.href = url;
|
|
1283
|
+
* link.download = 'converted.csv';
|
|
1284
|
+
* link.click();
|
|
1285
|
+
* ```
|
|
1286
|
+
*/
|
|
1287
|
+
async excelToCsv(lib, excelData, options) {
|
|
1288
|
+
const params = {};
|
|
1289
|
+
if (options === null || options === void 0 ? void 0 : options.sheet_name) {
|
|
1290
|
+
params.sheet_name = options.sheet_name;
|
|
1291
|
+
}
|
|
1292
|
+
return this.request('POST', `media/library/${lib}/convert/excel-to-csv`, {
|
|
1293
|
+
data: excelData,
|
|
1294
|
+
params,
|
|
1295
|
+
responseType: 'text',
|
|
1296
|
+
headers: {
|
|
1297
|
+
'Content-Type': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
|
1298
|
+
}
|
|
1299
|
+
});
|
|
1300
|
+
}
|
|
781
1301
|
async request(method, endpoint, params) {
|
|
782
1302
|
return await this.client.request({
|
|
783
1303
|
method: method,
|
|
784
|
-
url: `/v2
|
|
1304
|
+
url: `/v2/${endpoint}`,
|
|
785
1305
|
...params
|
|
786
1306
|
});
|
|
787
1307
|
}
|
|
@@ -855,7 +1375,7 @@ var ProtokolSDK09 = (function (exports, axios) {
|
|
|
855
1375
|
this.integrations = {
|
|
856
1376
|
'protokol-invoicing': new Invoicing().setClient(this.client),
|
|
857
1377
|
'protokol-vpfr': new VPFR().setClient(this.client),
|
|
858
|
-
'protokol-
|
|
1378
|
+
'protokol-dms': new DMS().setClient(this.client),
|
|
859
1379
|
'serbia-utilities': new SerbiaUtil().setClient(this.client),
|
|
860
1380
|
'protokol-payments': new Payments().setClient(this.client),
|
|
861
1381
|
};
|
|
@@ -864,7 +1384,7 @@ var ProtokolSDK09 = (function (exports, axios) {
|
|
|
864
1384
|
return this.getInterfaceOf('serbia-utilities');
|
|
865
1385
|
}
|
|
866
1386
|
getDMS() {
|
|
867
|
-
return this.getInterfaceOf('protokol-
|
|
1387
|
+
return this.getInterfaceOf('protokol-dms');
|
|
868
1388
|
}
|
|
869
1389
|
getVPFR() {
|
|
870
1390
|
return this.getInterfaceOf('protokol-vpfr');
|
|
@@ -893,12 +1413,12 @@ var ProtokolSDK09 = (function (exports, axios) {
|
|
|
893
1413
|
exports.Apps = Apps;
|
|
894
1414
|
exports.Component = Component;
|
|
895
1415
|
exports.ComponentUtils = ComponentUtils;
|
|
1416
|
+
exports.DMS = DMS;
|
|
896
1417
|
exports.Forge = Forge;
|
|
897
1418
|
exports.Functions = Functions;
|
|
898
1419
|
exports.Integration = Integrations;
|
|
899
1420
|
exports.Integrations = Integrations;
|
|
900
1421
|
exports.Invoicing = Invoicing;
|
|
901
|
-
exports.Media = DMS;
|
|
902
1422
|
exports.Payments = Payments;
|
|
903
1423
|
exports.Ratchet = Ratchet;
|
|
904
1424
|
exports.Roles = Roles;
|