@ptkl/sdk 0.10.0 → 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();
@@ -1012,9 +1227,12 @@ class DMS extends IntegrationsBaseClient {
1012
1227
  if (payload.public) {
1013
1228
  formData.append('is_public', "true");
1014
1229
  }
1230
+ if (payload.replace) {
1231
+ formData.append('replace', "true");
1232
+ }
1015
1233
  if (payload.expiresAt)
1016
1234
  formData.append('expiresAt', new Date(payload.expiresAt).toISOString());
1017
- if (Object.keys(payload.metadata).length > 0)
1235
+ if (payload.metadata && Object.keys(payload.metadata).length > 0)
1018
1236
  formData.append('metadata', JSON.stringify(payload.metadata));
1019
1237
  return await this.request("POST", "media/upload", {
1020
1238
  data: formData,
@@ -1027,6 +1245,28 @@ class DMS extends IntegrationsBaseClient {
1027
1245
  async delete(data) {
1028
1246
  return this.request('POST', 'media/delete', data);
1029
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
+ */
1030
1270
  async uploadBase64(data) {
1031
1271
  return this.request('POST', `media/upload`, {
1032
1272
  data,
@@ -1035,7 +1275,7 @@ class DMS extends IntegrationsBaseClient {
1035
1275
  }
1036
1276
  });
1037
1277
  }
1038
- async getMedia(lib, key, encoding) {
1278
+ async getMedia(key, encoding) {
1039
1279
  return this.request('GET', `media/get/${key}`, {
1040
1280
  params: {
1041
1281
  encoding
@@ -1043,7 +1283,7 @@ class DMS extends IntegrationsBaseClient {
1043
1283
  responseType: (!encoding) ? 'blob' : null
1044
1284
  });
1045
1285
  }
1046
- async download(lib, key) {
1286
+ async download(key) {
1047
1287
  return this.request('POST', `media/download`, {
1048
1288
  data: {
1049
1289
  key
@@ -1055,7 +1295,7 @@ class DMS extends IntegrationsBaseClient {
1055
1295
  return this.request('GET', `media/exif/${key}`);
1056
1296
  }
1057
1297
  async html2pdf(data) {
1058
- const { output_pdf = false, input_path, input_html, output_path, output_file_name, output_type, data: templateData } = data;
1298
+ const { output_pdf = false, input_path, input_html, output_path, output_file_name, output_type, data: templateData, replace, } = data;
1059
1299
  const type = output_pdf ? 'arraybuffer' : 'json';
1060
1300
  const contentType = output_pdf ? 'application/pdf' : 'application/json';
1061
1301
  return this.request('POST', `media/pdf/html2pdf`, {
@@ -1066,7 +1306,27 @@ class DMS extends IntegrationsBaseClient {
1066
1306
  input_html,
1067
1307
  output_file_name,
1068
1308
  output_type,
1069
- 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,
1070
1330
  },
1071
1331
  headers: {
1072
1332
  'Content-Type': contentType
@@ -1083,8 +1343,8 @@ class DMS extends IntegrationsBaseClient {
1083
1343
  async dirs(data) {
1084
1344
  return await this.request("POST", `media/library/dirs`, { data });
1085
1345
  }
1086
- async fillPdf(lib, data) {
1087
- 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;
1088
1348
  const responseType = output_pdf ? 'arraybuffer' : 'json';
1089
1349
  const contentType = output_pdf ? 'application/pdf' : 'application/json';
1090
1350
  return this.request('POST', `media/pdf/fill`, {
@@ -1095,6 +1355,7 @@ class DMS extends IntegrationsBaseClient {
1095
1355
  output_type,
1096
1356
  output_file_name,
1097
1357
  form_data,
1358
+ replace,
1098
1359
  forms
1099
1360
  },
1100
1361
  headers: {
@@ -1172,7 +1433,7 @@ class DMS extends IntegrationsBaseClient {
1172
1433
  * // excelResult.data is a Blob
1173
1434
  * ```
1174
1435
  */
1175
- async convertData(lib, data, params) {
1436
+ async convertData(data, params) {
1176
1437
  const { from, to, sheet_name, include_header, include_footer, header_as_comment, footer_as_comment, separator_rows, field_order, } = params;
1177
1438
  const queryParams = { from, to };
1178
1439
  // Add optional parameters if provided
@@ -1239,7 +1500,7 @@ class DMS extends IntegrationsBaseClient {
1239
1500
  * // }
1240
1501
  * ```
1241
1502
  */
1242
- async getDataInfo(lib, data, params) {
1503
+ async getDataInfo(data, params) {
1243
1504
  const { format } = params;
1244
1505
  return this.request('POST', `media/convert/info`, {
1245
1506
  data,
@@ -1283,7 +1544,7 @@ class DMS extends IntegrationsBaseClient {
1283
1544
  * }
1284
1545
  * ```
1285
1546
  */
1286
- async validateData(lib, data, params) {
1547
+ async validateData(data, params) {
1287
1548
  const { format } = params;
1288
1549
  return this.request('POST', `media/convert/validate`, {
1289
1550
  data,
@@ -1331,7 +1592,7 @@ class DMS extends IntegrationsBaseClient {
1331
1592
  * // Auto-detects header, items, and footer sections
1332
1593
  * ```
1333
1594
  */
1334
- async jsonToCsv(lib, jsonData, options) {
1595
+ async jsonToCsv(jsonData, options) {
1335
1596
  let params = {};
1336
1597
  if (options === null || options === void 0 ? void 0 : options.field_order) {
1337
1598
  params.field_order = options.field_order.join(',');
@@ -1390,7 +1651,7 @@ class DMS extends IntegrationsBaseClient {
1390
1651
  * link.click();
1391
1652
  * ```
1392
1653
  */
1393
- async jsonToExcel(lib, jsonData, options) {
1654
+ async jsonToExcel(jsonData, options) {
1394
1655
  const params = {};
1395
1656
  if (options === null || options === void 0 ? void 0 : options.sheet_name) {
1396
1657
  params.sheet_name = options.sheet_name;
@@ -1429,7 +1690,7 @@ class DMS extends IntegrationsBaseClient {
1429
1690
  * // ]
1430
1691
  * ```
1431
1692
  */
1432
- async csvToJson(lib, csvData) {
1693
+ async csvToJson(csvData) {
1433
1694
  return this.request('POST', `media/convert/csv-to-json`, {
1434
1695
  data: csvData,
1435
1696
  responseType: 'json',
@@ -1462,7 +1723,7 @@ class DMS extends IntegrationsBaseClient {
1462
1723
  * // Use url for download or further processing
1463
1724
  * ```
1464
1725
  */
1465
- async csvToExcel(lib, csvData, options) {
1726
+ async csvToExcel(csvData, options) {
1466
1727
  const params = {};
1467
1728
  if (options === null || options === void 0 ? void 0 : options.sheet_name) {
1468
1729
  params.sheet_name = options.sheet_name;
@@ -1502,7 +1763,7 @@ class DMS extends IntegrationsBaseClient {
1502
1763
  * const jsonFromBuffer = await dms.excelToJson(libraryRef, arrayBuffer);
1503
1764
  * ```
1504
1765
  */
1505
- async excelToJson(lib, excelData, options) {
1766
+ async excelToJson(excelData, options) {
1506
1767
  const params = {};
1507
1768
  if (options === null || options === void 0 ? void 0 : options.sheet_name) {
1508
1769
  params.sheet_name = options.sheet_name;
@@ -1546,7 +1807,7 @@ class DMS extends IntegrationsBaseClient {
1546
1807
  * link.click();
1547
1808
  * ```
1548
1809
  */
1549
- async excelToCsv(lib, excelData, options) {
1810
+ async excelToCsv(excelData, options) {
1550
1811
  const params = {};
1551
1812
  if (options === null || options === void 0 ? void 0 : options.sheet_name) {
1552
1813
  params.sheet_name = options.sheet_name;