@topanlabs/reksadana 1.0.0

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.
@@ -0,0 +1,3 @@
1
+ export { scrapeAll, fetchStock } from './scraper';
2
+ export type { Fund, Stock } from './types';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAClD,YAAY,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fetchStock = exports.scrapeAll = void 0;
4
+ var scraper_1 = require("./scraper");
5
+ Object.defineProperty(exports, "scrapeAll", { enumerable: true, get: function () { return scraper_1.scrapeAll; } });
6
+ Object.defineProperty(exports, "fetchStock", { enumerable: true, get: function () { return scraper_1.fetchStock; } });
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,qCAAkD;AAAzC,oGAAA,SAAS,OAAA;AAAE,qGAAA,UAAU,OAAA"}
@@ -0,0 +1,4 @@
1
+ import type { Stock, Fund } from './types';
2
+ export declare function fetchStock(symbol: string): Promise<Stock | null>;
3
+ export declare function scrapeAll(): Promise<Fund[]>;
4
+ //# sourceMappingURL=scraper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scraper.d.ts","sourceRoot":"","sources":["../src/scraper.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,KAAK,EAAE,IAAI,EAA0C,MAAM,SAAS,CAAC;AAiDnF,wBAAsB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,CAatE;AAgCD,wBAAsB,SAAS,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC,CAoCjD"}
@@ -0,0 +1,144 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.fetchStock = fetchStock;
37
+ exports.scrapeAll = scrapeAll;
38
+ const axios_1 = __importStar(require("axios"));
39
+ const CryptoJS = __importStar(require("crypto-js"));
40
+ // ─── Decryption ───────────────────────────────────────────────────────────────
41
+ /**
42
+ * The encrypted string embeds its own IV and key:
43
+ * [0..31] → IV (32 hex chars)
44
+ * [32..-32] → ciphertext (hex-encoded)
45
+ * [-32..] → AES key (32 UTF-8 chars)
46
+ */
47
+ function decrypt(data) {
48
+ const iv = CryptoJS.enc.Hex.parse(data.slice(0, 32));
49
+ const secret = CryptoJS.enc.Utf8.parse(data.slice(-32));
50
+ const encryptedData = data.slice(32, -32);
51
+ const bytes = CryptoJS.AES.decrypt(encryptedData, secret, {
52
+ iv,
53
+ mode: CryptoJS.mode.CBC,
54
+ format: CryptoJS.format.Hex,
55
+ });
56
+ return JSON.parse(bytes.toString(CryptoJS.enc.Utf8));
57
+ }
58
+ // ─── API Fetcher ──────────────────────────────────────────────────────────────
59
+ const BIBIT_API_URL = 'https://api.bibit.id/products/list';
60
+ const BIBIT_STOCKS_API_URL = 'https://api.bibit.id/stocks/companies';
61
+ const PAGE_LIMIT = 25;
62
+ const DELAY_MS = 300;
63
+ const HEADERS = {
64
+ Accept: 'application/json',
65
+ 'Accept-Encoding': 'gzip',
66
+ 'Accept-Language': 'en-US,en;q=0.9',
67
+ Pragma: 'no-cache',
68
+ 'Cache-Control': 'no-cache',
69
+ Origin: 'https://bibit.id',
70
+ Referer: 'https://bibit.id/reksadana',
71
+ 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36',
72
+ };
73
+ function sleep(ms) {
74
+ return new Promise((resolve) => setTimeout(resolve, ms));
75
+ }
76
+ // ─── Stock Fetcher ────────────────────────────────────────────────────────────
77
+ async function fetchStock(symbol) {
78
+ try {
79
+ const response = await axios_1.default.get(`${BIBIT_STOCKS_API_URL}/${encodeURIComponent(symbol)}`, {
80
+ headers: { ...HEADERS, Referer: 'https://bibit.id/saham' },
81
+ decompress: true,
82
+ });
83
+ return response.data.data;
84
+ }
85
+ catch (err) {
86
+ if (err instanceof axios_1.AxiosError && err.response?.status === 422) {
87
+ return null;
88
+ }
89
+ throw err;
90
+ }
91
+ }
92
+ async function fetchPage(page) {
93
+ const response = await axios_1.default.get(BIBIT_API_URL, {
94
+ headers: HEADERS,
95
+ params: {
96
+ page,
97
+ limit: PAGE_LIMIT,
98
+ sort_by: 7, // 7 = sort by name
99
+ sort: 'asc',
100
+ tradable: 1, // only funds listed on bibit.id/reksadana
101
+ },
102
+ decompress: true,
103
+ });
104
+ const encrypted = response.data?.data;
105
+ if (!encrypted || typeof encrypted !== 'string') {
106
+ throw new Error(`Unexpected response shape on page ${page}: ${JSON.stringify(response.data)}`);
107
+ }
108
+ // Log the decrypted shape once on the first page so field names can be verified
109
+ const decrypted = decrypt(encrypted);
110
+ if (!Array.isArray(decrypted)) {
111
+ throw new Error(`Decrypted data is not an array on page ${page}`);
112
+ }
113
+ return decrypted;
114
+ }
115
+ // ─── Main Scraper ─────────────────────────────────────────────────────────────
116
+ async function scrapeAll() {
117
+ const results = [];
118
+ let page = 1;
119
+ console.log('Starting scrape of https://bibit.id/reksadana ...\n');
120
+ while (true) {
121
+ console.log(` Fetching page ${page} ...`);
122
+ const rawFunds = await fetchPage(page);
123
+ if (rawFunds.length === 0) {
124
+ console.log(' No more records, stopping.');
125
+ break;
126
+ }
127
+ for (const fund of rawFunds) {
128
+ results.push({
129
+ id: fund.id,
130
+ name: fund.name.trim(),
131
+ last_nav: fund.nav?.value ?? 0,
132
+ });
133
+ }
134
+ console.log(` → Got ${rawFunds.length} funds (total so far: ${results.length})`);
135
+ if (rawFunds.length < PAGE_LIMIT) {
136
+ // Last page (partial)
137
+ break;
138
+ }
139
+ page += 1;
140
+ await sleep(DELAY_MS);
141
+ }
142
+ return results;
143
+ }
144
+ //# sourceMappingURL=scraper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scraper.js","sourceRoot":"","sources":["../src/scraper.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmDA,gCAaC;AAgCD,8BAoCC;AApID,+CAA0C;AAC1C,oDAAsC;AAGtC,iFAAiF;AAEjF;;;;;GAKG;AACH,SAAS,OAAO,CAAC,IAAY;IAC3B,MAAM,E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+ id: number;
3
+ symbol: string;
4
+ name: string;
5
+ price: number;
6
+ change: number;
7
+ percent: number;
8
+ price_updated_at: string;
9
+ type: string;
10
+ sub_sector: string;
11
+ is_sharia: number;
12
+ ipo_date: string;
13
+ }
14
+ export interface RawStockResponse {
15
+ message: string;
16
+ data: Stock;
17
+ }
18
+ export interface Fund {
19
+ id: number;
20
+ name: string;
21
+ last_nav: number;
22
+ }
23
+ export interface RawFund {
24
+ id: number;
25
+ name: string;
26
+ nav?: {
27
+ value: number | null;
28
+ date: string | null;
29
+ first_date: string | null;
30
+ };
31
+ [key: string]: unknown;
32
+ }
33
+ export interface ApiResponse {
34
+ message: string;
35
+ data: string;
36
+ }
37
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,KAAK;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,gBAAgB,EAAE,MAAM,CAAC;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,KAAK,CAAC;CACb;AAED,MAAM,WAAW,IAAI;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;CAClB;AAGD,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE;QACJ,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;QACrB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;QACpB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;KAC3B,CAAC;IACF,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;CACd"}
package/dist/types.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@topanlabs/reksadana",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": ["dist"],
8
+ "scripts": {
9
+ "build": "tsc",
10
+ "test": "echo \"Error: no test specified\" && exit 1"
11
+ },
12
+ "keywords": [],
13
+ "author": "taufan",
14
+ "license": "MIT",
15
+ "type": "commonjs",
16
+ "dependencies": {
17
+ "axios": "^1.16.1",
18
+ "crypto-js": "^4.2.0"
19
+ },
20
+ "devDependencies": {
21
+ "@types/crypto-js": "^4.2.2",
22
+ "@types/node": "^25.9.1",
23
+ "ts-node": "^10.9.2",
24
+ "typescript": "^6.0.3"
25
+ }
26
+ }