@kumbify/sdk 1.0.4 → 1.0.6

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/README.md CHANGED
@@ -8,7 +8,7 @@ This SDK makes it easy to integrate messaging (email + SMS) into your apps with
8
8
 
9
9
  ---
10
10
 
11
- ### Installation
11
+ ### Installation
12
12
 
13
13
  Install using npm:
14
14
 
@@ -22,13 +22,12 @@ or using Yarn:
22
22
  yarn add @kumbify/sdk
23
23
  ```
24
24
 
25
- ### Importing
25
+ ### Importing
26
26
 
27
27
  ```ts
28
28
  import { KMailClient, KSMSClient } from "@kumbify/sdk";
29
29
  ```
30
30
 
31
-
32
31
  ### Email — KMailClient
33
32
 
34
33
  #### 📍 Create an Email Client
@@ -39,15 +38,16 @@ const mailClient = new KMailClient({
39
38
  });
40
39
  ```
41
40
 
42
- ### 📤 Send a Simple Email
43
-
44
41
  ```ts
42
+ // 📤 Send a Simple Email
45
43
  const sendMail = await mailClient.sendSimpleMail({
46
- body_html: "<h1>Hello from Kumbify</h1><p>This is a test email</p>",
47
- body_text: "Hello from Kumbify — this is a test email.",
48
- from_address: "no-reply@kumbify.app",
44
+ from: "no-reply@kumbify.com",
49
45
  subject: "Welcome Email",
50
- to_address: ["recipient@example.com"],
46
+ to: ["user1@example.com"],
47
+ body: {
48
+ html: "<h1>Hello from Kumbify</h1><p>This is a test email</p>",
49
+ text: "Hello from Kumbify — this is a test email.",
50
+ },
51
51
  });
52
52
 
53
53
  console.log("Email Response:", sendMail);
@@ -57,11 +57,11 @@ console.log("Email Response:", sendMail);
57
57
 
58
58
  | Property | Type | Description |
59
59
  | -------------- | -------- | --------------------------------- |
60
- | `body_html` | string | HTML email content |
61
- | `body_text` | string | Plain text email content |
62
- | `from_address` | string | Sender email address |
60
+ | `body.html` | string | HTML email content |
61
+ | `body.text` | string | Plain text email content |
62
+ | `from` | string | Sender email address |
63
63
  | `subject` | string | Email subject |
64
- | `to_address` | string[] | List of recipient email addresses |
64
+ | `to` | string[] | List of recipient email addresses |
65
65
 
66
66
  ---
67
67
 
@@ -75,9 +75,9 @@ const smsClient = new KSMSClient({
75
75
  });
76
76
  ```
77
77
 
78
- #### 📤 Send an SMS Message
79
-
80
78
  ```ts
79
+ // 📤 Send an SMS Message
80
+
81
81
  await smsClient.sendSMS({
82
82
  message: "Your verification code is 123456",
83
83
  from: "kumbify-app",
@@ -97,7 +97,7 @@ console.log("SMS sent successfully!");
97
97
 
98
98
  ---
99
99
 
100
- ### Example Usage All Together
100
+ ### Example Usage All Together
101
101
 
102
102
  ```ts
103
103
  import { KMailClient, KSMSClient } from "@kumbify/sdk";
@@ -107,11 +107,13 @@ const smsClient = new KSMSClient({ apiKey: "SMS_KEY" });
107
107
 
108
108
  // Send Email
109
109
  await mailClient.sendSimpleMail({
110
- body_html: "<p>Hello!</p>",
111
- body_text: "Hello!",
112
- from_address: "no-reply@kumbify.com",
110
+ from: "no-reply@kumbify.com",
113
111
  subject: "Test Email",
114
- to_address: ["user1@example.com"],
112
+ to: ["user1@example.com"],
113
+ body: {
114
+ html: "<p>Hello!</p>",
115
+ text: "Hello!",
116
+ },
115
117
  });
116
118
 
117
119
  // Send SMS
@@ -1,6 +1,6 @@
1
1
  import { IKMailResponseMail, IKMailSendMailSimpleMessage, IKMailSendMailTemplateMessage } from "../utils/types";
2
2
  export declare class KMailClient {
3
- apiKey: string;
3
+ private apiKey;
4
4
  constructor({ apiKey }: {
5
5
  apiKey: string;
6
6
  });
@@ -5,8 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.KMailClient = void 0;
7
7
  const helpers_1 = require("../utils/helpers");
8
- const axios_1 = require("axios");
9
- const axios_2 = __importDefault(require("axios"));
8
+ const axios_1 = __importDefault(require("axios"));
10
9
  class KMailClient {
11
10
  apiKey;
12
11
  constructor({ apiKey }) {
@@ -14,27 +13,41 @@ class KMailClient {
14
13
  }
15
14
  async sendSimpleMail({ ...data }) {
16
15
  try {
17
- const response = await axios_2.default.post(helpers_1.APP_CONFIG.KMAIL_URL + "/send", {
18
- ...data,
16
+ const response = await axios_1.default.post(helpers_1.APP_CONFIG.KMAIL_URL + "/send", {
17
+ from_address: data.from,
18
+ to_address: data.to,
19
+ subject: data.subject,
20
+ body_html: data.body.html,
21
+ body_text: data.body.text,
19
22
  }, { headers: { "kumbi-api-key": "Bearer " + this.apiKey } });
20
23
  return response.data;
21
24
  }
22
25
  catch (error) {
23
- if (error instanceof axios_1.AxiosError) {
24
- throw new Error("Message: " + error.response.data);
26
+ if (axios_1.default.isAxiosError(error)) {
27
+ const status = error.response?.status;
28
+ const data = error.response?.data;
29
+ throw new Error(`Mail failed (status: ${status}): ${JSON.stringify(data)}`);
25
30
  }
26
- throw new Error("Failed while send simple mail: " + error);
31
+ throw new Error(`Mail failed: ${String(error)}`);
27
32
  }
28
33
  }
29
34
  async sendTemplateMail({ ...data }) {
30
35
  try {
31
- const response = await axios_2.default.post(helpers_1.APP_CONFIG.KMAIL_URL + "/send", {
32
- ...data,
36
+ const response = await axios_1.default.post(helpers_1.APP_CONFIG.KMAIL_URL + "/send", {
37
+ from_address: data.from,
38
+ to_address: data.to,
39
+ template_name: data.template.name,
40
+ template_data: data.template.data,
33
41
  }, { headers: { "kumbi-api-key": "Bearer " + this.apiKey } });
34
42
  return response.data;
35
43
  }
36
- catch (err) {
37
- throw new Error("Failed while send template mail: " + err);
44
+ catch (error) {
45
+ if (axios_1.default.isAxiosError(error)) {
46
+ const status = error.response?.status;
47
+ const data = error.response?.data;
48
+ throw new Error(`Mail failed (status: ${status}): ${JSON.stringify(data)}`);
49
+ }
50
+ throw new Error(`Mail failed: ${String(error)}`);
38
51
  }
39
52
  }
40
53
  }
@@ -1 +1 @@
1
- {"version":3,"file":"KMailClient.js","sourceRoot":"","sources":["../../src/kmail/KMailClient.ts"],"names":[],"mappings":";;;;;;AAKA,8CAA8C;AAC9C,iCAAmC;AAEnC,kD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AC;YACH,MAAM,QAAQ,GAAG,MAAM,eAAK,CAAC,IAAI,CAC/B,oBAAU,CAAC,SAAS,GAAG,OAAO,EAC9B;gBACE,YAAY,EAAE,IAAI,CAAC,IAAI;gBACvB,UAAU,EAAE,IAAI,CAAC,EAAE;gBACnB,aAAa,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI;gBACjC,aAAa,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI;aAClC,EACD,EAAE,OAAO,EAAE,EAAE,eAAe,EAAE,SAAS,GAAG,IAAI,CAAC,MAAM,EAAE,EAAE,CAC1D,CAAC;YAEF,OAAO,QAAQ,CAAC,IAAI,CAAC;QACvB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,eAAK,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE,CAAC;gBAC9B,MAAM,MAAM,GAAG,KAAK,CAAC,QAAQ,EAAE,MAAM,CAAC;gBACtC,MAAM,IAAI,GAAG,KAAK,CAAC,QAAQ,EAAE,IAAI,CAAC;gBAClC,MAAM,IAAI,KAAK,CACb,wBAAwB,MAAM,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAC3D,CAAC;YACJ,CAAC;YAED,MAAM,IAAI,KAAK,CAAC,gBAAgB,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACnD,CAAC;IACH,CAAC;CACF;AA3DD,kCA2DC"}
@@ -1,6 +1,6 @@
1
1
  import { IKSMSSendMessage } from "../utils/types";
2
2
  export declare class KSMSClient {
3
- apiKey: string;
3
+ private apiKey;
4
4
  constructor({ apiKey }: {
5
5
  apiKey: string;
6
6
  });
@@ -4,9 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.KSMSClient = void 0;
7
- const axios_1 = require("axios");
8
7
  const helpers_1 = require("../utils/helpers");
9
- const axios_2 = __importDefault(require("axios"));
8
+ const axios_1 = __importDefault(require("axios"));
10
9
  class KSMSClient {
11
10
  apiKey;
12
11
  constructor({ apiKey }) {
@@ -14,7 +13,7 @@ class KSMSClient {
14
13
  }
15
14
  async sendSMS({ ...data }) {
16
15
  try {
17
- const response = await axios_2.default.post(helpers_1.APP_CONFIG.KSMS_URL + "/send", {
16
+ const response = await axios_1.default.post(helpers_1.APP_CONFIG.KSMS_URL + "/send", {
18
17
  body: data.message,
19
18
  to: data.to,
20
19
  from: data.from,
@@ -22,10 +21,12 @@ class KSMSClient {
22
21
  return response.data;
23
22
  }
24
23
  catch (error) {
25
- if (error instanceof axios_1.AxiosError) {
26
- throw new Error("Message: " + error.response.data);
24
+ if (axios_1.default.isAxiosError(error)) {
25
+ const status = error.response?.status;
26
+ const data = error.response?.data;
27
+ throw new Error(`SMS failed (status: ${status}): ${JSON.stringify(data)}`);
27
28
  }
28
- throw new Error("Failed while send sms: ", error);
29
+ throw new Error(`SMS failed: ${String(error)}`);
29
30
  }
30
31
  }
31
32
  }
@@ -1 +1 @@
1
- {"version":3,"file":"KSMSClient.js","sourceRoot":"","sources":["../../src/ksms/KSMSClient.ts"],"names":[],"mappings":";;;;;;AAAA,iCAAmC;AACnC,8CAA8C;AAE9C,kDAA0B;AAE1B,MAAa,UAAU;IACrB,MAAM,CAAC;IAEP,YAAY,EAAE,MAAM,EAAsB;QACxC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,EAAE,GAAG,IAAI,EAAoB;QACzC,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,eAAK,CAAC,IAAI,CAC/B,oBAAU,CAAC,QAAQ,GAAG,OAAO,EAC7B;gBACE,IAAI,EAAE,IAAI,CAAC,OAAO;gBAClB,EAAE,EAAE,IAAI,CAAC,EAAE;gBACX,IAAI,EAAE,IAAI,CAAC,IAAI;aAChB,EACD,EAAE,OAAO,EAAE,EAAE,eAAe,EAAE,SAAS,GAAG,IAAI,CAAC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I,CAAC;gBAClC,MAAM,IAAI,KAAK,CACb,uBAAuB,MAAM,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAC1D,CAAC;YACJ,CAAC;YAED,MAAM,IAAI,KAAK,CAAC,eAAe,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAClD,CAAC;IACH,CAAC;CACF;AAhCD,gCAgCC"}
@@ -1,15 +1,19 @@
1
1
  export type IKMailSendMailSimpleMessage = {
2
- from_address: string;
3
- to_address: string[];
2
+ from: string;
3
+ to: string[];
4
4
  subject: string;
5
- body_html: string;
6
- body_text: string;
5
+ body: {
6
+ html: string;
7
+ text: string;
8
+ };
7
9
  };
8
10
  export type IKMailSendMailTemplateMessage = {
9
- from_address: string;
10
- to_address: string[];
11
- template_name: string;
12
- template_data: Record<string, any>;
11
+ from: string;
12
+ to: string[];
13
+ template: {
14
+ name: string;
15
+ data: Record<string, any>;
16
+ };
13
17
  };
14
18
  export type IKMailResponseMail = {
15
19
  success: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kumbify/sdk",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "Oficial Kumbify SDK to integrate our services in your applications",
5
5
  "homepage": "https://github.com/ricardocastl3/kumbify-sdk#readme",
6
6
  "bugs": {