@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.
- package/dist/index.cjs.js +438 -9
- package/dist/index.esm.js +438 -9
- package/dist/index.iife.js +438 -9
- package/dist/types/api/integrations/dms.d.ts +329 -16
- package/dist/types/api/workflow.d.ts +1 -0
- package/dist/types/types/integrations.d.ts +64 -0
- 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;
|
|
@@ -518,6 +517,9 @@ var ProtokolSDK09 = (function (exports, axios) {
|
|
|
518
517
|
async trigger(id, event, data) {
|
|
519
518
|
return await this.client.post(`/v1/project/workflow/workflow/${id}/event/${event}`, data);
|
|
520
519
|
}
|
|
520
|
+
async publish(event, data) {
|
|
521
|
+
return await this.client.post(`/v1/project/workflow/workflow/event/${event}`, data);
|
|
522
|
+
}
|
|
521
523
|
}
|
|
522
524
|
|
|
523
525
|
class Forge extends PlatformBaseClient {
|
|
@@ -617,7 +619,7 @@ var ProtokolSDK09 = (function (exports, axios) {
|
|
|
617
619
|
|
|
618
620
|
class IntegrationsBaseClient extends BaseClient {
|
|
619
621
|
constructor(options) {
|
|
620
|
-
var _a, _b;
|
|
622
|
+
var _a, _b, _c;
|
|
621
623
|
let { env = null, token, host, } = options !== null && options !== void 0 ? options : {};
|
|
622
624
|
let headers = {};
|
|
623
625
|
var project_uuid = null;
|
|
@@ -626,14 +628,13 @@ var ProtokolSDK09 = (function (exports, axios) {
|
|
|
626
628
|
headers['X-Project-Env'] = (_a = sessionStorage.getItem('forge_app_env')) !== null && _a !== void 0 ? _a : "dev";
|
|
627
629
|
}
|
|
628
630
|
else {
|
|
629
|
-
|
|
630
|
-
headers['X-Project-Env'] = "dev";
|
|
631
|
+
headers['X-Project-Env'] = (_b = localStorage.getItem('current_env')) !== null && _b !== void 0 ? _b : "dev";
|
|
631
632
|
}
|
|
632
633
|
}
|
|
633
634
|
if (typeof window !== "undefined") {
|
|
634
635
|
// @ts-ignore
|
|
635
636
|
const __global_env__ = window === null || window === void 0 ? void 0 : window.__ENV_VARIABLES__;
|
|
636
|
-
host = (
|
|
637
|
+
host = (_c = __global_env__.INTEGRATION_API) !== null && _c !== void 0 ? _c : host;
|
|
637
638
|
// @ts-ignore
|
|
638
639
|
token = token !== null && token !== void 0 ? token : __global_env__ === null || __global_env__ === void 0 ? void 0 : __global_env__.PROJECT_API_TOKEN;
|
|
639
640
|
// @ts-ignore
|
|
@@ -661,6 +662,57 @@ var ProtokolSDK09 = (function (exports, axios) {
|
|
|
661
662
|
}
|
|
662
663
|
}
|
|
663
664
|
|
|
665
|
+
/**
|
|
666
|
+
* Document Management System (DMS) API client
|
|
667
|
+
*
|
|
668
|
+
* Provides comprehensive document and media management capabilities including:
|
|
669
|
+
* - File upload, download, and management
|
|
670
|
+
* - PDF generation and form filling
|
|
671
|
+
* - Data conversion between JSON, CSV, and Excel formats
|
|
672
|
+
* - Media processing and EXIF data extraction
|
|
673
|
+
*
|
|
674
|
+
* ## Data Conversion Features
|
|
675
|
+
*
|
|
676
|
+
* The DMS class includes powerful data conversion capabilities that allow you to:
|
|
677
|
+
* - Convert between JSON, CSV, and Excel (.xlsx) formats
|
|
678
|
+
* - Validate data format integrity
|
|
679
|
+
* - Analyze data structure and metadata
|
|
680
|
+
* - Handle large datasets with memory-efficient processing
|
|
681
|
+
*
|
|
682
|
+
* ### Supported Formats
|
|
683
|
+
* - **JSON**: Array of objects (recommended for tabular data)
|
|
684
|
+
* - **CSV**: Comma-separated values with headers
|
|
685
|
+
* - **Excel**: .xlsx format with optional sheet specification
|
|
686
|
+
*
|
|
687
|
+
* ### Error Handling
|
|
688
|
+
* All conversion methods may throw errors with code 3003 for conversion failures.
|
|
689
|
+
* Always wrap calls in try-catch blocks for production use.
|
|
690
|
+
*
|
|
691
|
+
* @example
|
|
692
|
+
* ```typescript
|
|
693
|
+
* import { DMS } from 'protokol-sdk';
|
|
694
|
+
*
|
|
695
|
+
* const dms = new DMS({
|
|
696
|
+
* token: 'your-bearer-token',
|
|
697
|
+
* host: 'http://localhost:8086'
|
|
698
|
+
* });
|
|
699
|
+
*
|
|
700
|
+
* const libraryRef = 'your-library-uuid';
|
|
701
|
+
*
|
|
702
|
+
* // Convert JSON to CSV
|
|
703
|
+
* const jsonData = [
|
|
704
|
+
* { name: "John", age: 30 },
|
|
705
|
+
* { name: "Jane", age: 25 }
|
|
706
|
+
* ];
|
|
707
|
+
*
|
|
708
|
+
* try {
|
|
709
|
+
* const csvResult = await dms.jsonToCsv(libraryRef, jsonData);
|
|
710
|
+
* console.log(csvResult.data); // CSV string
|
|
711
|
+
* } catch (error) {
|
|
712
|
+
* console.error('Conversion failed:', error.message);
|
|
713
|
+
* }
|
|
714
|
+
* ```
|
|
715
|
+
*/
|
|
664
716
|
class DMS extends IntegrationsBaseClient {
|
|
665
717
|
async list(data) {
|
|
666
718
|
return this.request('POST', 'media/list', { data });
|
|
@@ -778,6 +830,383 @@ var ProtokolSDK09 = (function (exports, axios) {
|
|
|
778
830
|
responseType
|
|
779
831
|
});
|
|
780
832
|
}
|
|
833
|
+
// ===================================================================
|
|
834
|
+
// Data Converter Methods
|
|
835
|
+
// ===================================================================
|
|
836
|
+
//
|
|
837
|
+
// The following methods provide comprehensive data conversion capabilities
|
|
838
|
+
// between JSON, CSV, and Excel formats, along with validation and analysis tools.
|
|
839
|
+
// All methods require a valid library reference UUID and return AxiosResponse objects.
|
|
840
|
+
//
|
|
841
|
+
/**
|
|
842
|
+
* Convert data between different formats (JSON, CSV, Excel)
|
|
843
|
+
*
|
|
844
|
+
* @param lib - Library reference UUID
|
|
845
|
+
* @param data - Raw data to convert
|
|
846
|
+
* @param params - Conversion parameters
|
|
847
|
+
* @returns Promise resolving to converted data
|
|
848
|
+
*
|
|
849
|
+
* @example
|
|
850
|
+
* ```typescript
|
|
851
|
+
* // Convert JSON to CSV
|
|
852
|
+
* const jsonData = [
|
|
853
|
+
* { name: "John Doe", age: 30, email: "john@example.com" },
|
|
854
|
+
* { name: "Jane Smith", age: 25, email: "jane@example.com" }
|
|
855
|
+
* ];
|
|
856
|
+
*
|
|
857
|
+
* const csvResult = await dms.convertData(libraryRef, jsonData, {
|
|
858
|
+
* from: 'json',
|
|
859
|
+
* to: 'csv'
|
|
860
|
+
* });
|
|
861
|
+
* console.log(csvResult.data); // CSV string
|
|
862
|
+
*
|
|
863
|
+
* // Convert JSON to Excel with custom sheet name
|
|
864
|
+
* const excelResult = await dms.convertData(libraryRef, jsonData, {
|
|
865
|
+
* from: 'json',
|
|
866
|
+
* to: 'excel',
|
|
867
|
+
* sheet_name: 'Customer Data'
|
|
868
|
+
* });
|
|
869
|
+
* // excelResult.data is a Blob
|
|
870
|
+
* ```
|
|
871
|
+
*/
|
|
872
|
+
async convertData(lib, data, params) {
|
|
873
|
+
const { from, to, sheet_name } = params;
|
|
874
|
+
const queryParams = { from, to };
|
|
875
|
+
if (sheet_name) {
|
|
876
|
+
queryParams.sheet_name = sheet_name;
|
|
877
|
+
}
|
|
878
|
+
// Determine content type based on target format
|
|
879
|
+
let responseType = 'text';
|
|
880
|
+
if (to === 'json') {
|
|
881
|
+
responseType = 'json';
|
|
882
|
+
}
|
|
883
|
+
else if (to === 'excel' || to === 'xlsx') {
|
|
884
|
+
responseType = 'blob';
|
|
885
|
+
}
|
|
886
|
+
return this.request('POST', `media/library/${lib}/convert/data`, {
|
|
887
|
+
data,
|
|
888
|
+
params: queryParams,
|
|
889
|
+
responseType,
|
|
890
|
+
headers: {
|
|
891
|
+
'Content-Type': 'application/json'
|
|
892
|
+
}
|
|
893
|
+
});
|
|
894
|
+
}
|
|
895
|
+
/**
|
|
896
|
+
* Get information about data format and structure
|
|
897
|
+
*
|
|
898
|
+
* @param lib - Library reference UUID
|
|
899
|
+
* @param data - Raw data to analyze
|
|
900
|
+
* @param params - Analysis parameters
|
|
901
|
+
* @returns Promise resolving to data information
|
|
902
|
+
*
|
|
903
|
+
* @example
|
|
904
|
+
* ```typescript
|
|
905
|
+
* const jsonData = [
|
|
906
|
+
* { name: "John", age: 30, email: "john@example.com" },
|
|
907
|
+
* { name: "Jane", age: 25, email: "jane@example.com" }
|
|
908
|
+
* ];
|
|
909
|
+
*
|
|
910
|
+
* const dataInfo = await dms.getDataInfo(libraryRef, jsonData, {
|
|
911
|
+
* format: 'json'
|
|
912
|
+
* });
|
|
913
|
+
*
|
|
914
|
+
* console.log(dataInfo.data);
|
|
915
|
+
* // Output:
|
|
916
|
+
* // {
|
|
917
|
+
* // format: "json",
|
|
918
|
+
* // size_bytes: 245,
|
|
919
|
+
* // record_count: 2,
|
|
920
|
+
* // field_count: 3,
|
|
921
|
+
* // fields: ["name", "age", "email"],
|
|
922
|
+
* // library_ref: "98bee1cb-0f21-4582-a832-7c32b4b61831"
|
|
923
|
+
* // }
|
|
924
|
+
* ```
|
|
925
|
+
*/
|
|
926
|
+
async getDataInfo(lib, data, params) {
|
|
927
|
+
const { format } = params;
|
|
928
|
+
return this.request('POST', `media/library/${lib}/convert/info`, {
|
|
929
|
+
data,
|
|
930
|
+
params: { format },
|
|
931
|
+
headers: {
|
|
932
|
+
'Content-Type': 'application/json'
|
|
933
|
+
}
|
|
934
|
+
});
|
|
935
|
+
}
|
|
936
|
+
/**
|
|
937
|
+
* Validate data format without performing conversion
|
|
938
|
+
*
|
|
939
|
+
* @param lib - Library reference UUID
|
|
940
|
+
* @param data - Raw data to validate
|
|
941
|
+
* @param params - Validation parameters
|
|
942
|
+
* @returns Promise resolving to validation result
|
|
943
|
+
*
|
|
944
|
+
* @example
|
|
945
|
+
* ```typescript
|
|
946
|
+
* const jsonData = [{ name: "John", age: 30 }];
|
|
947
|
+
*
|
|
948
|
+
* const validation = await dms.validateData(libraryRef, jsonData, {
|
|
949
|
+
* format: 'json'
|
|
950
|
+
* });
|
|
951
|
+
*
|
|
952
|
+
* console.log(validation.data);
|
|
953
|
+
* // Output:
|
|
954
|
+
* // {
|
|
955
|
+
* // valid: true,
|
|
956
|
+
* // message: "Data is valid JSON format",
|
|
957
|
+
* // library_ref: "98bee1cb-0f21-4582-a832-7c32b4b61831"
|
|
958
|
+
* // }
|
|
959
|
+
*
|
|
960
|
+
* // Handle invalid data
|
|
961
|
+
* try {
|
|
962
|
+
* const invalidValidation = await dms.validateData(libraryRef, "invalid json", {
|
|
963
|
+
* format: 'json'
|
|
964
|
+
* });
|
|
965
|
+
* } catch (error) {
|
|
966
|
+
* console.error('Validation failed:', error.response?.data?.message);
|
|
967
|
+
* }
|
|
968
|
+
* ```
|
|
969
|
+
*/
|
|
970
|
+
async validateData(lib, data, params) {
|
|
971
|
+
const { format } = params;
|
|
972
|
+
return this.request('POST', `media/library/${lib}/convert/validate`, {
|
|
973
|
+
data,
|
|
974
|
+
params: { format },
|
|
975
|
+
headers: {
|
|
976
|
+
'Content-Type': 'application/json'
|
|
977
|
+
}
|
|
978
|
+
});
|
|
979
|
+
}
|
|
980
|
+
/**
|
|
981
|
+
* Convert JSON data to CSV format
|
|
982
|
+
*
|
|
983
|
+
* @param lib - Library reference UUID
|
|
984
|
+
* @param jsonData - JSON data (array of objects recommended for tabular data)
|
|
985
|
+
* @returns Promise resolving to CSV string
|
|
986
|
+
*
|
|
987
|
+
* @example
|
|
988
|
+
* ```typescript
|
|
989
|
+
* const jsonData = [
|
|
990
|
+
* { name: "John Doe", age: 30, email: "john@example.com" },
|
|
991
|
+
* { name: "Jane Smith", age: 25, email: "jane@example.com" }
|
|
992
|
+
* ];
|
|
993
|
+
*
|
|
994
|
+
* const csvResponse = await dms.jsonToCsv(libraryRef, jsonData);
|
|
995
|
+
* console.log(csvResponse.data);
|
|
996
|
+
* // Output:
|
|
997
|
+
* // name,age,email
|
|
998
|
+
* // John Doe,30,john@example.com
|
|
999
|
+
* // Jane Smith,25,jane@example.com
|
|
1000
|
+
* ```
|
|
1001
|
+
*/
|
|
1002
|
+
async jsonToCsv(lib, jsonData) {
|
|
1003
|
+
return this.request('POST', `media/library/${lib}/convert/json-to-csv`, {
|
|
1004
|
+
data: jsonData,
|
|
1005
|
+
responseType: 'text',
|
|
1006
|
+
headers: {
|
|
1007
|
+
'Content-Type': 'application/json'
|
|
1008
|
+
}
|
|
1009
|
+
});
|
|
1010
|
+
}
|
|
1011
|
+
/**
|
|
1012
|
+
* Convert JSON data to Excel (.xlsx) format
|
|
1013
|
+
*
|
|
1014
|
+
* @param lib - Library reference UUID
|
|
1015
|
+
* @param jsonData - JSON data (array of objects recommended for tabular data)
|
|
1016
|
+
* @param options - Optional conversion options
|
|
1017
|
+
* @returns Promise resolving to Excel file as Blob
|
|
1018
|
+
*
|
|
1019
|
+
* @example
|
|
1020
|
+
* ```typescript
|
|
1021
|
+
* const jsonData = [
|
|
1022
|
+
* { name: "John Doe", age: 30, email: "john@example.com" },
|
|
1023
|
+
* { name: "Jane Smith", age: 25, email: "jane@example.com" }
|
|
1024
|
+
* ];
|
|
1025
|
+
*
|
|
1026
|
+
* // Basic conversion
|
|
1027
|
+
* const excelResponse = await dms.jsonToExcel(libraryRef, jsonData);
|
|
1028
|
+
* const blob = excelResponse.data; // Blob for download
|
|
1029
|
+
*
|
|
1030
|
+
* // With custom sheet name
|
|
1031
|
+
* const excelWithOptions = await dms.jsonToExcel(libraryRef, jsonData, {
|
|
1032
|
+
* sheet_name: 'Customer Data'
|
|
1033
|
+
* });
|
|
1034
|
+
*
|
|
1035
|
+
* // Create download link
|
|
1036
|
+
* const url = URL.createObjectURL(excelWithOptions.data);
|
|
1037
|
+
* const link = document.createElement('a');
|
|
1038
|
+
* link.href = url;
|
|
1039
|
+
* link.download = 'data.xlsx';
|
|
1040
|
+
* link.click();
|
|
1041
|
+
* ```
|
|
1042
|
+
*/
|
|
1043
|
+
async jsonToExcel(lib, jsonData, options) {
|
|
1044
|
+
const params = {};
|
|
1045
|
+
if (options === null || options === void 0 ? void 0 : options.sheet_name) {
|
|
1046
|
+
params.sheet_name = options.sheet_name;
|
|
1047
|
+
}
|
|
1048
|
+
return this.request('POST', `media/library/${lib}/convert/json-to-excel`, {
|
|
1049
|
+
data: jsonData,
|
|
1050
|
+
params,
|
|
1051
|
+
responseType: 'blob',
|
|
1052
|
+
headers: {
|
|
1053
|
+
'Content-Type': 'application/json'
|
|
1054
|
+
}
|
|
1055
|
+
});
|
|
1056
|
+
}
|
|
1057
|
+
/**
|
|
1058
|
+
* Convert CSV data to JSON format
|
|
1059
|
+
*
|
|
1060
|
+
* @param lib - Library reference UUID
|
|
1061
|
+
* @param csvData - CSV data string (with headers in first row)
|
|
1062
|
+
* @returns Promise resolving to JSON array
|
|
1063
|
+
*
|
|
1064
|
+
* @example
|
|
1065
|
+
* ```typescript
|
|
1066
|
+
* const csvString = `name,age,email
|
|
1067
|
+
* John Doe,30,john@example.com
|
|
1068
|
+
* Jane Smith,25,jane@example.com`;
|
|
1069
|
+
*
|
|
1070
|
+
* const jsonResponse = await dms.csvToJson(libraryRef, csvString);
|
|
1071
|
+
* console.log(jsonResponse.data);
|
|
1072
|
+
* // Output:
|
|
1073
|
+
* // [
|
|
1074
|
+
* // { name: "John Doe", age: "30", email: "john@example.com" },
|
|
1075
|
+
* // { name: "Jane Smith", age: "25", email: "jane@example.com" }
|
|
1076
|
+
* // ]
|
|
1077
|
+
* ```
|
|
1078
|
+
*/
|
|
1079
|
+
async csvToJson(lib, csvData) {
|
|
1080
|
+
return this.request('POST', `media/library/${lib}/convert/csv-to-json`, {
|
|
1081
|
+
data: csvData,
|
|
1082
|
+
responseType: 'json',
|
|
1083
|
+
headers: {
|
|
1084
|
+
'Content-Type': 'text/csv'
|
|
1085
|
+
}
|
|
1086
|
+
});
|
|
1087
|
+
}
|
|
1088
|
+
/**
|
|
1089
|
+
* Convert CSV data to Excel (.xlsx) format
|
|
1090
|
+
*
|
|
1091
|
+
* @param lib - Library reference UUID
|
|
1092
|
+
* @param csvData - CSV data string (with headers in first row)
|
|
1093
|
+
* @param options - Optional conversion options
|
|
1094
|
+
* @returns Promise resolving to Excel file as Blob
|
|
1095
|
+
*
|
|
1096
|
+
* @example
|
|
1097
|
+
* ```typescript
|
|
1098
|
+
* const csvString = `name,age,email
|
|
1099
|
+
* John Doe,30,john@example.com
|
|
1100
|
+
* Jane Smith,25,jane@example.com`;
|
|
1101
|
+
*
|
|
1102
|
+
* const excelResponse = await dms.csvToExcel(libraryRef, csvString, {
|
|
1103
|
+
* sheet_name: 'Imported Data'
|
|
1104
|
+
* });
|
|
1105
|
+
*
|
|
1106
|
+
* // Handle the Excel blob
|
|
1107
|
+
* const blob = excelResponse.data;
|
|
1108
|
+
* const url = URL.createObjectURL(blob);
|
|
1109
|
+
* // Use url for download or further processing
|
|
1110
|
+
* ```
|
|
1111
|
+
*/
|
|
1112
|
+
async csvToExcel(lib, csvData, options) {
|
|
1113
|
+
const params = {};
|
|
1114
|
+
if (options === null || options === void 0 ? void 0 : options.sheet_name) {
|
|
1115
|
+
params.sheet_name = options.sheet_name;
|
|
1116
|
+
}
|
|
1117
|
+
return this.request('POST', `media/library/${lib}/convert/csv-to-excel`, {
|
|
1118
|
+
data: csvData,
|
|
1119
|
+
params,
|
|
1120
|
+
responseType: 'blob',
|
|
1121
|
+
headers: {
|
|
1122
|
+
'Content-Type': 'text/csv'
|
|
1123
|
+
}
|
|
1124
|
+
});
|
|
1125
|
+
}
|
|
1126
|
+
/**
|
|
1127
|
+
* Convert Excel (.xlsx) data to JSON format
|
|
1128
|
+
*
|
|
1129
|
+
* @param lib - Library reference UUID
|
|
1130
|
+
* @param excelData - Excel file data as Blob or ArrayBuffer
|
|
1131
|
+
* @param options - Optional conversion options
|
|
1132
|
+
* @returns Promise resolving to JSON array
|
|
1133
|
+
*
|
|
1134
|
+
* @example
|
|
1135
|
+
* ```typescript
|
|
1136
|
+
* // From file input
|
|
1137
|
+
* const fileInput = document.querySelector('input[type="file"]');
|
|
1138
|
+
* const file = fileInput.files[0]; // Excel file
|
|
1139
|
+
*
|
|
1140
|
+
* const jsonResponse = await dms.excelToJson(libraryRef, file, {
|
|
1141
|
+
* sheet_name: 'Sheet1' // optional, defaults to first sheet
|
|
1142
|
+
* });
|
|
1143
|
+
*
|
|
1144
|
+
* console.log(jsonResponse.data);
|
|
1145
|
+
* // Output: JSON array with data from Excel sheet
|
|
1146
|
+
*
|
|
1147
|
+
* // From ArrayBuffer
|
|
1148
|
+
* const arrayBuffer = await file.arrayBuffer();
|
|
1149
|
+
* const jsonFromBuffer = await dms.excelToJson(libraryRef, arrayBuffer);
|
|
1150
|
+
* ```
|
|
1151
|
+
*/
|
|
1152
|
+
async excelToJson(lib, excelData, options) {
|
|
1153
|
+
const params = {};
|
|
1154
|
+
if (options === null || options === void 0 ? void 0 : options.sheet_name) {
|
|
1155
|
+
params.sheet_name = options.sheet_name;
|
|
1156
|
+
}
|
|
1157
|
+
return this.request('POST', `media/library/${lib}/convert/excel-to-json`, {
|
|
1158
|
+
data: excelData,
|
|
1159
|
+
params,
|
|
1160
|
+
responseType: 'json',
|
|
1161
|
+
headers: {
|
|
1162
|
+
'Content-Type': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
|
1163
|
+
}
|
|
1164
|
+
});
|
|
1165
|
+
}
|
|
1166
|
+
/**
|
|
1167
|
+
* Convert Excel (.xlsx) data to CSV format
|
|
1168
|
+
*
|
|
1169
|
+
* @param lib - Library reference UUID
|
|
1170
|
+
* @param excelData - Excel file data as Blob or ArrayBuffer
|
|
1171
|
+
* @param options - Optional conversion options
|
|
1172
|
+
* @returns Promise resolving to CSV string
|
|
1173
|
+
*
|
|
1174
|
+
* @example
|
|
1175
|
+
* ```typescript
|
|
1176
|
+
* // From file input
|
|
1177
|
+
* const fileInput = document.querySelector('input[type="file"]');
|
|
1178
|
+
* const file = fileInput.files[0]; // Excel file
|
|
1179
|
+
*
|
|
1180
|
+
* const csvResponse = await dms.excelToCsv(libraryRef, file, {
|
|
1181
|
+
* sheet_name: 'Data' // optional, defaults to first sheet
|
|
1182
|
+
* });
|
|
1183
|
+
*
|
|
1184
|
+
* console.log(csvResponse.data);
|
|
1185
|
+
* // Output: CSV string with data from Excel sheet
|
|
1186
|
+
*
|
|
1187
|
+
* // Save as CSV file
|
|
1188
|
+
* const csvBlob = new Blob([csvResponse.data], { type: 'text/csv' });
|
|
1189
|
+
* const url = URL.createObjectURL(csvBlob);
|
|
1190
|
+
* const link = document.createElement('a');
|
|
1191
|
+
* link.href = url;
|
|
1192
|
+
* link.download = 'converted.csv';
|
|
1193
|
+
* link.click();
|
|
1194
|
+
* ```
|
|
1195
|
+
*/
|
|
1196
|
+
async excelToCsv(lib, excelData, options) {
|
|
1197
|
+
const params = {};
|
|
1198
|
+
if (options === null || options === void 0 ? void 0 : options.sheet_name) {
|
|
1199
|
+
params.sheet_name = options.sheet_name;
|
|
1200
|
+
}
|
|
1201
|
+
return this.request('POST', `media/library/${lib}/convert/excel-to-csv`, {
|
|
1202
|
+
data: excelData,
|
|
1203
|
+
params,
|
|
1204
|
+
responseType: 'text',
|
|
1205
|
+
headers: {
|
|
1206
|
+
'Content-Type': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
|
1207
|
+
}
|
|
1208
|
+
});
|
|
1209
|
+
}
|
|
781
1210
|
async request(method, endpoint, params) {
|
|
782
1211
|
return await this.client.request({
|
|
783
1212
|
method: method,
|