@kumbify/sdk 1.2.4 → 1.2.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kumbify/sdk",
3
- "version": "1.2.4",
3
+ "version": "1.2.5",
4
4
  "description": "Oficial Kumbify SDK to integrate our services in your applications",
5
5
  "homepage": "https://github.com/kumbify-oficial/kumbi-sdk#readme",
6
6
  "bugs": {
@@ -1,11 +0,0 @@
1
- import { IAPIConfig, IKMailResponseMail, IKMailSendMailSimpleMessage, IKMailSendMailTemplateMessage } from "../utils/types";
2
- export declare class KMailClient {
3
- private apiKey;
4
- private api;
5
- constructor({ apiKey, api }: {
6
- apiKey: string;
7
- api?: IAPIConfig;
8
- });
9
- sendSimpleMail({ ...data }: IKMailSendMailSimpleMessage): Promise<IKMailResponseMail>;
10
- sendTemplateMail({ ...data }: IKMailSendMailTemplateMessage): Promise<IKMailResponseMail>;
11
- }
@@ -1,64 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.KMailClient = void 0;
7
- const helpers_1 = require("../utils/helpers");
8
- const api_1 = require("../api/api");
9
- const APIError_1 = __importDefault(require("../errors/APIError"));
10
- class KMailClient {
11
- apiKey;
12
- api = { lang: "pt", version: "v1" };
13
- constructor({ apiKey, api }) {
14
- this.apiKey = apiKey;
15
- this.api = api;
16
- }
17
- async sendSimpleMail({ ...data }) {
18
- try {
19
- const response = await (0, api_1.fetchRequest)({
20
- url: helpers_1.APP_CONFIG.KMAIL_URL + "/send",
21
- method: "post",
22
- body: {
23
- from_address: data.from,
24
- to_address: data.to,
25
- subject: data.subject,
26
- body_html: data.body.html,
27
- body_text: data.body.text,
28
- },
29
- headers: {
30
- "kumbi-api-key": "Bearer " + this.apiKey,
31
- "accept-language": this.api.lang,
32
- },
33
- });
34
- return response;
35
- }
36
- catch (error) {
37
- APIError_1.default.CatchError({ error, section: "mail" });
38
- }
39
- }
40
- async sendTemplateMail({ ...data }) {
41
- try {
42
- const response = await (0, api_1.fetchRequest)({
43
- url: helpers_1.APP_CONFIG.KMAIL_URL + "/send",
44
- method: "post",
45
- body: {
46
- from_address: data.from,
47
- to_address: data.to,
48
- template_name: data.template.name,
49
- template_data: data.template.data,
50
- },
51
- headers: {
52
- "kumbi-api-key": "Bearer " + this.apiKey,
53
- "accept-language": this.api.lang,
54
- },
55
- });
56
- return response;
57
- }
58
- catch (error) {
59
- APIError_1.default.CatchError({ error, section: "mail" });
60
- }
61
- }
62
- }
63
- exports.KMailClient = KMailClient;
64
- //# sourceMappingURL=KMailClient.js.map
@@ -1,9 +0,0 @@
1
- import { IKMailResponseMail, IKMailSendMailSimpleMessage, IKMailSendMailTemplateMessage } from "../utils/types";
2
- export declare class KMailServer {
3
- apiKey: string;
4
- constructor({ apiKey }: {
5
- apiKey: string;
6
- });
7
- sendSimpleMail({ ...data }: IKMailSendMailSimpleMessage): Promise<IKMailResponseMail>;
8
- sendTemplateMail({ ...data }: IKMailSendMailTemplateMessage): Promise<IKMailResponseMail>;
9
- }
@@ -1,38 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.KMailServer = void 0;
7
- const helpers_1 = require("../utils/helpers");
8
- const axios_1 = __importDefault(require("axios"));
9
- class KMailServer {
10
- apiKey;
11
- constructor({ apiKey }) {
12
- this.apiKey = apiKey;
13
- }
14
- async sendSimpleMail({ ...data }) {
15
- try {
16
- const response = await axios_1.default.post(helpers_1.APP_CONFIG.KMAIL_URL + "/send", {
17
- ...data,
18
- }, { headers: { "kumbi-api-key": "Bearer " + this.apiKey } });
19
- return response.data;
20
- }
21
- catch (err) {
22
- throw new Error("Failed while send simple mail: " + err);
23
- }
24
- }
25
- async sendTemplateMail({ ...data }) {
26
- try {
27
- const response = await axios_1.default.post(helpers_1.APP_CONFIG.KMAIL_URL + "/send", {
28
- ...data,
29
- }, { headers: { "kumbi-api-key": "Bearer " + this.apiKey } });
30
- return response.data;
31
- }
32
- catch (err) {
33
- throw new Error("Failed while send template mail: " + err);
34
- }
35
- }
36
- }
37
- exports.KMailServer = KMailServer;
38
- //# sourceMappingURL=KMailServer.js.map
@@ -1,10 +0,0 @@
1
- import { IAPIConfig, IKSMSResponseMessage, IKSMSSendMessage } from "../utils/types";
2
- export declare class KSMSClient {
3
- private apiKey;
4
- private api;
5
- constructor({ apiKey, api }: {
6
- apiKey: string;
7
- api?: IAPIConfig;
8
- });
9
- sendSMS({ ...data }: IKSMSSendMessage): Promise<IKSMSResponseMessage>;
10
- }
@@ -1,40 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.KSMSClient = void 0;
7
- const helpers_1 = require("../utils/helpers");
8
- const api_1 = require("../api/api");
9
- const APIError_1 = __importDefault(require("../errors/APIError"));
10
- class KSMSClient {
11
- apiKey;
12
- api = { lang: "pt", version: "v1" };
13
- constructor({ apiKey, api }) {
14
- this.apiKey = apiKey;
15
- this.api = api;
16
- }
17
- async sendSMS({ ...data }) {
18
- try {
19
- const response = await (0, api_1.fetchRequest)({
20
- url: helpers_1.APP_CONFIG.KSMS_URL + "/send",
21
- method: "post",
22
- body: {
23
- body: data.message,
24
- to: data.to,
25
- from: data.from,
26
- },
27
- headers: {
28
- "kumbi-api-key": "Bearer " + this.apiKey,
29
- "accept-language": this.api.lang,
30
- },
31
- });
32
- return response;
33
- }
34
- catch (error) {
35
- APIError_1.default.CatchError({ error, section: "sms" });
36
- }
37
- }
38
- }
39
- exports.KSMSClient = KSMSClient;
40
- //# sourceMappingURL=KSMSClient.js.map
@@ -1,8 +0,0 @@
1
- import { IKSMSSendMessage } from "../utils/types";
2
- export declare class KSMSServer {
3
- apiKey: string;
4
- constructor({ apiKey }: {
5
- apiKey: string;
6
- });
7
- sendSMS({ ...data }: IKSMSSendMessage): Promise<any>;
8
- }
@@ -1,29 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.KSMSServer = void 0;
7
- const helpers_1 = require("../utils/helpers");
8
- const axios_1 = __importDefault(require("axios"));
9
- class KSMSServer {
10
- apiKey;
11
- constructor({ apiKey }) {
12
- this.apiKey = apiKey;
13
- }
14
- async sendSMS({ ...data }) {
15
- try {
16
- const response = await axios_1.default.post(helpers_1.APP_CONFIG.KSMS_URL + "/send", {
17
- body: data.message,
18
- to: data.to,
19
- from: data.from,
20
- }, { headers: { "kumbi-api-key": "Bearer " + this.apiKey } });
21
- return response.data;
22
- }
23
- catch (error) {
24
- throw new Error("Failed while send sms: ", error);
25
- }
26
- }
27
- }
28
- exports.KSMSServer = KSMSServer;
29
- //# sourceMappingURL=KSMSServer.js.map
@@ -1,49 +0,0 @@
1
- import { IAPIConfig, IOAuthUserInfoResponse, IOAuthUserTokenReponse } from "../utils/types";
2
- interface IOAuthClientTokenParams {
3
- type: "services" | "account";
4
- code: string;
5
- grant_type: "authorization_code" | "refresh_token";
6
- refresh_token?: string;
7
- redirect?: IOAuthRedirect;
8
- expires_in: "1h" | "1d" | "7d" | "never";
9
- }
10
- interface IOAuthRedirect {
11
- account?: string;
12
- service?: string;
13
- }
14
- interface IOAuthScopes {
15
- account?: OAuthAccountScopes[];
16
- service?: OAuthServiceScopes[];
17
- }
18
- interface IOAuthClientProps {
19
- clientId: string;
20
- clientSecret: string;
21
- scopes: IOAuthScopes;
22
- redirectUri: IOAuthRedirect;
23
- api?: IAPIConfig;
24
- }
25
- type OAuthServiceScopes = "gmail.send.email";
26
- type OAuthAccountScopes = "profile" | "subscription.read";
27
- export declare class OAuth2Client {
28
- private clientId;
29
- private clientSecret;
30
- private redirectUri;
31
- private scopes;
32
- private api;
33
- constructor({ clientId, clientSecret, redirectUri, scopes, api, }: IOAuthClientProps);
34
- generateOAuthAccountUrl({ state }: {
35
- state?: string;
36
- }): {
37
- url: string;
38
- };
39
- generateOAuthServiceUrl({ state }: {
40
- state?: string;
41
- }): {
42
- url: string;
43
- };
44
- generateToken({ ...data }: IOAuthClientTokenParams): Promise<IOAuthUserTokenReponse>;
45
- userInfo({ accessToken }: {
46
- accessToken: string;
47
- }): Promise<IOAuthUserInfoResponse>;
48
- }
49
- export {};
@@ -1,81 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.OAuth2Client = void 0;
7
- const helpers_1 = require("../utils/helpers");
8
- const api_1 = require("../api/api");
9
- const APIError_1 = __importDefault(require("../errors/APIError"));
10
- class OAuth2Client {
11
- clientId;
12
- clientSecret;
13
- redirectUri;
14
- scopes;
15
- api = { lang: "pt", version: "v1" };
16
- constructor({ clientId, clientSecret, redirectUri, scopes, api, }) {
17
- this.clientId = clientId;
18
- this.clientSecret = clientSecret;
19
- this.redirectUri = redirectUri;
20
- this.scopes = scopes;
21
- this.api = api;
22
- }
23
- generateOAuthAccountUrl({ state }) {
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
- return { url };
26
- }
27
- generateOAuthServiceUrl({ state }) {
28
- const url = `https://kumbify.com/${this.api.lang}/oauth/services?client_id=${this.clientId}&scopes=${this.scopes.service.join(",")}${state ? `&state=${state}` : ""}&redirect=${this.redirectUri.service}`;
29
- return { url };
30
- }
31
- async generateToken({ ...data }) {
32
- try {
33
- const redirectUri = data.redirect
34
- ? data.type == "account"
35
- ? data.redirect.account
36
- : data.redirect.service
37
- : "";
38
- const response = await (0, api_1.fetchRequest)({
39
- url: helpers_1.APP_CONFIG.OAUTH.API_BASE_URL + "/u/tokens/generate",
40
- method: "post",
41
- body: {
42
- code: data.code,
43
- grant_type: data.grant_type,
44
- refresh_token: data.refresh_token,
45
- client_id: this.clientId,
46
- redirect_uri: redirectUri,
47
- expires_in: data.expires_in,
48
- },
49
- headers: {
50
- "kumbi-app-key": `Bearer ${this.clientSecret}`,
51
- "accept-language": this.api.lang,
52
- },
53
- });
54
- return response;
55
- }
56
- catch (error) {
57
- APIError_1.default.CatchError({ error, section: "oauth" });
58
- }
59
- }
60
- async userInfo({ accessToken }) {
61
- try {
62
- const response = await (0, api_1.fetchRequest)({
63
- url: helpers_1.APP_CONFIG.OAUTH.API_BASE_URL + "/u/me",
64
- method: "post",
65
- body: {
66
- token: accessToken,
67
- },
68
- headers: {
69
- "kumbi-app-key": `Bearer ${this.clientSecret}`,
70
- "accept-language": this.api.lang,
71
- },
72
- });
73
- return response;
74
- }
75
- catch (error) {
76
- APIError_1.default.CatchError({ error, section: "oauth" });
77
- }
78
- }
79
- }
80
- exports.OAuth2Client = OAuth2Client;
81
- //# sourceMappingURL=OAuth2Client.js.map