Dodo Payments Sync Engine
DodoSync is a JavaScript/TypeScript library and CLI tool designed to synchronize Dodo Payments data with various SQL and NoSQL databases. It currently supports MongoDB, PostgreSQL, MySQL, and ClickHouse, with plans to expand to Snowflake and other databases, as well as ETL/realtime sync pipelines. The current stable version is 0.4.0, with minor releases adding new database support and features like rate limiting. Releases appear to be driven by feature additions rather than a strict time-based cadence. It offers both a command-line interface for quick setup and programmatic usage for integration into larger applications, providing flexibility for developers to manage payment data locally. Key differentiators include its multi-database support and the ability to define specific data scopes for synchronization.
Common errors
-
Error: Missing required argument: --database
cause The `--database` argument was not provided when running the CLI.fixAdd the `--database` argument with a supported type, e.g., `--database mongodb`. -
Error: `database` option is required.
cause The `database` property was omitted from the `DodoSync` constructor options.fixInclude `database: 'mongodb'` (or 'postgres', 'mysql', 'clickhouse') in the DodoSync constructor options. -
Error: Failed to connect to database at mongodb://localhost:27017. Reason: Authentication failed.
cause Incorrect database URI, credentials, or network configuration preventing a successful database connection.fixVerify the `databaseURI` (CLI) or `databaseURI` option (programmatic) is correct, including hostname, port, user, and password. Ensure the database server is reachable and configured for remote connections if necessary. -
TypeError: DodoSync is not a constructor
cause Attempting to import `DodoSync` using a CommonJS `require` statement or an incorrect ESM default import.fixUse a named ESM import: `import { DodoSync } from 'dodo-sync';`. If still encountering issues in a CommonJS environment, ensure your project is configured for ESM or use dynamic `import()`.
Warnings
- gotcha CLI arguments (`--api-key`) and programmatic options (`bearerToken`) for the Dodo Payments API key use different naming conventions. Ensure you use the correct key name for your chosen method of integration.
- gotcha This library is in its early stages (v0.4.0) and while features are being added, the API might evolve in future minor or major versions. Review changelogs carefully during upgrades.
- gotcha Database connection URIs are highly specific to the database type (MongoDB, PostgreSQL, MySQL, ClickHouse). Providing an incorrect or malformed URI will prevent the sync engine from connecting.
- gotcha The `--scopes` CLI argument and `scopes` programmatic option require a comma-separated string (CLI) or an array of strings (programmatic) representing valid Dodo Payments data entities (e.g., 'payments', 'customers'). Invalid or misspelled scopes will result in no data synchronization for those entities.
Install
-
npm install dodo-sync -
yarn add dodo-sync -
pnpm add dodo-sync
Imports
- DodoSync
const DodoSync = require('dodo-sync');import { DodoSync } from 'dodo-sync'; - DodoSync (CLI)
node dodo-sync.js
dodo-sync --database mongodb --database-uri ... --api-key ... --scopes ...
- DodoPaymentsOptions
import { DodoPaymentsOptions } from 'dodo-sync';import type { DodoPaymentsOptions } from 'dodo-sync';
Quickstart
import { DodoSync } from 'dodo-sync';
const syncDodoPayments = new DodoSync({
interval: 60, // Sync every 60 seconds
database: 'mongodb',
databaseURI: process.env.MONGODB_URI ?? 'mongodb://localhost:27017/dodo',
scopes: ['licences', 'payments', 'customers', 'subscriptions'],
dodoPaymentsOptions: {
bearerToken: process.env.DODO_PAYMENTS_API_KEY ?? 'dp_test_someapikey',
environment: 'test_mode' // or 'live_mode'
}
});
// Initialize connection
await syncDodoPayments.init();
// Start the sync loop
syncDodoPayments.start();
console.log('DodoSync started. Data will be synchronized every 60 seconds.');