refactor: ♻️ move address from channel to provider
This commit is contained in:
parent
3a22d0af45
commit
25151ca5cd
8 changed files with 77 additions and 49 deletions
|
@ -20,6 +20,13 @@ const mockedProviders: ProvidersConfig = [
|
||||||
password: "avatax-password",
|
password: "avatax-password",
|
||||||
username: "avatax-username",
|
username: "avatax-username",
|
||||||
},
|
},
|
||||||
|
address: {
|
||||||
|
city: "New York",
|
||||||
|
country: "US",
|
||||||
|
state: "NY",
|
||||||
|
street: "123 Main St",
|
||||||
|
zip: "10001",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -31,6 +38,13 @@ const mockedProviders: ProvidersConfig = [
|
||||||
credentials: {
|
credentials: {
|
||||||
apiKey: "taxjar-api-key",
|
apiKey: "taxjar-api-key",
|
||||||
},
|
},
|
||||||
|
address: {
|
||||||
|
city: "New York",
|
||||||
|
country: "US",
|
||||||
|
state: "NY",
|
||||||
|
street: "123 Main St",
|
||||||
|
zip: "10001",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
@ -38,13 +52,6 @@ const mockedEncryptedProviders = encrypt(JSON.stringify(mockedProviders), mocked
|
||||||
|
|
||||||
const mockedChannels: ChannelsConfig = {
|
const mockedChannels: ChannelsConfig = {
|
||||||
"default-channel": {
|
"default-channel": {
|
||||||
address: {
|
|
||||||
city: "New York",
|
|
||||||
country: "US",
|
|
||||||
state: "NY",
|
|
||||||
street: "123 Main St",
|
|
||||||
zip: "10001",
|
|
||||||
},
|
|
||||||
providerInstanceId: "1",
|
providerInstanceId: "1",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import { AddressLocationInfo as AvataxAddress } from "avatax/lib/models/AddressLocationInfo";
|
import { AddressLocationInfo as AvataxAddress } from "avatax/lib/models/AddressLocationInfo";
|
||||||
import { ChannelAddress } from "../channels-configuration/channels-config";
|
import { AvataxConfig } from "./avatax-config";
|
||||||
import { AddressFragment as SaleorAddress } from "../../../generated/graphql";
|
import { AddressFragment } from "../../../generated/graphql";
|
||||||
|
|
||||||
function mapSaleorAddressToAvataxAddress(address: SaleorAddress): AvataxAddress {
|
function mapSaleorAddressToAvataxAddress(address: AddressFragment): AvataxAddress {
|
||||||
return {
|
return {
|
||||||
line1: address.streetAddress1,
|
line1: address.streetAddress1,
|
||||||
line2: address.streetAddress2,
|
line2: address.streetAddress2,
|
||||||
|
@ -13,7 +13,7 @@ function mapSaleorAddressToAvataxAddress(address: SaleorAddress): AvataxAddress
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function mapChannelAddressToAvataxAddress(address: ChannelAddress): AvataxAddress {
|
function mapChannelAddressToAvataxAddress(address: AvataxConfig["address"]): AvataxAddress {
|
||||||
return {
|
return {
|
||||||
line1: address.street,
|
line1: address.street,
|
||||||
city: address.city,
|
city: address.city,
|
||||||
|
|
|
@ -1,7 +1,15 @@
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { obfuscateSecret } from "../../lib/utils";
|
import { obfuscateSecret } from "../../lib/utils";
|
||||||
|
|
||||||
const avataxCredentials = z.object({
|
const addressSchema = z.object({
|
||||||
|
country: z.string(),
|
||||||
|
zip: z.string(),
|
||||||
|
state: z.string(),
|
||||||
|
city: z.string(),
|
||||||
|
street: z.string(),
|
||||||
|
});
|
||||||
|
|
||||||
|
const avataxCredentialsSchema = z.object({
|
||||||
username: z.string().min(1, { message: "Username requires at least one character." }),
|
username: z.string().min(1, { message: "Username requires at least one character." }),
|
||||||
password: z.string().min(1, { message: "Password requires at least one character." }),
|
password: z.string().min(1, { message: "Password requires at least one character." }),
|
||||||
});
|
});
|
||||||
|
@ -12,7 +20,8 @@ export const avataxConfigSchema = z.object({
|
||||||
companyCode: z.string().optional(),
|
companyCode: z.string().optional(),
|
||||||
isAutocommit: z.boolean(),
|
isAutocommit: z.boolean(),
|
||||||
shippingTaxCode: z.string().optional(),
|
shippingTaxCode: z.string().optional(),
|
||||||
credentials: avataxCredentials,
|
credentials: avataxCredentialsSchema,
|
||||||
|
address: addressSchema,
|
||||||
});
|
});
|
||||||
|
|
||||||
export type AvataxConfig = z.infer<typeof avataxConfigSchema>;
|
export type AvataxConfig = z.infer<typeof avataxConfigSchema>;
|
||||||
|
@ -27,6 +36,13 @@ export const defaultAvataxConfig: AvataxConfig = {
|
||||||
username: "",
|
username: "",
|
||||||
password: "",
|
password: "",
|
||||||
},
|
},
|
||||||
|
address: {
|
||||||
|
city: "",
|
||||||
|
country: "",
|
||||||
|
state: "",
|
||||||
|
street: "",
|
||||||
|
zip: "",
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export const avataxInstanceConfigSchema = z.object({
|
export const avataxInstanceConfigSchema = z.object({
|
||||||
|
|
|
@ -1,19 +1,8 @@
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { ChannelFragment } from "../../../generated/graphql";
|
import { ChannelFragment } from "../../../generated/graphql";
|
||||||
|
|
||||||
const addressSchema = z.object({
|
|
||||||
country: z.string(),
|
|
||||||
zip: z.string(),
|
|
||||||
state: z.string(),
|
|
||||||
city: z.string(),
|
|
||||||
street: z.string(),
|
|
||||||
});
|
|
||||||
|
|
||||||
export type ChannelAddress = z.infer<typeof addressSchema>;
|
|
||||||
|
|
||||||
export const channelSchema = z.object({
|
export const channelSchema = z.object({
|
||||||
providerInstanceId: z.string(),
|
providerInstanceId: z.string(),
|
||||||
address: addressSchema,
|
|
||||||
});
|
});
|
||||||
export type ChannelConfig = z.infer<typeof channelSchema>;
|
export type ChannelConfig = z.infer<typeof channelSchema>;
|
||||||
|
|
||||||
|
@ -22,13 +11,6 @@ export type ChannelsConfig = z.infer<typeof channelsSchema>;
|
||||||
|
|
||||||
export const defaultChannelConfig: ChannelConfig = {
|
export const defaultChannelConfig: ChannelConfig = {
|
||||||
providerInstanceId: "",
|
providerInstanceId: "",
|
||||||
address: {
|
|
||||||
city: "",
|
|
||||||
country: "",
|
|
||||||
state: "",
|
|
||||||
street: "",
|
|
||||||
zip: "",
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const createDefaultChannelsConfig = (channels: ChannelFragment[]): ChannelsConfig => {
|
export const createDefaultChannelsConfig = (channels: ChannelFragment[]): ChannelsConfig => {
|
||||||
|
|
|
@ -29,6 +29,13 @@ const mockedProviders: ProvidersConfig = [
|
||||||
password: "avatax-password",
|
password: "avatax-password",
|
||||||
username: "avatax-username",
|
username: "avatax-username",
|
||||||
},
|
},
|
||||||
|
address: {
|
||||||
|
city: "New York",
|
||||||
|
country: "US",
|
||||||
|
state: "NY",
|
||||||
|
street: "123 Main St",
|
||||||
|
zip: "10001",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -40,6 +47,13 @@ const mockedProviders: ProvidersConfig = [
|
||||||
credentials: {
|
credentials: {
|
||||||
apiKey: "taxjar-api-key",
|
apiKey: "taxjar-api-key",
|
||||||
},
|
},
|
||||||
|
address: {
|
||||||
|
city: "New York",
|
||||||
|
country: "US",
|
||||||
|
state: "NY",
|
||||||
|
street: "123 Main St",
|
||||||
|
zip: "10001",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
@ -47,26 +61,12 @@ const mockedEncryptedProviders = encrypt(JSON.stringify(mockedProviders), mocked
|
||||||
|
|
||||||
const mockedChannelsWithInvalidProviderInstanceId: ChannelsConfig = {
|
const mockedChannelsWithInvalidProviderInstanceId: ChannelsConfig = {
|
||||||
"default-channel": {
|
"default-channel": {
|
||||||
address: {
|
|
||||||
city: "New York",
|
|
||||||
country: "US",
|
|
||||||
state: "NY",
|
|
||||||
street: "123 Main St",
|
|
||||||
zip: "10001",
|
|
||||||
},
|
|
||||||
providerInstanceId: "3",
|
providerInstanceId: "3",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const mockedValidChannels: ChannelsConfig = {
|
const mockedValidChannels: ChannelsConfig = {
|
||||||
"default-channel": {
|
"default-channel": {
|
||||||
address: {
|
|
||||||
city: "New York",
|
|
||||||
country: "US",
|
|
||||||
state: "NY",
|
|
||||||
street: "123 Main St",
|
|
||||||
zip: "10001",
|
|
||||||
},
|
|
||||||
providerInstanceId: "1",
|
providerInstanceId: "1",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,23 +1,39 @@
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { obfuscateSecret } from "../../lib/utils";
|
import { obfuscateSecret } from "../../lib/utils";
|
||||||
|
|
||||||
const credentials = z.object({
|
const addressSchema = z.object({
|
||||||
|
country: z.string(),
|
||||||
|
zip: z.string(),
|
||||||
|
state: z.string(),
|
||||||
|
city: z.string(),
|
||||||
|
street: z.string(),
|
||||||
|
});
|
||||||
|
|
||||||
|
const taxJarCredentialsSchema = z.object({
|
||||||
apiKey: z.string().min(1, { message: "API Key requires at least one character." }),
|
apiKey: z.string().min(1, { message: "API Key requires at least one character." }),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const taxJarConfigSchema = z.object({
|
export const taxJarConfigSchema = z.object({
|
||||||
name: z.string().min(1, { message: "Name requires at least one character." }),
|
name: z.string().min(1, { message: "Name requires at least one character." }),
|
||||||
isSandbox: z.boolean(),
|
isSandbox: z.boolean(),
|
||||||
credentials,
|
credentials: taxJarCredentialsSchema,
|
||||||
|
address: addressSchema,
|
||||||
});
|
});
|
||||||
export type TaxJarConfig = z.infer<typeof taxJarConfigSchema>;
|
export type TaxJarConfig = z.infer<typeof taxJarConfigSchema>;
|
||||||
|
|
||||||
export const defaultTaxJarConfig: TaxJarConfig = {
|
export const defaultTaxJarConfig: TaxJarConfig = {
|
||||||
name: "",
|
name: "",
|
||||||
|
isSandbox: false,
|
||||||
credentials: {
|
credentials: {
|
||||||
apiKey: "",
|
apiKey: "",
|
||||||
},
|
},
|
||||||
isSandbox: false,
|
address: {
|
||||||
|
city: "",
|
||||||
|
country: "",
|
||||||
|
state: "",
|
||||||
|
street: "",
|
||||||
|
zip: "",
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export const taxJarInstanceConfigSchema = z.object({
|
export const taxJarInstanceConfigSchema = z.object({
|
||||||
|
|
|
@ -9,8 +9,8 @@ import { TaxJarOrderCreatedAdapter } from "./order-created/taxjar-order-created-
|
||||||
|
|
||||||
export class TaxJarWebhookService implements ProviderWebhookService {
|
export class TaxJarWebhookService implements ProviderWebhookService {
|
||||||
client: TaxJarClient;
|
client: TaxJarClient;
|
||||||
config: TaxJarConfig;
|
|
||||||
private logger: Logger;
|
private logger: Logger;
|
||||||
|
private config: TaxJarConfig;
|
||||||
|
|
||||||
constructor(config: TaxJarConfig) {
|
constructor(config: TaxJarConfig) {
|
||||||
const taxJarClient = new TaxJarClient(config);
|
const taxJarClient = new TaxJarClient(config);
|
||||||
|
|
|
@ -39,6 +39,13 @@ const MOCKED_PROVIDERS: ProvidersConfig = [
|
||||||
credentials: {
|
credentials: {
|
||||||
apiKey: "1234",
|
apiKey: "1234",
|
||||||
},
|
},
|
||||||
|
address: {
|
||||||
|
city: "New York",
|
||||||
|
country: "US",
|
||||||
|
state: "NY",
|
||||||
|
street: "123 Main St",
|
||||||
|
zip: "10001",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
id: "1",
|
id: "1",
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue