saleor-apps-redis_apl/apps/taxes/src/modules/avatax/avatax-client-tax-code.service.ts

31 lines
1 KiB
TypeScript
Raw Normal View History

feat: tax code matcher (#564) * feat: :sparkles: add tax-classes-fetcher * refactor: :recycle: add "byId" suffix to crud-settings & remove upsert * feat: :sparkles: add updateMany method to CrudSettingsManager * feat: :sparkles: add avatax & taxjar tax-code-map-repository * refactor: :truck: move to tax-code directory * feat: :sparkles: add getTaxCodes methods to provider clients * refactor: :recycle: extract taxClass and taxCode schema * refactor: :truck: tax-code-map -> tax-code-match * feat: :sparkles: add taxjar-tax-code.service * feat: :sparkles: add avatax-tax-code.service * feat: :sparkles: add taxClass to graphql fragment * feat: :sparkles: use tax codes in calculate taxes * fix: :bug: undefined tax code bug & add tests * build: :construction_worker: add changeset * Update avatax-tax-code-mapper.ts * feat: :sparkles: add routers & get rid of adapters & mappers * refactor: :recycle: logger location -> name * refactor: :recycle: clean up & rephrase logs * refactor: :recycle: remove __typename from query * docs: :bulb: make comments about tax codes more informative * refactor: :recycle: use resolveOptionalOrThrow on tax code description * refactor: :recycle: rename tax-codes -> tax-classes, move and rename tax-code-schema * refactor: :truck: ctx -> authData * refactor: :truck: createUrqlClientFromCtx -> createUrqlClientFromAuthdata * refactor: :recycle: dont spread ctx * docs: :bulb: add comment about fallback tax code * refactor: :recycle: remove ..ctx * fix: :bug: use createGraphQLClient * feat: tax code matcher ui (#658) * feat: :sparkles: use tax codes in calculate taxes * feat: :sparkles: add getTaxCodes methods to provider clients * feat: :sparkles: add matcher tables * feat: :sparkles: add log errors middleware * fix: :loud_sound: fix misleading logs * fix: :bug: ctx appToken bug * feat: :sparkles: add Select override with wrapping label * feat: :sparkles: pre-select match * docs: :bulb: add comments about first connection * docs: :bulb: add comment about redirect * refactor: :fire: duplicate file * feat: :sparkles: add AppCard to tables * feat: :sparkles: add _error to breadcrumbs exceptions * fix: :bug: value not set on data * feat: :goal_net: add error for no channels configured * fix: :bug: replace update with upsert * refactor: :truck: channel-configuration-settings to repository * fix: :bug: updating a channel configuration * fix: :test_tube: fix wrong mock * fix: :bug: duplicating configs * Update cool-turtles-reflect.md
2023-06-20 15:53:27 +00:00
import Avatax from "avatax";
import { createLogger, Logger } from "../../lib/logger";
import { FetchResult } from "avatax/lib/utils/fetch_result";
import { TaxCodeModel } from "avatax/lib/models/TaxCodeModel";
export class AvataxClientTaxCodeService {
// * These are the tax codes that we don't want to show to the user. For some reason, Avatax has them as active.
private readonly notSuitableKeys = ["Expired Tax Code - Do Not Use"];
private logger: Logger;
constructor(private client: Avatax) {
this.logger = createLogger({ name: "AvataxClientTaxCodeService" });
}
private filterOutInvalid(response: FetchResult<TaxCodeModel>) {
return response.value.filter((taxCode) => {
return (
taxCode.isActive &&
taxCode.description &&
!this.notSuitableKeys.includes(taxCode.description)
);
});
}
async getTaxCodes() {
// * If we want to do filtering on the front-end, we can use the `filter` parameter.
const result = await this.client.listTaxCodes({});
return this.filterOutInvalid(result);
}
}