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