@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.cjs.js CHANGED
@@ -19500,12 +19500,210 @@ class Thunder extends PlatformBaseClient {
19500
19500
  }
19501
19501
 
19502
19502
  class Ratchet extends PlatformBaseClient {
19503
+ /**
19504
+ * Get all database connections for the current project
19505
+ *
19506
+ * @returns List of all configured ratchet connections
19507
+ *
19508
+ * @example
19509
+ * ```typescript
19510
+ * const ratchet = new Ratchet();
19511
+ * const connections = await ratchet.getConnections();
19512
+ * console.log(connections.data); // Array of connections
19513
+ * ```
19514
+ */
19515
+ async getConnections() {
19516
+ return await this.client.get("/v1/ratchet/connection");
19517
+ }
19518
+ /**
19519
+ * Get a specific database connection by ID
19520
+ *
19521
+ * @param id - Connection ID
19522
+ * @returns Connection details including queries
19523
+ *
19524
+ * @example
19525
+ * ```typescript
19526
+ * const ratchet = new Ratchet();
19527
+ * const connection = await ratchet.getConnection('users_db');
19528
+ * console.log(connection.data.queries); // Available queries for this connection
19529
+ * ```
19530
+ */
19531
+ async getConnection(id) {
19532
+ return await this.client.get(`/v1/ratchet/connection/${id}`);
19533
+ }
19534
+ /**
19535
+ * Create a new database connection
19536
+ *
19537
+ * Supports multiple database types:
19538
+ * - MySQL: Use credentials with host, dbname, user, password
19539
+ * - PostgreSQL: Use credentials with host, dbname, user, password
19540
+ * - MongoDB: Use DSN connection string
19541
+ * - BigQuery: Use service_account_json and project_id
19542
+ *
19543
+ * @param connection - Connection configuration
19544
+ * @returns Created connection details
19545
+ *
19546
+ * @example
19547
+ * ```typescript
19548
+ * const ratchet = new Ratchet();
19549
+ *
19550
+ * // MySQL/PostgreSQL connection
19551
+ * await ratchet.createConnection({
19552
+ * id: 'users_db',
19553
+ * type: 'MySQL',
19554
+ * credentials: {
19555
+ * type: 'Credentials',
19556
+ * host: 'localhost',
19557
+ * dbname: 'users',
19558
+ * user: 'admin',
19559
+ * password: 'secret'
19560
+ * }
19561
+ * });
19562
+ *
19563
+ * // MongoDB connection
19564
+ * await ratchet.createConnection({
19565
+ * id: 'mongo_db',
19566
+ * type: 'MongoDB',
19567
+ * credentials: {
19568
+ * type: 'DSN',
19569
+ * dsn: 'mongodb://localhost:27017/mydb'
19570
+ * }
19571
+ * });
19572
+ *
19573
+ * // BigQuery connection
19574
+ * await ratchet.createConnection({
19575
+ * id: 'analytics_bq',
19576
+ * type: 'BigQuery',
19577
+ * credentials: {
19578
+ * type: 'ServiceAccount',
19579
+ * service_account_json: '{"type":"service_account",...}',
19580
+ * project_id: 'my-project-id'
19581
+ * }
19582
+ * });
19583
+ * ```
19584
+ */
19585
+ async createConnection(connection) {
19586
+ return await this.client.post("/v1/ratchet/connection", connection);
19587
+ }
19588
+ /**
19589
+ * Update an existing database connection
19590
+ *
19591
+ * @param connection - Updated connection configuration
19592
+ * @returns Success status
19593
+ *
19594
+ * @example
19595
+ * ```typescript
19596
+ * const ratchet = new Ratchet();
19597
+ * await ratchet.updateConnection({
19598
+ * id: 'users_db',
19599
+ * type: 'postgres',
19600
+ * credentials: {
19601
+ * type: 'postgres',
19602
+ * host: 'localhost',
19603
+ * dbname: 'users',
19604
+ * user: 'admin',
19605
+ * password: 'new_secret'
19606
+ * },
19607
+ * queries: [
19608
+ * { id: 'get_user', expression: 'SELECT * FROM users WHERE id = $1' }
19609
+ * ]
19610
+ * });
19611
+ * ```
19612
+ */
19613
+ async updateConnection(connection) {
19614
+ return await this.client.put("/v1/ratchet/connection", connection);
19615
+ }
19616
+ /**
19617
+ * Delete a database connection
19618
+ *
19619
+ * @param id - Connection ID to delete
19620
+ * @returns Success status
19621
+ *
19622
+ * @example
19623
+ * ```typescript
19624
+ * const ratchet = new Ratchet();
19625
+ * await ratchet.deleteConnection('users_db');
19626
+ * ```
19627
+ */
19628
+ async deleteConnection(id) {
19629
+ return await this.client.delete(`/v1/ratchet/connection/${id}`);
19630
+ }
19631
+ /**
19632
+ * Test a database connection without saving it
19633
+ *
19634
+ * @param connection - Connection configuration to test
19635
+ * @returns Success status if connection is valid
19636
+ *
19637
+ * @example
19638
+ * ```typescript
19639
+ * const ratchet = new Ratchet();
19640
+ * const isValid = await ratchet.testConnection({
19641
+ * id: 'test_db',
19642
+ * type: 'postgres',
19643
+ * credentials: {
19644
+ * type: 'postgres',
19645
+ * host: 'localhost',
19646
+ * dbname: 'test',
19647
+ * user: 'admin',
19648
+ * password: 'secret'
19649
+ * }
19650
+ * });
19651
+ * ```
19652
+ */
19653
+ async testConnection(connection) {
19654
+ return await this.client.post("/v1/ratchet/test/connection", connection);
19655
+ }
19656
+ /**
19657
+ * Execute a predefined database query
19658
+ *
19659
+ * Runs a query that has been previously configured in a ratchet connection.
19660
+ * The query is identified by a qualified name in the format: `connectionId.queryId`
19661
+ *
19662
+ * @param name - Qualified name of the query (format: `connectionId.queryId`)
19663
+ * @param params - Array of parameters to pass to the query
19664
+ * @returns Query execution results
19665
+ *
19666
+ * @example
19667
+ * ```typescript
19668
+ * const ratchet = new Ratchet();
19669
+ *
19670
+ * // Execute a query with parameters
19671
+ * const result = await ratchet.query('users_db.get_user_by_id', [123]);
19672
+ *
19673
+ * // Execute a query without parameters
19674
+ * const allUsers = await ratchet.query('users_db.get_all_users', []);
19675
+ * ```
19676
+ */
19503
19677
  async query(name, params) {
19504
- return await this.client.post('/v1/ratchet/query', {
19678
+ return await this.client.post("/v1/ratchet/query", {
19505
19679
  name: name,
19506
- params: params
19680
+ params: params,
19507
19681
  });
19508
19682
  }
19683
+ /**
19684
+ * Inspect and execute a custom query without saving it
19685
+ *
19686
+ * This allows you to test queries before saving them to a connection.
19687
+ *
19688
+ * @param request - Query inspection request with connection name, query, and params
19689
+ * @returns Query execution results
19690
+ *
19691
+ * @example
19692
+ * ```typescript
19693
+ * const ratchet = new Ratchet();
19694
+ * const result = await ratchet.inspectQuery({
19695
+ * name: 'users_db.test_query',
19696
+ * query: {
19697
+ * id: 'test_query',
19698
+ * expression: 'SELECT * FROM users WHERE email = $1'
19699
+ * },
19700
+ * params: ['user@example.com']
19701
+ * });
19702
+ * ```
19703
+ */
19704
+ async inspectQuery(request) {
19705
+ return await this.client.post("/v1/ratchet/query/inspect", request);
19706
+ }
19509
19707
  }
19510
19708
 
19511
19709
  class Sandbox extends PlatformBaseClient {
@@ -19965,6 +20163,23 @@ class DMS extends IntegrationsBaseClient {
19965
20163
  async libraries() {
19966
20164
  return await this.requestv1("GET", "media/library/list");
19967
20165
  }
20166
+ /**
20167
+ * Upload files using multipart form data
20168
+ *
20169
+ * @param payload - Upload configuration with files, directory, and options
20170
+ * @returns Upload response from the server
20171
+ *
20172
+ * @example
20173
+ * ```typescript
20174
+ * const result = await dms.upload({
20175
+ * files: [file1, file2],
20176
+ * uploadDir: '/documents/invoices',
20177
+ * public: true,
20178
+ * replace: true,
20179
+ * metadata: { category: 'finance' }
20180
+ * });
20181
+ * ```
20182
+ */
19968
20183
  async upload(payload) {
19969
20184
  let files = payload.files;
19970
20185
  let formData = new FormData();
@@ -19981,9 +20196,12 @@ class DMS extends IntegrationsBaseClient {
19981
20196
  if (payload.public) {
19982
20197
  formData.append('is_public', "true");
19983
20198
  }
20199
+ if (payload.replace) {
20200
+ formData.append('replace', "true");
20201
+ }
19984
20202
  if (payload.expiresAt)
19985
20203
  formData.append('expiresAt', new Date(payload.expiresAt).toISOString());
19986
- if (Object.keys(payload.metadata).length > 0)
20204
+ if (payload.metadata && Object.keys(payload.metadata).length > 0)
19987
20205
  formData.append('metadata', JSON.stringify(payload.metadata));
19988
20206
  return await this.request("POST", "media/upload", {
19989
20207
  data: formData,
@@ -19996,6 +20214,28 @@ class DMS extends IntegrationsBaseClient {
19996
20214
  async delete(data) {
19997
20215
  return this.request('POST', 'media/delete', data);
19998
20216
  }
20217
+ /**
20218
+ * Upload files using base64-encoded content
20219
+ *
20220
+ * @param data - Upload payload with base64-encoded files
20221
+ * @returns Upload response from the server
20222
+ *
20223
+ * @example
20224
+ * ```typescript
20225
+ * const result = await dms.uploadBase64({
20226
+ * path: '/documents/reports',
20227
+ * is_public: false,
20228
+ * replace: true,
20229
+ * files: [
20230
+ * {
20231
+ * name: 'report.pdf',
20232
+ * content_type: 'application/pdf',
20233
+ * data: 'base64EncodedContent...'
20234
+ * }
20235
+ * ]
20236
+ * });
20237
+ * ```
20238
+ */
19999
20239
  async uploadBase64(data) {
20000
20240
  return this.request('POST', `media/upload`, {
20001
20241
  data,
@@ -20004,7 +20244,7 @@ class DMS extends IntegrationsBaseClient {
20004
20244
  }
20005
20245
  });
20006
20246
  }
20007
- async getMedia(lib, key, encoding) {
20247
+ async getMedia(key, encoding) {
20008
20248
  return this.request('GET', `media/get/${key}`, {
20009
20249
  params: {
20010
20250
  encoding
@@ -20012,7 +20252,7 @@ class DMS extends IntegrationsBaseClient {
20012
20252
  responseType: (!encoding) ? 'blob' : null
20013
20253
  });
20014
20254
  }
20015
- async download(lib, key) {
20255
+ async download(key) {
20016
20256
  return this.request('POST', `media/download`, {
20017
20257
  data: {
20018
20258
  key
@@ -20024,7 +20264,7 @@ class DMS extends IntegrationsBaseClient {
20024
20264
  return this.request('GET', `media/exif/${key}`);
20025
20265
  }
20026
20266
  async html2pdf(data) {
20027
- const { output_pdf = false, input_path, input_html, output_path, output_file_name, output_type, data: templateData } = data;
20267
+ const { output_pdf = false, input_path, input_html, output_path, output_file_name, output_type, data: templateData, replace, } = data;
20028
20268
  const type = output_pdf ? 'arraybuffer' : 'json';
20029
20269
  const contentType = output_pdf ? 'application/pdf' : 'application/json';
20030
20270
  return this.request('POST', `media/pdf/html2pdf`, {
@@ -20035,7 +20275,27 @@ class DMS extends IntegrationsBaseClient {
20035
20275
  input_html,
20036
20276
  output_file_name,
20037
20277
  output_type,
20038
- data: templateData
20278
+ data: templateData,
20279
+ replace,
20280
+ },
20281
+ headers: {
20282
+ 'Content-Type': contentType
20283
+ },
20284
+ responseType: type
20285
+ });
20286
+ }
20287
+ async pdf2html(data) {
20288
+ const { output_html = false, input_path, input_pdf, output_path, output_file_name, replace, } = data;
20289
+ const type = output_html ? 'arraybuffer' : 'json';
20290
+ const contentType = output_html ? 'text/html' : 'application/json';
20291
+ return this.request('POST', `media/pdf/pdf2html`, {
20292
+ data: {
20293
+ output_html,
20294
+ input_path,
20295
+ output_path,
20296
+ input_pdf,
20297
+ output_file_name,
20298
+ replace,
20039
20299
  },
20040
20300
  headers: {
20041
20301
  'Content-Type': contentType
@@ -20052,8 +20312,8 @@ class DMS extends IntegrationsBaseClient {
20052
20312
  async dirs(data) {
20053
20313
  return await this.request("POST", `media/library/dirs`, { data });
20054
20314
  }
20055
- async fillPdf(lib, data) {
20056
- const { input_path, output_path, output_pdf = false, output_type, output_file_name, form_data, forms } = data;
20315
+ async fillPdf(data) {
20316
+ const { input_path, output_path, output_pdf = false, output_type, output_file_name, replace, form_data, forms } = data;
20057
20317
  const responseType = output_pdf ? 'arraybuffer' : 'json';
20058
20318
  const contentType = output_pdf ? 'application/pdf' : 'application/json';
20059
20319
  return this.request('POST', `media/pdf/fill`, {
@@ -20064,6 +20324,7 @@ class DMS extends IntegrationsBaseClient {
20064
20324
  output_type,
20065
20325
  output_file_name,
20066
20326
  form_data,
20327
+ replace,
20067
20328
  forms
20068
20329
  },
20069
20330
  headers: {
@@ -20141,7 +20402,7 @@ class DMS extends IntegrationsBaseClient {
20141
20402
  * // excelResult.data is a Blob
20142
20403
  * ```
20143
20404
  */
20144
- async convertData(lib, data, params) {
20405
+ async convertData(data, params) {
20145
20406
  const { from, to, sheet_name, include_header, include_footer, header_as_comment, footer_as_comment, separator_rows, field_order, } = params;
20146
20407
  const queryParams = { from, to };
20147
20408
  // Add optional parameters if provided
@@ -20208,7 +20469,7 @@ class DMS extends IntegrationsBaseClient {
20208
20469
  * // }
20209
20470
  * ```
20210
20471
  */
20211
- async getDataInfo(lib, data, params) {
20472
+ async getDataInfo(data, params) {
20212
20473
  const { format } = params;
20213
20474
  return this.request('POST', `media/convert/info`, {
20214
20475
  data,
@@ -20252,7 +20513,7 @@ class DMS extends IntegrationsBaseClient {
20252
20513
  * }
20253
20514
  * ```
20254
20515
  */
20255
- async validateData(lib, data, params) {
20516
+ async validateData(data, params) {
20256
20517
  const { format } = params;
20257
20518
  return this.request('POST', `media/convert/validate`, {
20258
20519
  data,
@@ -20300,7 +20561,7 @@ class DMS extends IntegrationsBaseClient {
20300
20561
  * // Auto-detects header, items, and footer sections
20301
20562
  * ```
20302
20563
  */
20303
- async jsonToCsv(lib, jsonData, options) {
20564
+ async jsonToCsv(jsonData, options) {
20304
20565
  let params = {};
20305
20566
  if (options === null || options === void 0 ? void 0 : options.field_order) {
20306
20567
  params.field_order = options.field_order.join(',');
@@ -20359,7 +20620,7 @@ class DMS extends IntegrationsBaseClient {
20359
20620
  * link.click();
20360
20621
  * ```
20361
20622
  */
20362
- async jsonToExcel(lib, jsonData, options) {
20623
+ async jsonToExcel(jsonData, options) {
20363
20624
  const params = {};
20364
20625
  if (options === null || options === void 0 ? void 0 : options.sheet_name) {
20365
20626
  params.sheet_name = options.sheet_name;
@@ -20398,7 +20659,7 @@ class DMS extends IntegrationsBaseClient {
20398
20659
  * // ]
20399
20660
  * ```
20400
20661
  */
20401
- async csvToJson(lib, csvData) {
20662
+ async csvToJson(csvData) {
20402
20663
  return this.request('POST', `media/convert/csv-to-json`, {
20403
20664
  data: csvData,
20404
20665
  responseType: 'json',
@@ -20431,7 +20692,7 @@ class DMS extends IntegrationsBaseClient {
20431
20692
  * // Use url for download or further processing
20432
20693
  * ```
20433
20694
  */
20434
- async csvToExcel(lib, csvData, options) {
20695
+ async csvToExcel(csvData, options) {
20435
20696
  const params = {};
20436
20697
  if (options === null || options === void 0 ? void 0 : options.sheet_name) {
20437
20698
  params.sheet_name = options.sheet_name;
@@ -20471,7 +20732,7 @@ class DMS extends IntegrationsBaseClient {
20471
20732
  * const jsonFromBuffer = await dms.excelToJson(libraryRef, arrayBuffer);
20472
20733
  * ```
20473
20734
  */
20474
- async excelToJson(lib, excelData, options) {
20735
+ async excelToJson(excelData, options) {
20475
20736
  const params = {};
20476
20737
  if (options === null || options === void 0 ? void 0 : options.sheet_name) {
20477
20738
  params.sheet_name = options.sheet_name;
@@ -20515,7 +20776,7 @@ class DMS extends IntegrationsBaseClient {
20515
20776
  * link.click();
20516
20777
  * ```
20517
20778
  */
20518
- async excelToCsv(lib, excelData, options) {
20779
+ async excelToCsv(excelData, options) {
20519
20780
  const params = {};
20520
20781
  if (options === null || options === void 0 ? void 0 : options.sheet_name) {
20521
20782
  params.sheet_name = options.sheet_name;