tres-aries-wrapper
v1.0.3
Published
A wrapper for the aries-markets library
Maintainers
Readme
tres-aries-wrapper
A CommonJS (CJS) Wrapper for the @aries-markets/api (ESM) Library This project provides a simple, asynchronous wrapper that allows developers using a CommonJS module system (like many older Node.js projects, NestJS, or serverless functions) to easily access the functionality of the modern, ESM-only @aries-markets/api library without converting their entire project to ESM.
🚀 Installation
Install this wrapper package instead of the original ESM library:
npm install tres-aries-wrapper
💡 Usage inside a NestJS project (CommonJS)
import { getAriesApi } from 'tres-aries-wrapper';
import { Injectable } from '@nestjs/common';
@Injectable()
export class AptosService {
// Use the API inside an async method
async fetchAddressProfile() {
const ariesApi = await getAriesApi();
const client = ariesApi.getClient(API_URL);
const profile = await client.profile.find.query({ owner: walletAddress });
return profile;
}
}⚙️ How It Works
This wrapper solves the fundamental Node.js error: Error [ERR_REQUIRE_ESM].
The wrapper's internal index.js file is standard CommonJS.
It uses the dynamic import('@aries-markets/api') call, which is the only way for CJS to load an ESM module. This call is inherently asynchronous.
The getAriesApi() function returns the Promise that resolves once the underlying ESM library is loaded, giving you access to all its exports without breaking your main project's CJS module structure.
