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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@rlizana/odoo-rpc

v1.0.7

Published

A lightweight JS/TS library to interact with Odoo via JSON-RPC and session

Readme

odoo-rpc

Tests codecov npm npm GitHub

odoo-rpc is a lightweight JavaScript/TypeScript library to interact with Odoo (tested on Odoo 16, 17, 18) via JSON-RPC and session-based authentication.

It works in both Node.js and browser environments, making it suitable for frontend frameworks (Svelte, Vue, React) and backend scripts.


Features

  • Works with both Node.js and browser fetch
  • Automatic cookie handling (with fetch-cookie in Node)
  • Session-based login (/web/session/authenticate)
  • JSON-RPC calls to any Odoo model/method
  • Simplified API with env('model')
  • Report printing via /report/pdf/... (PDF download)
  • Built-in context and CSRF token support

How it works

Same code for Node.js and browser. The library uses fetch for HTTP requests, and in Node.js, it uses fetch-cookie to handle cookies automatically.

Install the library with npm

npm install @rlizana/odoo-rpc

Use it in your code:

import { Odoo } from '@rlizana/odoo-rpc'

const odoo = new Odoo('http://localhost:8069', 'test')
await odoo.login('admin', 'admin')

// Search and partners and read their names
let partners = await odoo
  .env('res.partner')
  .search([['name', 'ilike', 'Azure%']])
  .read(['name'])

// Modify a partner
let result = await odoo
  .env('res.partner')
  .write([partners[0].id], { name: 'New name' })

// Create a partner
let partner_id = await odoo
  .env('res.partner')
  .create({ name: 'New name' })

// Remove a partner
let result = await odoo
  .env('res.partner')
  .unlink([partner_id])

// Call any method
let names = await odoo
  .env('res.partner')
  .call('name_search', ['Azure%'], 0, 10)



Installation

Node.js

npm install @rlizana/odoo-rpc

Browser (ESM)

Use a bundler like Vite, Webpack or Rollup and import the browser version:

import { Odoo } from '@rlizana/odoo-rpc'

const odoo = new Odoo('http://localhost:8069', 'test')
await odoo.login('admin', 'admin')

Usage

1. Connect to Odoo

import { Odoo } from '@rlizana/odoo-rpc'

const odoo = new Odoo('http://localhost:8069', 'test')
await odoo.login('admin', 'admin')

console.log(is_loged()) // true if login was successful

2. Create a record

const id = await env('res.partner').create({
  name: 'My Partner'
})

3. Update a record

await env('res.partner').write([id], { email: '[email protected]' })

4. Search + Read

const partners = await env('res.partner')
  .search([['name', 'ilike', 'My']])
  .read(['name', 'email'])

5. Delete

await env('res.partner').unlink([id])

6. Call any method

await env('res.partner').call('default_get', [['name', 'email']])

7. Print a report (PDF)

const buffer = await env('sale.order').print('sale.report_saleorder', [7])
const blob = new Blob([buffer], { type: 'application/pdf' })
const url = URL.createObjectURL(blob)
window.open(url)

Usage in REPL (Interactive Testing)

The repl.ts script allows you to interactively test your connection and calls to Odoo in a Node.js terminal. It acts as a live sandbox where you can run methods like env('res.partner').search([]).read(['name']) and immediately see results from your Odoo instance.

To use it, just run:

npx tsx repl.ts

Or can use npm to run the script:

npm run shell

This will start a REPL session where you can type in your Odoo commands and see the results in real-time. It's a great way to test out different methods and see how they work without needing to write a full script. You can also use the REPL to test out different models and methods, making it a powerful tool for exploring the Odoo API.


Tests

To run unit and browser tests, you need an Odoo environment accessible at localhost:8069 with a database named odoo. You can easily set this up using Docker Compose:

docker compose -f tests/docker/docker-compose.yml up

This will start an Odoo container and a PostgreSQL container, exposing Odoo on port 8069 of your local machine and automatically creating the odoo database with user and password odoo.

Warning: Do not use a production database for testing. These tests may create, modify, and delete data. Always use a test database.

Once the environment is up, you can run the tests as many times as you want on the same database.

Unit tests (Node.js)

From the project root, run:

npm run test

This will run the unit tests using Vitest, connecting to the Docker Odoo.

Browser tests (Playwright)

To run end-to-end browser tests:

npm run test-browser

This will run the Playwright tests, also against the Odoo instance exposed at localhost:8069.