@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 CHANGED
@@ -19003,24 +19003,23 @@ const isBrowser = typeof window !== "undefined" &&
19003
19003
  */
19004
19004
  class PlatformBaseClient extends BaseClient {
19005
19005
  constructor(options) {
19006
- var _a, _b;
19006
+ var _a, _b, _c;
19007
19007
  let { env = null, token = null, host = null, } = options !== null && options !== void 0 ? options : {};
19008
19008
  let headers = {};
19009
19009
  var project_uuid = null;
19010
19010
  if (isBrowser) {
19011
- console.log("DEBUG", sessionStorage.getItem('protokol_context'));
19011
+ console.log("PlatformBaseClient: running in browser context");
19012
19012
  if (sessionStorage.getItem('protokol_context') == "forge") {
19013
19013
  headers['X-Project-Env'] = (_a = sessionStorage.getItem('forge_app_env')) !== null && _a !== void 0 ? _a : "dev";
19014
19014
  }
19015
19015
  else {
19016
- // this potentially means that it is running as dev server in local
19017
- headers['X-Project-Env'] = "dev";
19016
+ headers['X-Project-Env'] = (_b = localStorage.getItem('current_env')) !== null && _b !== void 0 ? _b : "dev";
19018
19017
  }
19019
19018
  }
19020
19019
  if (typeof window !== "undefined") {
19021
19020
  // @ts-ignore
19022
19021
  const __global_env__ = window === null || window === void 0 ? void 0 : window.__ENV_VARIABLES__;
19023
- host = (_b = __global_env__ === null || __global_env__ === void 0 ? void 0 : __global_env__.API_HOST) !== null && _b !== void 0 ? _b : host;
19022
+ host = (_c = __global_env__ === null || __global_env__ === void 0 ? void 0 : __global_env__.API_HOST) !== null && _c !== void 0 ? _c : host;
19024
19023
  // @ts-ignore
19025
19024
  env = env !== null && env !== void 0 ? env : __global_env__ === null || __global_env__ === void 0 ? void 0 : __global_env__.PROJECT_ENV;
19026
19025
  token = token !== null && token !== void 0 ? token : __global_env__ === null || __global_env__ === void 0 ? void 0 : __global_env__.PROJECT_API_TOKEN;
@@ -19486,6 +19485,9 @@ class Workflow extends PlatformBaseClient {
19486
19485
  async trigger(id, event, data) {
19487
19486
  return await this.client.post(`/v1/project/workflow/workflow/${id}/event/${event}`, data);
19488
19487
  }
19488
+ async publish(event, data) {
19489
+ return await this.client.post(`/v1/project/workflow/workflow/event/${event}`, data);
19490
+ }
19489
19491
  }
19490
19492
 
19491
19493
  class Forge extends PlatformBaseClient {
@@ -19585,7 +19587,7 @@ class Invoicing extends PlatformBaseClient {
19585
19587
 
19586
19588
  class IntegrationsBaseClient extends BaseClient {
19587
19589
  constructor(options) {
19588
- var _a, _b;
19590
+ var _a, _b, _c;
19589
19591
  let { env = null, token, host, } = options !== null && options !== void 0 ? options : {};
19590
19592
  let headers = {};
19591
19593
  var project_uuid = null;
@@ -19594,14 +19596,13 @@ class IntegrationsBaseClient extends BaseClient {
19594
19596
  headers['X-Project-Env'] = (_a = sessionStorage.getItem('forge_app_env')) !== null && _a !== void 0 ? _a : "dev";
19595
19597
  }
19596
19598
  else {
19597
- // this potentially means that it is running as dev server in local
19598
- headers['X-Project-Env'] = "dev";
19599
+ headers['X-Project-Env'] = (_b = localStorage.getItem('current_env')) !== null && _b !== void 0 ? _b : "dev";
19599
19600
  }
19600
19601
  }
19601
19602
  if (typeof window !== "undefined") {
19602
19603
  // @ts-ignore
19603
19604
  const __global_env__ = window === null || window === void 0 ? void 0 : window.__ENV_VARIABLES__;
19604
- host = (_b = __global_env__.INTEGRATION_API) !== null && _b !== void 0 ? _b : host;
19605
+ host = (_c = __global_env__.INTEGRATION_API) !== null && _c !== void 0 ? _c : host;
19605
19606
  // @ts-ignore
19606
19607
  token = token !== null && token !== void 0 ? token : __global_env__ === null || __global_env__ === void 0 ? void 0 : __global_env__.PROJECT_API_TOKEN;
19607
19608
  // @ts-ignore
@@ -19629,6 +19630,57 @@ class IntegrationsBaseClient extends BaseClient {
19629
19630
  }
19630
19631
  }
19631
19632
 
19633
+ /**
19634
+ * Document Management System (DMS) API client
19635
+ *
19636
+ * Provides comprehensive document and media management capabilities including:
19637
+ * - File upload, download, and management
19638
+ * - PDF generation and form filling
19639
+ * - Data conversion between JSON, CSV, and Excel formats
19640
+ * - Media processing and EXIF data extraction
19641
+ *
19642
+ * ## Data Conversion Features
19643
+ *
19644
+ * The DMS class includes powerful data conversion capabilities that allow you to:
19645
+ * - Convert between JSON, CSV, and Excel (.xlsx) formats
19646
+ * - Validate data format integrity
19647
+ * - Analyze data structure and metadata
19648
+ * - Handle large datasets with memory-efficient processing
19649
+ *
19650
+ * ### Supported Formats
19651
+ * - **JSON**: Array of objects (recommended for tabular data)
19652
+ * - **CSV**: Comma-separated values with headers
19653
+ * - **Excel**: .xlsx format with optional sheet specification
19654
+ *
19655
+ * ### Error Handling
19656
+ * All conversion methods may throw errors with code 3003 for conversion failures.
19657
+ * Always wrap calls in try-catch blocks for production use.
19658
+ *
19659
+ * @example
19660
+ * ```typescript
19661
+ * import { DMS } from 'protokol-sdk';
19662
+ *
19663
+ * const dms = new DMS({
19664
+ * token: 'your-bearer-token',
19665
+ * host: 'http://localhost:8086'
19666
+ * });
19667
+ *
19668
+ * const libraryRef = 'your-library-uuid';
19669
+ *
19670
+ * // Convert JSON to CSV
19671
+ * const jsonData = [
19672
+ * { name: "John", age: 30 },
19673
+ * { name: "Jane", age: 25 }
19674
+ * ];
19675
+ *
19676
+ * try {
19677
+ * const csvResult = await dms.jsonToCsv(libraryRef, jsonData);
19678
+ * console.log(csvResult.data); // CSV string
19679
+ * } catch (error) {
19680
+ * console.error('Conversion failed:', error.message);
19681
+ * }
19682
+ * ```
19683
+ */
19632
19684
  class DMS extends IntegrationsBaseClient {
19633
19685
  async list(data) {
19634
19686
  return this.request('POST', 'media/list', { data });
@@ -19746,6 +19798,383 @@ class DMS extends IntegrationsBaseClient {
19746
19798
  responseType
19747
19799
  });
19748
19800
  }
19801
+ // ===================================================================
19802
+ // Data Converter Methods
19803
+ // ===================================================================
19804
+ //
19805
+ // The following methods provide comprehensive data conversion capabilities
19806
+ // between JSON, CSV, and Excel formats, along with validation and analysis tools.
19807
+ // All methods require a valid library reference UUID and return AxiosResponse objects.
19808
+ //
19809
+ /**
19810
+ * Convert data between different formats (JSON, CSV, Excel)
19811
+ *
19812
+ * @param lib - Library reference UUID
19813
+ * @param data - Raw data to convert
19814
+ * @param params - Conversion parameters
19815
+ * @returns Promise resolving to converted data
19816
+ *
19817
+ * @example
19818
+ * ```typescript
19819
+ * // Convert JSON to CSV
19820
+ * const jsonData = [
19821
+ * { name: "John Doe", age: 30, email: "john@example.com" },
19822
+ * { name: "Jane Smith", age: 25, email: "jane@example.com" }
19823
+ * ];
19824
+ *
19825
+ * const csvResult = await dms.convertData(libraryRef, jsonData, {
19826
+ * from: 'json',
19827
+ * to: 'csv'
19828
+ * });
19829
+ * console.log(csvResult.data); // CSV string
19830
+ *
19831
+ * // Convert JSON to Excel with custom sheet name
19832
+ * const excelResult = await dms.convertData(libraryRef, jsonData, {
19833
+ * from: 'json',
19834
+ * to: 'excel',
19835
+ * sheet_name: 'Customer Data'
19836
+ * });
19837
+ * // excelResult.data is a Blob
19838
+ * ```
19839
+ */
19840
+ async convertData(lib, data, params) {
19841
+ const { from, to, sheet_name } = params;
19842
+ const queryParams = { from, to };
19843
+ if (sheet_name) {
19844
+ queryParams.sheet_name = sheet_name;
19845
+ }
19846
+ // Determine content type based on target format
19847
+ let responseType = 'text';
19848
+ if (to === 'json') {
19849
+ responseType = 'json';
19850
+ }
19851
+ else if (to === 'excel' || to === 'xlsx') {
19852
+ responseType = 'blob';
19853
+ }
19854
+ return this.request('POST', `media/library/${lib}/convert/data`, {
19855
+ data,
19856
+ params: queryParams,
19857
+ responseType,
19858
+ headers: {
19859
+ 'Content-Type': 'application/json'
19860
+ }
19861
+ });
19862
+ }
19863
+ /**
19864
+ * Get information about data format and structure
19865
+ *
19866
+ * @param lib - Library reference UUID
19867
+ * @param data - Raw data to analyze
19868
+ * @param params - Analysis parameters
19869
+ * @returns Promise resolving to data information
19870
+ *
19871
+ * @example
19872
+ * ```typescript
19873
+ * const jsonData = [
19874
+ * { name: "John", age: 30, email: "john@example.com" },
19875
+ * { name: "Jane", age: 25, email: "jane@example.com" }
19876
+ * ];
19877
+ *
19878
+ * const dataInfo = await dms.getDataInfo(libraryRef, jsonData, {
19879
+ * format: 'json'
19880
+ * });
19881
+ *
19882
+ * console.log(dataInfo.data);
19883
+ * // Output:
19884
+ * // {
19885
+ * // format: "json",
19886
+ * // size_bytes: 245,
19887
+ * // record_count: 2,
19888
+ * // field_count: 3,
19889
+ * // fields: ["name", "age", "email"],
19890
+ * // library_ref: "98bee1cb-0f21-4582-a832-7c32b4b61831"
19891
+ * // }
19892
+ * ```
19893
+ */
19894
+ async getDataInfo(lib, data, params) {
19895
+ const { format } = params;
19896
+ return this.request('POST', `media/library/${lib}/convert/info`, {
19897
+ data,
19898
+ params: { format },
19899
+ headers: {
19900
+ 'Content-Type': 'application/json'
19901
+ }
19902
+ });
19903
+ }
19904
+ /**
19905
+ * Validate data format without performing conversion
19906
+ *
19907
+ * @param lib - Library reference UUID
19908
+ * @param data - Raw data to validate
19909
+ * @param params - Validation parameters
19910
+ * @returns Promise resolving to validation result
19911
+ *
19912
+ * @example
19913
+ * ```typescript
19914
+ * const jsonData = [{ name: "John", age: 30 }];
19915
+ *
19916
+ * const validation = await dms.validateData(libraryRef, jsonData, {
19917
+ * format: 'json'
19918
+ * });
19919
+ *
19920
+ * console.log(validation.data);
19921
+ * // Output:
19922
+ * // {
19923
+ * // valid: true,
19924
+ * // message: "Data is valid JSON format",
19925
+ * // library_ref: "98bee1cb-0f21-4582-a832-7c32b4b61831"
19926
+ * // }
19927
+ *
19928
+ * // Handle invalid data
19929
+ * try {
19930
+ * const invalidValidation = await dms.validateData(libraryRef, "invalid json", {
19931
+ * format: 'json'
19932
+ * });
19933
+ * } catch (error) {
19934
+ * console.error('Validation failed:', error.response?.data?.message);
19935
+ * }
19936
+ * ```
19937
+ */
19938
+ async validateData(lib, data, params) {
19939
+ const { format } = params;
19940
+ return this.request('POST', `media/library/${lib}/convert/validate`, {
19941
+ data,
19942
+ params: { format },
19943
+ headers: {
19944
+ 'Content-Type': 'application/json'
19945
+ }
19946
+ });
19947
+ }
19948
+ /**
19949
+ * Convert JSON data to CSV format
19950
+ *
19951
+ * @param lib - Library reference UUID
19952
+ * @param jsonData - JSON data (array of objects recommended for tabular data)
19953
+ * @returns Promise resolving to CSV string
19954
+ *
19955
+ * @example
19956
+ * ```typescript
19957
+ * const jsonData = [
19958
+ * { name: "John Doe", age: 30, email: "john@example.com" },
19959
+ * { name: "Jane Smith", age: 25, email: "jane@example.com" }
19960
+ * ];
19961
+ *
19962
+ * const csvResponse = await dms.jsonToCsv(libraryRef, jsonData);
19963
+ * console.log(csvResponse.data);
19964
+ * // Output:
19965
+ * // name,age,email
19966
+ * // John Doe,30,john@example.com
19967
+ * // Jane Smith,25,jane@example.com
19968
+ * ```
19969
+ */
19970
+ async jsonToCsv(lib, jsonData) {
19971
+ return this.request('POST', `media/library/${lib}/convert/json-to-csv`, {
19972
+ data: jsonData,
19973
+ responseType: 'text',
19974
+ headers: {
19975
+ 'Content-Type': 'application/json'
19976
+ }
19977
+ });
19978
+ }
19979
+ /**
19980
+ * Convert JSON data to Excel (.xlsx) format
19981
+ *
19982
+ * @param lib - Library reference UUID
19983
+ * @param jsonData - JSON data (array of objects recommended for tabular data)
19984
+ * @param options - Optional conversion options
19985
+ * @returns Promise resolving to Excel file as Blob
19986
+ *
19987
+ * @example
19988
+ * ```typescript
19989
+ * const jsonData = [
19990
+ * { name: "John Doe", age: 30, email: "john@example.com" },
19991
+ * { name: "Jane Smith", age: 25, email: "jane@example.com" }
19992
+ * ];
19993
+ *
19994
+ * // Basic conversion
19995
+ * const excelResponse = await dms.jsonToExcel(libraryRef, jsonData);
19996
+ * const blob = excelResponse.data; // Blob for download
19997
+ *
19998
+ * // With custom sheet name
19999
+ * const excelWithOptions = await dms.jsonToExcel(libraryRef, jsonData, {
20000
+ * sheet_name: 'Customer Data'
20001
+ * });
20002
+ *
20003
+ * // Create download link
20004
+ * const url = URL.createObjectURL(excelWithOptions.data);
20005
+ * const link = document.createElement('a');
20006
+ * link.href = url;
20007
+ * link.download = 'data.xlsx';
20008
+ * link.click();
20009
+ * ```
20010
+ */
20011
+ async jsonToExcel(lib, jsonData, options) {
20012
+ const params = {};
20013
+ if (options === null || options === void 0 ? void 0 : options.sheet_name) {
20014
+ params.sheet_name = options.sheet_name;
20015
+ }
20016
+ return this.request('POST', `media/library/${lib}/convert/json-to-excel`, {
20017
+ data: jsonData,
20018
+ params,
20019
+ responseType: 'blob',
20020
+ headers: {
20021
+ 'Content-Type': 'application/json'
20022
+ }
20023
+ });
20024
+ }
20025
+ /**
20026
+ * Convert CSV data to JSON format
20027
+ *
20028
+ * @param lib - Library reference UUID
20029
+ * @param csvData - CSV data string (with headers in first row)
20030
+ * @returns Promise resolving to JSON array
20031
+ *
20032
+ * @example
20033
+ * ```typescript
20034
+ * const csvString = `name,age,email
20035
+ * John Doe,30,john@example.com
20036
+ * Jane Smith,25,jane@example.com`;
20037
+ *
20038
+ * const jsonResponse = await dms.csvToJson(libraryRef, csvString);
20039
+ * console.log(jsonResponse.data);
20040
+ * // Output:
20041
+ * // [
20042
+ * // { name: "John Doe", age: "30", email: "john@example.com" },
20043
+ * // { name: "Jane Smith", age: "25", email: "jane@example.com" }
20044
+ * // ]
20045
+ * ```
20046
+ */
20047
+ async csvToJson(lib, csvData) {
20048
+ return this.request('POST', `media/library/${lib}/convert/csv-to-json`, {
20049
+ data: csvData,
20050
+ responseType: 'json',
20051
+ headers: {
20052
+ 'Content-Type': 'text/csv'
20053
+ }
20054
+ });
20055
+ }
20056
+ /**
20057
+ * Convert CSV data to Excel (.xlsx) format
20058
+ *
20059
+ * @param lib - Library reference UUID
20060
+ * @param csvData - CSV data string (with headers in first row)
20061
+ * @param options - Optional conversion options
20062
+ * @returns Promise resolving to Excel file as Blob
20063
+ *
20064
+ * @example
20065
+ * ```typescript
20066
+ * const csvString = `name,age,email
20067
+ * John Doe,30,john@example.com
20068
+ * Jane Smith,25,jane@example.com`;
20069
+ *
20070
+ * const excelResponse = await dms.csvToExcel(libraryRef, csvString, {
20071
+ * sheet_name: 'Imported Data'
20072
+ * });
20073
+ *
20074
+ * // Handle the Excel blob
20075
+ * const blob = excelResponse.data;
20076
+ * const url = URL.createObjectURL(blob);
20077
+ * // Use url for download or further processing
20078
+ * ```
20079
+ */
20080
+ async csvToExcel(lib, csvData, options) {
20081
+ const params = {};
20082
+ if (options === null || options === void 0 ? void 0 : options.sheet_name) {
20083
+ params.sheet_name = options.sheet_name;
20084
+ }
20085
+ return this.request('POST', `media/library/${lib}/convert/csv-to-excel`, {
20086
+ data: csvData,
20087
+ params,
20088
+ responseType: 'blob',
20089
+ headers: {
20090
+ 'Content-Type': 'text/csv'
20091
+ }
20092
+ });
20093
+ }
20094
+ /**
20095
+ * Convert Excel (.xlsx) data to JSON format
20096
+ *
20097
+ * @param lib - Library reference UUID
20098
+ * @param excelData - Excel file data as Blob or ArrayBuffer
20099
+ * @param options - Optional conversion options
20100
+ * @returns Promise resolving to JSON array
20101
+ *
20102
+ * @example
20103
+ * ```typescript
20104
+ * // From file input
20105
+ * const fileInput = document.querySelector('input[type="file"]');
20106
+ * const file = fileInput.files[0]; // Excel file
20107
+ *
20108
+ * const jsonResponse = await dms.excelToJson(libraryRef, file, {
20109
+ * sheet_name: 'Sheet1' // optional, defaults to first sheet
20110
+ * });
20111
+ *
20112
+ * console.log(jsonResponse.data);
20113
+ * // Output: JSON array with data from Excel sheet
20114
+ *
20115
+ * // From ArrayBuffer
20116
+ * const arrayBuffer = await file.arrayBuffer();
20117
+ * const jsonFromBuffer = await dms.excelToJson(libraryRef, arrayBuffer);
20118
+ * ```
20119
+ */
20120
+ async excelToJson(lib, excelData, options) {
20121
+ const params = {};
20122
+ if (options === null || options === void 0 ? void 0 : options.sheet_name) {
20123
+ params.sheet_name = options.sheet_name;
20124
+ }
20125
+ return this.request('POST', `media/library/${lib}/convert/excel-to-json`, {
20126
+ data: excelData,
20127
+ params,
20128
+ responseType: 'json',
20129
+ headers: {
20130
+ 'Content-Type': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
20131
+ }
20132
+ });
20133
+ }
20134
+ /**
20135
+ * Convert Excel (.xlsx) data to CSV format
20136
+ *
20137
+ * @param lib - Library reference UUID
20138
+ * @param excelData - Excel file data as Blob or ArrayBuffer
20139
+ * @param options - Optional conversion options
20140
+ * @returns Promise resolving to CSV string
20141
+ *
20142
+ * @example
20143
+ * ```typescript
20144
+ * // From file input
20145
+ * const fileInput = document.querySelector('input[type="file"]');
20146
+ * const file = fileInput.files[0]; // Excel file
20147
+ *
20148
+ * const csvResponse = await dms.excelToCsv(libraryRef, file, {
20149
+ * sheet_name: 'Data' // optional, defaults to first sheet
20150
+ * });
20151
+ *
20152
+ * console.log(csvResponse.data);
20153
+ * // Output: CSV string with data from Excel sheet
20154
+ *
20155
+ * // Save as CSV file
20156
+ * const csvBlob = new Blob([csvResponse.data], { type: 'text/csv' });
20157
+ * const url = URL.createObjectURL(csvBlob);
20158
+ * const link = document.createElement('a');
20159
+ * link.href = url;
20160
+ * link.download = 'converted.csv';
20161
+ * link.click();
20162
+ * ```
20163
+ */
20164
+ async excelToCsv(lib, excelData, options) {
20165
+ const params = {};
20166
+ if (options === null || options === void 0 ? void 0 : options.sheet_name) {
20167
+ params.sheet_name = options.sheet_name;
20168
+ }
20169
+ return this.request('POST', `media/library/${lib}/convert/excel-to-csv`, {
20170
+ data: excelData,
20171
+ params,
20172
+ responseType: 'text',
20173
+ headers: {
20174
+ 'Content-Type': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
20175
+ }
20176
+ });
20177
+ }
19749
20178
  async request(method, endpoint, params) {
19750
20179
  return await this.client.request({
19751
20180
  method: method,