@kumbify/sdk 1.0.3 → 1.0.4
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
|
-
|
|
11
|
+
### Installation
|
|
12
12
|
|
|
13
13
|
Install using npm:
|
|
14
14
|
|
|
@@ -22,17 +22,16 @@ or using Yarn:
|
|
|
22
22
|
yarn add @kumbify/sdk
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
### Importing
|
|
26
26
|
|
|
27
27
|
```ts
|
|
28
28
|
import { KMailClient, KSMSClient } from "@kumbify/sdk";
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
-
---
|
|
32
31
|
|
|
33
|
-
|
|
32
|
+
### Email — KMailClient
|
|
34
33
|
|
|
35
|
-
|
|
34
|
+
#### 📍 Create an Email Client
|
|
36
35
|
|
|
37
36
|
```ts
|
|
38
37
|
const mailClient = new KMailClient({
|
|
@@ -66,9 +65,9 @@ console.log("Email Response:", sendMail);
|
|
|
66
65
|
|
|
67
66
|
---
|
|
68
67
|
|
|
69
|
-
|
|
68
|
+
### SMS — KSMSClient
|
|
70
69
|
|
|
71
|
-
|
|
70
|
+
#### 📍 Create an SMS Client
|
|
72
71
|
|
|
73
72
|
```ts
|
|
74
73
|
const smsClient = new KSMSClient({
|
|
@@ -76,7 +75,7 @@ const smsClient = new KSMSClient({
|
|
|
76
75
|
});
|
|
77
76
|
```
|
|
78
77
|
|
|
79
|
-
|
|
78
|
+
#### 📤 Send an SMS Message
|
|
80
79
|
|
|
81
80
|
```ts
|
|
82
81
|
await smsClient.sendSMS({
|
|
@@ -98,7 +97,7 @@ console.log("SMS sent successfully!");
|
|
|
98
97
|
|
|
99
98
|
---
|
|
100
99
|
|
|
101
|
-
|
|
100
|
+
### Example Usage All Together
|
|
102
101
|
|
|
103
102
|
```ts
|
|
104
103
|
import { KMailClient, KSMSClient } from "@kumbify/sdk";
|
|
@@ -125,7 +124,7 @@ await smsClient.sendSMS({
|
|
|
125
124
|
|
|
126
125
|
---
|
|
127
126
|
|
|
128
|
-
|
|
127
|
+
### Tips & Best Practices
|
|
129
128
|
|
|
130
129
|
✔️ Store your API keys in environment variables (never hardcode them).
|
|
131
130
|
✔️ Always handle promise rejections with `try/catch`.
|
|
@@ -133,7 +132,7 @@ await smsClient.sendSMS({
|
|
|
133
132
|
|
|
134
133
|
---
|
|
135
134
|
|
|
136
|
-
|
|
135
|
+
### Supported Environments
|
|
137
136
|
|
|
138
137
|
✔ Node.js
|
|
139
138
|
✔ TypeScript
|
|
@@ -5,7 +5,8 @@ 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 =
|
|
8
|
+
const axios_1 = require("axios");
|
|
9
|
+
const axios_2 = __importDefault(require("axios"));
|
|
9
10
|
class KMailClient {
|
|
10
11
|
apiKey;
|
|
11
12
|
constructor({ apiKey }) {
|
|
@@ -13,18 +14,21 @@ class KMailClient {
|
|
|
13
14
|
}
|
|
14
15
|
async sendSimpleMail({ ...data }) {
|
|
15
16
|
try {
|
|
16
|
-
const response = await
|
|
17
|
+
const response = await axios_2.default.post(helpers_1.APP_CONFIG.KMAIL_URL + "/send", {
|
|
17
18
|
...data,
|
|
18
19
|
}, { headers: { "kumbi-api-key": "Bearer " + this.apiKey } });
|
|
19
20
|
return response.data;
|
|
20
21
|
}
|
|
21
|
-
catch (
|
|
22
|
-
|
|
22
|
+
catch (error) {
|
|
23
|
+
if (error instanceof axios_1.AxiosError) {
|
|
24
|
+
throw new Error("Message: " + error.response.data);
|
|
25
|
+
}
|
|
26
|
+
throw new Error("Failed while send simple mail: " + error);
|
|
23
27
|
}
|
|
24
28
|
}
|
|
25
29
|
async sendTemplateMail({ ...data }) {
|
|
26
30
|
try {
|
|
27
|
-
const response = await
|
|
31
|
+
const response = await axios_2.default.post(helpers_1.APP_CONFIG.KMAIL_URL + "/send", {
|
|
28
32
|
...data,
|
|
29
33
|
}, { headers: { "kumbi-api-key": "Bearer " + this.apiKey } });
|
|
30
34
|
return response.data;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KMailClient.js","sourceRoot":"","sources":["../../src/kmail/KMailClient.ts"],"names":[],"mappings":";;;;;;AAKA,8CAA8C;
|
|
1
|
+
{"version":3,"file":"KMailClient.js","sourceRoot":"","sources":["../../src/kmail/KMailClient.ts"],"names":[],"mappings":";;;;;;AAKA,8CAA8C;AAC9C,iCAAmC;AAEnC,kDAA0B;AAE1B,MAAa,WAAW;IACtB,MAAM,CAAC;IACP,YAAY,EAAE,MAAM,EAAsB;QACxC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,EAAE,GAAG,IAAI,EAA+B;QAC3D,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,eAAK,CAAC,IAAI,CAC/B,oBAAU,CAAC,SAAS,GAAG,OAAO,EAC9B;gBACE,GAAG,IAAI;aACR,EACD,EAAE,OAAO,EAAE,EAAE,eAAe,EAAE,SAAS,GAAG,IAAI,CAAC,MAAM,EAAE,EAAE,CAC1D,CAAC;YACF,OAAO,QAAQ,CAAC,IAAI,CAAC;QACvB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,YAAY,kBAAU,EAAE,CAAC;gBAChC,MAAM,IAAI,KAAK,CAAC,WAAW,GAAG,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;YACrD,CAAC;YACD,MAAM,IAAI,KAAK,CAAC,iCAAiC,GAAG,KAAK,CAAC,CAAC;QAC7D,CAAC;IACH,CAAC;IAED,KAAK,CAAC,gBAAgB,CAAC,EAAE,GAAG,IAAI,EAAiC;QAC/D,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,eAAK,CAAC,IAAI,CAC/B,oBAAU,CAAC,SAAS,GAAG,OAAO,EAC9B;gBACE,GAAG,IAAI;aACR,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,GAAG,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,mCAAmC,GAAG,GAAG,CAAC,CAAC;QAC7D,CAAC;IACH,CAAC;CACF;AAvCD,kCAuCC"}
|
package/dist/ksms/KSMSClient.js
CHANGED
|
@@ -4,8 +4,9 @@ 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");
|
|
7
8
|
const helpers_1 = require("../utils/helpers");
|
|
8
|
-
const
|
|
9
|
+
const axios_2 = __importDefault(require("axios"));
|
|
9
10
|
class KSMSClient {
|
|
10
11
|
apiKey;
|
|
11
12
|
constructor({ apiKey }) {
|
|
@@ -13,7 +14,7 @@ class KSMSClient {
|
|
|
13
14
|
}
|
|
14
15
|
async sendSMS({ ...data }) {
|
|
15
16
|
try {
|
|
16
|
-
const response = await
|
|
17
|
+
const response = await axios_2.default.post(helpers_1.APP_CONFIG.KSMS_URL + "/send", {
|
|
17
18
|
body: data.message,
|
|
18
19
|
to: data.to,
|
|
19
20
|
from: data.from,
|
|
@@ -21,6 +22,9 @@ class KSMSClient {
|
|
|
21
22
|
return response.data;
|
|
22
23
|
}
|
|
23
24
|
catch (error) {
|
|
25
|
+
if (error instanceof axios_1.AxiosError) {
|
|
26
|
+
throw new Error("Message: " + error.response.data);
|
|
27
|
+
}
|
|
24
28
|
throw new Error("Failed while send sms: ", error);
|
|
25
29
|
}
|
|
26
30
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KSMSClient.js","sourceRoot":"","sources":["../../src/ksms/KSMSClient.ts"],"names":[],"mappings":";;;;;;AAAA,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,MAAM,EAAE,EAAE,CAC1D,CAAC;YAEF,OAAO,QAAQ,CAAC,IAAI,CAAC;QACvB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,yBAAyB,EAAE,KAAK,CAAC,CAAC;QACpD,CAAC;IACH,CAAC;CACF;
|
|
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,MAAM,EAAE,EAAE,CAC1D,CAAC;YAEF,OAAO,QAAQ,CAAC,IAAI,CAAC;QACvB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,YAAY,kBAAU,EAAE,CAAC;gBAChC,MAAM,IAAI,KAAK,CAAC,WAAW,GAAG,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;YACrD,CAAC;YACD,MAAM,IAAI,KAAK,CAAC,yBAAyB,EAAE,KAAK,CAAC,CAAC;QACpD,CAAC;IACH,CAAC;CACF;AA3BD,gCA2BC"}
|
package/package.json
CHANGED