npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@anhdn-mkt/mkt-business-meta

v0.1.2

Published

Business meta data for the marketing platform

Readme

mkt-business-meta

TypeScript library for Meta business automation flows:

  • Login (including 2FA)
  • Resolve business pages and page access tokens
  • Create Facebook posts and reels with media upload support

Built for Bun runtime.

Features

  • FbMetaClient with modular services: auth, businessPages, composer
  • Upload pipeline for:
    • image posts
    • video posts
    • mixed media posts
    • reels
  • File-path-first media input (filePath) with internal base64 conversion
  • Structured success/failure responses for all public APIs

Installation

bun add mkt-business-meta

For local development in this repo:

bun install

Quick Start

import { FbMetaClient } from 'mkt-business-meta'

const client = new FbMetaClient({
  appId: process.env.META_APP_ID!,
  appAccessToken: process.env.META_APP_ACCESS_TOKEN!,
  logLevel: 'info',
})

API Overview

1) Auth

const login = await client.auth.login({
  email: '[email protected]',
  password: 'your-password',
  // optional when account has 2FA
  twoFactorSecret: 'BASE32_SECRET',
})

Success response:

{
  success: true,
  data: {
    uid: string,
    accessToken: string,
    cookieHeader?: string,
    machineId?: string,
    cookies?: Array<{ name: string; value: string }>
  }
}

Error response:

{
  success: false,
  error: {
    message: string,
    code?: number,
    subcode?: number,
    raw?: unknown
  }
}

2) Business Pages / Page Tokens

const pageTokens = await client.businessPages.getPageAccessTokens({
  accessToken: '<USER_ACCESS_TOKEN>',
  // optional filter
  pageIds: ['1132154543308068'],
})

Success response:

{
  success: true,
  data: {
    pages: Array<{
      pageId: string,
      pageName?: string,
      actorId: string,
      accessToken: string,
      tokenSource: 'admin_info' | 'mailbox',
      scopeId?: string,
      scopeName?: string,
      scopeType?: string,
      fetchedAt: number
    }>,
    failedPages: Array<{
      pageId: string,
      pageName?: string,
      message: string
    }>,
    totalRequested: number,
    totalResolved: number,
    totalFailed: number
  }
}

Error response:

{
  success: false,
  error: {
    message: string,
    raw?: unknown
  }
}

3) Create Post

const post = await client.composer.createPost({
  pageId: '1132154543308068',
  accessToken: '<PAGE_ACCESS_TOKEN>',
  message: 'Hello from library',
  images: [
    { filePath: '/absolute/path/to/image-1.jpg' },
    { filePath: '/absolute/path/to/image-2.png' },
  ],
  videos: [{ filePath: '/absolute/path/to/video.mp4' }],
})

Success response:

{
  success: true,
  data: {
    postId: string,
    storyId: string,
    cacheId: string,
    postIdSource?: 'story' | 'video_fallback',
    channelErrors: Record<string, unknown>
  }
}

Error response:

{
  success: false,
  error: {
    message: string,
    raw?: unknown
  }
}

4) Create Reel

const reel = await client.composer.createReel({
  pageId: '1132154543308068',
  accessToken: '<PAGE_ACCESS_TOKEN>',
  // optional
  message: 'Reel caption',
  videos: [{ filePath: '/absolute/path/to/reel.mp4' }],
})

Success response:

{
  success: true,
  data: {
    postId: string,
    storyId: string,
    cacheId: string,
    postIdSource?: 'story' | 'video_fallback',
    channelErrors: Record<string, unknown>
  }
}

API Matrix

| API | Input | Success | Notes | | --- | --- | --- | --- | | auth.login | email, password, optional twoFactorSecret | uid, accessToken, optional cookies/machineId | Returns structured auth/session data | | businessPages.getPageAccessTokens | user access token, optional pageIds | list of page access tokens + failed pages summary | token source is admin_info or mailbox | | composer.createPost | page token, message, optional images/videos | postId, storyId, cacheId, postIdSource, channelErrors | single-video post can fallback postId = videoId | | composer.createReel | page token, one video, optional message | postId, storyId, cacheId, postIdSource, channelErrors | fallback postId = videoId when story id unavailable |

Error response:

{
  success: false,
  error: {
    message: string,
    raw?: unknown
  }
}

Exported Types

The package exports these public payload/response aliases from src/index.ts:

  • LoginPayload, LoginResponse
  • GetPageAccessTokensPayload, GetPageAccessTokensResponse
  • GetBusinessScopesResponse
  • CreatePostPayload, CreatePostResponse
  • CreateReelPayload, CreateReelResponse

Example:

import type {
  CreatePostPayload,
  CreatePostResponse,
  CreateReelPayload,
  CreateReelResponse,
  LoginPayload,
  LoginResponse,
} from 'mkt-business-meta'

Media Input Rules

  • images[].filePath is required for post images.
  • videos[].filePath is required for post/reel videos.
  • Library reads file content internally and sends base64 payload to Meta APIs.
  • Optional fields like filename, mimeType, and video metadata are supported.

Response Behavior

Create Post

  • content -> returns postId when story identifiers are available.
  • content + multiple images -> returns postId when story identifiers are available.
  • content + 1 video -> if story identifiers are missing, fallback postId = videoId.
  • content + multiple images + 1 video -> no video-id fallback; requires story identifiers.

Create Reel

  • only video -> returns postId from story when available; fallback postId = videoId.
  • text + video -> same behavior as above.

postIdSource values:

  • story: post id returned from story identifiers.
  • video_fallback: fallback from uploaded video id.

Error Shape

All services return either:

  • { success: true, data: ... }
  • { success: false, error: { message, raw? } }

Example:

{
  success: false,
  error: {
    message: 'There was a problem with this request. Try again later.',
    raw: unknown
  }
}

Development

bun run typecheck
bun run lint
bun test

Security Notes

  • Do not commit real access tokens.
  • Use environment variables for all credentials.
  • Revoke test tokens after validation.