fix: 🐛 not being able to update one credential (#662)
* fix: 🐛 not being able to update one credential * build: 👷 add changeset * fix: 🐛 address feedback * refactor: ♻️ remove unnecessary clone
This commit is contained in:
parent
3462cc343e
commit
e239fbb670
5 changed files with 40 additions and 27 deletions
5
.changeset/wild-pears-swim.md
Normal file
5
.changeset/wild-pears-swim.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"saleor-app-taxes": patch
|
||||
---
|
||||
|
||||
Fixed the issue with updating a provider. When updating one of the credentials, the user no longer sees "invalid credentials" error.
|
|
@ -1,12 +1,10 @@
|
|||
import { DeepPartial } from "@trpc/server";
|
||||
import { Client } from "urql";
|
||||
import { Logger, createLogger } from "../../../lib/logger";
|
||||
import { AvataxConnectionRepository } from "./avatax-connection-repository";
|
||||
import { AvataxConfig, AvataxConnection } from "../avatax-connection-schema";
|
||||
import { AvataxValidationService } from "./avatax-validation.service";
|
||||
import { DeepPartial } from "@trpc/server";
|
||||
import { PatchInputTransformer } from "../../provider-connections/patch-input-transformer";
|
||||
import { AuthData } from "@saleor/app-sdk/APL";
|
||||
import { createSettingsManager } from "../../app/metadata-manager";
|
||||
import { AvataxConfig, AvataxConnection } from "../avatax-connection-schema";
|
||||
import { AvataxConnectionRepository } from "./avatax-connection-repository";
|
||||
import { AvataxValidationService } from "./avatax-validation.service";
|
||||
|
||||
export class AvataxConnectionService {
|
||||
private logger: Logger;
|
||||
|
@ -44,9 +42,20 @@ export class AvataxConnectionService {
|
|||
const prevConfig = setting.config;
|
||||
|
||||
const validationService = new AvataxValidationService();
|
||||
const inputTransformer = new PatchInputTransformer();
|
||||
|
||||
const input = inputTransformer.transform(nextConfigPartial, prevConfig);
|
||||
// todo: add deepRightMerge
|
||||
const input: AvataxConfig = {
|
||||
...prevConfig,
|
||||
...nextConfigPartial,
|
||||
credentials: {
|
||||
...prevConfig.credentials,
|
||||
...nextConfigPartial.credentials,
|
||||
},
|
||||
address: {
|
||||
...prevConfig.address,
|
||||
...nextConfigPartial.address,
|
||||
},
|
||||
};
|
||||
|
||||
await validationService.validate(input);
|
||||
|
||||
|
|
|
@ -3,11 +3,10 @@ import { Box, Button, Text } from "@saleor/macaw-ui/next";
|
|||
import { useRouter } from "next/router";
|
||||
import React from "react";
|
||||
import { z } from "zod";
|
||||
import { Obfuscator } from "../../../lib/obfuscator";
|
||||
import { trpcClient } from "../../trpc/trpc-client";
|
||||
import { AvataxConnectionObfuscator } from "../avatax-connection-obfuscator";
|
||||
import { AvataxConfig } from "../avatax-connection-schema";
|
||||
import { AvataxConfigurationForm } from "./avatax-configuration-form";
|
||||
import { AvataxConnectionObfuscator } from "../avatax-connection-obfuscator";
|
||||
|
||||
const avataxObfuscator = new AvataxConnectionObfuscator();
|
||||
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
import { DeepPartial } from "@trpc/server";
|
||||
|
||||
export class PatchInputTransformer {
|
||||
transform<TObject extends object>(
|
||||
nextConfigPartial: DeepPartial<TObject>,
|
||||
prevConfig: TObject
|
||||
): TObject {
|
||||
return Object.assign(prevConfig, nextConfigPartial);
|
||||
}
|
||||
}
|
|
@ -1,11 +1,10 @@
|
|||
import { DeepPartial } from "@trpc/server";
|
||||
import { Client } from "urql";
|
||||
import { Logger, createLogger } from "../../../lib/logger";
|
||||
import { TaxJarConnectionRepository } from "./taxjar-connection-repository";
|
||||
import { TaxJarConfig, TaxJarConnection } from "../taxjar-connection-schema";
|
||||
import { TaxJarValidationService } from "./taxjar-validation.service";
|
||||
import { DeepPartial } from "@trpc/server";
|
||||
import { PatchInputTransformer } from "../../provider-connections/patch-input-transformer";
|
||||
import { createSettingsManager } from "../../app/metadata-manager";
|
||||
import { TaxJarConfig, TaxJarConnection } from "../taxjar-connection-schema";
|
||||
import { TaxJarConnectionRepository } from "./taxjar-connection-repository";
|
||||
import { TaxJarValidationService } from "./taxjar-validation.service";
|
||||
|
||||
export class TaxJarConnectionService {
|
||||
private logger: Logger;
|
||||
|
@ -43,9 +42,20 @@ export class TaxJarConnectionService {
|
|||
const prevConfig = setting.config;
|
||||
|
||||
const validationService = new TaxJarValidationService();
|
||||
const inputTransformer = new PatchInputTransformer();
|
||||
|
||||
const input = inputTransformer.transform(nextConfigPartial, prevConfig);
|
||||
// todo: add deepRightMerge
|
||||
const input: TaxJarConfig = {
|
||||
...prevConfig,
|
||||
...nextConfigPartial,
|
||||
credentials: {
|
||||
...prevConfig.credentials,
|
||||
...nextConfigPartial.credentials,
|
||||
},
|
||||
address: {
|
||||
...prevConfig.address,
|
||||
...nextConfigPartial.address,
|
||||
},
|
||||
};
|
||||
|
||||
await validationService.validate(input);
|
||||
|
||||
|
|
Loading…
Reference in a new issue