#!/usr/bin/env node /** * VIU Premium Account Wrapper (viu.interflazz.my.id) * Node.js ESM — output JSON pretty print * * Usage: * node viu.js * node viu.js --device-id=abc123 * DEVICE_ID=abc123 node viu.js */ import { createHash, randomBytes } from 'node:crypto'; import { parseArgs } from 'node:util'; const BASE_URL = 'https://viu.interflazz.my.id/?action=account'; const DEFAULT_HEADERS = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36', Accept: 'application/json', 'Content-Type': 'application/json', Origin: 'https://viu.interflazz.my.id', Referer: 'https://viu.interflazz.my.id/', }; /** * Generate device_id mirip fingerprint browser (32 hex chars) */ function generateDeviceId(seed = null) { if (seed) { return createHash('md5').update(String(seed)).digest('hex'); } return randomBytes(16).toString('hex'); } /** * Ambil akun VIU berdasarkan device_id * @param {string} deviceId * @returns {Promise} */ export async function getViuAccount(deviceId) { const res = await fetch(BASE_URL, { method: 'POST', headers: DEFAULT_HEADERS, body: JSON.stringify({ device_id: deviceId }), }); if (!res.ok) { throw new Error(`HTTP ${res.status}: ${res.statusText}`); } const data = await res.json(); if (!data.success) { throw new Error(data.message || 'Gagal mengambil akun'); } return { success: data.success, message: data.message, is_new: data.is_new, device_id: data.device_id, account: { email: data.account?.email ?? null, password: data.account?.password ?? null, }, fetched_at: new Date().toISOString(), }; } // CLI async function main() { const { values } = parseArgs({ options: { 'device-id': { type: 'string', short: 'd' }, help: { type: 'boolean', short: 'h' }, }, allowPositionals: false, }); if (values.help) { console.log(` Usage: node viu.js node viu.js --device-id node viu.js -d Env: DEVICE_ID=... (prioritas lebih rendah dari --device-id) `); process.exit(0); } const deviceId = values['device-id'] || process.env.DEVICE_ID || generateDeviceId(); try { const result = await getViuAccount(deviceId); console.log(JSON.stringify(result, null, 2)); } catch (err) { console.error( JSON.stringify( { success: false, error: err.message, device_id: deviceId, }, null, 2 ) ); process.exit(1); } } // Jalankan hanya jika file ini dieksekusi langsung const isMain = process.argv[1] && (import.meta.url.endsWith(process.argv[1].replace(/\\/g, '/')) || process.argv[1].endsWith('viu.js')); if (isMain) { main(); }