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

28 lines
834 B
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 { AvataxClient } from "../avatax-client";
import { AvataxConfig } from "../avatax-connection-schema";
import type { TaxCode } from "../../taxes/tax-code";
import { FetchResult } from "avatax/lib/utils/fetch_result";
import { TaxCodeModel } from "avatax/lib/models/TaxCodeModel";
import { taxProviderUtils } from "../../taxes/tax-provider-utils";
export class AvataxTaxCodesService {
private client: AvataxClient;
constructor(config: AvataxConfig) {
this.client = new AvataxClient(config);
}
private adapt(taxCodes: TaxCodeModel[]): TaxCode[] {
return taxCodes.map((item) => ({
description: taxProviderUtils.resolveOptionalOrThrow(item.description),
code: item.taxCode,
}));
}
async getAll() {
const response = await this.client.getTaxCodes();
return this.adapt(response);
}
}