Skip to content

Commit fd76254

Browse files
committed
Initial commit
0 parents  commit fd76254

9 files changed

+357
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
.env

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# MySLT API Library [WIP]
2+
3+
A TypeScript library for accessing MySLT's private API. Reverse Engineered from their [webportal](https://myslt.slt.lk).

example/index.ts

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import SLT from "../src/SLT";
2+
import dotenv from "dotenv";
3+
import process from "process";
4+
import { AccountList, ServiceList, UsageDetails } from "../src/Types";
5+
6+
dotenv.config();
7+
8+
(async () => {
9+
const slt = new SLT(process.env.MYSLT_USER!, process.env.MYSLT_PASS!);
10+
11+
let account: AccountList = await slt.login().then(() => slt.getAccountDetails());
12+
let service_list: ServiceList = await slt.getServiceDetails(account[0].telephoneno);
13+
let usage: UsageDetails = await slt.getAddonsUsage(
14+
service_list.listofBBService![0].serviceID
15+
);
16+
console.log(usage);
17+
})();

package.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "myslt-api",
3+
"version": "0.0.1",
4+
"description": "",
5+
"main": "dist/index.js",
6+
"scripts": {
7+
"cleanbuild": "rm -rf dist && tsc",
8+
"test": "tsc && node ./dist/example/index.js"
9+
},
10+
"keywords": [],
11+
"author": "minzique",
12+
"license": "MIT",
13+
"dependencies": {
14+
"axios": "^1.3.4",
15+
"dotenv": "^16.0.3"
16+
}
17+
}

pnpm-lock.yaml

+77
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/SLT.ts

+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import {
2+
loginUrl,
3+
getAccountDetailsUrl,
4+
getServiceDetailRequestUrl,
5+
getUsageSummaryUrl,
6+
getAddonsDataUrl,
7+
} from "./URLs";
8+
import {
9+
BaseAPIRespose,
10+
AccountDetails,
11+
AccountList,
12+
ServiceList,
13+
UsageSummaryResponse,
14+
} from "./Types";
15+
import { URLSearchParams } from "url";
16+
import axios, { AxiosInstance } from "axios";
17+
18+
export default class SLT {
19+
public username: string;
20+
public password: string;
21+
public auth_token?: string;
22+
public refresh_token?: string;
23+
24+
// public account_details?: AccountDetails;
25+
// public service_list?: ServiceList;
26+
27+
readonly request: AxiosInstance;
28+
29+
constructor(username: string, password: string) {
30+
this.username = username;
31+
this.password = password;
32+
this.request = axios.create({
33+
headers: {
34+
"X-IBM-Client-Id": "41aed706-8fdf-4b1e-883e-91e44d7f379b",
35+
},
36+
});
37+
}
38+
39+
async login() {
40+
return this.request
41+
.post(
42+
loginUrl,
43+
new URLSearchParams({
44+
username: this.username,
45+
password: this.password,
46+
channelID: "WEB",
47+
})
48+
)
49+
.then((response) => {
50+
if (response.data.hasOwnProperty("errorShow")) {
51+
throw new Error(response.data.errorShow);
52+
} else if (response.status === 200) {
53+
this.auth_token = response.data.accessToken;
54+
this.refresh_token = response.data.refreshToken;
55+
this.request.defaults.headers.common["Authorization"] =
56+
"Bearer " + this.auth_token;
57+
return response.data;
58+
} else {
59+
throw new Error(response.data.errorShow);
60+
}
61+
})
62+
.catch((err) => {
63+
if (err?.response.status === 401) {
64+
throw new Error("Invalid user name and password");
65+
} else {
66+
throw err;
67+
}
68+
});
69+
}
70+
71+
public async APIGetData(url: string) {
72+
return this.request
73+
.get(url)
74+
.then((response) => {
75+
if (response.data.isSuccess) {
76+
if (response.data.dataBundle.length === 0) {
77+
throw new Error("Unable to fetch data");
78+
}
79+
return response.data.dataBundle;
80+
} else {
81+
throw new Error(response.data.errorShow);
82+
}
83+
})
84+
.catch((err) => err);
85+
}
86+
87+
async getAccountDetails(username?: string): Promise<AccountList> {
88+
return this.APIGetData(
89+
getAccountDetailsUrl + "username=" + (username ? username : this.username)
90+
);
91+
}
92+
93+
async getServiceDetails(telephoneNo: string): Promise<ServiceList> {
94+
return this.APIGetData(getServiceDetailRequestUrl + "telephoneNo=" + telephoneNo);
95+
}
96+
97+
async getUsageSummary(serviceID: string): Promise<UsageSummaryResponse> {
98+
return this.APIGetData(getUsageSummaryUrl + "subscriberID=" + serviceID);
99+
}
100+
101+
async getAddonsUsage(serviceID: string) {
102+
return this.APIGetData(getAddonsDataUrl + "subscriberID=" + serviceID);
103+
}
104+
105+
public async getBBSummary(serviceID: string) {}
106+
}

src/Types.ts

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
export interface AccountDetails {
2+
accountno: string;
3+
telephoneno: string;
4+
status: string;
5+
}
6+
export interface AccountList extends Array<AccountDetails> {}
7+
8+
export interface ServiceDetails {
9+
serviceID: string; // subscriberID
10+
packageName: string;
11+
serviceStatus: string;
12+
serviceType: string;
13+
updatedDTM?: string;
14+
}
15+
16+
export interface ServiceList {
17+
accountNo: string;
18+
promotionName: string;
19+
accountCategory: string;
20+
contactNamewithInit?: string;
21+
contactMobile?: string;
22+
listofVoiceService?: ServiceDetails[];
23+
listofBBService?: ServiceDetails[];
24+
listofPEOService?: ServiceDetails[];
25+
}
26+
27+
export interface UsageDetails {
28+
name: string;
29+
limit?: string;
30+
remaining?: string;
31+
used: string;
32+
percentage?: number;
33+
volume_unit: string;
34+
expiry_date: string;
35+
claim?: unknown;
36+
unsubscribable: boolean;
37+
timestamp: number;
38+
subscriptionid?: string;
39+
}
40+
41+
export interface DataSummary {
42+
limit?: string;
43+
used?: string;
44+
volume_unit?: string;
45+
}
46+
export interface UsageSummaryResponse {
47+
status: string;
48+
reported_time: string;
49+
my_package_summary?: DataSummary;
50+
bonus_data_summary?: DataSummary;
51+
free_data_summary?: DataSummary;
52+
vas_data_summary?: DataSummary;
53+
extra_gb_data_summary?: DataSummary;
54+
my_package_info: {
55+
package_name: string;
56+
package_summary?: unknown; // probably `DataSummary` too
57+
usageDetails?: UsageDetails[];
58+
reported_time: string;
59+
};
60+
}
61+
// we don't use this, keeping it here as a reference
62+
export interface BaseAPIRespose {
63+
isSuccess: boolean;
64+
errorMessege?: string;
65+
exceptionDetail?: unknown;
66+
dataBundle?: {};
67+
errorShow?: string;
68+
errorCode?: unknown;
69+
}

src/URLs.ts

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Taken directly from myslt.slt.lk
2+
export const BASE_URL = 'https://omniscapp.slt.lk/mobitelint/slt/api/'
3+
4+
export const BILL_PAY = "https://billpay.slt.lk/";
5+
6+
export const firebaseID = '123123123'
7+
export const refreshTokenUrl = BASE_URL + "Account/RefreshToken"
8+
export const externalLoginUrl = BASE_URL + "Account/LoginExternal";
9+
export const loginUrl = BASE_URL + "Account/Login";
10+
export const signUpUrl = BASE_URL + "Account/RegisterV2"
11+
export const otpResendUrl = BASE_URL + "Account/ResendOTPV2";
12+
export const otpAuthenticateUrl = BASE_URL + "Account/OTPAuthRequest";
13+
export const forgotPasswordAuthenticateUrl = BASE_URL + "Account/ForgotPassword";
14+
export const getAddCategoryUrl = BASE_URL + "Banner/BannerDetailRequest?";
15+
export const getbannerImagesUrl = 'https://bannerportal.slt.lk/API/getBannerUrls';
16+
17+
// Account details
18+
export const getAccountDetailsUrl = BASE_URL + "AccountOMNI/GetAccountDetailRequest?";
19+
export const getServiceDetailRequestUrl = BASE_URL + "AccountOMNI/GetServiceDetailRequest?";
20+
export const billDetailsUrl = BASE_URL + "AccountOMNI/BillPaymentRequest?"
21+
export const getUsageSummaryUrl = BASE_URL + "BBVAS/UsageSummary?";
22+
export const getProfileRequestUrl = BASE_URL + "VAS/GetProfileRequest?";
23+
export const addAccountUrl = BASE_URL + "AccountOMNI/AddAccountRequest?";
24+
export const addVasAccountUrl = BASE_URL + "AccountOMNI/VASAccountRequest?";
25+
export const getSubmitClaimUrl = BASE_URL + "BBVAS/UpgradeLoyalty?";
26+
export const getVASBundleUnsubscriptionUrl = BASE_URL + "BBVAS/VASBundleUnsubscription?";
27+
28+
// VASUsage
29+
export const getExtraGBUrl = BASE_URL + "BBVAS/ExtraGB?";
30+
export const getBonusDataUrl = BASE_URL + "BBVAS/BonusData?";
31+
export const getAddonsDataUrl = BASE_URL + "BBVAS/GetDashboardVASBundles?";
32+
export const getFreeDataUrl = BASE_URL + "BBVAS/FreeData?";
33+
34+
export const getValidateDataGiftSubUrl = BASE_URL + "BBVAS/ValidateDataGiftSub?";
35+
36+
//bbHistory
37+
export const getHistoryGBDetailsUrl = BASE_URL + "BBVAS/GetPurchaseHistory?";
38+
39+
//bbDailyUsage
40+
export const getCurrentMonthsDailyUsageUrl = BASE_URL + "BBVAS/EnhancedCurrentDailyUsage?";
41+
export const getPreviousMonthsDailyUsageUrl = BASE_URL + "BBVAS/EnhancedPreviousDailyUsage?";
42+
export const purchaseProtocolReportUrl = BASE_URL + "BBVAS/PurchaseAdvancedReportsPostPaid?";
43+
export const UnsubscribeAdvancedReportsUrl = BASE_URL + "BBVAS/UnsubscribeAdvancedReports?";
44+
45+
export const getProtocolReportUrl = BASE_URL + "BBVAS/ProtocolReport?";
46+
47+
//get addon list DataUrl
48+
export const getAddonListDataUrl = BASE_URL + "BBVAS/GetVASDataBundlePackages?";
49+
export const getAddVASDataBundlePostPaidUrl = BASE_URL + "BBVAS/AddVASDataBundlePostPaid?";
50+
51+
52+
export const getAddVASDataBundlePostPaidV2Url = BASE_URL + "BBVAS/AddVASDataBundlePostPaidV2?";
53+
54+
//service related upgrade package
55+
export const getBBPackageComparisonUrl = BASE_URL + "BBExternal/GetBBPackagesV2?";
56+
export const getCurrentBBPackageUrl = BASE_URL + "BBExternal/GetCurrentBBPackageV2?";
57+
export const BBPackageChangeRequest = BASE_URL + "BBExternal/BBPackageChangeRequest?";
58+
59+
//getExtraGb Details
60+
export const getExtraGBDetailsUrl = BASE_URL + "BBVAS/GetExtraGBPackages?";
61+
export const getExtraGBPostPaidUrl = BASE_URL + "BBVAS/PurchaseExtraGBPostpaid?";
62+
63+
//bill history
64+
export const getBillHistoryRequestUrl = BASE_URL + "AccountOMNI/BillHistoryRequestV2?";

src/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from "./SLT";
2+
export * from "./Types";

0 commit comments

Comments
 (0)