Why use the Midaz SDK for TypeScript?
- Type-safe by design: Full TypeScript support with precise type definitions.
- Builder pattern: Fluent, readable interfaces to construct complex objects.
- Error handling: Clear error signals.
- Observability included: Tracing, metrics, and logs, off by default.
- Layered architecture: Clean separation between client, entities, API, and models.
- Automatic retries: Retries for transient failures.
- Concurrency controls: Built-in tools to run tasks in parallel with controlled throughput.
- Strict validation: Catch invalid input early with clear error messages.
Getting started
Prerequisite
- The Midaz SDK for TypeScript requires Node.js v18.18 to v24 and TypeScript v5.8 or later.
Installing the SDK
Install the Midaz SDK for TypeScript with one of the following commands:Authentication
The Midaz SDK for TypeScript authenticates through the Lerian Access Manager (OAuth). For a local stack with authentication disabled, you can build a client without it. You never call a
createClient factory. Build a configuration with createClientConfigWithAccessManager() (or createClientConfigBuilder() for a no-auth local stack) and pass it to new MidazClient(config).
Access Manager authentication
To integrate with external identity providers over OAuth:Local development (no authentication)
For a local Midaz stack with authentication disabled, build a client without the Access Manager:Quick start guide
The following sections give practical code examples for the Midaz SDK for TypeScript.
Create a client
The client is your main entry point to the SDK. It handles authentication and gives you access to all entity services. Example:withEnvironment() presets use example URLs. Set your Midaz address with withBaseUrls() or the MIDAZ_ONBOARDING_URL and MIDAZ_TRANSACTION_URL environment variables. Both URLs point to your Midaz ledger.
Create an Asset
Create assets with the builder pattern andcreateAssetBuilder.
Example:
name and code fields to the builder const assetInput = createAssetBuilder('US Dollar', 'USD'). Then you add any other properties with with* methods.
Create an Account
Create accounts with the builder pattern andcreateAccountBuilder.
Example:
name, assetCode, and account type to the builder const accountInput = createAccountBuilder('Savings Account', 'USD', 'savings'). Then you add any other properties with with* methods.
Create a Transaction
Create transactions with aCreateTransactionInput object and createTransaction.
Example:
send holds the amount. source.from lists the accounts that send it, and distribute.to lists the accounts that receive it. Each account is an account alias. Amounts are decimal strings.
Clean up resources
Using Access Manager for authentication
SDK architecture
The Midaz SDK uses a multi-layered service architecture. It has three layers, shown in Figure 1. Each layer serves a distinct purpose.
- Client interface: This is the main entry point for SDK users. It manages configuration such as authentication and environments. It gives access to the entity services through
client.entities. - Entity services layer: This layer holds domain-specific services, such as Accounts, Assets, and Transactions. Most services offer create, get, update, delete, and list methods. Some services also add specialized operations for their entity.
- Core services layer: All entity services use these foundational utilities. They handle HTTP requests, input validation, error processing, observability, and configuration.
Figure 1. The layered architecture of the Midaz SDK for TypeScript.
- Consistency through shared patterns across services.
- Scalability via dependency injection and service factories.
- Reliability through enhanced error handling and typed responses.
- Testability with support for mocking and integration testing.
Builder pattern
The Midaz SDK for TypeScript uses a builder pattern to help you assemble complex objects in a safe, adaptable way. Instead of a fixed set of inputs, it gives you a step-by-step, fluent, chainable interface. Builder functions in the SDK:
- Tell you the parameters in advance.
- Let you set optional fields with
.with*()methods and chain them. - Hide internal complexity for better readability.
Example
assetInput to the corresponding create method in the SDK.
Working with entities
Each entity service covers a distinct part of the financial domain, such as accounts, assets, or transactions. These services read and write data for each type of entity. They also offer specialized features for each use case.
You access each service through the SDK client. They follow a consistent structure, so you build and maintain financial features more easily.
Using utilities
The SDK provides utility modules for common operations: performance, error handling, configuration, and observability.
Error handling
The Midaz SDK for TypeScript helps you handle errors clearly and consistently. When an SDK operation fails, the SDK throws an error. An API error response throws an
HttpError with these fields:
status: The HTTP status code.statusText: The HTTP status text.response: The error body from Midaz.
ValidationError before the request. Use processError() to read both types in one shape.
Handle an error like this:
Best practices
- Validate input before you call SDK methods.
- Check your auth when you get status
401or403. - Retry on transient issues like status
500or503. - Use
statusCodeandmessageto show debug info in development logs.
CI/CD pipeline
We use GitHub Actions for automated, production-ready builds:
- Runs tests across multiple Node.js versions.
- Enforces code quality with ESLint and Prettier.
- Keeps dependencies up to date with Dependabot.
- Handles releases automatically with semantic versioning.
- Generates changelogs.
Want to contribute?
To contribute to the Midaz SDK for TypeScript, start with our contributing guide on GitHub.
License
This project is licensed under the Apache License 2.0. For details, see the License page.

