npm.io
2.1.0 • Published 5h ago

onlinesim-js-api

Licence
Apache-2.0
Version
2.1.0
Deps
0
Size
299 kB
Vulns
0
Weekly
0
Stars
17

onlinesim-js-api

npm version CI

Typed JavaScript/TypeScript client for the OnlineSim API: SMS numbers, rent, account and free numbers. Zero runtime dependencies (global fetch), Node.js 18+ and browsers, ESM and CommonJS.

npm install onlinesim-js-api
import { OnlineSim } from 'onlinesim-js-api'

const client = new OnlineSim({ apiKey: process.env.ONLINESIM_KEY })

const { balance, zbalance } = await client.user.balance()
console.log(`available: ${balance - zbalance} USD`)

const { tzid, number } = await client.numbers.getWithNumber('google', 44)
console.log(`enter ${number} in the app`)
console.log('code:', await client.numbers.waitCode(tzid))

Testing

MockOnlineSim is a built-in offline fake of the API: test your integration without network, key or money. More in the testing guide.

import assert from 'node:assert/strict'
import { MockOnlineSim } from 'onlinesim-js-api'

const mock = new MockOnlineSim({ balance: 10 })
const client = mock.client()

const tzid = await client.numbers.get('google', 44)
mock.addSmsAfter(tzid, 'Your code: 123-456', 2) // arrives on the third poll
assert.equal(await client.numbers.waitCode(tzid, { interval: 0 }), '123456')
assert.equal(mock.balance(), 9.8)

Documentation: https://s00d.github.io/onlinesim-js-api/ · Changes: CHANGELOG.md · License: Apache-2.0

Keywords