saleor-apps-redis_apl/apps/taxes/src/modules/avatax/avatax-configuration.service.ts

109 lines
3.5 KiB
TypeScript
Raw Normal View History

import { Client } from "urql";
import { createLogger, Logger } from "../../lib/logger";
feat: finalize order process (#355) * feat: :sparkles: add dummy order-created * refactor: :fire: unused private-providers-configuration-service * feat: :sparkles: add dummy order-fulfilled * refactor: :truck: move provider-config * refactor: :truck: crudSettingsConfigurator -> crudSettingsManager * refactor: :recycle: [tax-provider].ts -> [tax-provider]-webhook.service.ts * feat: :sparkles: add dummy createOrder * refactor: :recycle: distinguish between salesOrder and salesInvoice in avatax * refactor: :truck: [provider]-calculate.ts to [provider]-transform.ts * refactor: :truck: ResponseTaxPayload to tax-provider-webhook.ts * refactor: :truck: ResponseTaxPayload -> CalculateTaxesResponse * refactor: :recycle: webhooks with active-tax-provider.service.ts * feat: :sparkles: add skeleton orderCreate functionality * refactor: :recycle: [provider]-transform.ts -> [provider]-[webhook]-transform.ts * feat: :sparkles: add order-fulfilled with avatax call * refactor: :recycle: move getActiveTaxProvider to active-tax-provider * refactor: :label: export types for [provider]-client function args * refactor: :truck: UpdateAppMetadata -> UpdateMetadata * feat: :sparkles: fulfill order with id from metadata * build: :arrow_up: upgrade avatax * feat: :sparkles: commit transaction on fulfill in avatax * fix: :bug: return of webhooks to ensure valid retry behavior * refactor: :truck: [provider]-[webhook]-transform -> [provider]-[webhook]-map * refactor: :label: export types of avatax-calculate-taxes mapPayload * refactor: :recycle: extract address-map to separate function * refactor: :recycle: remove schema.ts * refactor: :recycle: move addressSchema to channels-config.ts * feat: :sparkles: add tests & placeholder tests for avatax & taxjar maps * refactor: :recycle: throw error if no metadata * refactor: :recycle: change EXTERNAL_ID_KEY to PROVIDER_ORDER_ID_KEY add comments * refactor: :recycle: comments -> it.todo in tests * refactor: :bulb: add comment about shipping_item_code * refactor: :white_check_mark: add todo items for tests * refactor: :recycle: remove export and add sumLines to taxJarOrderCreated * refactor: :recycle: address-map with avatarAddressFactory * docs: :bulb: add comment about MOCKED_SALEOR_PAYLOAD * refactor: :recycle: remove export of mapLines and add to avataxCalculateTaxes * style: :art: add newline-after-var warn to eslint-config-saleor * style: :art: autofix newline-after-var in taxes * test: :white_check_mark: restructure tests according to new naming in address-map * refactor: :recycle: add shippingItemCode to avataxCalculateTaxes wrapper object * refactor: :truck: payloadProps -> payloadArgs * refactor: :recycle: add Maps suffix to map wrapper objects * refactor: :recycle: remove data: null from ActiveTaxProviderResult * refactor: :recycle: maintain the object hierarchy in tests * refactor: :recycle: refactor webhook responses with WebhookResponseFactory * build: :arrow_up: vitest * test: :white_check_mark: add tests for get-app-config-test * test: :white_check_mark: add tests for getActiveTaxProvider * refactor: :recycle: use address fragment for taxBase and order * refactor: :recycle: rename WebhookResponseFactory -> WebhookResponse * style: :construction_worker: add multiline-comment-style * fix: :bug: dummy test in get-app-config.test.ts * refactor: :recycle: rename AddressFragment -> Address * refactor: :recycle: use debug instead of error in webhook-response noRetry * refactor: :recycle: refactor as variables in mutation * build: :construction_worker: add changeset * refactor: :recycle: split changesets in two * build: :arrow_up: vite * build: :arrow_up: vite && vitest in all apps
2023-04-17 11:58:21 +00:00
import { createSettingsManager } from "../app/metadata-manager";
import { CrudSettingsManager } from "../crud-settings/crud-settings.service";
import { providersSchema } from "../providers-configuration/providers-config";
import { TAX_PROVIDER_KEY } from "../providers-configuration/public-providers-configuration-service";
import { AvataxClient } from "./avatax-client";
import { AvataxConfig, AvataxInstanceConfig, avataxInstanceConfigSchema } from "./avatax-config";
const getSchema = avataxInstanceConfigSchema;
feat: finalize order process (#355) * feat: :sparkles: add dummy order-created * refactor: :fire: unused private-providers-configuration-service * feat: :sparkles: add dummy order-fulfilled * refactor: :truck: move provider-config * refactor: :truck: crudSettingsConfigurator -> crudSettingsManager * refactor: :recycle: [tax-provider].ts -> [tax-provider]-webhook.service.ts * feat: :sparkles: add dummy createOrder * refactor: :recycle: distinguish between salesOrder and salesInvoice in avatax * refactor: :truck: [provider]-calculate.ts to [provider]-transform.ts * refactor: :truck: ResponseTaxPayload to tax-provider-webhook.ts * refactor: :truck: ResponseTaxPayload -> CalculateTaxesResponse * refactor: :recycle: webhooks with active-tax-provider.service.ts * feat: :sparkles: add skeleton orderCreate functionality * refactor: :recycle: [provider]-transform.ts -> [provider]-[webhook]-transform.ts * feat: :sparkles: add order-fulfilled with avatax call * refactor: :recycle: move getActiveTaxProvider to active-tax-provider * refactor: :label: export types for [provider]-client function args * refactor: :truck: UpdateAppMetadata -> UpdateMetadata * feat: :sparkles: fulfill order with id from metadata * build: :arrow_up: upgrade avatax * feat: :sparkles: commit transaction on fulfill in avatax * fix: :bug: return of webhooks to ensure valid retry behavior * refactor: :truck: [provider]-[webhook]-transform -> [provider]-[webhook]-map * refactor: :label: export types of avatax-calculate-taxes mapPayload * refactor: :recycle: extract address-map to separate function * refactor: :recycle: remove schema.ts * refactor: :recycle: move addressSchema to channels-config.ts * feat: :sparkles: add tests & placeholder tests for avatax & taxjar maps * refactor: :recycle: throw error if no metadata * refactor: :recycle: change EXTERNAL_ID_KEY to PROVIDER_ORDER_ID_KEY add comments * refactor: :recycle: comments -> it.todo in tests * refactor: :bulb: add comment about shipping_item_code * refactor: :white_check_mark: add todo items for tests * refactor: :recycle: remove export and add sumLines to taxJarOrderCreated * refactor: :recycle: address-map with avatarAddressFactory * docs: :bulb: add comment about MOCKED_SALEOR_PAYLOAD * refactor: :recycle: remove export of mapLines and add to avataxCalculateTaxes * style: :art: add newline-after-var warn to eslint-config-saleor * style: :art: autofix newline-after-var in taxes * test: :white_check_mark: restructure tests according to new naming in address-map * refactor: :recycle: add shippingItemCode to avataxCalculateTaxes wrapper object * refactor: :truck: payloadProps -> payloadArgs * refactor: :recycle: add Maps suffix to map wrapper objects * refactor: :recycle: remove data: null from ActiveTaxProviderResult * refactor: :recycle: maintain the object hierarchy in tests * refactor: :recycle: refactor webhook responses with WebhookResponseFactory * build: :arrow_up: vitest * test: :white_check_mark: add tests for get-app-config-test * test: :white_check_mark: add tests for getActiveTaxProvider * refactor: :recycle: use address fragment for taxBase and order * refactor: :recycle: rename WebhookResponseFactory -> WebhookResponse * style: :construction_worker: add multiline-comment-style * fix: :bug: dummy test in get-app-config.test.ts * refactor: :recycle: rename AddressFragment -> Address * refactor: :recycle: use debug instead of error in webhook-response noRetry * refactor: :recycle: refactor as variables in mutation * build: :construction_worker: add changeset * refactor: :recycle: split changesets in two * build: :arrow_up: vite * build: :arrow_up: vite && vitest in all apps
2023-04-17 11:58:21 +00:00
export class AvataxConfigurationService {
feat: finalize order process (#355) * feat: :sparkles: add dummy order-created * refactor: :fire: unused private-providers-configuration-service * feat: :sparkles: add dummy order-fulfilled * refactor: :truck: move provider-config * refactor: :truck: crudSettingsConfigurator -> crudSettingsManager * refactor: :recycle: [tax-provider].ts -> [tax-provider]-webhook.service.ts * feat: :sparkles: add dummy createOrder * refactor: :recycle: distinguish between salesOrder and salesInvoice in avatax * refactor: :truck: [provider]-calculate.ts to [provider]-transform.ts * refactor: :truck: ResponseTaxPayload to tax-provider-webhook.ts * refactor: :truck: ResponseTaxPayload -> CalculateTaxesResponse * refactor: :recycle: webhooks with active-tax-provider.service.ts * feat: :sparkles: add skeleton orderCreate functionality * refactor: :recycle: [provider]-transform.ts -> [provider]-[webhook]-transform.ts * feat: :sparkles: add order-fulfilled with avatax call * refactor: :recycle: move getActiveTaxProvider to active-tax-provider * refactor: :label: export types for [provider]-client function args * refactor: :truck: UpdateAppMetadata -> UpdateMetadata * feat: :sparkles: fulfill order with id from metadata * build: :arrow_up: upgrade avatax * feat: :sparkles: commit transaction on fulfill in avatax * fix: :bug: return of webhooks to ensure valid retry behavior * refactor: :truck: [provider]-[webhook]-transform -> [provider]-[webhook]-map * refactor: :label: export types of avatax-calculate-taxes mapPayload * refactor: :recycle: extract address-map to separate function * refactor: :recycle: remove schema.ts * refactor: :recycle: move addressSchema to channels-config.ts * feat: :sparkles: add tests & placeholder tests for avatax & taxjar maps * refactor: :recycle: throw error if no metadata * refactor: :recycle: change EXTERNAL_ID_KEY to PROVIDER_ORDER_ID_KEY add comments * refactor: :recycle: comments -> it.todo in tests * refactor: :bulb: add comment about shipping_item_code * refactor: :white_check_mark: add todo items for tests * refactor: :recycle: remove export and add sumLines to taxJarOrderCreated * refactor: :recycle: address-map with avatarAddressFactory * docs: :bulb: add comment about MOCKED_SALEOR_PAYLOAD * refactor: :recycle: remove export of mapLines and add to avataxCalculateTaxes * style: :art: add newline-after-var warn to eslint-config-saleor * style: :art: autofix newline-after-var in taxes * test: :white_check_mark: restructure tests according to new naming in address-map * refactor: :recycle: add shippingItemCode to avataxCalculateTaxes wrapper object * refactor: :truck: payloadProps -> payloadArgs * refactor: :recycle: add Maps suffix to map wrapper objects * refactor: :recycle: remove data: null from ActiveTaxProviderResult * refactor: :recycle: maintain the object hierarchy in tests * refactor: :recycle: refactor webhook responses with WebhookResponseFactory * build: :arrow_up: vitest * test: :white_check_mark: add tests for get-app-config-test * test: :white_check_mark: add tests for getActiveTaxProvider * refactor: :recycle: use address fragment for taxBase and order * refactor: :recycle: rename WebhookResponseFactory -> WebhookResponse * style: :construction_worker: add multiline-comment-style * fix: :bug: dummy test in get-app-config.test.ts * refactor: :recycle: rename AddressFragment -> Address * refactor: :recycle: use debug instead of error in webhook-response noRetry * refactor: :recycle: refactor as variables in mutation * build: :construction_worker: add changeset * refactor: :recycle: split changesets in two * build: :arrow_up: vite * build: :arrow_up: vite && vitest in all apps
2023-04-17 11:58:21 +00:00
private crudSettingsManager: CrudSettingsManager;
private logger: Logger;
constructor(client: Client, saleorApiUrl: string) {
const settingsManager = createSettingsManager(client);
feat: finalize order process (#355) * feat: :sparkles: add dummy order-created * refactor: :fire: unused private-providers-configuration-service * feat: :sparkles: add dummy order-fulfilled * refactor: :truck: move provider-config * refactor: :truck: crudSettingsConfigurator -> crudSettingsManager * refactor: :recycle: [tax-provider].ts -> [tax-provider]-webhook.service.ts * feat: :sparkles: add dummy createOrder * refactor: :recycle: distinguish between salesOrder and salesInvoice in avatax * refactor: :truck: [provider]-calculate.ts to [provider]-transform.ts * refactor: :truck: ResponseTaxPayload to tax-provider-webhook.ts * refactor: :truck: ResponseTaxPayload -> CalculateTaxesResponse * refactor: :recycle: webhooks with active-tax-provider.service.ts * feat: :sparkles: add skeleton orderCreate functionality * refactor: :recycle: [provider]-transform.ts -> [provider]-[webhook]-transform.ts * feat: :sparkles: add order-fulfilled with avatax call * refactor: :recycle: move getActiveTaxProvider to active-tax-provider * refactor: :label: export types for [provider]-client function args * refactor: :truck: UpdateAppMetadata -> UpdateMetadata * feat: :sparkles: fulfill order with id from metadata * build: :arrow_up: upgrade avatax * feat: :sparkles: commit transaction on fulfill in avatax * fix: :bug: return of webhooks to ensure valid retry behavior * refactor: :truck: [provider]-[webhook]-transform -> [provider]-[webhook]-map * refactor: :label: export types of avatax-calculate-taxes mapPayload * refactor: :recycle: extract address-map to separate function * refactor: :recycle: remove schema.ts * refactor: :recycle: move addressSchema to channels-config.ts * feat: :sparkles: add tests & placeholder tests for avatax & taxjar maps * refactor: :recycle: throw error if no metadata * refactor: :recycle: change EXTERNAL_ID_KEY to PROVIDER_ORDER_ID_KEY add comments * refactor: :recycle: comments -> it.todo in tests * refactor: :bulb: add comment about shipping_item_code * refactor: :white_check_mark: add todo items for tests * refactor: :recycle: remove export and add sumLines to taxJarOrderCreated * refactor: :recycle: address-map with avatarAddressFactory * docs: :bulb: add comment about MOCKED_SALEOR_PAYLOAD * refactor: :recycle: remove export of mapLines and add to avataxCalculateTaxes * style: :art: add newline-after-var warn to eslint-config-saleor * style: :art: autofix newline-after-var in taxes * test: :white_check_mark: restructure tests according to new naming in address-map * refactor: :recycle: add shippingItemCode to avataxCalculateTaxes wrapper object * refactor: :truck: payloadProps -> payloadArgs * refactor: :recycle: add Maps suffix to map wrapper objects * refactor: :recycle: remove data: null from ActiveTaxProviderResult * refactor: :recycle: maintain the object hierarchy in tests * refactor: :recycle: refactor webhook responses with WebhookResponseFactory * build: :arrow_up: vitest * test: :white_check_mark: add tests for get-app-config-test * test: :white_check_mark: add tests for getActiveTaxProvider * refactor: :recycle: use address fragment for taxBase and order * refactor: :recycle: rename WebhookResponseFactory -> WebhookResponse * style: :construction_worker: add multiline-comment-style * fix: :bug: dummy test in get-app-config.test.ts * refactor: :recycle: rename AddressFragment -> Address * refactor: :recycle: use debug instead of error in webhook-response noRetry * refactor: :recycle: refactor as variables in mutation * build: :construction_worker: add changeset * refactor: :recycle: split changesets in two * build: :arrow_up: vite * build: :arrow_up: vite && vitest in all apps
2023-04-17 11:58:21 +00:00
this.crudSettingsManager = new CrudSettingsManager(
settingsManager,
saleorApiUrl,
TAX_PROVIDER_KEY
);
this.logger = createLogger({
service: "AvataxConfigurationService",
metadataKey: TAX_PROVIDER_KEY,
});
}
async getAll(): Promise<AvataxInstanceConfig[]> {
this.logger.debug(".getAll called");
feat: finalize order process (#355) * feat: :sparkles: add dummy order-created * refactor: :fire: unused private-providers-configuration-service * feat: :sparkles: add dummy order-fulfilled * refactor: :truck: move provider-config * refactor: :truck: crudSettingsConfigurator -> crudSettingsManager * refactor: :recycle: [tax-provider].ts -> [tax-provider]-webhook.service.ts * feat: :sparkles: add dummy createOrder * refactor: :recycle: distinguish between salesOrder and salesInvoice in avatax * refactor: :truck: [provider]-calculate.ts to [provider]-transform.ts * refactor: :truck: ResponseTaxPayload to tax-provider-webhook.ts * refactor: :truck: ResponseTaxPayload -> CalculateTaxesResponse * refactor: :recycle: webhooks with active-tax-provider.service.ts * feat: :sparkles: add skeleton orderCreate functionality * refactor: :recycle: [provider]-transform.ts -> [provider]-[webhook]-transform.ts * feat: :sparkles: add order-fulfilled with avatax call * refactor: :recycle: move getActiveTaxProvider to active-tax-provider * refactor: :label: export types for [provider]-client function args * refactor: :truck: UpdateAppMetadata -> UpdateMetadata * feat: :sparkles: fulfill order with id from metadata * build: :arrow_up: upgrade avatax * feat: :sparkles: commit transaction on fulfill in avatax * fix: :bug: return of webhooks to ensure valid retry behavior * refactor: :truck: [provider]-[webhook]-transform -> [provider]-[webhook]-map * refactor: :label: export types of avatax-calculate-taxes mapPayload * refactor: :recycle: extract address-map to separate function * refactor: :recycle: remove schema.ts * refactor: :recycle: move addressSchema to channels-config.ts * feat: :sparkles: add tests & placeholder tests for avatax & taxjar maps * refactor: :recycle: throw error if no metadata * refactor: :recycle: change EXTERNAL_ID_KEY to PROVIDER_ORDER_ID_KEY add comments * refactor: :recycle: comments -> it.todo in tests * refactor: :bulb: add comment about shipping_item_code * refactor: :white_check_mark: add todo items for tests * refactor: :recycle: remove export and add sumLines to taxJarOrderCreated * refactor: :recycle: address-map with avatarAddressFactory * docs: :bulb: add comment about MOCKED_SALEOR_PAYLOAD * refactor: :recycle: remove export of mapLines and add to avataxCalculateTaxes * style: :art: add newline-after-var warn to eslint-config-saleor * style: :art: autofix newline-after-var in taxes * test: :white_check_mark: restructure tests according to new naming in address-map * refactor: :recycle: add shippingItemCode to avataxCalculateTaxes wrapper object * refactor: :truck: payloadProps -> payloadArgs * refactor: :recycle: add Maps suffix to map wrapper objects * refactor: :recycle: remove data: null from ActiveTaxProviderResult * refactor: :recycle: maintain the object hierarchy in tests * refactor: :recycle: refactor webhook responses with WebhookResponseFactory * build: :arrow_up: vitest * test: :white_check_mark: add tests for get-app-config-test * test: :white_check_mark: add tests for getActiveTaxProvider * refactor: :recycle: use address fragment for taxBase and order * refactor: :recycle: rename WebhookResponseFactory -> WebhookResponse * style: :construction_worker: add multiline-comment-style * fix: :bug: dummy test in get-app-config.test.ts * refactor: :recycle: rename AddressFragment -> Address * refactor: :recycle: use debug instead of error in webhook-response noRetry * refactor: :recycle: refactor as variables in mutation * build: :construction_worker: add changeset * refactor: :recycle: split changesets in two * build: :arrow_up: vite * build: :arrow_up: vite && vitest in all apps
2023-04-17 11:58:21 +00:00
const { data } = await this.crudSettingsManager.readAll();
const validation = providersSchema.safeParse(data);
if (!validation.success) {
this.logger.error({ error: validation.error.format() }, "Validation error while getAll");
throw new Error(validation.error.message);
}
const instances = validation.data.filter(
(instance) => instance.provider === "avatax"
) as AvataxInstanceConfig[];
return instances;
}
async get(id: string): Promise<AvataxInstanceConfig> {
this.logger.debug(`.get called with id: ${id}`);
feat: finalize order process (#355) * feat: :sparkles: add dummy order-created * refactor: :fire: unused private-providers-configuration-service * feat: :sparkles: add dummy order-fulfilled * refactor: :truck: move provider-config * refactor: :truck: crudSettingsConfigurator -> crudSettingsManager * refactor: :recycle: [tax-provider].ts -> [tax-provider]-webhook.service.ts * feat: :sparkles: add dummy createOrder * refactor: :recycle: distinguish between salesOrder and salesInvoice in avatax * refactor: :truck: [provider]-calculate.ts to [provider]-transform.ts * refactor: :truck: ResponseTaxPayload to tax-provider-webhook.ts * refactor: :truck: ResponseTaxPayload -> CalculateTaxesResponse * refactor: :recycle: webhooks with active-tax-provider.service.ts * feat: :sparkles: add skeleton orderCreate functionality * refactor: :recycle: [provider]-transform.ts -> [provider]-[webhook]-transform.ts * feat: :sparkles: add order-fulfilled with avatax call * refactor: :recycle: move getActiveTaxProvider to active-tax-provider * refactor: :label: export types for [provider]-client function args * refactor: :truck: UpdateAppMetadata -> UpdateMetadata * feat: :sparkles: fulfill order with id from metadata * build: :arrow_up: upgrade avatax * feat: :sparkles: commit transaction on fulfill in avatax * fix: :bug: return of webhooks to ensure valid retry behavior * refactor: :truck: [provider]-[webhook]-transform -> [provider]-[webhook]-map * refactor: :label: export types of avatax-calculate-taxes mapPayload * refactor: :recycle: extract address-map to separate function * refactor: :recycle: remove schema.ts * refactor: :recycle: move addressSchema to channels-config.ts * feat: :sparkles: add tests & placeholder tests for avatax & taxjar maps * refactor: :recycle: throw error if no metadata * refactor: :recycle: change EXTERNAL_ID_KEY to PROVIDER_ORDER_ID_KEY add comments * refactor: :recycle: comments -> it.todo in tests * refactor: :bulb: add comment about shipping_item_code * refactor: :white_check_mark: add todo items for tests * refactor: :recycle: remove export and add sumLines to taxJarOrderCreated * refactor: :recycle: address-map with avatarAddressFactory * docs: :bulb: add comment about MOCKED_SALEOR_PAYLOAD * refactor: :recycle: remove export of mapLines and add to avataxCalculateTaxes * style: :art: add newline-after-var warn to eslint-config-saleor * style: :art: autofix newline-after-var in taxes * test: :white_check_mark: restructure tests according to new naming in address-map * refactor: :recycle: add shippingItemCode to avataxCalculateTaxes wrapper object * refactor: :truck: payloadProps -> payloadArgs * refactor: :recycle: add Maps suffix to map wrapper objects * refactor: :recycle: remove data: null from ActiveTaxProviderResult * refactor: :recycle: maintain the object hierarchy in tests * refactor: :recycle: refactor webhook responses with WebhookResponseFactory * build: :arrow_up: vitest * test: :white_check_mark: add tests for get-app-config-test * test: :white_check_mark: add tests for getActiveTaxProvider * refactor: :recycle: use address fragment for taxBase and order * refactor: :recycle: rename WebhookResponseFactory -> WebhookResponse * style: :construction_worker: add multiline-comment-style * fix: :bug: dummy test in get-app-config.test.ts * refactor: :recycle: rename AddressFragment -> Address * refactor: :recycle: use debug instead of error in webhook-response noRetry * refactor: :recycle: refactor as variables in mutation * build: :construction_worker: add changeset * refactor: :recycle: split changesets in two * build: :arrow_up: vite * build: :arrow_up: vite && vitest in all apps
2023-04-17 11:58:21 +00:00
const { data } = await this.crudSettingsManager.read(id);
this.logger.debug(`Fetched setting from CrudSettingsManager`);
const validation = getSchema.safeParse(data);
if (!validation.success) {
this.logger.error({ error: validation.error.format() }, "Validation error while get");
throw new Error(validation.error.message);
}
return validation.data;
}
async post(config: AvataxConfig): Promise<{ id: string }> {
this.logger.debug(`.post called with value: ${JSON.stringify(config)}`);
const avataxClient = new AvataxClient(config);
const validation = await avataxClient.ping();
if (!validation.authenticated) {
this.logger.error(validation.error);
throw new Error(validation.error);
}
feat: finalize order process (#355) * feat: :sparkles: add dummy order-created * refactor: :fire: unused private-providers-configuration-service * feat: :sparkles: add dummy order-fulfilled * refactor: :truck: move provider-config * refactor: :truck: crudSettingsConfigurator -> crudSettingsManager * refactor: :recycle: [tax-provider].ts -> [tax-provider]-webhook.service.ts * feat: :sparkles: add dummy createOrder * refactor: :recycle: distinguish between salesOrder and salesInvoice in avatax * refactor: :truck: [provider]-calculate.ts to [provider]-transform.ts * refactor: :truck: ResponseTaxPayload to tax-provider-webhook.ts * refactor: :truck: ResponseTaxPayload -> CalculateTaxesResponse * refactor: :recycle: webhooks with active-tax-provider.service.ts * feat: :sparkles: add skeleton orderCreate functionality * refactor: :recycle: [provider]-transform.ts -> [provider]-[webhook]-transform.ts * feat: :sparkles: add order-fulfilled with avatax call * refactor: :recycle: move getActiveTaxProvider to active-tax-provider * refactor: :label: export types for [provider]-client function args * refactor: :truck: UpdateAppMetadata -> UpdateMetadata * feat: :sparkles: fulfill order with id from metadata * build: :arrow_up: upgrade avatax * feat: :sparkles: commit transaction on fulfill in avatax * fix: :bug: return of webhooks to ensure valid retry behavior * refactor: :truck: [provider]-[webhook]-transform -> [provider]-[webhook]-map * refactor: :label: export types of avatax-calculate-taxes mapPayload * refactor: :recycle: extract address-map to separate function * refactor: :recycle: remove schema.ts * refactor: :recycle: move addressSchema to channels-config.ts * feat: :sparkles: add tests & placeholder tests for avatax & taxjar maps * refactor: :recycle: throw error if no metadata * refactor: :recycle: change EXTERNAL_ID_KEY to PROVIDER_ORDER_ID_KEY add comments * refactor: :recycle: comments -> it.todo in tests * refactor: :bulb: add comment about shipping_item_code * refactor: :white_check_mark: add todo items for tests * refactor: :recycle: remove export and add sumLines to taxJarOrderCreated * refactor: :recycle: address-map with avatarAddressFactory * docs: :bulb: add comment about MOCKED_SALEOR_PAYLOAD * refactor: :recycle: remove export of mapLines and add to avataxCalculateTaxes * style: :art: add newline-after-var warn to eslint-config-saleor * style: :art: autofix newline-after-var in taxes * test: :white_check_mark: restructure tests according to new naming in address-map * refactor: :recycle: add shippingItemCode to avataxCalculateTaxes wrapper object * refactor: :truck: payloadProps -> payloadArgs * refactor: :recycle: add Maps suffix to map wrapper objects * refactor: :recycle: remove data: null from ActiveTaxProviderResult * refactor: :recycle: maintain the object hierarchy in tests * refactor: :recycle: refactor webhook responses with WebhookResponseFactory * build: :arrow_up: vitest * test: :white_check_mark: add tests for get-app-config-test * test: :white_check_mark: add tests for getActiveTaxProvider * refactor: :recycle: use address fragment for taxBase and order * refactor: :recycle: rename WebhookResponseFactory -> WebhookResponse * style: :construction_worker: add multiline-comment-style * fix: :bug: dummy test in get-app-config.test.ts * refactor: :recycle: rename AddressFragment -> Address * refactor: :recycle: use debug instead of error in webhook-response noRetry * refactor: :recycle: refactor as variables in mutation * build: :construction_worker: add changeset * refactor: :recycle: split changesets in two * build: :arrow_up: vite * build: :arrow_up: vite && vitest in all apps
2023-04-17 11:58:21 +00:00
const result = await this.crudSettingsManager.create({
provider: "avatax",
config: config,
});
return result.data;
}
async patch(id: string, config: Partial<AvataxConfig>): Promise<void> {
this.logger.debug(`.patch called with id: ${id} and value: ${JSON.stringify(config)}`);
const data = await this.get(id);
// omit the key "id" from the result
const { id: _, ...setting } = data;
feat: finalize order process (#355) * feat: :sparkles: add dummy order-created * refactor: :fire: unused private-providers-configuration-service * feat: :sparkles: add dummy order-fulfilled * refactor: :truck: move provider-config * refactor: :truck: crudSettingsConfigurator -> crudSettingsManager * refactor: :recycle: [tax-provider].ts -> [tax-provider]-webhook.service.ts * feat: :sparkles: add dummy createOrder * refactor: :recycle: distinguish between salesOrder and salesInvoice in avatax * refactor: :truck: [provider]-calculate.ts to [provider]-transform.ts * refactor: :truck: ResponseTaxPayload to tax-provider-webhook.ts * refactor: :truck: ResponseTaxPayload -> CalculateTaxesResponse * refactor: :recycle: webhooks with active-tax-provider.service.ts * feat: :sparkles: add skeleton orderCreate functionality * refactor: :recycle: [provider]-transform.ts -> [provider]-[webhook]-transform.ts * feat: :sparkles: add order-fulfilled with avatax call * refactor: :recycle: move getActiveTaxProvider to active-tax-provider * refactor: :label: export types for [provider]-client function args * refactor: :truck: UpdateAppMetadata -> UpdateMetadata * feat: :sparkles: fulfill order with id from metadata * build: :arrow_up: upgrade avatax * feat: :sparkles: commit transaction on fulfill in avatax * fix: :bug: return of webhooks to ensure valid retry behavior * refactor: :truck: [provider]-[webhook]-transform -> [provider]-[webhook]-map * refactor: :label: export types of avatax-calculate-taxes mapPayload * refactor: :recycle: extract address-map to separate function * refactor: :recycle: remove schema.ts * refactor: :recycle: move addressSchema to channels-config.ts * feat: :sparkles: add tests & placeholder tests for avatax & taxjar maps * refactor: :recycle: throw error if no metadata * refactor: :recycle: change EXTERNAL_ID_KEY to PROVIDER_ORDER_ID_KEY add comments * refactor: :recycle: comments -> it.todo in tests * refactor: :bulb: add comment about shipping_item_code * refactor: :white_check_mark: add todo items for tests * refactor: :recycle: remove export and add sumLines to taxJarOrderCreated * refactor: :recycle: address-map with avatarAddressFactory * docs: :bulb: add comment about MOCKED_SALEOR_PAYLOAD * refactor: :recycle: remove export of mapLines and add to avataxCalculateTaxes * style: :art: add newline-after-var warn to eslint-config-saleor * style: :art: autofix newline-after-var in taxes * test: :white_check_mark: restructure tests according to new naming in address-map * refactor: :recycle: add shippingItemCode to avataxCalculateTaxes wrapper object * refactor: :truck: payloadProps -> payloadArgs * refactor: :recycle: add Maps suffix to map wrapper objects * refactor: :recycle: remove data: null from ActiveTaxProviderResult * refactor: :recycle: maintain the object hierarchy in tests * refactor: :recycle: refactor webhook responses with WebhookResponseFactory * build: :arrow_up: vitest * test: :white_check_mark: add tests for get-app-config-test * test: :white_check_mark: add tests for getActiveTaxProvider * refactor: :recycle: use address fragment for taxBase and order * refactor: :recycle: rename WebhookResponseFactory -> WebhookResponse * style: :construction_worker: add multiline-comment-style * fix: :bug: dummy test in get-app-config.test.ts * refactor: :recycle: rename AddressFragment -> Address * refactor: :recycle: use debug instead of error in webhook-response noRetry * refactor: :recycle: refactor as variables in mutation * build: :construction_worker: add changeset * refactor: :recycle: split changesets in two * build: :arrow_up: vite * build: :arrow_up: vite && vitest in all apps
2023-04-17 11:58:21 +00:00
return this.crudSettingsManager.update(id, {
...setting,
config: { ...setting.config, ...config },
});
}
async put(id: string, config: AvataxConfig): Promise<void> {
const data = await this.get(id);
// omit the key "id" from the result
const { id: _, ...setting } = data;
this.logger.debug(`.put called with id: ${id} and value: ${JSON.stringify(config)}`);
feat: finalize order process (#355) * feat: :sparkles: add dummy order-created * refactor: :fire: unused private-providers-configuration-service * feat: :sparkles: add dummy order-fulfilled * refactor: :truck: move provider-config * refactor: :truck: crudSettingsConfigurator -> crudSettingsManager * refactor: :recycle: [tax-provider].ts -> [tax-provider]-webhook.service.ts * feat: :sparkles: add dummy createOrder * refactor: :recycle: distinguish between salesOrder and salesInvoice in avatax * refactor: :truck: [provider]-calculate.ts to [provider]-transform.ts * refactor: :truck: ResponseTaxPayload to tax-provider-webhook.ts * refactor: :truck: ResponseTaxPayload -> CalculateTaxesResponse * refactor: :recycle: webhooks with active-tax-provider.service.ts * feat: :sparkles: add skeleton orderCreate functionality * refactor: :recycle: [provider]-transform.ts -> [provider]-[webhook]-transform.ts * feat: :sparkles: add order-fulfilled with avatax call * refactor: :recycle: move getActiveTaxProvider to active-tax-provider * refactor: :label: export types for [provider]-client function args * refactor: :truck: UpdateAppMetadata -> UpdateMetadata * feat: :sparkles: fulfill order with id from metadata * build: :arrow_up: upgrade avatax * feat: :sparkles: commit transaction on fulfill in avatax * fix: :bug: return of webhooks to ensure valid retry behavior * refactor: :truck: [provider]-[webhook]-transform -> [provider]-[webhook]-map * refactor: :label: export types of avatax-calculate-taxes mapPayload * refactor: :recycle: extract address-map to separate function * refactor: :recycle: remove schema.ts * refactor: :recycle: move addressSchema to channels-config.ts * feat: :sparkles: add tests & placeholder tests for avatax & taxjar maps * refactor: :recycle: throw error if no metadata * refactor: :recycle: change EXTERNAL_ID_KEY to PROVIDER_ORDER_ID_KEY add comments * refactor: :recycle: comments -> it.todo in tests * refactor: :bulb: add comment about shipping_item_code * refactor: :white_check_mark: add todo items for tests * refactor: :recycle: remove export and add sumLines to taxJarOrderCreated * refactor: :recycle: address-map with avatarAddressFactory * docs: :bulb: add comment about MOCKED_SALEOR_PAYLOAD * refactor: :recycle: remove export of mapLines and add to avataxCalculateTaxes * style: :art: add newline-after-var warn to eslint-config-saleor * style: :art: autofix newline-after-var in taxes * test: :white_check_mark: restructure tests according to new naming in address-map * refactor: :recycle: add shippingItemCode to avataxCalculateTaxes wrapper object * refactor: :truck: payloadProps -> payloadArgs * refactor: :recycle: add Maps suffix to map wrapper objects * refactor: :recycle: remove data: null from ActiveTaxProviderResult * refactor: :recycle: maintain the object hierarchy in tests * refactor: :recycle: refactor webhook responses with WebhookResponseFactory * build: :arrow_up: vitest * test: :white_check_mark: add tests for get-app-config-test * test: :white_check_mark: add tests for getActiveTaxProvider * refactor: :recycle: use address fragment for taxBase and order * refactor: :recycle: rename WebhookResponseFactory -> WebhookResponse * style: :construction_worker: add multiline-comment-style * fix: :bug: dummy test in get-app-config.test.ts * refactor: :recycle: rename AddressFragment -> Address * refactor: :recycle: use debug instead of error in webhook-response noRetry * refactor: :recycle: refactor as variables in mutation * build: :construction_worker: add changeset * refactor: :recycle: split changesets in two * build: :arrow_up: vite * build: :arrow_up: vite && vitest in all apps
2023-04-17 11:58:21 +00:00
return this.crudSettingsManager.update(id, {
...setting,
config: { ...config },
});
}
async delete(id: string): Promise<void> {
this.logger.debug(`.delete called with id: ${id}`);
feat: finalize order process (#355) * feat: :sparkles: add dummy order-created * refactor: :fire: unused private-providers-configuration-service * feat: :sparkles: add dummy order-fulfilled * refactor: :truck: move provider-config * refactor: :truck: crudSettingsConfigurator -> crudSettingsManager * refactor: :recycle: [tax-provider].ts -> [tax-provider]-webhook.service.ts * feat: :sparkles: add dummy createOrder * refactor: :recycle: distinguish between salesOrder and salesInvoice in avatax * refactor: :truck: [provider]-calculate.ts to [provider]-transform.ts * refactor: :truck: ResponseTaxPayload to tax-provider-webhook.ts * refactor: :truck: ResponseTaxPayload -> CalculateTaxesResponse * refactor: :recycle: webhooks with active-tax-provider.service.ts * feat: :sparkles: add skeleton orderCreate functionality * refactor: :recycle: [provider]-transform.ts -> [provider]-[webhook]-transform.ts * feat: :sparkles: add order-fulfilled with avatax call * refactor: :recycle: move getActiveTaxProvider to active-tax-provider * refactor: :label: export types for [provider]-client function args * refactor: :truck: UpdateAppMetadata -> UpdateMetadata * feat: :sparkles: fulfill order with id from metadata * build: :arrow_up: upgrade avatax * feat: :sparkles: commit transaction on fulfill in avatax * fix: :bug: return of webhooks to ensure valid retry behavior * refactor: :truck: [provider]-[webhook]-transform -> [provider]-[webhook]-map * refactor: :label: export types of avatax-calculate-taxes mapPayload * refactor: :recycle: extract address-map to separate function * refactor: :recycle: remove schema.ts * refactor: :recycle: move addressSchema to channels-config.ts * feat: :sparkles: add tests & placeholder tests for avatax & taxjar maps * refactor: :recycle: throw error if no metadata * refactor: :recycle: change EXTERNAL_ID_KEY to PROVIDER_ORDER_ID_KEY add comments * refactor: :recycle: comments -> it.todo in tests * refactor: :bulb: add comment about shipping_item_code * refactor: :white_check_mark: add todo items for tests * refactor: :recycle: remove export and add sumLines to taxJarOrderCreated * refactor: :recycle: address-map with avatarAddressFactory * docs: :bulb: add comment about MOCKED_SALEOR_PAYLOAD * refactor: :recycle: remove export of mapLines and add to avataxCalculateTaxes * style: :art: add newline-after-var warn to eslint-config-saleor * style: :art: autofix newline-after-var in taxes * test: :white_check_mark: restructure tests according to new naming in address-map * refactor: :recycle: add shippingItemCode to avataxCalculateTaxes wrapper object * refactor: :truck: payloadProps -> payloadArgs * refactor: :recycle: add Maps suffix to map wrapper objects * refactor: :recycle: remove data: null from ActiveTaxProviderResult * refactor: :recycle: maintain the object hierarchy in tests * refactor: :recycle: refactor webhook responses with WebhookResponseFactory * build: :arrow_up: vitest * test: :white_check_mark: add tests for get-app-config-test * test: :white_check_mark: add tests for getActiveTaxProvider * refactor: :recycle: use address fragment for taxBase and order * refactor: :recycle: rename WebhookResponseFactory -> WebhookResponse * style: :construction_worker: add multiline-comment-style * fix: :bug: dummy test in get-app-config.test.ts * refactor: :recycle: rename AddressFragment -> Address * refactor: :recycle: use debug instead of error in webhook-response noRetry * refactor: :recycle: refactor as variables in mutation * build: :construction_worker: add changeset * refactor: :recycle: split changesets in two * build: :arrow_up: vite * build: :arrow_up: vite && vitest in all apps
2023-04-17 11:58:21 +00:00
return this.crudSettingsManager.delete(id);
}
}