
* feat: ✨ add tax-classes-fetcher * refactor: ♻️ add "byId" suffix to crud-settings & remove upsert * feat: ✨ add updateMany method to CrudSettingsManager * feat: ✨ add avatax & taxjar tax-code-map-repository * refactor: 🚚 move to tax-code directory * feat: ✨ add getTaxCodes methods to provider clients * refactor: ♻️ extract taxClass and taxCode schema * refactor: 🚚 tax-code-map -> tax-code-match * feat: ✨ add taxjar-tax-code.service * feat: ✨ add avatax-tax-code.service * feat: ✨ add taxClass to graphql fragment * feat: ✨ use tax codes in calculate taxes * fix: 🐛 undefined tax code bug & add tests * build: 👷 add changeset * Update avatax-tax-code-mapper.ts * feat: ✨ add routers & get rid of adapters & mappers * refactor: ♻️ logger location -> name * refactor: ♻️ clean up & rephrase logs * refactor: ♻️ remove __typename from query * docs: 💡 make comments about tax codes more informative * refactor: ♻️ use resolveOptionalOrThrow on tax code description * refactor: ♻️ rename tax-codes -> tax-classes, move and rename tax-code-schema * refactor: 🚚 ctx -> authData * refactor: 🚚 createUrqlClientFromCtx -> createUrqlClientFromAuthdata * refactor: ♻️ dont spread ctx * docs: 💡 add comment about fallback tax code * refactor: ♻️ remove ..ctx * fix: 🐛 use createGraphQLClient * feat: tax code matcher ui (#658) * feat: ✨ use tax codes in calculate taxes * feat: ✨ add getTaxCodes methods to provider clients * feat: ✨ add matcher tables * feat: ✨ add log errors middleware * fix: 🔊 fix misleading logs * fix: 🐛 ctx appToken bug * feat: ✨ add Select override with wrapping label * feat: ✨ pre-select match * docs: 💡 add comments about first connection * docs: 💡 add comment about redirect * refactor: 🔥 duplicate file * feat: ✨ add AppCard to tables * feat: ✨ add _error to breadcrumbs exceptions * fix: 🐛 value not set on data * feat: 🥅 add error for no channels configured * fix: 🐛 replace update with upsert * refactor: 🚚 channel-configuration-settings to repository * fix: 🐛 updating a channel configuration * fix: 🧪 fix wrong mock * fix: 🐛 duplicating configs * Update cool-turtles-reflect.md
62 lines
1.8 KiB
TypeScript
62 lines
1.8 KiB
TypeScript
import TaxJar from "taxjar";
|
|
import { AddressParams, Config, CreateOrderParams, TaxParams } from "taxjar/dist/util/types";
|
|
import { createLogger, Logger } from "../../lib/logger";
|
|
import { TaxJarConfig } from "./taxjar-connection-schema";
|
|
|
|
const createTaxJarSettings = (config: TaxJarConfig): Config => {
|
|
const settings: Config = {
|
|
apiKey: config.credentials.apiKey,
|
|
apiUrl: config.isSandbox ? TaxJar.SANDBOX_API_URL : TaxJar.DEFAULT_API_URL,
|
|
};
|
|
|
|
return settings;
|
|
};
|
|
|
|
export type FetchTaxForOrderArgs = {
|
|
params: TaxParams;
|
|
};
|
|
|
|
export type CreateOrderArgs = {
|
|
params: CreateOrderParams;
|
|
};
|
|
|
|
export type ValidateAddressArgs = {
|
|
params: AddressParams;
|
|
};
|
|
|
|
export class TaxJarClient {
|
|
private client: TaxJar;
|
|
private logger: Logger;
|
|
|
|
constructor(providerConfig: TaxJarConfig) {
|
|
this.logger = createLogger({ name: "TaxJarClient" });
|
|
const settings = createTaxJarSettings(providerConfig);
|
|
const taxJarClient = new TaxJar(settings);
|
|
|
|
this.client = taxJarClient;
|
|
}
|
|
|
|
async fetchTaxForOrder({ params }: FetchTaxForOrderArgs) {
|
|
const response = await this.client.taxForOrder(params);
|
|
|
|
return response;
|
|
}
|
|
|
|
async createOrder({ params }: CreateOrderArgs) {
|
|
return this.client.createOrder(params);
|
|
}
|
|
|
|
/**
|
|
* TaxJar validateAddress doesn't work. It's turned off for now.
|
|
* @see https://github.com/taxjar/taxjar-node/issues/70
|
|
* @todo Revisit this when TaxJar fixes the issue. Alternatively, create a custom validation.
|
|
*/
|
|
async validateAddress({ params }: ValidateAddressArgs) {
|
|
// return this.client.validateAddress(params);
|
|
}
|
|
|
|
async getTaxCodes() {
|
|
// ! This function doesn't accept any params. This may be troublesome if we want to do pagination/filtering on the frontend.
|
|
return this.client.categories();
|
|
}
|
|
}
|