@kumbify/sdk 1.1.1 → 1.1.3
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
|
@@ -30,11 +30,15 @@ import { KMailClient, KSMSClient } from "@kumbify/sdk";
|
|
|
30
30
|
|
|
31
31
|
### Email — KMailClient
|
|
32
32
|
|
|
33
|
-
####
|
|
33
|
+
#### Create an Email Client
|
|
34
34
|
|
|
35
35
|
```ts
|
|
36
36
|
const mailClient = new KMailClient({
|
|
37
37
|
apiKey: "YOUR_EMAIL_API_KEY",
|
|
38
|
+
api: {
|
|
39
|
+
lang: "en",
|
|
40
|
+
version: "v1",
|
|
41
|
+
},
|
|
38
42
|
});
|
|
39
43
|
```
|
|
40
44
|
|
|
@@ -55,13 +59,13 @@ console.log("Email Response: ", sendMail);
|
|
|
55
59
|
|
|
56
60
|
**Parameters explained:**
|
|
57
61
|
|
|
58
|
-
| Property
|
|
59
|
-
|
|
|
60
|
-
| `body.html`
|
|
61
|
-
| `body.text`
|
|
62
|
-
| `from`
|
|
63
|
-
| `subject`
|
|
64
|
-
| `to`
|
|
62
|
+
| Property | Type | Description |
|
|
63
|
+
| ----------- | -------- | --------------------------------- |
|
|
64
|
+
| `body.html` | string | HTML email content |
|
|
65
|
+
| `body.text` | string | Plain text email content |
|
|
66
|
+
| `from` | string | Sender email address |
|
|
67
|
+
| `subject` | string | Email subject |
|
|
68
|
+
| `to` | string[] | List of recipient email addresses |
|
|
65
69
|
|
|
66
70
|
---
|
|
67
71
|
|
|
@@ -75,14 +79,13 @@ const sendMail = await mailClient.sendTemplateMail({
|
|
|
75
79
|
data: {
|
|
76
80
|
customer: {
|
|
77
81
|
name: "Ricardo Castle",
|
|
78
|
-
email: "doe@gmail.com"
|
|
79
|
-
}
|
|
82
|
+
email: "doe@gmail.com",
|
|
83
|
+
},
|
|
80
84
|
},
|
|
81
85
|
},
|
|
82
86
|
});
|
|
83
87
|
|
|
84
88
|
console.log("Email Response: ", sendMail);
|
|
85
|
-
|
|
86
89
|
```
|
|
87
90
|
|
|
88
91
|
**Parameters explained:**
|
|
@@ -98,11 +101,15 @@ console.log("Email Response: ", sendMail);
|
|
|
98
101
|
|
|
99
102
|
### SMS — KSMSClient
|
|
100
103
|
|
|
101
|
-
####
|
|
104
|
+
#### Create an SMS Client
|
|
102
105
|
|
|
103
106
|
```ts
|
|
104
107
|
const smsClient = new KSMSClient({
|
|
105
108
|
apiKey: "YOUR_SMS_API_KEY",
|
|
109
|
+
api: {
|
|
110
|
+
lang: "en",
|
|
111
|
+
version: "v1",
|
|
112
|
+
},
|
|
106
113
|
});
|
|
107
114
|
```
|
|
108
115
|
|
|
@@ -119,11 +126,12 @@ console.log("SMS sent successfully!");
|
|
|
119
126
|
|
|
120
127
|
**Parameters explained:**
|
|
121
128
|
|
|
122
|
-
| Property | Type
|
|
123
|
-
| --------- |
|
|
124
|
-
| `message` | string
|
|
125
|
-
| `from` | string
|
|
126
|
-
| `to` | string[] | List of recipient phone numbers
|
|
129
|
+
| Property | Type | Description |
|
|
130
|
+
| --------- | -------- | ------------------------------------ |
|
|
131
|
+
| `message` | string | SMS content |
|
|
132
|
+
| `from` | string | Sender identifier (visible to users) |
|
|
133
|
+
| `to` | string[] | List of recipient phone numbers |
|
|
134
|
+
|
|
127
135
|
---
|
|
128
136
|
|
|
129
137
|
### Example Usage All Together
|
|
@@ -155,6 +163,45 @@ await smsClient.sendSMS({
|
|
|
155
163
|
|
|
156
164
|
---
|
|
157
165
|
|
|
166
|
+
### OAuth2Client
|
|
167
|
+
|
|
168
|
+
#### Create an OAuth2 Client
|
|
169
|
+
|
|
170
|
+
```ts
|
|
171
|
+
const oauthClient = new OAuth2Client({
|
|
172
|
+
clientId: process.env.KUMBIFY_CLIENT_ID,
|
|
173
|
+
clientSecret: process.env.KUMBIFY_CLIENT_SECRET,
|
|
174
|
+
redirectUri: {
|
|
175
|
+
account: "",
|
|
176
|
+
service: "",
|
|
177
|
+
},
|
|
178
|
+
scopes: {
|
|
179
|
+
account: ["profile", "subscription.read"],
|
|
180
|
+
services: ["gmail.send.email"],
|
|
181
|
+
},
|
|
182
|
+
api: {
|
|
183
|
+
lang: "pt",
|
|
184
|
+
version: "v1",
|
|
185
|
+
},
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
// Generate OAuth Account URL
|
|
189
|
+
const oauthAccountUrl = oauthClient.generateOAuthAccountUrl({});
|
|
190
|
+
|
|
191
|
+
// Generate OAuth Service URL
|
|
192
|
+
const oauthServiceUrl = oauthClient.generateOAuthServiceUrl({});
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
| Property | Type | Description |
|
|
196
|
+
| -------------- | ------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
197
|
+
| `clientId` | string | SMS content |
|
|
198
|
+
| `clientSecret` | string | Sender identifier (visible to users) |
|
|
199
|
+
| `redirectUri` | object | URL redirect type, choose the one that meets your needs. **Service** if using the client to obtain service permissions. **Account** if using it for sign-in |
|
|
200
|
+
| `scopes` | object | Scope type: choose the one that meets your needs. **Service**: if using the client to obtain service permissions, such as sending emails. **Account**: if using it for user account permissions, such as profile access |
|
|
201
|
+
| `api` | object | API Definitions |
|
|
202
|
+
|
|
203
|
+
---
|
|
204
|
+
|
|
158
205
|
### Tips & Best Practices
|
|
159
206
|
|
|
160
207
|
- Store your API keys in environment variables (never hardcode them).
|
|
@@ -23,7 +23,7 @@ interface IOAuthClientProps {
|
|
|
23
23
|
api?: IAPIConfig;
|
|
24
24
|
}
|
|
25
25
|
type OAuthServiceScopes = "gmail.send.email";
|
|
26
|
-
type OAuthAccountScopes = "profile
|
|
26
|
+
type OAuthAccountScopes = "profile" | "subscription.read";
|
|
27
27
|
export declare class OAuth2Client {
|
|
28
28
|
private clientId;
|
|
29
29
|
private clientSecret;
|
|
@@ -36,9 +36,7 @@ export declare class OAuth2Client {
|
|
|
36
36
|
}): {
|
|
37
37
|
url: string;
|
|
38
38
|
};
|
|
39
|
-
generateOAuthServiceUrl({ state
|
|
40
|
-
redirect_url: string;
|
|
41
|
-
scopes: OAuthServiceScopes;
|
|
39
|
+
generateOAuthServiceUrl({ state }: {
|
|
42
40
|
state?: string;
|
|
43
41
|
}): {
|
|
44
42
|
url: string;
|
|
@@ -21,11 +21,11 @@ class OAuth2Client {
|
|
|
21
21
|
this.api = api;
|
|
22
22
|
}
|
|
23
23
|
generateOAuthAccountUrl({ state }) {
|
|
24
|
-
const url =
|
|
24
|
+
const url = `https://kumbify.com/${this.api.lang}/oauth?client_id=${this.clientId}&scopes=${this.scopes.account.join(",")}${state ? `&state=${state}` : ""}&redirect=${this.redirectUri.account}`;
|
|
25
25
|
return { url };
|
|
26
26
|
}
|
|
27
|
-
generateOAuthServiceUrl({ state
|
|
28
|
-
const url =
|
|
27
|
+
generateOAuthServiceUrl({ state }) {
|
|
28
|
+
const url = `https://kumbify.com/${this.api.lang}/oauth/services?client_id=${this.clientId}&scopes=${this.scopes.services.join(",")}${state ? `&state=${state}` : ""}&redirect=${this.redirectUri.service}`;
|
|
29
29
|
return { url };
|
|
30
30
|
}
|
|
31
31
|
async generateToken({ ...data }) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OAuth2Client.js","sourceRoot":"","sources":["../../src/oauth/OAuth2Client.ts"],"names":[],"mappings":";;;;;;AAAA,8CAA8C;AAC9C,oCAA0C;AAO1C,kEAA0C;AAgC1C,MAAa,YAAY;IACf,QAAQ,CAAC;IACT,YAAY,CAAC;IACb,WAAW,CAAC;IACZ,MAAM,CAAC;IACP,GAAG,GAAe,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAExD,YAAY,EACV,QAAQ,EACR,YAAY,EACZ,WAAW,EACX,MAAM,EACN,GAAG,GACe;QAClB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAA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