textverified
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

NodeJS TextVerified API (v1)

license npm downloads GitHub last commit

📦 Installing

Using yarn:

yarn add textverified

Using npm:

npm install textverified

🛠️ Example

import 'dotenv/config';
import { TextVerifiedApi } from 'textverified';

const tvApi = new TextVerifiedApi();

export async function checkAuth(simpleTokenOrclientKey: string, clientSecret?: string) {
  tvApi.loadCache();
  if (clientSecret) {
    await tvApi.clientAuth(simpleTokenOrclientKey, clientSecret);
  } else {
    await tvApi.simpleAuth(simpleTokenOrclientKey);
  }
  if (!tvApi.isAuth) {
    throw new Error('TextVerified: unauthorized');
  }
}

export async function checkTargetGmail() {
  try {
    const targets = await tvApi.getTargets();
    return targets.find((target) => target.normalizedName === 'gmail');
  } catch (err: any) {
    console.log('[TextVerified] targets err', err.message);
  }
  return null;
}

export async function checkBalance() {
  try {
    const user = await tvApi.getUser();
    console.log('[TextVerified] users', user);
    return user.credit_balance;
  } catch (err: any) {
    console.log('[TextVerified] users err', err.message);
  }
  return null;
}

const main = async () => {
  const failTarget = await checkTargetGmail();
  console.log('[TextVerified] failTarget Gmail', failTarget);

  const simpleTokenOrclientKey = process.env.TV_SIMPLE_TOKEN || process.env.TV_CLIENT_KEY;
  const clientSecret = process.env.TV_CLIENT_SECRET;
  await checkAuth(simpleTokenOrclientKey!, clientSecret);

  const target = await checkTargetGmail();
  console.log('[TextVerified] target Gmail', target);

  // ...
  const balance = await checkBalance();
  console.log('[TextVerified] balance', balance);
};
main().then();

Readme

Keywords

Package Sidebar

Install

npm i textverified

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

26.2 kB

Total Files

12

Last publish

Collaborators

  • xtcry