@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.
@@ -18991,7 +18991,6 @@ const isSandbox = typeof window !== "undefined";
18991
18991
  *
18992
18992
  * @class PlatformBaseClient
18993
18993
  * @extends BaseClient
18994
- * @constructor
18995
18994
  * @param {AxiosInstance} [client] - The axios instance to use for the client
18996
18995
  *
18997
18996
  * @example
@@ -19112,12 +19111,6 @@ class Component extends PlatformBaseClient {
19112
19111
  dateTo: ctx.dateTo,
19113
19112
  dateField: ctx.dateField,
19114
19113
  };
19115
- if (Object.keys(ctx.$adv || []).length > 0) {
19116
- params.$adv = JSON.stringify([ctx.$adv]);
19117
- }
19118
- if (ctx.$aggregate && ctx.$aggregate.length > 0) {
19119
- params.$aggregate = JSON.stringify(ctx.$aggregate);
19120
- }
19121
19114
  return await this.client.post(`/v4/system/component/${this.ref}/models`, {
19122
19115
  ...params,
19123
19116
  options: opts
@@ -19162,9 +19155,26 @@ class Component extends PlatformBaseClient {
19162
19155
  /**
19163
19156
  * Update model by uuid
19164
19157
  *
19165
- * @param uuid string - The uuid of the model
19166
- * @param data
19167
- * @returns
19158
+ * Regular fields in `data` are applied via `$set`. You can include MongoDB
19159
+ * update operators (prefixed with `$`) directly in the data object for
19160
+ * granular updates like incrementing, pushing to arrays, etc.
19161
+ *
19162
+ * @param uuid - The uuid of the model to update
19163
+ * @param data - Fields to update, optionally including update operators
19164
+ * @param options - Update options
19165
+ * @returns The updated model
19166
+ *
19167
+ * @example
19168
+ * // Simple update (backwards compatible)
19169
+ * await component.update(uuid, { name: "John" }, opts)
19170
+ *
19171
+ * // With update operators
19172
+ * await component.update(uuid, {
19173
+ * name: "John",
19174
+ * $inc: { login_count: 1 },
19175
+ * $push: { tags: "verified" },
19176
+ * $addToSet: { roles: "admin" }
19177
+ * }, opts)
19168
19178
  */
19169
19179
  async update(uuid, data, options) {
19170
19180
  return await this.client.post(`/v4/system/component/${this.ref}/model/${uuid}`, {
@@ -19201,9 +19211,20 @@ class Component extends PlatformBaseClient {
19201
19211
  /**
19202
19212
  * Modify models by filters
19203
19213
  *
19204
- * @param data
19205
- * @param options
19206
- * @returns
19214
+ * Updates all models matching the given filters. Supports inline update
19215
+ * operators in the data payload for granular operations.
19216
+ *
19217
+ * @param filters - Query filters to match models
19218
+ * @param data - Fields to update, optionally including update operators
19219
+ * @param options - Modify options (e.g. upsert)
19220
+ * @returns The modified models
19221
+ *
19222
+ * @example
19223
+ * await component.modify(
19224
+ * { status: "active" },
19225
+ * { $inc: { impression_count: 1 }, $addToSet: { viewers: "user-1" } },
19226
+ * { upsert: false }
19227
+ * )
19207
19228
  */
19208
19229
  async modify(filters, data, options) {
19209
19230
  return await this.client.patch(`/v4/system/component/${this.ref}/modify/model`, {
@@ -19213,12 +19234,23 @@ class Component extends PlatformBaseClient {
19213
19234
  });
19214
19235
  }
19215
19236
  /**
19216
- * Concurrent update model by uuid
19237
+ * Concurrent update model by uuid with optimistic locking
19217
19238
  *
19218
- * @param uuid string - The uuid of the model
19219
- * @param version number - The version of the model
19220
- * @param data
19221
- * @returns
19239
+ * Uses version-based concurrency control the update will fail with a
19240
+ * conflict error if the document has been modified since the provided version.
19241
+ * Supports inline update operators in the data payload.
19242
+ *
19243
+ * @param uuid - The uuid of the model
19244
+ * @param version - The expected __version__ of the model
19245
+ * @param data - Fields to update, optionally including update operators
19246
+ * @param options - Update options
19247
+ * @returns The updated model
19248
+ *
19249
+ * @example
19250
+ * await component.concurrentUpdate(uuid, model.__version__, {
19251
+ * status: "processed",
19252
+ * $inc: { retry_count: 1 }
19253
+ * }, opts)
19222
19254
  */
19223
19255
  async concurrentUpdate(uuid, version, data, options) {
19224
19256
  return await this.client.post(`/v4/system/component/${this.ref}/model/${uuid}`, {
@@ -19339,6 +19371,115 @@ class Component extends PlatformBaseClient {
19339
19371
  async revisions(uuid) {
19340
19372
  return await this.client.get(`/v3/system/component/${this.ref}/model/${uuid}/revisions`);
19341
19373
  }
19374
+ /**
19375
+ * Install a new extension on the component
19376
+ *
19377
+ * @param extension - The extension definition to install
19378
+ * @param version - The component version to install the extension on
19379
+ * @returns Updated component settings
19380
+ *
19381
+ * @example
19382
+ * ```typescript
19383
+ * await component.installExtension({
19384
+ * name: 'shipping_tracker',
19385
+ * is_active: true,
19386
+ * fields: [...],
19387
+ * config: { api_key: 'key' }
19388
+ * }, '0.1.0')
19389
+ * ```
19390
+ */
19391
+ async installExtension(extension, version) {
19392
+ return await this.client.post(`/v4/system/component/${this.ref}/${version}/extensions`, extension);
19393
+ }
19394
+ /**
19395
+ * Update an existing extension on the component
19396
+ *
19397
+ * @param name - The name of the extension to update
19398
+ * @param version - The component version
19399
+ * @param data - Partial extension data to update
19400
+ * @returns Updated component settings
19401
+ *
19402
+ * @example
19403
+ * ```typescript
19404
+ * await component.updateExtension('shipping_tracker', '0.1.0', {
19405
+ * is_active: false,
19406
+ * config: { api_key: 'new-key' }
19407
+ * })
19408
+ * ```
19409
+ */
19410
+ async updateExtension(name, version, data) {
19411
+ return await this.client.patch(`/v4/system/component/${this.ref}/${version}/extensions/${name}`, data);
19412
+ }
19413
+ /**
19414
+ * Delete an extension from the component
19415
+ *
19416
+ * @param name - The name of the extension to delete
19417
+ * @param version - The component version
19418
+ * @returns Updated component settings
19419
+ *
19420
+ * @example
19421
+ * ```typescript
19422
+ * await component.deleteExtension('shipping_tracker', '0.1.0')
19423
+ * ```
19424
+ */
19425
+ async deleteExtension(name, version) {
19426
+ return await this.client.delete(`/v4/system/component/${this.ref}/${version}/extensions/${name}`);
19427
+ }
19428
+ /**
19429
+ * Install a new policy on the component
19430
+ *
19431
+ * @param policy - The policy definition to install
19432
+ * @param version - The component version to install the policy on
19433
+ * @returns Updated component settings
19434
+ *
19435
+ * @example
19436
+ * ```typescript
19437
+ * await component.installPolicy({
19438
+ * type: 'field_access',
19439
+ * name: 'restrict_email',
19440
+ * enabled: true,
19441
+ * priority: 1,
19442
+ * config: { fields: ['email'], actions: ['see'], roles: ['role-uuid'] }
19443
+ * }, '0.1.0')
19444
+ * ```
19445
+ */
19446
+ async installPolicy(policy, version) {
19447
+ return await this.client.post(`/v4/system/component/${this.ref}/${version}/policies`, policy);
19448
+ }
19449
+ /**
19450
+ * Update an existing policy on the component
19451
+ *
19452
+ * @param name - The name of the policy to update
19453
+ * @param version - The component version
19454
+ * @param data - Partial policy data to update
19455
+ * @returns Updated component settings
19456
+ *
19457
+ * @example
19458
+ * ```typescript
19459
+ * await component.updatePolicy('restrict_email', '0.1.0', {
19460
+ * enabled: false,
19461
+ * priority: 2
19462
+ * })
19463
+ * ```
19464
+ */
19465
+ async updatePolicy(name, version, data) {
19466
+ return await this.client.patch(`/v4/system/component/${this.ref}/${version}/policies/${name}`, data);
19467
+ }
19468
+ /**
19469
+ * Delete a policy from the component
19470
+ *
19471
+ * @param name - The name of the policy to delete
19472
+ * @param version - The component version
19473
+ * @returns Updated component settings
19474
+ *
19475
+ * @example
19476
+ * ```typescript
19477
+ * await component.deletePolicy('restrict_email', '0.1.0')
19478
+ * ```
19479
+ */
19480
+ async deletePolicy(name, version) {
19481
+ return await this.client.delete(`/v4/system/component/${this.ref}/${version}/policies/${name}`);
19482
+ }
19342
19483
  /**
19343
19484
  * Internal method to handle NDJSON streaming responses
19344
19485
  *
@@ -19430,8 +19571,7 @@ class Functions extends PlatformBaseClient {
19430
19571
  * Run platform function
19431
19572
  *
19432
19573
  * @param id - Function ID
19433
- * @param input - Input data
19434
- * @param query - Query parameters
19574
+ * @param d - Object containing input data, query parameters, and headers
19435
19575
  * @returns - Function result
19436
19576
  *
19437
19577
  * @example
@@ -19957,7 +20097,7 @@ class Project extends PlatformBaseClient {
19957
20097
  }
19958
20098
  /**
19959
20099
  * Invite a user to the project
19960
- * @param email Array of emails
20100
+ * @param emails Array of emails
19961
20101
  * @param roles Array of role UUIDs
19962
20102
  */
19963
20103
  async invite(emails, roles) {
@@ -20537,7 +20677,6 @@ class DMS extends IntegrationsBaseClient {
20537
20677
  * - Explicit structure: JSON with `header`, `items`, and `footer` properties
20538
20678
  * - Auto-detection: Mixed JSON arrays with metadata objects and summary rows
20539
20679
  *
20540
- * @param lib - Library reference UUID
20541
20680
  * @param data - Raw data to convert
20542
20681
  * @param params - Conversion parameters including structured data options
20543
20682
  * @returns Promise resolving to converted data
@@ -20630,7 +20769,6 @@ class DMS extends IntegrationsBaseClient {
20630
20769
  /**
20631
20770
  * Get information about data format and structure
20632
20771
  *
20633
- * @param lib - Library reference UUID
20634
20772
  * @param data - Raw data to analyze
20635
20773
  * @param params - Analysis parameters
20636
20774
  * @returns Promise resolving to data information
@@ -20671,7 +20809,6 @@ class DMS extends IntegrationsBaseClient {
20671
20809
  /**
20672
20810
  * Validate data format without performing conversion
20673
20811
  *
20674
- * @param lib - Library reference UUID
20675
20812
  * @param data - Raw data to validate
20676
20813
  * @param params - Validation parameters
20677
20814
  * @returns Promise resolving to validation result
@@ -20719,7 +20856,6 @@ class DMS extends IntegrationsBaseClient {
20719
20856
  * - Regular arrays are converted directly to CSV
20720
20857
  * - Structured data (with metadata objects) is automatically detected and formatted
20721
20858
  *
20722
- * @param lib - Library reference UUID
20723
20859
  * @param jsonData - JSON data (array of objects or structured data)
20724
20860
  * @returns Promise resolving to CSV string
20725
20861
  *
@@ -20770,7 +20906,6 @@ class DMS extends IntegrationsBaseClient {
20770
20906
  * Supports both regular JSON arrays and structured data patterns.
20771
20907
  * Excel files are always generated with .xlsx extension.
20772
20908
  *
20773
- * @param lib - Library reference UUID
20774
20909
  * @param jsonData - JSON data (array of objects or structured data)
20775
20910
  * @param options - Optional conversion options
20776
20911
  * @returns Promise resolving to Excel file as Blob
@@ -20829,7 +20964,6 @@ class DMS extends IntegrationsBaseClient {
20829
20964
  /**
20830
20965
  * Convert CSV data to JSON format
20831
20966
  *
20832
- * @param lib - Library reference UUID
20833
20967
  * @param csvData - CSV data string (with headers in first row)
20834
20968
  * @returns Promise resolving to JSON array
20835
20969
  *
@@ -20860,7 +20994,6 @@ class DMS extends IntegrationsBaseClient {
20860
20994
  /**
20861
20995
  * Convert CSV data to Excel (.xlsx) format
20862
20996
  *
20863
- * @param lib - Library reference UUID
20864
20997
  * @param csvData - CSV data string (with headers in first row)
20865
20998
  * @param options - Optional conversion options
20866
20999
  * @returns Promise resolving to Excel file as Blob
@@ -20898,7 +21031,6 @@ class DMS extends IntegrationsBaseClient {
20898
21031
  /**
20899
21032
  * Convert Excel (.xlsx) data to JSON format
20900
21033
  *
20901
- * @param lib - Library reference UUID
20902
21034
  * @param excelData - Excel file data as Blob or ArrayBuffer
20903
21035
  * @param options - Optional conversion options
20904
21036
  * @returns Promise resolving to JSON array
@@ -20938,7 +21070,6 @@ class DMS extends IntegrationsBaseClient {
20938
21070
  /**
20939
21071
  * Convert Excel (.xlsx) data to CSV format
20940
21072
  *
20941
- * @param lib - Library reference UUID
20942
21073
  * @param excelData - Excel file data as Blob or ArrayBuffer
20943
21074
  * @param options - Optional conversion options
20944
21075
  * @returns Promise resolving to CSV string
@@ -21002,6 +21133,148 @@ class DMS extends IntegrationsBaseClient {
21002
21133
  }
21003
21134
  }
21004
21135
 
21136
+ /**
21137
+ * SDK client for the Protokol Mail integration.
21138
+ *
21139
+ * Provides methods to send emails, list email logs, resend failed emails,
21140
+ * and manage attachments through the Protokol Mail API.
21141
+ *
21142
+ * @example
21143
+ * ```typescript
21144
+ * import { Mail } from "@ptkl/sdk/beta"
21145
+ *
21146
+ * const mail = new Mail()
21147
+ *
21148
+ * // Send an email
21149
+ * const result = await mail.send({
21150
+ * to: ["user@example.com"],
21151
+ * subject: "Hello",
21152
+ * body: "<h1>Welcome!</h1>"
21153
+ * })
21154
+ *
21155
+ * console.log(result.message_id)
21156
+ * ```
21157
+ */
21158
+ class Mail extends IntegrationsBaseClient {
21159
+ /**
21160
+ * Send an email. The email is queued for async delivery.
21161
+ *
21162
+ * Supports both JSON body (with base64-encoded attachments) and
21163
+ * multipart/form-data (with file uploads).
21164
+ *
21165
+ * @param input - The email content and recipients
21166
+ * @returns The queued email's message ID and status
21167
+ *
21168
+ * @example
21169
+ * ```typescript
21170
+ * const result = await mail.send({
21171
+ * to: ["recipient@example.com"],
21172
+ * cc: ["cc@example.com"],
21173
+ * subject: "Invoice #123",
21174
+ * body: "<p>Please find your invoice attached.</p>",
21175
+ * reply_to: "billing@company.com",
21176
+ * sender_name: "Billing Department",
21177
+ * attachments: [{
21178
+ * file_name: "invoice.pdf",
21179
+ * mime_type: "application/pdf",
21180
+ * content: "base64encodedcontent...",
21181
+ * size: 12345
21182
+ * }]
21183
+ * })
21184
+ * ```
21185
+ */
21186
+ async send(input) {
21187
+ const { data } = await this.client.post("/protokol-mail/v1/emails", input);
21188
+ return data;
21189
+ }
21190
+ /**
21191
+ * List emails for the current project with optional filtering and pagination.
21192
+ *
21193
+ * @param params - Optional query parameters for filtering and pagination
21194
+ * @returns Paginated list of email log entries
21195
+ *
21196
+ * @example
21197
+ * ```typescript
21198
+ * // List all emails
21199
+ * const emails = await mail.list()
21200
+ *
21201
+ * // List failed emails, page 2
21202
+ * const failed = await mail.list({ status: "failed", page: 2, limit: 10 })
21203
+ * ```
21204
+ */
21205
+ async list(params) {
21206
+ const { data } = await this.client.get("/protokol-mail/v1/emails", { params });
21207
+ return data;
21208
+ }
21209
+ /**
21210
+ * Get a single email by its message ID.
21211
+ *
21212
+ * @param messageId - The UUID of the email message
21213
+ * @returns The full email log entry
21214
+ *
21215
+ * @example
21216
+ * ```typescript
21217
+ * const email = await mail.get("550e8400-e29b-41d4-a716-446655440000")
21218
+ * console.log(email.status, email.subject)
21219
+ * ```
21220
+ */
21221
+ async get(messageId) {
21222
+ const { data } = await this.client.get(`/protokol-mail/v1/emails/${messageId}`);
21223
+ return data;
21224
+ }
21225
+ /**
21226
+ * Resend a previously failed email. Resets the retry counter and
21227
+ * re-queues the email for delivery.
21228
+ *
21229
+ * @param messageId - The UUID of the email to resend
21230
+ * @returns Confirmation with the message ID
21231
+ *
21232
+ * @example
21233
+ * ```typescript
21234
+ * await mail.resend("550e8400-e29b-41d4-a716-446655440000")
21235
+ * ```
21236
+ */
21237
+ async resend(messageId) {
21238
+ const { data } = await this.client.post(`/protokol-mail/v1/emails/${messageId}/resend`);
21239
+ return data;
21240
+ }
21241
+ /**
21242
+ * List attachment metadata for a specific email.
21243
+ *
21244
+ * @param messageId - The UUID of the email message
21245
+ * @returns Array of attachment metadata entries
21246
+ *
21247
+ * @example
21248
+ * ```typescript
21249
+ * const attachments = await mail.listAttachments("550e8400-e29b-41d4-a716-446655440000")
21250
+ * attachments.forEach(att => console.log(att.file_name, att.file_size))
21251
+ * ```
21252
+ */
21253
+ async listAttachments(messageId) {
21254
+ const { data } = await this.client.get(`/protokol-mail/v1/emails/${messageId}/attachments`);
21255
+ return data;
21256
+ }
21257
+ /**
21258
+ * Download an attachment's binary content.
21259
+ *
21260
+ * @param messageId - The UUID of the email message
21261
+ * @param attachmentId - The UUID of the attachment
21262
+ * @returns The raw binary data as an ArrayBuffer
21263
+ *
21264
+ * @example
21265
+ * ```typescript
21266
+ * const content = await mail.downloadAttachment(
21267
+ * "550e8400-e29b-41d4-a716-446655440000",
21268
+ * "660e8400-e29b-41d4-a716-446655440000"
21269
+ * )
21270
+ * ```
21271
+ */
21272
+ async downloadAttachment(messageId, attachmentId) {
21273
+ const { data } = await this.client.get(`/protokol-mail/v1/emails/${messageId}/attachments/${attachmentId}`, { responseType: "arraybuffer" });
21274
+ return data;
21275
+ }
21276
+ }
21277
+
21005
21278
  class VPFR extends IntegrationsBaseClient {
21006
21279
  async request(method, endpoint, params) {
21007
21280
  return await this.client.request({
@@ -21869,6 +22142,7 @@ class Integrations extends IntegrationsBaseClient {
21869
22142
  this.integrations = {
21870
22143
  'serbia-minfin': new MinFin().setClient(this.client),
21871
22144
  'protokol-dms': new DMS().setClient(this.client),
22145
+ 'protokol-mail': new Mail().setClient(this.client),
21872
22146
  'nbs': new NBS().setClient(this.client),
21873
22147
  'protokol-payments': new Payments().setClient(this.client),
21874
22148
  'protokol-minimax': new Minimax().setClient(this.client),
@@ -21886,6 +22160,9 @@ class Integrations extends IntegrationsBaseClient {
21886
22160
  getMinimax() {
21887
22161
  return this.getInterfaceOf('protokol-minimax');
21888
22162
  }
22163
+ getMail() {
22164
+ return this.getInterfaceOf('protokol-mail');
22165
+ }
21889
22166
  getNBS() {
21890
22167
  return this.getInterfaceOf('nbs');
21891
22168
  }
@@ -21942,6 +22219,7 @@ exports.Functions = Functions;
21942
22219
  exports.Integration = Integrations;
21943
22220
  exports.Integrations = Integrations;
21944
22221
  exports.Invoicing = Invoicing;
22222
+ exports.Mail = Mail;
21945
22223
  exports.NBS = NBS;
21946
22224
  exports.Payments = Payments;
21947
22225
  exports.Platform = Platform;