@ptkl/sdk 1.1.0 → 1.3.0

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
- import { FindParams, FindOptions, FindResponse, FindAdvancedParams, FindAggregateParams, Model, UpdateOptions, ModifyOptions, StreamHandler, AggregateChainable, ComponentOptions, UpdateManyOptions, CreateManyOptions } from "../types/component";
1
+ import { FindParams, FindOptions, FindResponse, FindAdvancedParams, FindAggregateParams, Model, UpdateOptions, ModifyOptions, StreamHandler, AggregateChainable, ComponentOptions, UpdateManyOptions, CreateManyOptions, Extension, Policy } from "../types/component";
2
2
  import PlatformBaseClient from "./platformBaseClient";
3
3
  import { AxiosResponse } from "axios";
4
4
  export default class Component extends PlatformBaseClient {
@@ -50,9 +50,26 @@ export default class Component extends PlatformBaseClient {
50
50
  /**
51
51
  * Update model by uuid
52
52
  *
53
- * @param uuid string - The uuid of the model
54
- * @param data
55
- * @returns
53
+ * Regular fields in `data` are applied via `$set`. You can include MongoDB
54
+ * update operators (prefixed with `$`) directly in the data object for
55
+ * granular updates like incrementing, pushing to arrays, etc.
56
+ *
57
+ * @param uuid - The uuid of the model to update
58
+ * @param data - Fields to update, optionally including update operators
59
+ * @param options - Update options
60
+ * @returns The updated model
61
+ *
62
+ * @example
63
+ * // Simple update (backwards compatible)
64
+ * await component.update(uuid, { name: "John" }, opts)
65
+ *
66
+ * // With update operators
67
+ * await component.update(uuid, {
68
+ * name: "John",
69
+ * $inc: { login_count: 1 },
70
+ * $push: { tags: "verified" },
71
+ * $addToSet: { roles: "admin" }
72
+ * }, opts)
56
73
  */
57
74
  update(uuid: string, data: Record<string, any>, options: UpdateOptions): Promise<AxiosResponse<any, any>>;
58
75
  /**
@@ -74,18 +91,40 @@ export default class Component extends PlatformBaseClient {
74
91
  /**
75
92
  * Modify models by filters
76
93
  *
77
- * @param data
78
- * @param options
79
- * @returns
94
+ * Updates all models matching the given filters. Supports inline update
95
+ * operators in the data payload for granular operations.
96
+ *
97
+ * @param filters - Query filters to match models
98
+ * @param data - Fields to update, optionally including update operators
99
+ * @param options - Modify options (e.g. upsert)
100
+ * @returns The modified models
101
+ *
102
+ * @example
103
+ * await component.modify(
104
+ * { status: "active" },
105
+ * { $inc: { impression_count: 1 }, $addToSet: { viewers: "user-1" } },
106
+ * { upsert: false }
107
+ * )
80
108
  */
81
109
  modify(filters: Record<string, any>, data: Record<string, any>, options: ModifyOptions): Promise<AxiosResponse<any, any>>;
82
110
  /**
83
- * Concurrent update model by uuid
111
+ * Concurrent update model by uuid with optimistic locking
84
112
  *
85
- * @param uuid string - The uuid of the model
86
- * @param version number - The version of the model
87
- * @param data
88
- * @returns
113
+ * Uses version-based concurrency control the update will fail with a
114
+ * conflict error if the document has been modified since the provided version.
115
+ * Supports inline update operators in the data payload.
116
+ *
117
+ * @param uuid - The uuid of the model
118
+ * @param version - The expected __version__ of the model
119
+ * @param data - Fields to update, optionally including update operators
120
+ * @param options - Update options
121
+ * @returns The updated model
122
+ *
123
+ * @example
124
+ * await component.concurrentUpdate(uuid, model.__version__, {
125
+ * status: "processed",
126
+ * $inc: { retry_count: 1 }
127
+ * }, opts)
89
128
  */
90
129
  concurrentUpdate(uuid: string, version: number, data: Record<string, any>, options: UpdateOptions): Promise<AxiosResponse<any, any>>;
91
130
  create(model: Record<string, any>): Promise<AxiosResponse<any, any>>;
@@ -122,6 +161,103 @@ export default class Component extends PlatformBaseClient {
122
161
  workflow(event: string, input: any): Promise<AxiosResponse<any, any>>;
123
162
  function(name: string, input: any): Promise<AxiosResponse<any, any>>;
124
163
  revisions(uuid: string): Promise<AxiosResponse<any, any>>;
164
+ /**
165
+ * Install a new extension on the component
166
+ *
167
+ * @param extension - The extension definition to install
168
+ * @param version - The component version to install the extension on
169
+ * @returns Updated component settings
170
+ *
171
+ * @example
172
+ * ```typescript
173
+ * await component.installExtension({
174
+ * name: 'shipping_tracker',
175
+ * is_active: true,
176
+ * fields: [...],
177
+ * config: { api_key: 'key' }
178
+ * }, '0.1.0')
179
+ * ```
180
+ */
181
+ installExtension(extension: Extension, version: string): Promise<AxiosResponse<any, any>>;
182
+ /**
183
+ * Update an existing extension on the component
184
+ *
185
+ * @param name - The name of the extension to update
186
+ * @param version - The component version
187
+ * @param data - Partial extension data to update
188
+ * @returns Updated component settings
189
+ *
190
+ * @example
191
+ * ```typescript
192
+ * await component.updateExtension('shipping_tracker', '0.1.0', {
193
+ * is_active: false,
194
+ * config: { api_key: 'new-key' }
195
+ * })
196
+ * ```
197
+ */
198
+ updateExtension(name: string, version: string, data: Partial<Extension>): Promise<AxiosResponse<any, any>>;
199
+ /**
200
+ * Delete an extension from the component
201
+ *
202
+ * @param name - The name of the extension to delete
203
+ * @param version - The component version
204
+ * @returns Updated component settings
205
+ *
206
+ * @example
207
+ * ```typescript
208
+ * await component.deleteExtension('shipping_tracker', '0.1.0')
209
+ * ```
210
+ */
211
+ deleteExtension(name: string, version: string): Promise<AxiosResponse<any, any>>;
212
+ /**
213
+ * Install a new policy on the component
214
+ *
215
+ * @param policy - The policy definition to install
216
+ * @param version - The component version to install the policy on
217
+ * @returns Updated component settings
218
+ *
219
+ * @example
220
+ * ```typescript
221
+ * await component.installPolicy({
222
+ * type: 'field_access',
223
+ * name: 'restrict_email',
224
+ * enabled: true,
225
+ * priority: 1,
226
+ * config: { fields: ['email'], actions: ['see'], roles: ['role-uuid'] }
227
+ * }, '0.1.0')
228
+ * ```
229
+ */
230
+ installPolicy(policy: Policy, version: string): Promise<AxiosResponse<any, any>>;
231
+ /**
232
+ * Update an existing policy on the component
233
+ *
234
+ * @param name - The name of the policy to update
235
+ * @param version - The component version
236
+ * @param data - Partial policy data to update
237
+ * @returns Updated component settings
238
+ *
239
+ * @example
240
+ * ```typescript
241
+ * await component.updatePolicy('restrict_email', '0.1.0', {
242
+ * enabled: false,
243
+ * priority: 2
244
+ * })
245
+ * ```
246
+ */
247
+ updatePolicy(name: string, version: string, data: Partial<Policy>): Promise<AxiosResponse<any, any>>;
248
+ /**
249
+ * Delete a policy from the component
250
+ *
251
+ * @param name - The name of the policy to delete
252
+ * @param version - The component version
253
+ * @returns Updated component settings
254
+ *
255
+ * @example
256
+ * ```typescript
257
+ * await component.deletePolicy('restrict_email', '0.1.0')
258
+ * ```
259
+ */
260
+ deletePolicy(name: string, version: string): Promise<AxiosResponse<any, any>>;
125
261
  /**
126
262
  * Internal method to handle NDJSON streaming responses
127
263
  *
@@ -129,4 +265,4 @@ export default class Component extends PlatformBaseClient {
129
265
  */
130
266
  private _streamNDJSON;
131
267
  }
132
- export { FindParams, FindOptions, FindResponse, FindAdvancedParams, FindAggregateParams, Model, UpdateOptions, StreamHandler, AggregateChainable, ComponentOptions, };
268
+ export { FindParams, FindOptions, FindResponse, FindAdvancedParams, FindAggregateParams, Model, UpdateOptions, StreamHandler, AggregateChainable, ComponentOptions, Extension, };
@@ -7,8 +7,7 @@ export default class Functions extends PlatformBaseClient {
7
7
  * Run platform function
8
8
  *
9
9
  * @param id - Function ID
10
- * @param input - Input data
11
- * @param query - Query parameters
10
+ * @param d - Object containing input data, query parameters, and headers
12
11
  * @returns - Function result
13
12
  *
14
13
  * @example
@@ -21,3 +21,4 @@ export { default as DMS } from './integrations/dms';
21
21
  export { default as SerbiaMinFin } from './integrations/serbia/minfin';
22
22
  export { default as NBS } from './integrations/serbia/nbs';
23
23
  export { default as VPFR } from './integrations/serbia/minfin/vpfr';
24
+ export { default as Mail } from './integrations/mail';
@@ -150,7 +150,6 @@ export default class DMS extends IntegrationsBaseClient {
150
150
  * - Explicit structure: JSON with `header`, `items`, and `footer` properties
151
151
  * - Auto-detection: Mixed JSON arrays with metadata objects and summary rows
152
152
  *
153
- * @param lib - Library reference UUID
154
153
  * @param data - Raw data to convert
155
154
  * @param params - Conversion parameters including structured data options
156
155
  * @returns Promise resolving to converted data
@@ -208,7 +207,6 @@ export default class DMS extends IntegrationsBaseClient {
208
207
  /**
209
208
  * Get information about data format and structure
210
209
  *
211
- * @param lib - Library reference UUID
212
210
  * @param data - Raw data to analyze
213
211
  * @param params - Analysis parameters
214
212
  * @returns Promise resolving to data information
@@ -240,7 +238,6 @@ export default class DMS extends IntegrationsBaseClient {
240
238
  /**
241
239
  * Validate data format without performing conversion
242
240
  *
243
- * @param lib - Library reference UUID
244
241
  * @param data - Raw data to validate
245
242
  * @param params - Validation parameters
246
243
  * @returns Promise resolving to validation result
@@ -279,7 +276,6 @@ export default class DMS extends IntegrationsBaseClient {
279
276
  * - Regular arrays are converted directly to CSV
280
277
  * - Structured data (with metadata objects) is automatically detected and formatted
281
278
  *
282
- * @param lib - Library reference UUID
283
279
  * @param jsonData - JSON data (array of objects or structured data)
284
280
  * @returns Promise resolving to CSV string
285
281
  *
@@ -317,7 +313,6 @@ export default class DMS extends IntegrationsBaseClient {
317
313
  * Supports both regular JSON arrays and structured data patterns.
318
314
  * Excel files are always generated with .xlsx extension.
319
315
  *
320
- * @param lib - Library reference UUID
321
316
  * @param jsonData - JSON data (array of objects or structured data)
322
317
  * @param options - Optional conversion options
323
318
  * @returns Promise resolving to Excel file as Blob
@@ -360,7 +355,6 @@ export default class DMS extends IntegrationsBaseClient {
360
355
  /**
361
356
  * Convert CSV data to JSON format
362
357
  *
363
- * @param lib - Library reference UUID
364
358
  * @param csvData - CSV data string (with headers in first row)
365
359
  * @returns Promise resolving to JSON array
366
360
  *
@@ -383,7 +377,6 @@ export default class DMS extends IntegrationsBaseClient {
383
377
  /**
384
378
  * Convert CSV data to Excel (.xlsx) format
385
379
  *
386
- * @param lib - Library reference UUID
387
380
  * @param csvData - CSV data string (with headers in first row)
388
381
  * @param options - Optional conversion options
389
382
  * @returns Promise resolving to Excel file as Blob
@@ -408,7 +401,6 @@ export default class DMS extends IntegrationsBaseClient {
408
401
  /**
409
402
  * Convert Excel (.xlsx) data to JSON format
410
403
  *
411
- * @param lib - Library reference UUID
412
404
  * @param excelData - Excel file data as Blob or ArrayBuffer
413
405
  * @param options - Optional conversion options
414
406
  * @returns Promise resolving to JSON array
@@ -435,7 +427,6 @@ export default class DMS extends IntegrationsBaseClient {
435
427
  /**
436
428
  * Convert Excel (.xlsx) data to CSV format
437
429
  *
438
- * @param lib - Library reference UUID
439
430
  * @param excelData - Excel file data as Blob or ArrayBuffer
440
431
  * @param options - Optional conversion options
441
432
  * @returns Promise resolving to CSV string
@@ -0,0 +1,125 @@
1
+ import IntegrationsBaseClient from "../integrationsBaseClient";
2
+ import { SendEmailRequest, SendEmailResponse, MailLog, EmailListResponse, ListEmailsParams, AttachmentMeta } from "../../types/integrations/mail";
3
+ /**
4
+ * SDK client for the Protokol Mail integration.
5
+ *
6
+ * Provides methods to send emails, list email logs, resend failed emails,
7
+ * and manage attachments through the Protokol Mail API.
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import { Mail } from "@ptkl/sdk/beta"
12
+ *
13
+ * const mail = new Mail()
14
+ *
15
+ * // Send an email
16
+ * const result = await mail.send({
17
+ * to: ["user@example.com"],
18
+ * subject: "Hello",
19
+ * body: "<h1>Welcome!</h1>"
20
+ * })
21
+ *
22
+ * console.log(result.message_id)
23
+ * ```
24
+ */
25
+ export default class Mail extends IntegrationsBaseClient {
26
+ /**
27
+ * Send an email. The email is queued for async delivery.
28
+ *
29
+ * Supports both JSON body (with base64-encoded attachments) and
30
+ * multipart/form-data (with file uploads).
31
+ *
32
+ * @param input - The email content and recipients
33
+ * @returns The queued email's message ID and status
34
+ *
35
+ * @example
36
+ * ```typescript
37
+ * const result = await mail.send({
38
+ * to: ["recipient@example.com"],
39
+ * cc: ["cc@example.com"],
40
+ * subject: "Invoice #123",
41
+ * body: "<p>Please find your invoice attached.</p>",
42
+ * reply_to: "billing@company.com",
43
+ * sender_name: "Billing Department",
44
+ * attachments: [{
45
+ * file_name: "invoice.pdf",
46
+ * mime_type: "application/pdf",
47
+ * content: "base64encodedcontent...",
48
+ * size: 12345
49
+ * }]
50
+ * })
51
+ * ```
52
+ */
53
+ send(input: SendEmailRequest): Promise<SendEmailResponse>;
54
+ /**
55
+ * List emails for the current project with optional filtering and pagination.
56
+ *
57
+ * @param params - Optional query parameters for filtering and pagination
58
+ * @returns Paginated list of email log entries
59
+ *
60
+ * @example
61
+ * ```typescript
62
+ * // List all emails
63
+ * const emails = await mail.list()
64
+ *
65
+ * // List failed emails, page 2
66
+ * const failed = await mail.list({ status: "failed", page: 2, limit: 10 })
67
+ * ```
68
+ */
69
+ list(params?: ListEmailsParams): Promise<EmailListResponse>;
70
+ /**
71
+ * Get a single email by its message ID.
72
+ *
73
+ * @param messageId - The UUID of the email message
74
+ * @returns The full email log entry
75
+ *
76
+ * @example
77
+ * ```typescript
78
+ * const email = await mail.get("550e8400-e29b-41d4-a716-446655440000")
79
+ * console.log(email.status, email.subject)
80
+ * ```
81
+ */
82
+ get(messageId: string): Promise<MailLog>;
83
+ /**
84
+ * Resend a previously failed email. Resets the retry counter and
85
+ * re-queues the email for delivery.
86
+ *
87
+ * @param messageId - The UUID of the email to resend
88
+ * @returns Confirmation with the message ID
89
+ *
90
+ * @example
91
+ * ```typescript
92
+ * await mail.resend("550e8400-e29b-41d4-a716-446655440000")
93
+ * ```
94
+ */
95
+ resend(messageId: string): Promise<SendEmailResponse>;
96
+ /**
97
+ * List attachment metadata for a specific email.
98
+ *
99
+ * @param messageId - The UUID of the email message
100
+ * @returns Array of attachment metadata entries
101
+ *
102
+ * @example
103
+ * ```typescript
104
+ * const attachments = await mail.listAttachments("550e8400-e29b-41d4-a716-446655440000")
105
+ * attachments.forEach(att => console.log(att.file_name, att.file_size))
106
+ * ```
107
+ */
108
+ listAttachments(messageId: string): Promise<AttachmentMeta[]>;
109
+ /**
110
+ * Download an attachment's binary content.
111
+ *
112
+ * @param messageId - The UUID of the email message
113
+ * @param attachmentId - The UUID of the attachment
114
+ * @returns The raw binary data as an ArrayBuffer
115
+ *
116
+ * @example
117
+ * ```typescript
118
+ * const content = await mail.downloadAttachment(
119
+ * "550e8400-e29b-41d4-a716-446655440000",
120
+ * "660e8400-e29b-41d4-a716-446655440000"
121
+ * )
122
+ * ```
123
+ */
124
+ downloadAttachment(messageId: string, attachmentId: string): Promise<ArrayBuffer>;
125
+ }
@@ -1,5 +1,6 @@
1
1
  import Invoicing from "./integrations/invoicing";
2
2
  import DMS from "./integrations/dms";
3
+ import Mail from "./integrations/mail";
3
4
  import MinFin from "./integrations/serbia/minfin";
4
5
  import IntegrationsBaseClient from "./integrationsBaseClient";
5
6
  import Payments from "./integrations/payments";
@@ -16,6 +17,7 @@ export default class Integrations extends IntegrationsBaseClient {
16
17
  getInvoicing(): Invoicing;
17
18
  getPayments(): Payments;
18
19
  getMinimax(): Minimax;
20
+ getMail(): Mail;
19
21
  getNBS(): NBS;
20
22
  getSerbiaMinFin(): MinFin;
21
23
  isInstalled(id: string): Promise<boolean>;
@@ -6,7 +6,6 @@ import BaseClient from "./baseClient";
6
6
  *
7
7
  * @class PlatformBaseClient
8
8
  * @extends BaseClient
9
- * @constructor
10
9
  * @param {AxiosInstance} [client] - The axios instance to use for the client
11
10
  *
12
11
  * @example
@@ -24,7 +24,7 @@ export default class Project extends PlatformBaseClient {
24
24
  archive(): Promise<AxiosResponse<any>>;
25
25
  /**
26
26
  * Invite a user to the project
27
- * @param email Array of emails
27
+ * @param emails Array of emails
28
28
  * @param roles Array of role UUIDs
29
29
  */
30
30
  invite(emails: string[], roles: string[]): Promise<AxiosResponse<any>>;