@kumbify/sdk 1.2.3 → 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/dist/clients/kmail/KMailClient.js +2 -2
- package/dist/clients/ksms/KSMSClient.js +1 -1
- package/dist/clients/oauth/KOAuth2Client.js +2 -2
- package/dist/clients/payment/KPaymentClient.js +6 -23
- package/dist/clients/payment/interfaces.d.ts +5 -13
- package/package.json +6 -2
- package/dist/kmail/KMailClient.d.ts +0 -11
- package/dist/kmail/KMailClient.js +0 -64
- package/dist/kmail/KMailServer.d.ts +0 -9
- package/dist/kmail/KMailServer.js +0 -38
- package/dist/ksms/KSMSClient.d.ts +0 -10
- package/dist/ksms/KSMSClient.js +0 -40
- package/dist/ksms/KSMSServer.d.ts +0 -8
- package/dist/ksms/KSMSServer.js +0 -29
- package/dist/oauth/OAuth2Client.d.ts +0 -49
- package/dist/oauth/OAuth2Client.js +0 -81
|
@@ -32,7 +32,7 @@ class KMailClient {
|
|
|
32
32
|
},
|
|
33
33
|
headers: {
|
|
34
34
|
"kumbi-api-key": "Bearer " + this.config.apiKey,
|
|
35
|
-
|
|
35
|
+
lang: this.config.api.lang,
|
|
36
36
|
},
|
|
37
37
|
});
|
|
38
38
|
return response;
|
|
@@ -54,7 +54,7 @@ class KMailClient {
|
|
|
54
54
|
},
|
|
55
55
|
headers: {
|
|
56
56
|
"kumbi-api-key": "Bearer " + this.config.apiKey,
|
|
57
|
-
|
|
57
|
+
lang: this.config.api.lang,
|
|
58
58
|
},
|
|
59
59
|
});
|
|
60
60
|
return response;
|
|
@@ -48,7 +48,7 @@ class KOAuth2Client {
|
|
|
48
48
|
},
|
|
49
49
|
headers: {
|
|
50
50
|
"kumbi-app-key": `Bearer ${this.clientSecret}`,
|
|
51
|
-
|
|
51
|
+
lang: this.api.lang,
|
|
52
52
|
},
|
|
53
53
|
});
|
|
54
54
|
return response;
|
|
@@ -67,7 +67,7 @@ class KOAuth2Client {
|
|
|
67
67
|
},
|
|
68
68
|
headers: {
|
|
69
69
|
"kumbi-app-key": `Bearer ${this.clientSecret}`,
|
|
70
|
-
|
|
70
|
+
lang: this.api.lang,
|
|
71
71
|
},
|
|
72
72
|
});
|
|
73
73
|
return response;
|
|
@@ -10,12 +10,6 @@ const APIError_1 = __importDefault(require("../../errors/APIError"));
|
|
|
10
10
|
class KPaymentClient {
|
|
11
11
|
config = {
|
|
12
12
|
apiKey: "",
|
|
13
|
-
provider: {
|
|
14
|
-
angolan: {
|
|
15
|
-
seller: "paypay",
|
|
16
|
-
},
|
|
17
|
-
type: "angolan",
|
|
18
|
-
},
|
|
19
13
|
api: {
|
|
20
14
|
lang: "pt",
|
|
21
15
|
version: "v1",
|
|
@@ -27,12 +21,12 @@ class KPaymentClient {
|
|
|
27
21
|
async makeStripePayment({ ...data }) {
|
|
28
22
|
try {
|
|
29
23
|
const response = await (0, api_1.fetchRequest)({
|
|
30
|
-
url: `${helpers_1.APP_CONFIG.PAYMENT.API_BASE_URL}
|
|
24
|
+
url: `${helpers_1.APP_CONFIG.PAYMENT.API_BASE_URL}/stripe`,
|
|
31
25
|
method: "post",
|
|
32
26
|
body: data,
|
|
33
27
|
headers: {
|
|
34
28
|
"kumbi-api-key": `Bearer ${this.config.apiKey}`,
|
|
35
|
-
|
|
29
|
+
lang: this.config.api.lang,
|
|
36
30
|
},
|
|
37
31
|
});
|
|
38
32
|
return response;
|
|
@@ -44,12 +38,12 @@ class KPaymentClient {
|
|
|
44
38
|
async makeCryptoPayment({ ...data }) {
|
|
45
39
|
try {
|
|
46
40
|
const response = await (0, api_1.fetchRequest)({
|
|
47
|
-
url: `${helpers_1.APP_CONFIG.PAYMENT.API_BASE_URL}
|
|
41
|
+
url: `${helpers_1.APP_CONFIG.PAYMENT.API_BASE_URL}/crypto`,
|
|
48
42
|
method: "post",
|
|
49
43
|
body: data,
|
|
50
44
|
headers: {
|
|
51
45
|
"kumbi-api-key": `Bearer ${this.config.apiKey}`,
|
|
52
|
-
|
|
46
|
+
lang: this.config.api.lang,
|
|
53
47
|
},
|
|
54
48
|
});
|
|
55
49
|
return response;
|
|
@@ -60,18 +54,7 @@ class KPaymentClient {
|
|
|
60
54
|
}
|
|
61
55
|
async makeAngolanPayment({ ...data }) {
|
|
62
56
|
try {
|
|
63
|
-
|
|
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}`;
|
|
57
|
+
const url = `${helpers_1.APP_CONFIG.PAYMENT.API_BASE_URL}/${data.provider}`;
|
|
75
58
|
const response = await (0, api_1.fetchRequest)({
|
|
76
59
|
url: url,
|
|
77
60
|
method: "post",
|
|
@@ -80,7 +63,7 @@ class KPaymentClient {
|
|
|
80
63
|
},
|
|
81
64
|
headers: {
|
|
82
65
|
"kumbi-api-key": `Bearer ${this.config.apiKey}`,
|
|
83
|
-
|
|
66
|
+
lang: this.config.api.lang,
|
|
84
67
|
},
|
|
85
68
|
});
|
|
86
69
|
return response;
|
|
@@ -1,23 +1,14 @@
|
|
|
1
1
|
import { IAPIConfig } from "../../utils/types";
|
|
2
2
|
type EAngolanPaymentProviders = "paypay";
|
|
3
|
-
type EInternationalPaymentProviders = "stripe" | "crypto";
|
|
4
3
|
export interface IPaymentParams {
|
|
5
4
|
api?: IAPIConfig;
|
|
6
5
|
apiKey: string;
|
|
7
|
-
provider: {
|
|
8
|
-
angolan?: {
|
|
9
|
-
seller: EAngolanPaymentProviders;
|
|
10
|
-
};
|
|
11
|
-
international?: {
|
|
12
|
-
seller: EInternationalPaymentProviders;
|
|
13
|
-
};
|
|
14
|
-
type: "angolan" | "international";
|
|
15
|
-
};
|
|
16
6
|
}
|
|
17
7
|
export interface IMakeAngolanPaymentParams {
|
|
18
8
|
amount: number;
|
|
19
9
|
subject: string;
|
|
20
10
|
method: "reference" | "multicaixa";
|
|
11
|
+
provider: EAngolanPaymentProviders;
|
|
21
12
|
transfer?: {
|
|
22
13
|
iban: string;
|
|
23
14
|
owner_name: string;
|
|
@@ -52,13 +43,12 @@ export interface IProduct {
|
|
|
52
43
|
*/
|
|
53
44
|
export type StripeCurrencies = "USD" | "EUR";
|
|
54
45
|
export interface IMakeStripePaymentParams {
|
|
55
|
-
amount: number;
|
|
56
46
|
transactionId: string;
|
|
57
47
|
customer: {
|
|
58
48
|
email: string;
|
|
59
49
|
name: string;
|
|
60
50
|
};
|
|
61
|
-
|
|
51
|
+
products: IProduct[];
|
|
62
52
|
redirect: {
|
|
63
53
|
success_url?: string;
|
|
64
54
|
cancel_url?: string;
|
|
@@ -66,6 +56,7 @@ export interface IMakeStripePaymentParams {
|
|
|
66
56
|
stripeCurrency: StripeCurrencies;
|
|
67
57
|
}
|
|
68
58
|
export interface IMakeStripePaymentResponse {
|
|
59
|
+
success: boolean;
|
|
69
60
|
url: string;
|
|
70
61
|
}
|
|
71
62
|
/**
|
|
@@ -73,7 +64,6 @@ export interface IMakeStripePaymentResponse {
|
|
|
73
64
|
*/
|
|
74
65
|
type CryptoCurrencies = "USDC" | "ETH" | "BTC" | "USDT";
|
|
75
66
|
export interface IMakeCryptoPaymentParams {
|
|
76
|
-
amount: number;
|
|
77
67
|
transactionId: string;
|
|
78
68
|
customer: {
|
|
79
69
|
email?: string;
|
|
@@ -84,6 +74,8 @@ export interface IMakeCryptoPaymentParams {
|
|
|
84
74
|
cryptoCurrency: CryptoCurrencies;
|
|
85
75
|
}
|
|
86
76
|
export interface IMakeCryptoPaymentResponse {
|
|
77
|
+
success: boolean;
|
|
87
78
|
address: string;
|
|
79
|
+
checkoutLink: string;
|
|
88
80
|
}
|
|
89
81
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kumbify/sdk",
|
|
3
|
-
"version": "1.2.
|
|
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": {
|
|
@@ -25,10 +25,14 @@
|
|
|
25
25
|
"scripts": {
|
|
26
26
|
"changeset": "changeset",
|
|
27
27
|
"version-pack": "changeset version",
|
|
28
|
-
"publish-pack": "tsc && changeset publish"
|
|
28
|
+
"publish-pack": "tsc && changeset publish",
|
|
29
|
+
"test-mail": "ts-node-dev ./src/clients/kmail/KMailClient.ts",
|
|
30
|
+
"test-sms": "ts-node-dev ./src/clients/ksms/KSMSClient.ts",
|
|
31
|
+
"test-payment": "ts-node-dev ./src/clients/payment/KPaymentClient.ts"
|
|
29
32
|
},
|
|
30
33
|
"devDependencies": {
|
|
31
34
|
"@changesets/cli": "^2.29.8",
|
|
35
|
+
"ts-node-dev": "^2.0.0",
|
|
32
36
|
"typescript": "^5.9.3"
|
|
33
37
|
},
|
|
34
38
|
"dependencies": {
|
|
@@ -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
|
-
}
|
package/dist/ksms/KSMSClient.js
DELETED
|
@@ -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
|
package/dist/ksms/KSMSServer.js
DELETED
|
@@ -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
|