@nivo-lat/sdk
v0.3.0
Published
Official Nivo SDK
Maintainers
Readme
@nivo-lat/sdk
Official Node.js SDK for Nivo.
Installation
npm install @nivo-lat/sdkUsage
import { NivoAPI } from '@nivo-lat/sdk'
const nivo = new NivoAPI('your-api-key')Get your API key from the Nivo dashboard under Settings > API Keys.
Auth
import { createClient } from '@nivo-lat/sdk'
const nivo = createClient('https://api.nivo.lat', 'nivo_pub_...')
await nivo.auth.signUp({ email: '[email protected]', password: 'secret123' })
await nivo.auth.signIn.withMagicLink({ email: '[email protected]' })
await nivo.auth.signIn.withSms({ phone: '+5511999999999' })
await nivo.auth.verifySmsOtp({ phone: '+5511999999999', token: '123456' })Managed Mail & SMS
Managed messaging requires a secret project key.
const nivo = createClient('https://api.nivo.lat', 'nivo_secret_...')
await nivo.mail.send({
to: '[email protected]',
subject: 'Welcome',
html: '<p>Hello from Nivo</p>',
})
await nivo.sms.send({
to: '+5511999999999',
message: 'Your code is 123456',
})Apps
// List all apps
const apps = await nivo.apps.list()
// Create a zip-upload app
const app = await nivo.apps.create({
name: 'customer-123-bot',
type: 'site',
buildSystem: 'nivopack',
runtime: 'node20',
startCmd: 'npm start',
sourceType: 'zip',
envVars: { CUSTOMER_TOKEN: 'secret' },
})
// Upload new code and wait for deployment
await nivo.apps.uploadAndWait(app.id, './app.zip')
// Create a GitHub app
const githubApp = await nivo.apps.create({
name: 'github-bot',
sourceType: 'github',
repoFullName: 'company/bot-template',
repoBranch: 'main',
startCmd: 'npm start',
})
// Deploy latest GitHub commit from the configured branch
await nivo.apps.deployAndWait(githubApp.id)
// Manage runtime
await nivo.apps.restart(app.id)
await nivo.apps.updateRam(app.id, 512)
const stats = await nivo.apps.stats(app.id)
// Fetch runtime logs
const logs = await nivo.apps.logs(app.id, { tail: 200 })
// Merge env vars without deleting existing keys
await nivo.apps.updateEnv(app.id, { CUSTOMER_TOKEN: 'new-token' })
// Explicit full replacement
await nivo.apps.replaceEnv(app.id, { ONLY_THIS: 'value' })Databases
// List databases
const databases = await nivo.databases.list()
// Create a database
const db = await nivo.databases.create({
name: 'customer_123',
password: 'strong-password',
engine: 'postgresql',
ramMb: 512,
})
await nivo.databases.restart(db.id)
await nivo.databases.updateRam(db.id, 1024)
const dbStats = await nivo.databases.stats(db.id)
// Execute a query
const result = await nivo.databases.query(db.id, 'SELECT * FROM users LIMIT 10')
// List tables
const tables = await nivo.databases.tables(db.id)
// Get rows from a table
const rows = await nivo.databases.tableRows(db.id, 'users', { limit: 50 })Storage
// List buckets
const buckets = await nivo.storage.listBuckets()
// Create a bucket
const bucket = await nivo.storage.createBucket({ name: 'customer-assets', public: false })
// Upload a file
const uploaded = await nivo.storage.upload(bucket.id, fileBuffer, {
filename: 'photo.png',
folder: 'avatars',
})
// List files
const files = await nivo.storage.listFiles(bucket.id)
// Signed private download URL
const url = await nivo.storage.signedUrl(uploaded.file.id)Error handling
import { NivoAPI, NivoError } from '@nivo-lat/sdk'
try {
await nivo.apps.get('invalid-id')
} catch (err) {
if (err instanceof NivoError) {
console.error(err.status, err.message)
}
}