@ptkl/sdk 0.10.0 → 0.10.2

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,196 @@
1
1
  import PlatformBaseClient from "./platformBaseClient";
2
+ import { AxiosResponse } from "axios";
3
+ import { RatchetQueryResponse, RatchetConnection, CreateRatchetConnectionRequest, InspectQueryRequest } from "../types/ratchet";
2
4
  export default class Ratchet extends PlatformBaseClient {
3
- query(name: string, params: any): Promise<import("axios").AxiosResponse<any, any>>;
5
+ /**
6
+ * Get all database connections for the current project
7
+ *
8
+ * @returns List of all configured ratchet connections
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * const ratchet = new Ratchet();
13
+ * const connections = await ratchet.getConnections();
14
+ * console.log(connections.data); // Array of connections
15
+ * ```
16
+ */
17
+ getConnections(): Promise<AxiosResponse<RatchetConnection[]>>;
18
+ /**
19
+ * Get a specific database connection by ID
20
+ *
21
+ * @param id - Connection ID
22
+ * @returns Connection details including queries
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * const ratchet = new Ratchet();
27
+ * const connection = await ratchet.getConnection('users_db');
28
+ * console.log(connection.data.queries); // Available queries for this connection
29
+ * ```
30
+ */
31
+ getConnection(id: string): Promise<AxiosResponse<RatchetConnection>>;
32
+ /**
33
+ * Create a new database connection
34
+ *
35
+ * Supports multiple database types:
36
+ * - MySQL: Use credentials with host, dbname, user, password
37
+ * - PostgreSQL: Use credentials with host, dbname, user, password
38
+ * - MongoDB: Use DSN connection string
39
+ * - BigQuery: Use service_account_json and project_id
40
+ *
41
+ * @param connection - Connection configuration
42
+ * @returns Created connection details
43
+ *
44
+ * @example
45
+ * ```typescript
46
+ * const ratchet = new Ratchet();
47
+ *
48
+ * // MySQL/PostgreSQL connection
49
+ * await ratchet.createConnection({
50
+ * id: 'users_db',
51
+ * type: 'MySQL',
52
+ * credentials: {
53
+ * type: 'Credentials',
54
+ * host: 'localhost',
55
+ * dbname: 'users',
56
+ * user: 'admin',
57
+ * password: 'secret'
58
+ * }
59
+ * });
60
+ *
61
+ * // MongoDB connection
62
+ * await ratchet.createConnection({
63
+ * id: 'mongo_db',
64
+ * type: 'MongoDB',
65
+ * credentials: {
66
+ * type: 'DSN',
67
+ * dsn: 'mongodb://localhost:27017/mydb'
68
+ * }
69
+ * });
70
+ *
71
+ * // BigQuery connection
72
+ * await ratchet.createConnection({
73
+ * id: 'analytics_bq',
74
+ * type: 'BigQuery',
75
+ * credentials: {
76
+ * type: 'ServiceAccount',
77
+ * service_account_json: '{"type":"service_account",...}',
78
+ * project_id: 'my-project-id'
79
+ * }
80
+ * });
81
+ * ```
82
+ */
83
+ createConnection(connection: CreateRatchetConnectionRequest): Promise<AxiosResponse<RatchetConnection>>;
84
+ /**
85
+ * Update an existing database connection
86
+ *
87
+ * @param connection - Updated connection configuration
88
+ * @returns Success status
89
+ *
90
+ * @example
91
+ * ```typescript
92
+ * const ratchet = new Ratchet();
93
+ * await ratchet.updateConnection({
94
+ * id: 'users_db',
95
+ * type: 'postgres',
96
+ * credentials: {
97
+ * type: 'postgres',
98
+ * host: 'localhost',
99
+ * dbname: 'users',
100
+ * user: 'admin',
101
+ * password: 'new_secret'
102
+ * },
103
+ * queries: [
104
+ * { id: 'get_user', expression: 'SELECT * FROM users WHERE id = $1' }
105
+ * ]
106
+ * });
107
+ * ```
108
+ */
109
+ updateConnection(connection: RatchetConnection): Promise<AxiosResponse<{
110
+ status: boolean;
111
+ }>>;
112
+ /**
113
+ * Delete a database connection
114
+ *
115
+ * @param id - Connection ID to delete
116
+ * @returns Success status
117
+ *
118
+ * @example
119
+ * ```typescript
120
+ * const ratchet = new Ratchet();
121
+ * await ratchet.deleteConnection('users_db');
122
+ * ```
123
+ */
124
+ deleteConnection(id: string): Promise<AxiosResponse<{
125
+ status: boolean;
126
+ }>>;
127
+ /**
128
+ * Test a database connection without saving it
129
+ *
130
+ * @param connection - Connection configuration to test
131
+ * @returns Success status if connection is valid
132
+ *
133
+ * @example
134
+ * ```typescript
135
+ * const ratchet = new Ratchet();
136
+ * const isValid = await ratchet.testConnection({
137
+ * id: 'test_db',
138
+ * type: 'postgres',
139
+ * credentials: {
140
+ * type: 'postgres',
141
+ * host: 'localhost',
142
+ * dbname: 'test',
143
+ * user: 'admin',
144
+ * password: 'secret'
145
+ * }
146
+ * });
147
+ * ```
148
+ */
149
+ testConnection(connection: RatchetConnection): Promise<AxiosResponse<{
150
+ status: boolean;
151
+ }>>;
152
+ /**
153
+ * Execute a predefined database query
154
+ *
155
+ * Runs a query that has been previously configured in a ratchet connection.
156
+ * The query is identified by a qualified name in the format: `connectionId.queryId`
157
+ *
158
+ * @param name - Qualified name of the query (format: `connectionId.queryId`)
159
+ * @param params - Array of parameters to pass to the query
160
+ * @returns Query execution results
161
+ *
162
+ * @example
163
+ * ```typescript
164
+ * const ratchet = new Ratchet();
165
+ *
166
+ * // Execute a query with parameters
167
+ * const result = await ratchet.query('users_db.get_user_by_id', [123]);
168
+ *
169
+ * // Execute a query without parameters
170
+ * const allUsers = await ratchet.query('users_db.get_all_users', []);
171
+ * ```
172
+ */
173
+ query<T = any>(name: string, params: any[] | Record<string, any>): Promise<AxiosResponse<RatchetQueryResponse<T>>>;
174
+ /**
175
+ * Inspect and execute a custom query without saving it
176
+ *
177
+ * This allows you to test queries before saving them to a connection.
178
+ *
179
+ * @param request - Query inspection request with connection name, query, and params
180
+ * @returns Query execution results
181
+ *
182
+ * @example
183
+ * ```typescript
184
+ * const ratchet = new Ratchet();
185
+ * const result = await ratchet.inspectQuery({
186
+ * name: 'users_db.test_query',
187
+ * query: {
188
+ * id: 'test_query',
189
+ * expression: 'SELECT * FROM users WHERE email = $1'
190
+ * },
191
+ * params: ['user@example.com']
192
+ * });
193
+ * ```
194
+ */
195
+ inspectQuery<T = any>(request: InspectQueryRequest): Promise<AxiosResponse<RatchetQueryResponse<T>>>;
4
196
  }
@@ -25,4 +25,5 @@ export type * from './types/integrations';
25
25
  export type * from './types/users';
26
26
  export type * from './types/project';
27
27
  export type * from './types/config';
28
+ export type * from './types/ratchet';
28
29
  export default Platform;
@@ -47,4 +47,38 @@ type UpdateOptions = {
47
47
  type ModifyOptions = {
48
48
  upsert: boolean;
49
49
  };
50
- export { FindParams, FindOptions, FindResponse, FindAdvancedParams, FindAggregateParams, Model, UpdateOptions, ModifyOptions, };
50
+ type ComponentLabel = {
51
+ locales: Record<string, string>;
52
+ };
53
+ type ComponentWorkspace = {
54
+ uuid: string;
55
+ CreatedAt: string;
56
+ UpdatedAt: string;
57
+ DeletedAt: string | null;
58
+ workspace_uuid: string;
59
+ component_uuid: string;
60
+ };
61
+ type ComponentListItem = {
62
+ uuid: string;
63
+ CreatedAt: string;
64
+ UpdatedAt: string;
65
+ DeletedAt: string | null;
66
+ name: string;
67
+ label: ComponentLabel;
68
+ tag: string;
69
+ icon: string | null;
70
+ is_active: boolean;
71
+ is_public: boolean;
72
+ visible: boolean;
73
+ project_uuid: string;
74
+ scope: string;
75
+ sort: number;
76
+ public_version: string;
77
+ dev_version: string;
78
+ versions: string[] | null;
79
+ dependencies: string[];
80
+ workspaces: ComponentWorkspace[];
81
+ storage_size: number;
82
+ };
83
+ type ComponentListResponse = ComponentListItem[];
84
+ export { FindParams, FindOptions, FindResponse, FindAdvancedParams, FindAggregateParams, Model, UpdateOptions, ModifyOptions, ComponentListResponse, ComponentListItem, ComponentLabel, ComponentWorkspace, };
@@ -45,6 +45,7 @@ export type PDFFillOptions = {
45
45
  input_path?: string;
46
46
  output_path?: string;
47
47
  output_pdf?: boolean;
48
+ replace?: boolean;
48
49
  output_type?: PDFOutputType;
49
50
  output_file_name?: string;
50
51
  form_data?: Record<string, any>;
@@ -57,6 +58,16 @@ export type HTML2PDFOptions = {
57
58
  output_pdf?: boolean;
58
59
  output_type?: PDFOutputType;
59
60
  output_file_name?: string;
61
+ replace?: boolean;
62
+ data?: Record<string, any>;
63
+ };
64
+ export type PDF2HTMLOptions = {
65
+ input_path?: string;
66
+ input_pdf?: string;
67
+ output_path?: string;
68
+ output_html?: string;
69
+ output_file_name?: string;
70
+ replace?: boolean;
60
71
  data?: Record<string, any>;
61
72
  };
62
73
  /**
@@ -148,3 +159,163 @@ export type NbsIpsQrCode = {
148
159
  PurposeOfPayment: string;
149
160
  PaymentOrderNumber: string;
150
161
  };
162
+ /**
163
+ * Payload for multipart form upload
164
+ */
165
+ export type MediaUploadPayload = {
166
+ /** Array of files to upload */
167
+ files: File[];
168
+ /** Directory path where files should be uploaded */
169
+ uploadDir: string;
170
+ /** Whether files should be publicly accessible */
171
+ public?: boolean;
172
+ /** If true, replace files if they already exist */
173
+ replace?: boolean;
174
+ /** Expiration timestamp in ISO 8601 format (RFC3339) */
175
+ expiresAt?: string;
176
+ /** Additional metadata as key-value pairs */
177
+ metadata?: Record<string, string>;
178
+ };
179
+ /**
180
+ * File structure for base64 upload
181
+ */
182
+ export type MediaUploadBase64File = {
183
+ /** Name of the file including extension */
184
+ name: string;
185
+ /** MIME type of the file (e.g., 'image/png', 'application/pdf') */
186
+ content_type: string;
187
+ /** Base64-encoded file content */
188
+ data: string;
189
+ };
190
+ /**
191
+ * Payload for base64/JSON upload
192
+ */
193
+ export type MediaUploadBase64Payload = {
194
+ /** Reference identifier for the upload operation */
195
+ ref?: string;
196
+ /** Directory path where files should be uploaded */
197
+ path: string;
198
+ /** Whether files should be publicly accessible */
199
+ is_public?: boolean;
200
+ /** If true, replace files if they already exist */
201
+ replace?: boolean;
202
+ /** Expiration timestamp (Date object or ISO 8601 string) */
203
+ expires_at?: Date | string;
204
+ /** Additional metadata as key-value pairs */
205
+ metadata?: Record<string, string>;
206
+ /** Array of files with base64-encoded content */
207
+ files: MediaUploadBase64File[];
208
+ };
209
+ /**
210
+ * Filters for document listing endpoints
211
+ */
212
+ export type DocumentListParams = {
213
+ /** Optional text to search within documents */
214
+ searchText?: string;
215
+ /** Whether to search recursively through directories */
216
+ recursive?: boolean;
217
+ };
218
+ export type DocumentSourceType = "component" | string;
219
+ export type DocumentSource = {
220
+ type: DocumentSourceType;
221
+ value: string;
222
+ label: string;
223
+ tag: string;
224
+ };
225
+ export type DocumentFieldDataMapping = {
226
+ sourceField?: string;
227
+ };
228
+ export type DocumentFieldSource = "text" | "options" | "datepicker" | DocumentSource["tag"];
229
+ export type DocumentField = {
230
+ field: string;
231
+ label?: string | null;
232
+ source: DocumentFieldSource;
233
+ value?: string | number | null;
234
+ format?: string;
235
+ data?: DocumentFieldDataMapping;
236
+ };
237
+ export type DocumentAuditEntry = {
238
+ time: string;
239
+ name?: string;
240
+ uuid?: string;
241
+ };
242
+ export type DocumentVariant = {
243
+ name: string;
244
+ version: number;
245
+ content: string;
246
+ sources?: DocumentSource[];
247
+ fields?: DocumentField[];
248
+ createdBy?: DocumentAuditEntry;
249
+ updatedBy?: DocumentAuditEntry;
250
+ deletedBy?: DocumentAuditEntry;
251
+ };
252
+ export type DocumentResponse = {
253
+ name: string;
254
+ variants: DocumentVariant[];
255
+ createdBy?: DocumentAuditEntry;
256
+ updatedBy?: DocumentAuditEntry;
257
+ deletedBy?: DocumentAuditEntry;
258
+ };
259
+ export type DocumentListItem = {
260
+ name: string;
261
+ createdBy?: DocumentAuditEntry;
262
+ updatedBy?: DocumentAuditEntry;
263
+ deletedBy?: DocumentAuditEntry;
264
+ };
265
+ export type DocumentListResponse = DocumentListItem[];
266
+ /**
267
+ * Payload for creating a document
268
+ */
269
+ export type DocumentCreatePayload = {
270
+ /** Document path (including directory and filename) */
271
+ path: string;
272
+ /** Document content (plain text or structured) */
273
+ content?: string;
274
+ /** Document variant identifier */
275
+ variant?: string;
276
+ /** Optional document sources metadata */
277
+ sources?: DocumentSource[];
278
+ /** Optional custom fields metadata */
279
+ fields?: DocumentField[];
280
+ };
281
+ /**
282
+ * Payload for updating an existing document
283
+ */
284
+ export type DocumentUpdatePayload = {
285
+ /** Document path (including directory and filename) */
286
+ path: string;
287
+ /** Variant to update */
288
+ variant?: string;
289
+ /** Current version used for optimistic locking */
290
+ version?: number;
291
+ /** Updated content */
292
+ content?: string;
293
+ /** Updated sources metadata */
294
+ sources?: DocumentSource[];
295
+ /** Updated fields metadata */
296
+ fields?: DocumentField[];
297
+ };
298
+ /**
299
+ * Payload for restoring a deleted document
300
+ */
301
+ export type DocumentRestorePayload = {
302
+ /** Path of the deleted document */
303
+ path: string;
304
+ /** Optional new path to restore to */
305
+ newPath?: string;
306
+ };
307
+ /**
308
+ * Payload for creating a document comment
309
+ */
310
+ export type DocumentCommentPayload = {
311
+ /** Target document path */
312
+ path: string;
313
+ /** Comment body */
314
+ content: string;
315
+ /** Variant the comment belongs to */
316
+ variant?: string;
317
+ /** Comment start position */
318
+ from?: number;
319
+ /** Comment end position */
320
+ to?: number;
321
+ };
@@ -0,0 +1,38 @@
1
+ export interface RatchetQueryRequest {
2
+ name: string;
3
+ params: any[];
4
+ }
5
+ export interface RatchetQueryResponse<T = any> {
6
+ data: T;
7
+ status: boolean;
8
+ }
9
+ export interface RatchetCredentials {
10
+ type: string;
11
+ dsn?: string;
12
+ user?: string;
13
+ password?: string;
14
+ host?: string;
15
+ dbname?: string;
16
+ service_account_json?: string;
17
+ project_id?: string;
18
+ }
19
+ export interface RatchetQuery {
20
+ id: string;
21
+ expression: string;
22
+ }
23
+ export interface RatchetConnection {
24
+ id: string;
25
+ type: string;
26
+ credentials: RatchetCredentials;
27
+ queries?: RatchetQuery[];
28
+ }
29
+ export interface CreateRatchetConnectionRequest {
30
+ id: string;
31
+ type: string;
32
+ credentials: RatchetCredentials;
33
+ }
34
+ export interface InspectQueryRequest {
35
+ name: string;
36
+ query: RatchetQuery;
37
+ params: any[];
38
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ptkl/sdk",
3
- "version": "0.10.0",
3
+ "version": "0.10.2",
4
4
  "scripts": {
5
5
  "build": "rollup -c",
6
6
  "build:monaco": "npm run build && node scripts/generate-monaco-types.cjs",