@ntegral/nestjs-taxjar
Provides an injectable taxjar client to provide access to taxjar sales tax api in nestjs modules
Table Of Contents
About
@ntegral/nestjs-taxjar
implements a module, TaxJarModule
, which when imported into
your nestjs project provides a Taxjar client to any class that injects it. This
lets TaxJar Sales Tax API be worked into your dependency injection workflow without having to
do any extra work outside of the initial setup.
Installation
npm install --save @ntegral/nestjs-taxjar taxjar
Getting Started
The simplest way to use @ntegral/nestjs-taxjar
is to use TaxJarModule.forRoot
import { Module } from '@nestjs-common';
import { TaxJarModule } from '@ntegral/nestjs-taxjar';
@Module({
imports: [
TaxJarModule.forRoot({
apiKey: 'taxjar_api_key'
}),
],
})
export class AppModule {}
The async way @ntegral/nestjs-taxjar
is to use TaxJarModule.forRootAsync
import { Module } from '@nestjs-common';
import { TaxJarModule } from '@ntegral/nestjs-taxjar';
import { ConfigModule } from '@ntegral/nestjs-config';
import { ConfigService } from '@ntegral/nestjs-config';
@Module({
imports: [
TaxJarModule.forRootAsync({
imports: [ConfigModule],
useFactory: async (cfg:ConfigService) => ({
apiKey: cfg.get('TAXJAR_API_KEY')
}),
inject: [ConfigService],
})
]
})
export class AppModule {}
You can then inject the Taxjar client into any of your injectables by using a custom decorator
import { Injectable } from '@nestjs/common';
import { InjectTaxJar } from '@ntegral/nestjs-taxjar';
import Taxjar = require('taxjar');
@Injectable()
export class AppService {
public constructor(@InjectTaxJar() private readonly client: Taxjar) {
client.ratesForLocation('30339').then(res => {
res.rate; //rate object
});
... and more
}
}
Contributing
I would greatly appreciate any contributions to make this project better. Please make sure to follow the below guidelines before getting your hands dirty.
- Fork the repository
- Create your branch (
git checkout -b my-branch
) - Commit any changes to your branch
- Push your changes to your remote branch
- Open a pull request
License
Distributed under the ISC License. See LICENSE
for more information.
Acknowledgements
Copyright © 2020 Ntegral Inc.