nepse-api-helper
Advanced tools
Comparing version 1.2.0 to 1.2.1
@@ -5,9 +5,10 @@ import { Prove } from "./prove"; | ||
import { MarketStatus } from "./marketStatus"; | ||
declare let security_brief_cache: SecurityBrief[]; | ||
declare function instantiate_nepse_helper(): Promise<void>; | ||
declare function get_valid_token(proveObj: Prove): string; | ||
declare function get_raw_access_object(): Promise<Prove | null>; | ||
declare function get_access_token(): Promise<string | null>; | ||
declare function GetMarketStatus(): Promise<MarketStatus | null>; | ||
declare function GetSecurityBriefs(): Promise<SecurityBrief[]>; | ||
declare function UpdateSecurityBriefs(): Promise<void>; | ||
declare function GetSecurityDetail(symbol: string): Promise<SecurityDetail | null>; | ||
export { UpdateSecurityBriefs, GetSecurityDetail, GetSecurityBriefs, GetMarketStatus, get_access_token, get_raw_access_object, get_valid_token }; | ||
declare function get_market_status(): Promise<MarketStatus | null>; | ||
declare function get_security_briefs(): Promise<SecurityBrief[]>; | ||
declare function get_security_detail(symbol: string): Promise<SecurityDetail | null>; | ||
export { get_security_detail, get_security_briefs, get_market_status, get_access_token, get_raw_access_object, get_valid_token, instantiate_nepse_helper, security_brief_cache }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.get_valid_token = exports.get_raw_access_object = exports.get_access_token = exports.GetMarketStatus = exports.GetSecurityBriefs = exports.GetSecurityDetail = exports.UpdateSecurityBriefs = void 0; | ||
exports.security_brief_cache = exports.instantiate_nepse_helper = exports.get_valid_token = exports.get_raw_access_object = exports.get_access_token = exports.get_market_status = exports.get_security_briefs = exports.get_security_detail = void 0; | ||
const constants_1 = require("./constants"); | ||
let securityBriefList = []; | ||
function cdx(saltNum, data) { | ||
let salt_num_divided_10 = Math.floor(saltNum / 10); | ||
let temp1 = salt_num_divided_10 % 10; | ||
let temp2 = salt_num_divided_10 * 10; | ||
let salt_num_divided_100 = Math.floor(saltNum / 100); | ||
let temp3 = salt_num_divided_100 % 10; | ||
let temp4 = saltNum - temp2; | ||
let index = temp1 + temp4 + temp3; | ||
let result = data[index] + 22; | ||
return result; | ||
let security_brief_cache = []; | ||
exports.security_brief_cache = security_brief_cache; | ||
let wasm_instantiated = false; | ||
let cdx; | ||
let rdx; | ||
let bdx; | ||
let ndx; | ||
let mdx; | ||
async function instantiate_nepse_helper() { | ||
const response = await fetch(`${constants_1.BASE_URL}/assets/prod/css.wasm`); | ||
const buffer = await response.arrayBuffer(); | ||
const wasm = await WebAssembly.instantiate(buffer); | ||
wasm_instantiated = true; | ||
cdx = wasm.instance.exports.cdx; | ||
rdx = wasm.instance.exports.rdx; | ||
bdx = wasm.instance.exports.bdx; | ||
ndx = wasm.instance.exports.ndx; | ||
mdx = wasm.instance.exports.mdx; | ||
exports.security_brief_cache = security_brief_cache = await get_security_briefs(); | ||
} | ||
function rdx(saltNum, data) { | ||
let salt_num_divided_10 = Math.floor(saltNum / 10); //var0 | ||
let salt_num_divided_100 = Math.floor(saltNum / 100); | ||
let temp_10_mod_10 = salt_num_divided_10 % 10; | ||
let temp_100_mod_10 = salt_num_divided_100 % 10; | ||
let temp1 = temp_10_mod_10 + temp_100_mod_10; //var2 | ||
let temp2 = salt_num_divided_10 * 10; | ||
let temp3 = saltNum - temp2; | ||
let temp4 = temp3 + temp1; | ||
let temp_shifted = temp4 << 2; | ||
let index = (temp_shifted + (2 ** 10)) % data.length; | ||
let result = temp1 + data[index] + 32; | ||
return result; | ||
} | ||
function bdx(saltNum, data) { | ||
let salt_num_divided_10 = Math.floor(saltNum / 10); //var0 | ||
let salt_num_divided_100 = Math.floor(saltNum / 100); | ||
let temp_10_mod_10 = salt_num_divided_10 % 10; | ||
let temp_100_mod_10 = salt_num_divided_100 % 10; | ||
let temp1 = temp_10_mod_10 + temp_100_mod_10; | ||
let temp2 = salt_num_divided_10 * 10; | ||
let temp3 = saltNum - temp2; | ||
let temp4 = temp1 + temp3; | ||
let temp_shifted = temp4 << 2; | ||
let index = (temp_shifted + (2 ** 10)) % data.length; | ||
let result = data[index] + temp1 + 60; | ||
return result; | ||
} | ||
function ndx(saltNum, data) { | ||
let salt_num_divided_10 = Math.floor(saltNum / 10); //var0 | ||
let salt_num_divided_100 = Math.floor(saltNum / 100); | ||
let temp_10_mod_10 = salt_num_divided_10 % 10; //var2 | ||
let temp_100_mod_10 = salt_num_divided_100 % 10; | ||
let temp1 = salt_num_divided_10 * 10; | ||
let temp2 = saltNum - temp1; | ||
let temp3 = temp_10_mod_10 + temp2; | ||
let temp4 = temp_100_mod_10 + temp3; //b | ||
let temp_shifted = temp4 << 2; | ||
let index = (temp_shifted + (2 ** 10)) % data.length; | ||
let result = data[index] + temp_10_mod_10 + 88; | ||
return result; | ||
} | ||
function mdx(saltNum, data) { | ||
let salt_num_divided_10 = Math.floor(saltNum / 10); //var2 | ||
let salt_num_divided_100 = Math.floor(saltNum / 100); | ||
let temp_10_mod_10 = salt_num_divided_10 % 10; | ||
let temp_100_mod_10 = salt_num_divided_100 % 10; //var0 | ||
let temp1 = salt_num_divided_10 * 10; | ||
let temp2 = saltNum - temp1; | ||
let temp3 = temp2 + temp_10_mod_10; | ||
let temp4 = temp3 + temp_100_mod_10; | ||
let temp_shifted = temp4 << 2; | ||
let index = (temp_shifted + (2 ** 10)) % data.length; | ||
let result = data[index] + 110 + temp_100_mod_10; | ||
return result; | ||
} | ||
exports.instantiate_nepse_helper = instantiate_nepse_helper; | ||
function get_valid_token(proveObj) { | ||
const dataArr = [5, 8, 4, 7, 9, 4, 6, 9, 5, 5, 6, 5, 3, 5, 4, 4, 9, 6, 6, 8, 8, 6, 8, 6, 5, 8, 4, 9, 5, 9, 8, 5, 3, 4, 7, 7, 4, 7, 3, 9]; | ||
const num1 = cdx(proveObj.salt2, dataArr); | ||
const num2 = rdx(proveObj.salt2, dataArr); | ||
const num3 = bdx(proveObj.salt2, dataArr); | ||
const num4 = ndx(proveObj.salt2, dataArr); | ||
const num5 = mdx(proveObj.salt2, dataArr); | ||
const raw_at = proveObj.accessToken; | ||
const access_token = raw_at.slice(0, num1) + | ||
raw_at.slice(num1 + 1, num2) + | ||
raw_at.slice(num2 + 1, num3) + | ||
raw_at.slice(num3 + 1, num4) + | ||
raw_at.slice(num4 + 1, num5) + | ||
raw_at.slice(num5); | ||
return access_token; | ||
if (!wasm_instantiated) { | ||
throw "library not instantiated. please call instantiate method before doing anything"; | ||
} | ||
return proveObj.accessToken.slice(0, cdx(proveObj.salt1, proveObj.salt2, proveObj.salt3, proveObj.salt4, proveObj.salt5)) + | ||
proveObj.accessToken.slice(cdx(proveObj.salt1, proveObj.salt2, proveObj.salt3, proveObj.salt4, proveObj.salt5) + 1, rdx(proveObj.salt1, proveObj.salt2, proveObj.salt4, proveObj.salt3, proveObj.salt5)) + | ||
proveObj.accessToken.slice(rdx(proveObj.salt1, proveObj.salt2, proveObj.salt4, proveObj.salt3, proveObj.salt5) + 1, bdx(proveObj.salt1, proveObj.salt2, proveObj.salt4, proveObj.salt3, proveObj.salt5)) + | ||
proveObj.accessToken.slice(bdx(proveObj.salt1, proveObj.salt2, proveObj.salt4, proveObj.salt3, proveObj.salt5) + 1, ndx(proveObj.salt1, proveObj.salt2, proveObj.salt4, proveObj.salt3, proveObj.salt5)) + | ||
proveObj.accessToken.slice(ndx(proveObj.salt1, proveObj.salt2, proveObj.salt4, proveObj.salt3, proveObj.salt5) + 1, mdx(proveObj.salt1, proveObj.salt2, proveObj.salt4, proveObj.salt3, proveObj.salt5)) + | ||
proveObj.accessToken.slice(mdx(proveObj.salt1, proveObj.salt2, proveObj.salt4, proveObj.salt3, proveObj.salt5) + 1); | ||
} | ||
@@ -117,3 +65,3 @@ exports.get_valid_token = get_valid_token; | ||
exports.get_access_token = get_access_token; | ||
async function GetMarketStatus() { | ||
async function get_market_status() { | ||
const token = await get_access_token(); | ||
@@ -141,4 +89,4 @@ return await fetch(`${constants_1.BASE_URL}/api/nots/nepse-data/market-open`, { | ||
} | ||
exports.GetMarketStatus = GetMarketStatus; | ||
async function GetSecurityBriefs() { | ||
exports.get_market_status = get_market_status; | ||
async function get_security_briefs() { | ||
const token = await get_access_token(); | ||
@@ -162,8 +110,4 @@ const securityBriefDetails = await fetch(`${constants_1.BASE_URL}/api/nots/security?nonDelisted=false`, { | ||
} | ||
exports.GetSecurityBriefs = GetSecurityBriefs; | ||
async function UpdateSecurityBriefs() { | ||
securityBriefList = await GetSecurityBriefs(); | ||
} | ||
exports.UpdateSecurityBriefs = UpdateSecurityBriefs; | ||
function GetValidBodyId(marketId) { | ||
exports.get_security_briefs = get_security_briefs; | ||
function get_valid_body_id(marketId) { | ||
const dummyData = [147, 117, 239, 143, 157, 312, 161, 612, 512, 804, 411, 527, 170, 511, 421, 667, 764, 621, 301, 106, 133, 793, 411, 511, 312, 423, 344, 346, 653, 758, 342, 222, 236, 811, 711, 611, 122, 447, 128, 199, 183, 135, 489, 703, 800, 745, 152, 863, 134, 211, 142, 564, 375, 793, 212, 153, 138, 153, 648, 611, 151, 649, 318, 143, 117, 756, 119, 141, 717, 113, 112, 146, 162, 660, 693, 261, 362, 354, 251, 641, 157, 178, 631, 192, 734, 445, 192, 883, 187, 122, 591, 731, 852, 384, 565, 596, 451, 772, 624, 691]; | ||
@@ -175,10 +119,11 @@ const currentDate = new Date(); | ||
} | ||
async function GetSecurityDetail(symbol) { | ||
const security = securityBriefList.find(s => s.symbol.toLowerCase() === symbol.toLowerCase()); | ||
async function get_security_detail(symbol) { | ||
const security = security_brief_cache.find(s => s.symbol.toLowerCase() === symbol.toLowerCase()); | ||
if (!security) { | ||
return null; | ||
} | ||
const marketStatus = await GetMarketStatus(); | ||
const bodyId = GetValidBodyId(marketStatus?.id ?? 0); | ||
const marketStatus = await get_market_status(); | ||
const bodyId = get_valid_body_id(marketStatus?.id ?? 0); | ||
const token = await get_access_token(); | ||
console.log(`${constants_1.BASE_URL}/api/nots/security/${security.id}`); | ||
const securityDetail = await fetch(`${constants_1.BASE_URL}/api/nots/security/${security.id}`, { | ||
@@ -188,5 +133,3 @@ headers: { | ||
"Accept": "application/json, text/plain, */*", | ||
"Origin": `${constants_1.BASE_URL}`, | ||
"Referer": `${constants_1.BASE_URL}/company/detail/${security.id}`, | ||
"Referrer-Policy": "strict-origin-when-cross-origin", | ||
"Authorization": `Salter ${token}`, | ||
@@ -220,2 +163,2 @@ "Content-Type": "application/json" | ||
} | ||
exports.GetSecurityDetail = GetSecurityDetail; | ||
exports.get_security_detail = get_security_detail; |
@@ -12,2 +12,4 @@ interface Prove { | ||
tokenType: string | null; | ||
isDisplayActive: boolean; | ||
popupDocFor: string; | ||
} | ||
@@ -14,0 +16,0 @@ interface ProveExtra { |
@@ -6,29 +6,36 @@ "use strict"; | ||
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; | ||
(0, vitest_1.it)("getting access token", async () => { | ||
const access_token = await (0, lib_1.get_access_token)(); | ||
const is_token = access_token?.startsWith("ey"); | ||
console.log(access_token); | ||
(0, vitest_1.expect)(is_token, "received string is not a token").toBe(true); | ||
(0, vitest_1.describe)("all library tests", async () => { | ||
await (0, lib_1.instantiate_nepse_helper)(); | ||
(0, vitest_1.it)("getting access token", async () => { | ||
const access_token = await (0, lib_1.get_access_token)(); | ||
const is_token = access_token?.startsWith("ey"); | ||
(0, vitest_1.expect)(is_token, "received string is not a token").toBe(true); | ||
}); | ||
(0, vitest_1.it)("getting valid token", async () => { | ||
var raw_object = { | ||
"serverTime": 1687699998000, | ||
"salt": "O5!Z>1{_a0iO1%\\/`4P=", | ||
"accessToken": "eyJlbmMiOiJBMTI4Q0JDLUhTMjU2WIiwiYWxnIjoiZGlyIn0c..nL1Y5vBX2Fy7lWfEyWkk2A.RqxCxJWW2D6zbXFi-Nyp-jTx9OqmAvvvkP3CP34m1uDjVECrJXYNaN-cbHkqYhg8BWF771G1ykoXPLrZZb6oSHC-TdoZkF4Ht0K3ULKjNXCQccGGFAMDwuT60MDrA_vYNiEeRQ7fZN-VnnIdA1rSaANsw.J9AiD_43-ch8-QH8b46Dzw", | ||
"tokenType": "", | ||
"refreshToken": "eyJlbmMiOiJBMTI4Q0JDLUhTMjU2tIiwiYWxnIjoiZGlyIWn0..LrCh8OiSrVDJafrkdWY6DQ.OQHxknRQi5YuU_L5YP9LfmEG8yv8VTVCL0G0-y7LOmhD_yoYBTSrsMW0d-cz9PkibvlDvfJfEQK5ufo5UDyno4k7cNDoaCgofdvOBkgcIJoUAx4xzGEjiJERQPlDULTisPejtVP1kGhMIN9chR7KTI1lQ.N-1qatEKCM-lMZ1C8zqIJw", | ||
"salt1": 63629, | ||
"salt2": 56377, | ||
"salt3": 62477, | ||
"salt4": 85843, | ||
"salt5": 28870, | ||
"isDisplayActive": false, | ||
"popupDocFor": "pdf" | ||
}; | ||
const valid_token = (0, lib_1.get_valid_token)(raw_object); | ||
(0, vitest_1.expect)(valid_token, "token is not valid").toBe("eyJlbmMiOiJBMTI4Q0JDLUhTMjU2IiwiYWxnIjoiZGlyIn0..nL1Y5vBX2Fy7lWfEyWkk2A.RqCxJWW2D6zbXFi-Nyp-jTx9OqAvvvkP3CP34m1uDjVCrJXYNaN-cbHkqYhg8BWF771G1ykoXPLrZZb6oSHC-TdoZkF4Ht0K3ULKjNXCQccGGFAMDwuT60MDrA_vYNiEeRQ7fZN-VnnIdA1rSaANsw.J9AiD_43-ch8-QH8b46Dzw"); | ||
}); | ||
(0, vitest_1.it)("getting market status", async () => { | ||
const market_status = await (0, lib_1.get_market_status)(); | ||
(0, vitest_1.expect)(market_status?.id, "market status does not have id").toBeGreaterThan(0); | ||
}); | ||
(0, vitest_1.it)("getting security detail", async () => { | ||
const detail = await (0, lib_1.get_security_detail)('HLI'); | ||
console.log(detail); | ||
(0, vitest_1.expect)(true, "lets ignore this test for now").toBe(true); | ||
}); | ||
}); | ||
(0, vitest_1.it)("getting valid token", async () => { | ||
var raw_object = { | ||
accessToken: "eyJlbmMiOiJBMTI4Q0JDLUhTM2jU2IiwiYWxnIjoiZGlyInx0..ATvO5OnUl6HR--p96EK1XA.ZOriDcHOEvjJ4pxg42p2MCvZ0cwRhaAufuEbBuDxLQJ0NTl9Mevw01RGaE7ZsTpq2A15aCxgEHPSeh0-7mAGXDFDxTgve1-V8wbBTPwJfol56a9bGSRUTJG3fP35umM3vEmHw7Yg0Eyzt3wkkuUr_chYg.iCxuiUPUIyRW_a_dz1ad8Q", | ||
refreshToken: "eyJlbmMiOiJBMTI4Q0JDLUhTMjU2IiMwiYWxnIjoiZGlyIn0..srNseMEDki5uz_--BljzHTg.ETmnLQc45T10qUtvEY8bha6JeWaV0RZPrlHnc3gtMaUSi3kmIyHHlrngBi9Ny4gfPI4UR_VQR6c2wYFoq-tDdC3vp8T70S83TJuK9LjWmwyzjh7J6nbgXoaZzAtld1No1YJUxFF_fCIRSDPMtdYNy8Tlw.hLr9ZbDlU9_KaRStbIxhvA", | ||
salt: "(XR4l]1Xm|{]S{TFDwQ!", | ||
salt1: 97598, | ||
salt2: 40480, | ||
salt3: 63155, | ||
salt4: 28193, | ||
salt5: 73601, | ||
serverTime: 1687626519000, | ||
tokenType: "" | ||
}; | ||
const valid_token = (0, lib_1.get_valid_token)(raw_object); | ||
console.log(valid_token); | ||
(0, vitest_1.expect)(valid_token, "token is not valid").toBe("eyJlbmMiOiJBMTI4Q0JDLUhTMjU2IiwiYWxnIjoiZGlyIn0..ATvO5OnUl6HR--p96EK1XA.ZriDcHOEvjJ4pxg42p2MCvZ0wRhaAufuEbBuDxLQJNTl9Mevw01RGaE7ZsTpq2A15aCxgEHPSeh0-7mAGXDFDxTgve1-V8wbBTPwJfol56a9bGSRUTJG3fP35umM3vEmHw7Yg0Eyzt3wkkuUr_chYg.iCxuiUPUIyRW_a_dz1ad8Q"); | ||
}); | ||
// it("getting market status", async () => { | ||
// const market_status = await GetMarketStatus(); | ||
// console.log(market_status); | ||
// expect(true, "true").toBe(true); | ||
// }) |
{ | ||
"name": "nepse-api-helper", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "a wrapper to use nepse api easily since they set up weird restrictions", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
30989
504