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

@pcassima/odoo-jsonrpc

v1.0.3

Published

JSON-RPC client for Odoo, using Typescript

Downloads

29

Readme

ODOO JSON-RPC

Simple package to connect to a Odoo database and access its data over JSON-RPC.

The package has full Typescript support.

Installation

npm i @pcassima/odoo-jsonrpc

Usage

Creating a new client

Assuming all credentials have been defined using environment variables, a client can be created as follows:

import { Client } from "@pcassima/odoo-jsonrpc";

const client = new Client({
    host: process.env.ODOO_HOST,
    db: process.env.ODOO_DB,
    port: process.env.ODOO_PORT,
    username: process.env.ODOO_USER,
    password: process.env.ODOO_PASS,
});

Searching for records

Search for records can easily be done with the search method:

const recordIds = await client.search(
    'product.template',
    [['sale_ok', '=', true]],
);

Additionally a limit, offset and order can be passed in:

const recordIds = await client.search(
    'product.template',
    [['sale_ok', '=', true]],
    80,          // limit
    40,          // offset
    "name DESC", // order
);

Typing

Types have been created for the following objects:

  • Odoo Domains
  • Odoo web_read specification

These can easily be imported using the following code:

import { type OdooDomain, type OdooWebReadSpecification } from "@pcassima/odoo-jsonrpc";

Astrojs

This package was intended to be used with Astrojs and specifically its object loaders.

An Odoo loader can easily be defined as follows

export function odooDataLoader(options: OdooDataLoaderOptions): Loader {
  return {
    name: "odoo-data-loader",
    async load({ store, logger, parseData }) {
      logger.info(`Fetching data from Odoo model: ${options.model}`);

      try {
        const client = new Client(options.config);
        const recordIds = await client.search(
          options.model,
          options.domain,
          options.limit,
          options.offset,
          options.order
        );
        const records = await client.webRead(options.model, recordIds, options.specification);

        logger.info(`Fetched ${records.length} from Odoo.`);

        (options.transform ? records.map(options.transform) : records).map((record: any) =>
          parseData({ id: String(record.id), data: record })
            .then((data) => {
              store.set({ id: String(data.id), data });
            })
            .catch((error) => logger.info(error))
        );
      } catch (error) {
        logger.error("Failed to fetch data from Odoo.");
        if (error instanceof Error) {
          logger.error(error.message);
        }
      }
    },
  };
}

Where the OdooDataLoaderOptions type is defined as follows:

export type OdooDataLoaderOptions = {
  config: Config;
  model: string;
  domain: OdooDomain;
  specification: OdooWebReadSpecification;
  limit?: number;
  offset?: number;
  order?: string;
  transform?: (record: any) => any;
};

The credentials can easily be provided using a .env file and used as follows:

export const odooConfig = {
  host: import.meta.env.ODOO_HOST,
  db: import.meta.env.ODOO_DB,
  port: import.meta.env.ODOO_PORT,
  username: import.meta.env.ODOO_USER,
  password: import.meta.env.ODOO_PASS,
};