@kumbify/sdk 1.1.6 → 1.2.1

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
@@ -168,7 +168,8 @@ await smsClient.sendSMS({
168
168
  #### Create an OAuth2 Client
169
169
 
170
170
  ```ts
171
- const oauthClient = new OAuth2Client({
171
+
172
+ const oauthClient = new KOAuth2Client({
172
173
  clientId: process.env.KUMBIFY_CLIENT_ID,
173
174
  clientSecret: process.env.KUMBIFY_CLIENT_SECRET,
174
175
  redirectUri: {
@@ -0,0 +1,12 @@
1
+ import { IAPIConfig, IKMailResponseMail, IKMailSendMailSimpleMessage, IKMailSendMailTemplateMessage } from "../../utils/types";
2
+ interface IKMailParams {
3
+ apiKey: string;
4
+ api?: IAPIConfig;
5
+ }
6
+ export declare class KMailClient {
7
+ private config;
8
+ constructor({ ...data }: IKMailParams);
9
+ sendSimpleMail({ ...data }: IKMailSendMailSimpleMessage): Promise<IKMailResponseMail>;
10
+ sendTemplateMail({ ...data }: IKMailSendMailTemplateMessage): Promise<IKMailResponseMail>;
11
+ }
12
+ export {};
@@ -0,0 +1,68 @@
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
+ config = {
12
+ apiKey: "",
13
+ api: {
14
+ lang: "pt",
15
+ version: "v1",
16
+ },
17
+ };
18
+ constructor({ ...data }) {
19
+ this.config = data;
20
+ }
21
+ async sendSimpleMail({ ...data }) {
22
+ try {
23
+ const response = await (0, api_1.fetchRequest)({
24
+ url: helpers_1.APP_CONFIG.KMAIL_URL + "/send",
25
+ method: "post",
26
+ body: {
27
+ from_address: data.from,
28
+ to_address: data.to,
29
+ subject: data.subject,
30
+ body_html: data.body.html,
31
+ body_text: data.body.text,
32
+ },
33
+ headers: {
34
+ "kumbi-api-key": "Bearer " + this.config.apiKey,
35
+ "accept-language": this.config.api.lang,
36
+ },
37
+ });
38
+ return response;
39
+ }
40
+ catch (error) {
41
+ APIError_1.default.CatchError({ error, section: "mail" });
42
+ }
43
+ }
44
+ async sendTemplateMail({ ...data }) {
45
+ try {
46
+ const response = await (0, api_1.fetchRequest)({
47
+ url: helpers_1.APP_CONFIG.KMAIL_URL + "/send",
48
+ method: "post",
49
+ body: {
50
+ from_address: data.from,
51
+ to_address: data.to,
52
+ template_name: data.template.name,
53
+ template_data: data.template.data,
54
+ },
55
+ headers: {
56
+ "kumbi-api-key": "Bearer " + this.config.apiKey,
57
+ "accept-language": this.config.api.lang,
58
+ },
59
+ });
60
+ return response;
61
+ }
62
+ catch (error) {
63
+ APIError_1.default.CatchError({ error, section: "mail" });
64
+ }
65
+ }
66
+ }
67
+ exports.KMailClient = KMailClient;
68
+ //# sourceMappingURL=KMailClient.js.map
@@ -0,0 +1,11 @@
1
+ import { IAPIConfig, IKSMSResponseMessage, IKSMSSendMessage } from "../../utils/types";
2
+ interface IKSMSParams {
3
+ apiKey: string;
4
+ api?: IAPIConfig;
5
+ }
6
+ export declare class KSMSClient {
7
+ private config;
8
+ constructor({ ...data }: IKSMSParams);
9
+ sendSMS({ ...data }: IKSMSSendMessage): Promise<IKSMSResponseMessage>;
10
+ }
11
+ export {};
@@ -0,0 +1,44 @@
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
+ config = {
12
+ apiKey: "",
13
+ api: {
14
+ lang: "pt",
15
+ version: "v1",
16
+ },
17
+ };
18
+ constructor({ ...data }) {
19
+ this.config = data;
20
+ }
21
+ async sendSMS({ ...data }) {
22
+ try {
23
+ const response = await (0, api_1.fetchRequest)({
24
+ url: helpers_1.APP_CONFIG.KSMS_URL + "/send",
25
+ method: "post",
26
+ body: {
27
+ body: data.message,
28
+ to: data.to,
29
+ from: data.from,
30
+ },
31
+ headers: {
32
+ "kumbi-api-key": "Bearer " + this.config.apiKey,
33
+ "accept-language": this.config.api.lang,
34
+ },
35
+ });
36
+ return response;
37
+ }
38
+ catch (error) {
39
+ APIError_1.default.CatchError({ error, section: "sms" });
40
+ }
41
+ }
42
+ }
43
+ exports.KSMSClient = KSMSClient;
44
+ //# sourceMappingURL=KSMSClient.js.map
@@ -0,0 +1,49 @@
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 KOAuth2Client {
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 {};
@@ -0,0 +1,81 @@
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.KOAuth2Client = 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 KOAuth2Client {
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.KOAuth2Client = KOAuth2Client;
81
+ //# sourceMappingURL=KOAuth2Client.js.map
@@ -0,0 +1,8 @@
1
+ import { IMakeAngolanPaymentParams, IMakeAngolanPaymentResponse, IMakeCryptoPaymentParams, IMakeCryptoPaymentResponse, IMakeStripePaymentParams, IMakeStripePaymentResponse, IPaymentParams } from "./interfaces";
2
+ export declare class KPaymentClient {
3
+ private config;
4
+ constructor({ ...data }: IPaymentParams);
5
+ makeStripePayment({ ...data }: IMakeStripePaymentParams): Promise<IMakeStripePaymentResponse>;
6
+ makeCryptoPayment({ ...data }: IMakeCryptoPaymentParams): Promise<IMakeCryptoPaymentResponse>;
7
+ makeAngolanPayment({ ...data }: IMakeAngolanPaymentParams): Promise<IMakeAngolanPaymentResponse>;
8
+ }
@@ -0,0 +1,94 @@
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.KPaymentClient = void 0;
7
+ const api_1 = require("../../api/api");
8
+ const helpers_1 = require("../../utils/helpers");
9
+ const APIError_1 = __importDefault(require("../../errors/APIError"));
10
+ class KPaymentClient {
11
+ config = {
12
+ apiKey: "",
13
+ provider: {
14
+ angolan: {
15
+ seller: "paypay",
16
+ },
17
+ type: "angolan",
18
+ },
19
+ api: {
20
+ lang: "pt",
21
+ version: "v1",
22
+ },
23
+ };
24
+ constructor({ ...data }) {
25
+ this.config = data;
26
+ }
27
+ async makeStripePayment({ ...data }) {
28
+ try {
29
+ const response = await (0, api_1.fetchRequest)({
30
+ url: `${helpers_1.APP_CONFIG.PAYMENT.API_BASE_URL}/${this.config.provider.international.seller}`,
31
+ method: "post",
32
+ body: data,
33
+ headers: {
34
+ "kumbi-api-key": `Bearer ${this.config.apiKey}`,
35
+ "accept-language": this.config.api.lang,
36
+ },
37
+ });
38
+ return response;
39
+ }
40
+ catch (error) {
41
+ APIError_1.default.CatchError({ error, section: "payment" });
42
+ }
43
+ }
44
+ async makeCryptoPayment({ ...data }) {
45
+ try {
46
+ const response = await (0, api_1.fetchRequest)({
47
+ url: `${helpers_1.APP_CONFIG.PAYMENT.API_BASE_URL}/${this.config.provider.international.seller}`,
48
+ method: "post",
49
+ body: data,
50
+ headers: {
51
+ "kumbi-api-key": `Bearer ${this.config.apiKey}`,
52
+ "accept-language": this.config.api.lang,
53
+ },
54
+ });
55
+ return response;
56
+ }
57
+ catch (error) {
58
+ APIError_1.default.CatchError({ error, section: "payment" });
59
+ }
60
+ }
61
+ async makeAngolanPayment({ ...data }) {
62
+ try {
63
+ if (this.config.provider.angolan.seller == "paypay" &&
64
+ data.method == "multicaixa") {
65
+ let message = {
66
+ pt: "O método de pagamento via multicaixa express está indisponível para PayPay",
67
+ en: "The Multicaixa Express payment method is unavailable for PayPay",
68
+ };
69
+ APIError_1.default.ErrorMessage({
70
+ section: "payment",
71
+ message: this.config.api.lang == "en" ? message.en : message.pt,
72
+ });
73
+ }
74
+ const url = `${helpers_1.APP_CONFIG.PAYMENT.API_BASE_URL}/${this.config.provider.angolan}`;
75
+ const response = await (0, api_1.fetchRequest)({
76
+ url: url,
77
+ method: "post",
78
+ body: {
79
+ ...data,
80
+ },
81
+ headers: {
82
+ "kumbi-api-key": `Bearer ${this.config.apiKey}`,
83
+ "accept-language": this.config.api.lang,
84
+ },
85
+ });
86
+ return response;
87
+ }
88
+ catch (error) {
89
+ APIError_1.default.CatchError({ error, section: "payment" });
90
+ }
91
+ }
92
+ }
93
+ exports.KPaymentClient = KPaymentClient;
94
+ //# sourceMappingURL=KPaymentClient.js.map
@@ -0,0 +1,87 @@
1
+ import { IAPIConfig } from "../../utils/types";
2
+ type EAngolanPaymentProviders = "paypay";
3
+ type EInternationalPaymentProviders = "stripe" | "crypto";
4
+ export interface IPaymentParams {
5
+ api?: IAPIConfig;
6
+ apiKey: string;
7
+ provider: {
8
+ angolan?: {
9
+ seller: EAngolanPaymentProviders;
10
+ };
11
+ international?: {
12
+ seller: EInternationalPaymentProviders;
13
+ };
14
+ type: "angolan" | "international";
15
+ };
16
+ }
17
+ export interface IMakeAngolanPaymentParams {
18
+ amount: number;
19
+ subject: string;
20
+ method: "reference" | "multicaixa";
21
+ transfer?: {
22
+ iban: string;
23
+ owner_name: string;
24
+ };
25
+ payment?: {
26
+ customer?: {
27
+ phone: string;
28
+ };
29
+ };
30
+ transaction: {
31
+ id: string;
32
+ type: "payment" | "transfer";
33
+ };
34
+ }
35
+ export interface IMakeAngolanPaymentResponse {
36
+ transactionId: string;
37
+ trade: {
38
+ entity?: string;
39
+ reference?: number;
40
+ timestamp: string;
41
+ status: "pending" | "success" | "failed";
42
+ };
43
+ }
44
+ export interface IProduct {
45
+ amount: number;
46
+ name?: string;
47
+ description?: string;
48
+ quantity: number;
49
+ }
50
+ /**
51
+ * Stripe Types
52
+ */
53
+ export type StripeCurrencies = "USD" | "EUR";
54
+ export interface IMakeStripePaymentParams {
55
+ transactionId: string;
56
+ customer: {
57
+ email: string;
58
+ name: string;
59
+ };
60
+ product: IProduct[];
61
+ redirect: {
62
+ success_url?: string;
63
+ cancel_url?: string;
64
+ };
65
+ currency: StripeCurrencies;
66
+ }
67
+ export interface IMakeStripePaymentResponse {
68
+ url: string;
69
+ }
70
+ /**
71
+ * Crypto types
72
+ */
73
+ type CryptoCurrencies = "USDC" | "ETH" | "BTC" | "USDT";
74
+ export interface IMakeCryptoPaymentParams {
75
+ transactionId: string;
76
+ customer: {
77
+ email: string;
78
+ name: string;
79
+ phone: string;
80
+ };
81
+ products: IProduct[];
82
+ currency: CryptoCurrencies;
83
+ }
84
+ export interface IMakeCryptoPaymentResponse {
85
+ address: string;
86
+ }
87
+ export {};
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=interfaces.js.map
@@ -1,7 +1,12 @@
1
1
  declare class APIError {
2
+ SectionMessage(section: string): string;
2
3
  CatchError({ error, section, }: {
3
4
  error: any;
4
- section: "mail" | "sms" | "oauth";
5
+ section: "mail" | "sms" | "oauth" | "payment";
6
+ }): void;
7
+ ErrorMessage({ section, message, }: {
8
+ section: "mail" | "sms" | "oauth" | "payment";
9
+ message?: string;
5
10
  }): void;
6
11
  }
7
12
  declare const _default: APIError;
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const axios_1 = __importDefault(require("axios"));
7
7
  class APIError {
8
- CatchError({ error, section, }) {
8
+ SectionMessage(section) {
9
9
  let errorSection = "";
10
10
  switch (section) {
11
11
  case "mail":
@@ -17,7 +17,14 @@ class APIError {
17
17
  case "sms":
18
18
  errorSection = "SMS Service: Failed =>";
19
19
  break;
20
+ case "payment":
21
+ errorSection = "Payment Service: Failed =>";
22
+ break;
20
23
  }
24
+ return errorSection;
25
+ }
26
+ CatchError({ error, section, }) {
27
+ let errorSection = this.SectionMessage(section);
21
28
  if (axios_1.default.isAxiosError(error)) {
22
29
  const status = error.response?.status;
23
30
  const data = error.response?.data;
@@ -25,6 +32,10 @@ class APIError {
25
32
  }
26
33
  throw new Error(`${errorSection} ${String(error)}`);
27
34
  }
35
+ ErrorMessage({ section, message, }) {
36
+ let errorSection = this.SectionMessage(section);
37
+ throw new Error(`${errorSection} ${message}`);
38
+ }
28
39
  }
29
40
  exports.default = new APIError();
30
41
  //# sourceMappingURL=APIError.js.map
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
- export * from "./kmail/KMailClient";
2
- export * from "./ksms/KSMSClient";
3
- export * from "./oauth/OAuth2Client";
1
+ export * from "./clients/kmail/KMailClient";
2
+ export * from "./clients/ksms/KSMSClient";
3
+ export * from "./clients/oauth/KOAuth2Client";
4
+ export * from "./clients/payment/KPaymentClient";
package/dist/index.js CHANGED
@@ -14,7 +14,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./kmail/KMailClient"), exports);
18
- __exportStar(require("./ksms/KSMSClient"), exports);
19
- __exportStar(require("./oauth/OAuth2Client"), exports);
17
+ __exportStar(require("./clients/kmail/KMailClient"), exports);
18
+ __exportStar(require("./clients/ksms/KSMSClient"), exports);
19
+ __exportStar(require("./clients/oauth/KOAuth2Client"), exports);
20
+ __exportStar(require("./clients/payment/KPaymentClient"), exports);
20
21
  //# sourceMappingURL=index.js.map
@@ -3,7 +3,8 @@ export declare const APP_CONFIG: {
3
3
  KMAIL_URL: string;
4
4
  OAUTH: {
5
5
  API_BASE_URL: string;
6
- SERVICE: string;
7
- ACCOUNT: string;
6
+ };
7
+ PAYMENT: {
8
+ API_BASE_URL: string;
8
9
  };
9
10
  };
@@ -6,8 +6,9 @@ exports.APP_CONFIG = {
6
6
  KMAIL_URL: "https://oi.kumbify.com/api/email",
7
7
  OAUTH: {
8
8
  API_BASE_URL: "https://8n8.kumbify.com/api/",
9
- SERVICE: "https://kumbify.com/pt/oauth/services",
10
- ACCOUNT: "https://kumbify.com/pt/oauth",
9
+ },
10
+ PAYMENT: {
11
+ API_BASE_URL: "https://oi.kumbify.com/api/pay",
11
12
  },
12
13
  };
13
14
  //# sourceMappingURL=helpers.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kumbify/sdk",
3
- "version": "1.1.6",
3
+ "version": "1.2.1",
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": {