@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.
@@ -0,0 +1,156 @@
1
+ /**
2
+ * Represents the status of an email in the system.
3
+ */
4
+ export type EmailStatus = "pending" | "sent" | "failed";
5
+ /**
6
+ * Represents a mail log entry returned by the API.
7
+ */
8
+ export type MailLog = {
9
+ /** Unique message identifier (UUID) */
10
+ message_id: string;
11
+ /** Project scope UUID */
12
+ project_uuid: string;
13
+ /** Tenant scope UUID */
14
+ tenant_uuid: string;
15
+ /** Associated workflow component UUID */
16
+ component_uuid?: string;
17
+ /** Environment: "dev" or "live" */
18
+ env: string;
19
+ /** Sender address (auto-generated from tenant) */
20
+ from: string;
21
+ /** Recipient email addresses */
22
+ to: string[];
23
+ /** CC email addresses */
24
+ cc: string[];
25
+ /** BCC email addresses */
26
+ bcc: string[];
27
+ /** Reply-to email address */
28
+ reply_to?: string;
29
+ /** Email subject line */
30
+ subject: string;
31
+ /** Email body (HTML) */
32
+ body: string;
33
+ /** Attachment metadata as JSON string */
34
+ attachments?: string;
35
+ /** Current sending status */
36
+ status: EmailStatus;
37
+ /** Number of send retry attempts */
38
+ retry_count: number;
39
+ /** Maximum allowed retries */
40
+ max_retries: number;
41
+ /** Error message from last failed attempt */
42
+ error_message?: string;
43
+ /** Timestamp when email was successfully sent */
44
+ sent_at?: string;
45
+ /** Timestamp when email was opened (tracking pixel) */
46
+ read_at?: string;
47
+ /** IP address of reader */
48
+ read_ip?: string;
49
+ /** User agent of reader */
50
+ read_user_agent?: string;
51
+ /** Whether the email was reported as spam */
52
+ spam_reported: boolean;
53
+ /** Timestamp of spam report */
54
+ spam_reported_at?: string;
55
+ /** Who reported the spam */
56
+ spam_reported_by?: string;
57
+ /** IP address of spam reporter */
58
+ spam_report_ip?: string;
59
+ /** Record creation timestamp */
60
+ created_at: string;
61
+ /** Record update timestamp */
62
+ updated_at: string;
63
+ };
64
+ /**
65
+ * Attachment input for sending an email.
66
+ * Provide either a `file_id` (DMS reference) or `content` (base64-encoded data).
67
+ */
68
+ export type AttachmentInput = {
69
+ /** DMS file ID reference */
70
+ file_id?: string;
71
+ /** File name */
72
+ file_name: string;
73
+ /** MIME type (e.g. "application/pdf") */
74
+ mime_type: string;
75
+ /** Base64-encoded file content */
76
+ content?: string;
77
+ /** File size in bytes */
78
+ size?: number;
79
+ };
80
+ /**
81
+ * Request payload for sending an email.
82
+ */
83
+ export type SendEmailRequest = {
84
+ /** Recipient email addresses (required) */
85
+ to: string[];
86
+ /** CC email addresses */
87
+ cc?: string[];
88
+ /** BCC email addresses */
89
+ bcc?: string[];
90
+ /** Email subject (required) */
91
+ subject: string;
92
+ /** Email body in HTML (required) */
93
+ body: string;
94
+ /** Reply-to email address */
95
+ reply_to?: string;
96
+ /** Custom sender display name */
97
+ sender_name?: string;
98
+ /** File attachments */
99
+ attachments?: AttachmentInput[];
100
+ };
101
+ /**
102
+ * Response from the send email endpoint.
103
+ */
104
+ export type SendEmailResponse = {
105
+ /** Whether the operation succeeded */
106
+ status: boolean;
107
+ /** The generated message ID (UUID) */
108
+ message_id: string;
109
+ /** Human-readable status message */
110
+ message: string;
111
+ };
112
+ /**
113
+ * Paginated list response for emails.
114
+ */
115
+ export type EmailListResponse = {
116
+ /** Array of mail log entries */
117
+ data: MailLog[];
118
+ /** Total number of matching emails */
119
+ total: number;
120
+ /** Current page number */
121
+ page: number;
122
+ /** Number of items per page */
123
+ limit: number;
124
+ };
125
+ /**
126
+ * Query parameters for listing emails.
127
+ */
128
+ export type ListEmailsParams = {
129
+ /** Filter by email status */
130
+ status?: EmailStatus;
131
+ /** Page number (1-indexed) */
132
+ page?: number;
133
+ /** Items per page (max 100, default 20) */
134
+ limit?: number;
135
+ };
136
+ /**
137
+ * Attachment metadata returned by the list attachments endpoint.
138
+ */
139
+ export type AttachmentMeta = {
140
+ /** Attachment record UUID */
141
+ uuid: string;
142
+ /** Linked message ID */
143
+ message_id: string;
144
+ /** File name */
145
+ file_name: string;
146
+ /** MIME type */
147
+ mime_type: string;
148
+ /** File size in bytes */
149
+ file_size: number;
150
+ /** Record creation timestamp */
151
+ created_at: string;
152
+ };
153
+ /**
154
+ * Events published by the mail system for workflow triggers.
155
+ */
156
+ export type MailEventType = "protokol-mail.email.sent" | "protokol-mail.email.failed" | "protokol-mail.email.opened" | "protokol-mail.email.spam_reported";
@@ -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
@@ -20,5 +20,6 @@ export { default as Invoicing } from './integrations/invoicing';
20
20
  export { default as DMS } from './integrations/dms';
21
21
  export { default as SerbiaUtil } from './integrations/serbiaUtil';
22
22
  export { default as VPFR } from './integrations/vpfr';
23
+ export { default as Mail } from './integrations/mail';
23
24
  import Platfrom from './platform';
24
25
  export default Platfrom;
@@ -0,0 +1,69 @@
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"
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
+ * @param input - The email content and recipients
30
+ * @returns The queued email's message ID and status
31
+ */
32
+ send(input: SendEmailRequest): Promise<SendEmailResponse>;
33
+ /**
34
+ * List emails for the current project with optional filtering and pagination.
35
+ *
36
+ * @param params - Optional query parameters for filtering and pagination
37
+ * @returns Paginated list of email log entries
38
+ */
39
+ list(params?: ListEmailsParams): Promise<EmailListResponse>;
40
+ /**
41
+ * Get a single email by its message ID.
42
+ *
43
+ * @param messageId - The UUID of the email message
44
+ * @returns The full email log entry
45
+ */
46
+ get(messageId: string): Promise<MailLog>;
47
+ /**
48
+ * Resend a previously failed email.
49
+ *
50
+ * @param messageId - The UUID of the email to resend
51
+ * @returns Confirmation with the message ID
52
+ */
53
+ resend(messageId: string): Promise<SendEmailResponse>;
54
+ /**
55
+ * List attachment metadata for a specific email.
56
+ *
57
+ * @param messageId - The UUID of the email message
58
+ * @returns Array of attachment metadata entries
59
+ */
60
+ listAttachments(messageId: string): Promise<AttachmentMeta[]>;
61
+ /**
62
+ * Download an attachment's binary content.
63
+ *
64
+ * @param messageId - The UUID of the email message
65
+ * @param attachmentId - The UUID of the attachment
66
+ * @returns The raw binary data as an ArrayBuffer
67
+ */
68
+ downloadAttachment(messageId: string, attachmentId: string): Promise<ArrayBuffer>;
69
+ }
@@ -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 VPFR from "./integrations/vpfr";
4
5
  import IntegrationsBaseClient from "./integrationsBaseClient";
5
6
  import Payments from "./integrations/payments";
@@ -15,6 +16,7 @@ export default class Integrations extends IntegrationsBaseClient {
15
16
  getDMS(): DMS;
16
17
  getVPFR(): VPFR;
17
18
  getInvoicing(): Invoicing;
19
+ getMail(): Mail;
18
20
  getPayments(): Payments;
19
21
  getMinimax(): Minimax;
20
22
  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>>;
@@ -18993,7 +18993,6 @@ const isSandbox = typeof window !== "undefined";
18993
18993
  *
18994
18994
  * @class PlatformBaseClient
18995
18995
  * @extends BaseClient
18996
- * @constructor
18997
18996
  * @param {AxiosInstance} [client] - The axios instance to use for the client
18998
18997
  *
18999
18998
  * @example
@@ -19443,8 +19442,7 @@ class Functions extends PlatformBaseClient {
19443
19442
  * Run platform function
19444
19443
  *
19445
19444
  * @param id - Function ID
19446
- * @param input - Input data
19447
- * @param query - Query parameters
19445
+ * @param d - Object containing input data, query parameters, and headers
19448
19446
  * @returns - Function result
19449
19447
  *
19450
19448
  * @example
@@ -19959,7 +19957,7 @@ class Project extends PlatformBaseClient {
19959
19957
  }
19960
19958
  /**
19961
19959
  * Invite a user to the project
19962
- * @param email Array of emails
19960
+ * @param emails Array of emails
19963
19961
  * @param roles Array of role UUIDs
19964
19962
  */
19965
19963
  async invite(emails, roles) {
@@ -20928,6 +20926,92 @@ class DMS extends IntegrationsBaseClient {
20928
20926
  }
20929
20927
  }
20930
20928
 
20929
+ /**
20930
+ * SDK client for the Protokol Mail integration.
20931
+ *
20932
+ * Provides methods to send emails, list email logs, resend failed emails,
20933
+ * and manage attachments through the Protokol Mail API.
20934
+ *
20935
+ * @example
20936
+ * ```typescript
20937
+ * import { Mail } from "@ptkl/sdk"
20938
+ *
20939
+ * const mail = new Mail()
20940
+ *
20941
+ * // Send an email
20942
+ * const result = await mail.send({
20943
+ * to: ["user@example.com"],
20944
+ * subject: "Hello",
20945
+ * body: "<h1>Welcome!</h1>"
20946
+ * })
20947
+ *
20948
+ * console.log(result.message_id)
20949
+ * ```
20950
+ */
20951
+ class Mail extends IntegrationsBaseClient {
20952
+ /**
20953
+ * Send an email. The email is queued for async delivery.
20954
+ *
20955
+ * @param input - The email content and recipients
20956
+ * @returns The queued email's message ID and status
20957
+ */
20958
+ async send(input) {
20959
+ const { data } = await this.client.post("/protokol-mail/v1/emails", input);
20960
+ return data;
20961
+ }
20962
+ /**
20963
+ * List emails for the current project with optional filtering and pagination.
20964
+ *
20965
+ * @param params - Optional query parameters for filtering and pagination
20966
+ * @returns Paginated list of email log entries
20967
+ */
20968
+ async list(params) {
20969
+ const { data } = await this.client.get("/protokol-mail/v1/emails", { params });
20970
+ return data;
20971
+ }
20972
+ /**
20973
+ * Get a single email by its message ID.
20974
+ *
20975
+ * @param messageId - The UUID of the email message
20976
+ * @returns The full email log entry
20977
+ */
20978
+ async get(messageId) {
20979
+ const { data } = await this.client.get(`/protokol-mail/v1/emails/${messageId}`);
20980
+ return data;
20981
+ }
20982
+ /**
20983
+ * Resend a previously failed email.
20984
+ *
20985
+ * @param messageId - The UUID of the email to resend
20986
+ * @returns Confirmation with the message ID
20987
+ */
20988
+ async resend(messageId) {
20989
+ const { data } = await this.client.post(`/protokol-mail/v1/emails/${messageId}/resend`);
20990
+ return data;
20991
+ }
20992
+ /**
20993
+ * List attachment metadata for a specific email.
20994
+ *
20995
+ * @param messageId - The UUID of the email message
20996
+ * @returns Array of attachment metadata entries
20997
+ */
20998
+ async listAttachments(messageId) {
20999
+ const { data } = await this.client.get(`/protokol-mail/v1/emails/${messageId}/attachments`);
21000
+ return data;
21001
+ }
21002
+ /**
21003
+ * Download an attachment's binary content.
21004
+ *
21005
+ * @param messageId - The UUID of the email message
21006
+ * @param attachmentId - The UUID of the attachment
21007
+ * @returns The raw binary data as an ArrayBuffer
21008
+ */
21009
+ async downloadAttachment(messageId, attachmentId) {
21010
+ const { data } = await this.client.get(`/protokol-mail/v1/emails/${messageId}/attachments/${attachmentId}`, { responseType: "arraybuffer" });
21011
+ return data;
21012
+ }
21013
+ }
21014
+
20931
21015
  class SerbiaUtil extends IntegrationsBaseClient {
20932
21016
  async nbsSearch(params) {
20933
21017
  return await this.services("GET", "nbs/search", {
@@ -21783,6 +21867,7 @@ class Integrations extends IntegrationsBaseClient {
21783
21867
  'protokol-invoicing': new Invoicing().setClient(this.client),
21784
21868
  'protokol-vpfr': new VPFR().setClient(this.client),
21785
21869
  'protokol-dms': new DMS().setClient(this.client),
21870
+ 'protokol-mail': new Mail().setClient(this.client),
21786
21871
  'serbia-utilities': new SerbiaUtil().setClient(this.client),
21787
21872
  'protokol-payments': new Payments().setClient(this.client),
21788
21873
  'protokol-minimax': new Minimax().setClient(this.client),
@@ -21800,6 +21885,9 @@ class Integrations extends IntegrationsBaseClient {
21800
21885
  getInvoicing() {
21801
21886
  return this.getInterfaceOf('protokol-invoicing');
21802
21887
  }
21888
+ getMail() {
21889
+ return this.getInterfaceOf('protokol-mail');
21890
+ }
21803
21891
  getPayments() {
21804
21892
  return this.getInterfaceOf('protokol-payments');
21805
21893
  }
@@ -21835,6 +21923,7 @@ exports.Functions = Functions;
21835
21923
  exports.Integration = Integrations;
21836
21924
  exports.Integrations = Integrations;
21837
21925
  exports.Invoicing = Invoicing;
21926
+ exports.Mail = Mail;
21838
21927
  exports.Payments = Payments;
21839
21928
  exports.Platform = Platform;
21840
21929
  exports.Project = Project;
@@ -24,7 +24,6 @@ const isSandbox = typeof window !== "undefined";
24
24
  *
25
25
  * @class PlatformBaseClient
26
26
  * @extends BaseClient
27
- * @constructor
28
27
  * @param {AxiosInstance} [client] - The axios instance to use for the client
29
28
  *
30
29
  * @example
@@ -474,8 +473,7 @@ class Functions extends PlatformBaseClient {
474
473
  * Run platform function
475
474
  *
476
475
  * @param id - Function ID
477
- * @param input - Input data
478
- * @param query - Query parameters
476
+ * @param d - Object containing input data, query parameters, and headers
479
477
  * @returns - Function result
480
478
  *
481
479
  * @example
@@ -990,7 +988,7 @@ class Project extends PlatformBaseClient {
990
988
  }
991
989
  /**
992
990
  * Invite a user to the project
993
- * @param email Array of emails
991
+ * @param emails Array of emails
994
992
  * @param roles Array of role UUIDs
995
993
  */
996
994
  async invite(emails, roles) {
@@ -1959,6 +1957,92 @@ class DMS extends IntegrationsBaseClient {
1959
1957
  }
1960
1958
  }
1961
1959
 
1960
+ /**
1961
+ * SDK client for the Protokol Mail integration.
1962
+ *
1963
+ * Provides methods to send emails, list email logs, resend failed emails,
1964
+ * and manage attachments through the Protokol Mail API.
1965
+ *
1966
+ * @example
1967
+ * ```typescript
1968
+ * import { Mail } from "@ptkl/sdk"
1969
+ *
1970
+ * const mail = new Mail()
1971
+ *
1972
+ * // Send an email
1973
+ * const result = await mail.send({
1974
+ * to: ["user@example.com"],
1975
+ * subject: "Hello",
1976
+ * body: "<h1>Welcome!</h1>"
1977
+ * })
1978
+ *
1979
+ * console.log(result.message_id)
1980
+ * ```
1981
+ */
1982
+ class Mail extends IntegrationsBaseClient {
1983
+ /**
1984
+ * Send an email. The email is queued for async delivery.
1985
+ *
1986
+ * @param input - The email content and recipients
1987
+ * @returns The queued email's message ID and status
1988
+ */
1989
+ async send(input) {
1990
+ const { data } = await this.client.post("/protokol-mail/v1/emails", input);
1991
+ return data;
1992
+ }
1993
+ /**
1994
+ * List emails for the current project with optional filtering and pagination.
1995
+ *
1996
+ * @param params - Optional query parameters for filtering and pagination
1997
+ * @returns Paginated list of email log entries
1998
+ */
1999
+ async list(params) {
2000
+ const { data } = await this.client.get("/protokol-mail/v1/emails", { params });
2001
+ return data;
2002
+ }
2003
+ /**
2004
+ * Get a single email by its message ID.
2005
+ *
2006
+ * @param messageId - The UUID of the email message
2007
+ * @returns The full email log entry
2008
+ */
2009
+ async get(messageId) {
2010
+ const { data } = await this.client.get(`/protokol-mail/v1/emails/${messageId}`);
2011
+ return data;
2012
+ }
2013
+ /**
2014
+ * Resend a previously failed email.
2015
+ *
2016
+ * @param messageId - The UUID of the email to resend
2017
+ * @returns Confirmation with the message ID
2018
+ */
2019
+ async resend(messageId) {
2020
+ const { data } = await this.client.post(`/protokol-mail/v1/emails/${messageId}/resend`);
2021
+ return data;
2022
+ }
2023
+ /**
2024
+ * List attachment metadata for a specific email.
2025
+ *
2026
+ * @param messageId - The UUID of the email message
2027
+ * @returns Array of attachment metadata entries
2028
+ */
2029
+ async listAttachments(messageId) {
2030
+ const { data } = await this.client.get(`/protokol-mail/v1/emails/${messageId}/attachments`);
2031
+ return data;
2032
+ }
2033
+ /**
2034
+ * Download an attachment's binary content.
2035
+ *
2036
+ * @param messageId - The UUID of the email message
2037
+ * @param attachmentId - The UUID of the attachment
2038
+ * @returns The raw binary data as an ArrayBuffer
2039
+ */
2040
+ async downloadAttachment(messageId, attachmentId) {
2041
+ const { data } = await this.client.get(`/protokol-mail/v1/emails/${messageId}/attachments/${attachmentId}`, { responseType: "arraybuffer" });
2042
+ return data;
2043
+ }
2044
+ }
2045
+
1962
2046
  class SerbiaUtil extends IntegrationsBaseClient {
1963
2047
  async nbsSearch(params) {
1964
2048
  return await this.services("GET", "nbs/search", {
@@ -2814,6 +2898,7 @@ class Integrations extends IntegrationsBaseClient {
2814
2898
  'protokol-invoicing': new Invoicing().setClient(this.client),
2815
2899
  'protokol-vpfr': new VPFR().setClient(this.client),
2816
2900
  'protokol-dms': new DMS().setClient(this.client),
2901
+ 'protokol-mail': new Mail().setClient(this.client),
2817
2902
  'serbia-utilities': new SerbiaUtil().setClient(this.client),
2818
2903
  'protokol-payments': new Payments().setClient(this.client),
2819
2904
  'protokol-minimax': new Minimax().setClient(this.client),
@@ -2831,6 +2916,9 @@ class Integrations extends IntegrationsBaseClient {
2831
2916
  getInvoicing() {
2832
2917
  return this.getInterfaceOf('protokol-invoicing');
2833
2918
  }
2919
+ getMail() {
2920
+ return this.getInterfaceOf('protokol-mail');
2921
+ }
2834
2922
  getPayments() {
2835
2923
  return this.getInterfaceOf('protokol-payments');
2836
2924
  }
@@ -2855,4 +2943,4 @@ class Integrations extends IntegrationsBaseClient {
2855
2943
  // Export all API modules for version 0.9
2856
2944
  // This version has specific method signatures and behaviors for v0.9
2857
2945
 
2858
- export { APIUser, Apps, Component, ComponentUtils, Config, DMS, Forge, Functions, Integrations as Integration, Integrations, Invoicing, Payments, Platform, Project, Ratchet, Sandbox, SerbiaUtil, System, Thunder, Users, VPFR, Workflow, Platform as default };
2946
+ export { APIUser, Apps, Component, ComponentUtils, Config, DMS, Forge, Functions, Integrations as Integration, Integrations, Invoicing, Mail, Payments, Platform, Project, Ratchet, Sandbox, SerbiaUtil, System, Thunder, Users, VPFR, Workflow, Platform as default };