UNPKG

valzyysdk

Version:

CLI dan modul untuk mengakses data dari API JKT48Connect, termasuk data member, teater, event, pembayaran, dan lainnya.

209 lines (192 loc) 8.84 kB
#!/usr/bin/env node // Import version checker const RuntimeVersionChecker = require('./version-checker'); // Initialize version checker - CHECK HAPPENS ON EVERY REQUIRE! const versionChecker = new RuntimeVersionChecker('@jkt48connect-corp/sdk'); // IMMEDIATE VERSION CHECK - This runs as soon as module is required let versionCheckPromise = null; function ensureVersionCheck() { if (!versionCheckPromise) { versionCheckPromise = versionChecker.enforceLatestVersion(); } return versionCheckPromise; } // Import all modules const checkApiKey = require("./modules/checkApiKey"); const { getTheater, getTheaterDetail } = require("./modules/jkt48-theater"); const { getEvents, getEventDetail } = require("./modules/jkt48-events"); const { getMemberDetail, getAllMembers, getBirthdayMembers} = require("./modules/jkt48-member"); const { getLive, getRecentLive, getIdn, getShowroom, getDetailRecentLive } = require("./modules/jkt48-live"); const { createPayment, checkPaymentStatus } = require("./modules/payment"); const { getNews, getNewsDetail } = require("./modules/jkt48-news"); const { getBrat } = require("./modules/brat"); const { downloadTiktok } = require("./modules/downloader"); const { Pinterest } = require("./modules/pinterest"); const { getYoutube, getReplay } = require("./modules/jkt48-youtube"); // Wrapper that ensures version check before ANY function execution function createProtectedFunction(originalFunction, functionName) { return async function(...args) { try { // CRITICAL: This check happens EVERY TIME function is called await ensureVersionCheck(); // Only execute original function if version check passes return await originalFunction(...args); } catch (error) { // If it's a version error, re-throw to stop execution if (error.message && (error.message.includes('outdated') || error.code === 1)) { throw new Error(`❌ Cannot execute ${functionName}: Package version is outdated. Please update first.`); } // For other errors, log and re-throw console.error(`Error in ${functionName}:`, error.message); throw error; } }; } // Create protected versions of ALL exported functions const protectedFunctions = { checkApiKey: createProtectedFunction(checkApiKey, 'checkApiKey'), getTheater: createProtectedFunction(getTheater, 'getTheater'), getTheaterDetail: createProtectedFunction(getTheaterDetail, 'getTheaterDetail'), getEvents: createProtectedFunction(getEvents, 'getEvents'), getEventDetail: createProtectedFunction(getEventDetail, 'getEventDetail'), getMemberDetail: createProtectedFunction(getMemberDetail, 'getMemberDetail'), getAllMembers: createProtectedFunction(getAllMembers, 'getAllMembers'), getLive: createProtectedFunction(getLive, 'getLive'), getRecentLive: createProtectedFunction(getRecentLive, 'getRecentLive'), createPayment: createProtectedFunction(createPayment, 'createPayment'), checkPaymentStatus: createProtectedFunction(checkPaymentStatus, 'checkPaymentStatus'), getNews: createProtectedFunction(getNews, 'getNews'), getNewsDetail: createProtectedFunction(getNewsDetail, 'getNewsDetail'), getBrat: createProtectedFunction(getBrat, 'getBrat'), getBirthdayMembers: createProtectedFunction(getBirthdayMembers, 'getBirthdayMembers'), downloadTiktok: createProtectedFunction(downloadTiktok, 'downloadTiktok'), getIdn: createProtectedFunction(getIdn, 'getIdn'), getShowroom: createProtectedFunction(getShowroom, 'getShowroom'), Pinterest: createProtectedFunction(Pinterest, 'Pinterest'), getYoutube: createProtectedFunction(getYoutube, 'getYoutube'), getDetailRecentLive: createProtectedFunction(getDetailRecentLive, 'getDetailRecentLive'), getReplay: createProtectedFunction(getReplay, 'getReplay'), }; // CLI usage if (require.main === module) { const args = process.argv.slice(2); const command = args[0]; const apiKey = args[1]; const id = args[2]; // VERSION CHECK HAPPENS IMMEDIATELY FOR CLI USAGE ensureVersionCheck().then(() => { if (!command || !apiKey) { console.log(` Usage: <command> <api_key> [additional_params] Commands: check, theater, events, eventDetail, theaterDetail, memberDetail, recentDetail, Birthday, Brat, Tiktok, allMembers, live, IdnLive, ShowroomLive, recentLive, createPayment, checkPaymentStatus, news, newsDetail, Youtube, replayYoutube, Pinterest For detailed documentation, please visit: https://docs.jkt48connect.my.id For more features and the latest updates, please use the newest module version: @jkt48/core This new version includes the Growagarden feature and many more JKT48 features. `); process.exit(1); } // Execute commands - version already checked above switch (command) { case "check": checkApiKey(apiKey).then((data) => console.log(data)).catch(console.error); break; case "theater": getTheater(apiKey).then((data) => console.log(data)).catch(console.error); break; case "events": getEvents(apiKey).then((data) => console.log(data)).catch(console.error); break; case "eventDetail": if (!id) return console.error("Error: Event ID is required for eventDetail."); getEventDetail(apiKey, id).then((data) => console.log(data)).catch(console.error); break; case "theaterDetail": if (!id) return console.error("Error: Theater ID is required for theaterDetail."); getTheaterDetail(apiKey, id).then((data) => console.log(data)).catch(console.error); break; case "memberDetail": if (!id) return console.error("Error: Member ID is required for memberDetail."); getMemberDetail(apiKey, id).then((data) => console.log(data)).catch(console.error); break; case "allMembers": getAllMembers(apiKey).then((data) => console.log(data)).catch(console.error); break; case "live": getLive(apiKey).then((data) => console.log(data)).catch(console.error); break; case "recentLive": getRecentLive(apiKey).then((data) => console.log(data)).catch(console.error); break; case "IdnLive": getIdn(apiKey).then((data) => console.log(data)).catch(console.error); break; case "recentDetail": if (!id) return console.error("Error: Data ID is required for recentDetail."); getDetailRecentLive(id, apiKey).then((data) => console.log(data)).catch(console.error); break; case "ShowroomLive": getShowroom(apiKey).then((data) => console.log(data)).catch(console.error); break; case "YouTube": getYoutube(apiKey).then((data) => console.log(data)).catch(console.error); break; case "replayYoutube": getReplay(apiKey).then((data) => console.log(data)).catch(console.error); break; case "Birthday": getBirthdayMembers(apiKey).then((data) => console.log(data)).catch(console.error); break; case "createPayment": const amount = args[2]; const qris = args[3]; if (!amount || !qris) return console.error("Error: Amount and QR Code are required for createPayment."); createPayment(apiKey, amount, qris); break; case "Brat": const text = args[2]; if (!text) return console.error("Error: text are required for brat."); getBrat(apiKey, text); break; case "Pinterest": const query = args[2]; if (!query) return console.error("Error: query are required for pinterest."); Pinterest(apiKey, query); break; case "Tiktok": const url = args[2]; if (!url) return console.error("Error: url are required for Tiktok downloader."); downloadTiktok(apiKey, url); break; case "checkPaymentStatus": const merchantId = args[2]; const keyOrkut = args[3]; if (!merchantId || !keyOrkut) return console.error("Error: Merchant ID and Key Orkut are required for checkPaymentStatus."); checkPaymentStatus(apiKey, merchantId, keyOrkut); break; case "news": getNews(apiKey).then((data) => console.log(data)).catch(console.error); break; case "newsDetail": if (!id) return console.error("Error: News ID is required for newsDetail."); getNewsDetail(apiKey, id).then((data) => console.log(data)).catch(console.error); break; default: console.error("Error: Invalid command."); } }).catch((error) => { console.error('❌ Failed to initialize package:', error.message); process.exit(1); }); } // EXPORT PROTECTED FUNCTIONS - Version check happens on EVERY function call module.exports = protectedFunctions;