0.0.4 • Published 10 months ago
bloks-parser v0.0.4
bloks-parser
Response parser utility for Meta's Bloks Framework.
🚀 Quick Start
Install:
# npm
npm i bloks-parser
# yarn
yarn add bloks-parser
Import:
// ESM / TypeScript
import { bloks } from "bloks-parser";
// CommonJS
const { bloks } = require("bloks-parser");
Usage:
const data = bloks(bloksResponse);
// { isError: boolean, isTwoFactor: boolean, isAuthenticated: boolean, data?: any, message?: string }
if (data.isTwoFactor) {
const {
pk,
username,
two_factor_identifier,
trusted_notification_polling_nonce,
device_id,
} = data.data!.two_factor_info!;
}
if (!data.isAuthenticated) {
throw new Error(data.message!);
}
if (data.isAuthenticated) {
const token = data.data!.headers?.["IG-Set-Authorization"].replace(
"Bearer IGT:2:",
"",
);
const {
pk, // <== number
pk_id, // <== string
username,
full_name,
is_private,
is_verified,
profile_pic_url,
} = data.data!.login_response!.logged_in_user;
}
🙌🏻 Contribution
- Clone repository
- Install dependencies with
yarn install
- Use
yarn dev
to start vitest watcher verifying changes - Use
yarn test
before pushing to ensure all tests and lint checks passing
📄 License
Code licensed under MIT License.