@ptkl/sdk 0.9.15 → 0.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- var ProtokolSDK09 = (function (exports, axios) {
1
+ var ProtokolSDK010 = (function (exports, axios) {
2
2
  'use strict';
3
3
 
4
4
  class BaseClient {
@@ -532,12 +532,210 @@ var ProtokolSDK09 = (function (exports, axios) {
532
532
  }
533
533
 
534
534
  class Ratchet extends PlatformBaseClient {
535
+ /**
536
+ * Get all database connections for the current project
537
+ *
538
+ * @returns List of all configured ratchet connections
539
+ *
540
+ * @example
541
+ * ```typescript
542
+ * const ratchet = new Ratchet();
543
+ * const connections = await ratchet.getConnections();
544
+ * console.log(connections.data); // Array of connections
545
+ * ```
546
+ */
547
+ async getConnections() {
548
+ return await this.client.get("/v1/ratchet/connection");
549
+ }
550
+ /**
551
+ * Get a specific database connection by ID
552
+ *
553
+ * @param id - Connection ID
554
+ * @returns Connection details including queries
555
+ *
556
+ * @example
557
+ * ```typescript
558
+ * const ratchet = new Ratchet();
559
+ * const connection = await ratchet.getConnection('users_db');
560
+ * console.log(connection.data.queries); // Available queries for this connection
561
+ * ```
562
+ */
563
+ async getConnection(id) {
564
+ return await this.client.get(`/v1/ratchet/connection/${id}`);
565
+ }
566
+ /**
567
+ * Create a new database connection
568
+ *
569
+ * Supports multiple database types:
570
+ * - MySQL: Use credentials with host, dbname, user, password
571
+ * - PostgreSQL: Use credentials with host, dbname, user, password
572
+ * - MongoDB: Use DSN connection string
573
+ * - BigQuery: Use service_account_json and project_id
574
+ *
575
+ * @param connection - Connection configuration
576
+ * @returns Created connection details
577
+ *
578
+ * @example
579
+ * ```typescript
580
+ * const ratchet = new Ratchet();
581
+ *
582
+ * // MySQL/PostgreSQL connection
583
+ * await ratchet.createConnection({
584
+ * id: 'users_db',
585
+ * type: 'MySQL',
586
+ * credentials: {
587
+ * type: 'Credentials',
588
+ * host: 'localhost',
589
+ * dbname: 'users',
590
+ * user: 'admin',
591
+ * password: 'secret'
592
+ * }
593
+ * });
594
+ *
595
+ * // MongoDB connection
596
+ * await ratchet.createConnection({
597
+ * id: 'mongo_db',
598
+ * type: 'MongoDB',
599
+ * credentials: {
600
+ * type: 'DSN',
601
+ * dsn: 'mongodb://localhost:27017/mydb'
602
+ * }
603
+ * });
604
+ *
605
+ * // BigQuery connection
606
+ * await ratchet.createConnection({
607
+ * id: 'analytics_bq',
608
+ * type: 'BigQuery',
609
+ * credentials: {
610
+ * type: 'ServiceAccount',
611
+ * service_account_json: '{"type":"service_account",...}',
612
+ * project_id: 'my-project-id'
613
+ * }
614
+ * });
615
+ * ```
616
+ */
617
+ async createConnection(connection) {
618
+ return await this.client.post("/v1/ratchet/connection", connection);
619
+ }
620
+ /**
621
+ * Update an existing database connection
622
+ *
623
+ * @param connection - Updated connection configuration
624
+ * @returns Success status
625
+ *
626
+ * @example
627
+ * ```typescript
628
+ * const ratchet = new Ratchet();
629
+ * await ratchet.updateConnection({
630
+ * id: 'users_db',
631
+ * type: 'postgres',
632
+ * credentials: {
633
+ * type: 'postgres',
634
+ * host: 'localhost',
635
+ * dbname: 'users',
636
+ * user: 'admin',
637
+ * password: 'new_secret'
638
+ * },
639
+ * queries: [
640
+ * { id: 'get_user', expression: 'SELECT * FROM users WHERE id = $1' }
641
+ * ]
642
+ * });
643
+ * ```
644
+ */
645
+ async updateConnection(connection) {
646
+ return await this.client.put("/v1/ratchet/connection", connection);
647
+ }
648
+ /**
649
+ * Delete a database connection
650
+ *
651
+ * @param id - Connection ID to delete
652
+ * @returns Success status
653
+ *
654
+ * @example
655
+ * ```typescript
656
+ * const ratchet = new Ratchet();
657
+ * await ratchet.deleteConnection('users_db');
658
+ * ```
659
+ */
660
+ async deleteConnection(id) {
661
+ return await this.client.delete(`/v1/ratchet/connection/${id}`);
662
+ }
663
+ /**
664
+ * Test a database connection without saving it
665
+ *
666
+ * @param connection - Connection configuration to test
667
+ * @returns Success status if connection is valid
668
+ *
669
+ * @example
670
+ * ```typescript
671
+ * const ratchet = new Ratchet();
672
+ * const isValid = await ratchet.testConnection({
673
+ * id: 'test_db',
674
+ * type: 'postgres',
675
+ * credentials: {
676
+ * type: 'postgres',
677
+ * host: 'localhost',
678
+ * dbname: 'test',
679
+ * user: 'admin',
680
+ * password: 'secret'
681
+ * }
682
+ * });
683
+ * ```
684
+ */
685
+ async testConnection(connection) {
686
+ return await this.client.post("/v1/ratchet/test/connection", connection);
687
+ }
688
+ /**
689
+ * Execute a predefined database query
690
+ *
691
+ * Runs a query that has been previously configured in a ratchet connection.
692
+ * The query is identified by a qualified name in the format: `connectionId.queryId`
693
+ *
694
+ * @param name - Qualified name of the query (format: `connectionId.queryId`)
695
+ * @param params - Array of parameters to pass to the query
696
+ * @returns Query execution results
697
+ *
698
+ * @example
699
+ * ```typescript
700
+ * const ratchet = new Ratchet();
701
+ *
702
+ * // Execute a query with parameters
703
+ * const result = await ratchet.query('users_db.get_user_by_id', [123]);
704
+ *
705
+ * // Execute a query without parameters
706
+ * const allUsers = await ratchet.query('users_db.get_all_users', []);
707
+ * ```
708
+ */
535
709
  async query(name, params) {
536
- return await this.client.post('/v1/ratchet/query', {
710
+ return await this.client.post("/v1/ratchet/query", {
537
711
  name: name,
538
- params: params
712
+ params: params,
539
713
  });
540
714
  }
715
+ /**
716
+ * Inspect and execute a custom query without saving it
717
+ *
718
+ * This allows you to test queries before saving them to a connection.
719
+ *
720
+ * @param request - Query inspection request with connection name, query, and params
721
+ * @returns Query execution results
722
+ *
723
+ * @example
724
+ * ```typescript
725
+ * const ratchet = new Ratchet();
726
+ * const result = await ratchet.inspectQuery({
727
+ * name: 'users_db.test_query',
728
+ * query: {
729
+ * id: 'test_query',
730
+ * expression: 'SELECT * FROM users WHERE email = $1'
731
+ * },
732
+ * params: ['user@example.com']
733
+ * });
734
+ * ```
735
+ */
736
+ async inspectQuery(request) {
737
+ return await this.client.post("/v1/ratchet/query/inspect", request);
738
+ }
541
739
  }
542
740
 
543
741
  class Sandbox extends PlatformBaseClient {
@@ -997,6 +1195,23 @@ var ProtokolSDK09 = (function (exports, axios) {
997
1195
  async libraries() {
998
1196
  return await this.requestv1("GET", "media/library/list");
999
1197
  }
1198
+ /**
1199
+ * Upload files using multipart form data
1200
+ *
1201
+ * @param payload - Upload configuration with files, directory, and options
1202
+ * @returns Upload response from the server
1203
+ *
1204
+ * @example
1205
+ * ```typescript
1206
+ * const result = await dms.upload({
1207
+ * files: [file1, file2],
1208
+ * uploadDir: '/documents/invoices',
1209
+ * public: true,
1210
+ * replace: true,
1211
+ * metadata: { category: 'finance' }
1212
+ * });
1213
+ * ```
1214
+ */
1000
1215
  async upload(payload) {
1001
1216
  let files = payload.files;
1002
1217
  let formData = new FormData();
@@ -1010,13 +1225,15 @@ var ProtokolSDK09 = (function (exports, axios) {
1010
1225
  });
1011
1226
  if (count == files.length) {
1012
1227
  formData.append('path', payload.uploadDir);
1013
- formData.append('ref', payload.uuid);
1014
1228
  if (payload.public) {
1015
1229
  formData.append('is_public', "true");
1016
1230
  }
1231
+ if (payload.replace) {
1232
+ formData.append('replace', "true");
1233
+ }
1017
1234
  if (payload.expiresAt)
1018
1235
  formData.append('expiresAt', new Date(payload.expiresAt).toISOString());
1019
- if (Object.keys(payload.metadata).length > 0)
1236
+ if (payload.metadata && Object.keys(payload.metadata).length > 0)
1020
1237
  formData.append('metadata', JSON.stringify(payload.metadata));
1021
1238
  return await this.request("POST", "media/upload", {
1022
1239
  data: formData,
@@ -1029,6 +1246,28 @@ var ProtokolSDK09 = (function (exports, axios) {
1029
1246
  async delete(data) {
1030
1247
  return this.request('POST', 'media/delete', data);
1031
1248
  }
1249
+ /**
1250
+ * Upload files using base64-encoded content
1251
+ *
1252
+ * @param data - Upload payload with base64-encoded files
1253
+ * @returns Upload response from the server
1254
+ *
1255
+ * @example
1256
+ * ```typescript
1257
+ * const result = await dms.uploadBase64({
1258
+ * path: '/documents/reports',
1259
+ * is_public: false,
1260
+ * replace: true,
1261
+ * files: [
1262
+ * {
1263
+ * name: 'report.pdf',
1264
+ * content_type: 'application/pdf',
1265
+ * data: 'base64EncodedContent...'
1266
+ * }
1267
+ * ]
1268
+ * });
1269
+ * ```
1270
+ */
1032
1271
  async uploadBase64(data) {
1033
1272
  return this.request('POST', `media/upload`, {
1034
1273
  data,
@@ -1037,30 +1276,30 @@ var ProtokolSDK09 = (function (exports, axios) {
1037
1276
  }
1038
1277
  });
1039
1278
  }
1040
- async getMedia(lib, key, encoding) {
1041
- return this.request('GET', `media/library/${lib}/get/${key}`, {
1279
+ async getMedia(key, encoding) {
1280
+ return this.request('GET', `media/get/${key}`, {
1042
1281
  params: {
1043
1282
  encoding
1044
1283
  },
1045
1284
  responseType: (!encoding) ? 'blob' : null
1046
1285
  });
1047
1286
  }
1048
- async download(lib, key) {
1049
- return this.request('POST', `media/library/${lib}/download`, {
1287
+ async download(key) {
1288
+ return this.request('POST', `media/download`, {
1050
1289
  data: {
1051
1290
  key
1052
1291
  },
1053
1292
  responseType: 'blob'
1054
1293
  });
1055
1294
  }
1056
- async getExifData(lib, key) {
1057
- return this.request('GET', `media/library/${lib}/exif/${key}`);
1295
+ async getExifData(key) {
1296
+ return this.request('GET', `media/exif/${key}`);
1058
1297
  }
1059
- async html2pdf(lib, data) {
1060
- const { output_pdf = false, input_path, input_html, output_path, output_file_name, output_type, data: templateData } = data;
1298
+ async html2pdf(data) {
1299
+ const { output_pdf = false, input_path, input_html, output_path, output_file_name, output_type, data: templateData, replace, } = data;
1061
1300
  const type = output_pdf ? 'arraybuffer' : 'json';
1062
1301
  const contentType = output_pdf ? 'application/pdf' : 'application/json';
1063
- return this.request('POST', `media/library/${lib}/html2pdf`, {
1302
+ return this.request('POST', `media/pdf/html2pdf`, {
1064
1303
  data: {
1065
1304
  output_pdf,
1066
1305
  input_path,
@@ -1068,7 +1307,27 @@ var ProtokolSDK09 = (function (exports, axios) {
1068
1307
  input_html,
1069
1308
  output_file_name,
1070
1309
  output_type,
1071
- data: templateData
1310
+ data: templateData,
1311
+ replace,
1312
+ },
1313
+ headers: {
1314
+ 'Content-Type': contentType
1315
+ },
1316
+ responseType: type
1317
+ });
1318
+ }
1319
+ async pdf2html(data) {
1320
+ const { output_html = false, input_path, input_pdf, output_path, output_file_name, replace, } = data;
1321
+ const type = output_html ? 'arraybuffer' : 'json';
1322
+ const contentType = output_html ? 'text/html' : 'application/json';
1323
+ return this.request('POST', `media/pdf/pdf2html`, {
1324
+ data: {
1325
+ output_html,
1326
+ input_path,
1327
+ output_path,
1328
+ input_pdf,
1329
+ output_file_name,
1330
+ replace,
1072
1331
  },
1073
1332
  headers: {
1074
1333
  'Content-Type': contentType
@@ -1076,20 +1335,20 @@ var ProtokolSDK09 = (function (exports, axios) {
1076
1335
  responseType: type
1077
1336
  });
1078
1337
  }
1079
- async createDir(lib, path) {
1080
- return this.request('POST', `media/library/${lib}/dir`, { data: { path } });
1338
+ async createDir(path) {
1339
+ return this.request('POST', `media/library/dir`, { data: { path } });
1081
1340
  }
1082
- async deleteDir(lib, path) {
1083
- return this.request('POST', `media/library/${lib}/delete/dir`, { data: { path } });
1341
+ async deleteDir(path) {
1342
+ return this.request('DELETE', `media/library/dir`, { data: { path } });
1084
1343
  }
1085
- async dirs(lib, data) {
1086
- return await this.request("POST", `media/library/${lib}/dirs`, { data });
1344
+ async dirs(data) {
1345
+ return await this.request("POST", `media/library/dirs`, { data });
1087
1346
  }
1088
- async fillPdf(lib, data) {
1089
- const { input_path, output_path, output_pdf = false, output_type, output_file_name, form_data, forms } = data;
1347
+ async fillPdf(data) {
1348
+ const { input_path, output_path, output_pdf = false, output_type, output_file_name, replace, form_data, forms } = data;
1090
1349
  const responseType = output_pdf ? 'arraybuffer' : 'json';
1091
1350
  const contentType = output_pdf ? 'application/pdf' : 'application/json';
1092
- return this.request('POST', `media/library/${lib}/pdf/fill`, {
1351
+ return this.request('POST', `media/pdf/fill`, {
1093
1352
  data: {
1094
1353
  input_path,
1095
1354
  output_path,
@@ -1097,6 +1356,7 @@ var ProtokolSDK09 = (function (exports, axios) {
1097
1356
  output_type,
1098
1357
  output_file_name,
1099
1358
  form_data,
1359
+ replace,
1100
1360
  forms
1101
1361
  },
1102
1362
  headers: {
@@ -1174,7 +1434,7 @@ var ProtokolSDK09 = (function (exports, axios) {
1174
1434
  * // excelResult.data is a Blob
1175
1435
  * ```
1176
1436
  */
1177
- async convertData(lib, data, params) {
1437
+ async convertData(data, params) {
1178
1438
  const { from, to, sheet_name, include_header, include_footer, header_as_comment, footer_as_comment, separator_rows, field_order, } = params;
1179
1439
  const queryParams = { from, to };
1180
1440
  // Add optional parameters if provided
@@ -1201,7 +1461,7 @@ var ProtokolSDK09 = (function (exports, axios) {
1201
1461
  else if (to === 'excel' || to === 'xlsx') {
1202
1462
  responseType = 'blob';
1203
1463
  }
1204
- return this.request('POST', `media/library/${lib}/convert/data`, {
1464
+ return this.request('POST', `media/convert/data`, {
1205
1465
  data,
1206
1466
  params: queryParams,
1207
1467
  responseType,
@@ -1241,9 +1501,9 @@ var ProtokolSDK09 = (function (exports, axios) {
1241
1501
  * // }
1242
1502
  * ```
1243
1503
  */
1244
- async getDataInfo(lib, data, params) {
1504
+ async getDataInfo(data, params) {
1245
1505
  const { format } = params;
1246
- return this.request('POST', `media/library/${lib}/convert/info`, {
1506
+ return this.request('POST', `media/convert/info`, {
1247
1507
  data,
1248
1508
  params: { format },
1249
1509
  headers: {
@@ -1285,9 +1545,9 @@ var ProtokolSDK09 = (function (exports, axios) {
1285
1545
  * }
1286
1546
  * ```
1287
1547
  */
1288
- async validateData(lib, data, params) {
1548
+ async validateData(data, params) {
1289
1549
  const { format } = params;
1290
- return this.request('POST', `media/library/${lib}/convert/validate`, {
1550
+ return this.request('POST', `media/convert/validate`, {
1291
1551
  data,
1292
1552
  params: { format },
1293
1553
  headers: {
@@ -1333,12 +1593,12 @@ var ProtokolSDK09 = (function (exports, axios) {
1333
1593
  * // Auto-detects header, items, and footer sections
1334
1594
  * ```
1335
1595
  */
1336
- async jsonToCsv(lib, jsonData, options) {
1596
+ async jsonToCsv(jsonData, options) {
1337
1597
  let params = {};
1338
1598
  if (options === null || options === void 0 ? void 0 : options.field_order) {
1339
1599
  params.field_order = options.field_order.join(',');
1340
1600
  }
1341
- return this.request('POST', `media/library/${lib}/convert/json-to-csv`, {
1601
+ return this.request('POST', `media/convert/json-to-csv`, {
1342
1602
  params,
1343
1603
  data: jsonData,
1344
1604
  responseType: 'text',
@@ -1392,7 +1652,7 @@ var ProtokolSDK09 = (function (exports, axios) {
1392
1652
  * link.click();
1393
1653
  * ```
1394
1654
  */
1395
- async jsonToExcel(lib, jsonData, options) {
1655
+ async jsonToExcel(jsonData, options) {
1396
1656
  const params = {};
1397
1657
  if (options === null || options === void 0 ? void 0 : options.sheet_name) {
1398
1658
  params.sheet_name = options.sheet_name;
@@ -1400,7 +1660,7 @@ var ProtokolSDK09 = (function (exports, axios) {
1400
1660
  if (options === null || options === void 0 ? void 0 : options.field_order) {
1401
1661
  params.field_order = options.field_order.join(',');
1402
1662
  }
1403
- return this.request('POST', `media/library/${lib}/convert/json-to-excel`, {
1663
+ return this.request('POST', `media/convert/json-to-excel`, {
1404
1664
  data: jsonData,
1405
1665
  params,
1406
1666
  responseType: 'blob',
@@ -1431,8 +1691,8 @@ var ProtokolSDK09 = (function (exports, axios) {
1431
1691
  * // ]
1432
1692
  * ```
1433
1693
  */
1434
- async csvToJson(lib, csvData) {
1435
- return this.request('POST', `media/library/${lib}/convert/csv-to-json`, {
1694
+ async csvToJson(csvData) {
1695
+ return this.request('POST', `media/convert/csv-to-json`, {
1436
1696
  data: csvData,
1437
1697
  responseType: 'json',
1438
1698
  headers: {
@@ -1464,12 +1724,12 @@ var ProtokolSDK09 = (function (exports, axios) {
1464
1724
  * // Use url for download or further processing
1465
1725
  * ```
1466
1726
  */
1467
- async csvToExcel(lib, csvData, options) {
1727
+ async csvToExcel(csvData, options) {
1468
1728
  const params = {};
1469
1729
  if (options === null || options === void 0 ? void 0 : options.sheet_name) {
1470
1730
  params.sheet_name = options.sheet_name;
1471
1731
  }
1472
- return this.request('POST', `media/library/${lib}/convert/csv-to-excel`, {
1732
+ return this.request('POST', `media/convert/csv-to-excel`, {
1473
1733
  data: csvData,
1474
1734
  params,
1475
1735
  responseType: 'blob',
@@ -1504,12 +1764,12 @@ var ProtokolSDK09 = (function (exports, axios) {
1504
1764
  * const jsonFromBuffer = await dms.excelToJson(libraryRef, arrayBuffer);
1505
1765
  * ```
1506
1766
  */
1507
- async excelToJson(lib, excelData, options) {
1767
+ async excelToJson(excelData, options) {
1508
1768
  const params = {};
1509
1769
  if (options === null || options === void 0 ? void 0 : options.sheet_name) {
1510
1770
  params.sheet_name = options.sheet_name;
1511
1771
  }
1512
- return this.request('POST', `media/library/${lib}/convert/excel-to-json`, {
1772
+ return this.request('POST', `media/convert/excel-to-json`, {
1513
1773
  data: excelData,
1514
1774
  params,
1515
1775
  responseType: 'json',
@@ -1548,12 +1808,12 @@ var ProtokolSDK09 = (function (exports, axios) {
1548
1808
  * link.click();
1549
1809
  * ```
1550
1810
  */
1551
- async excelToCsv(lib, excelData, options) {
1811
+ async excelToCsv(excelData, options) {
1552
1812
  const params = {};
1553
1813
  if (options === null || options === void 0 ? void 0 : options.sheet_name) {
1554
1814
  params.sheet_name = options.sheet_name;
1555
1815
  }
1556
- return this.request('POST', `media/library/${lib}/convert/excel-to-csv`, {
1816
+ return this.request('POST', `media/convert/excel-to-csv`, {
1557
1817
  data: excelData,
1558
1818
  params,
1559
1819
  responseType: 'text',
@@ -1565,7 +1825,7 @@ var ProtokolSDK09 = (function (exports, axios) {
1565
1825
  async request(method, endpoint, params) {
1566
1826
  return await this.client.request({
1567
1827
  method: method,
1568
- url: `/v2/dms/${endpoint}`,
1828
+ url: `/v3/dms/${endpoint}`,
1569
1829
  ...params
1570
1830
  });
1571
1831
  }