Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disable aws sdk in checkout calculate taxes #1589

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/perfect-cobras-do.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"app-avatax": patch
---

Debugging: Disable importing dynamodb in checkout_calculate_taxes. This will disable logs feature even if flag is enabled
22 changes: 22 additions & 0 deletions apps/avatax/src/modules/client-logs/dynamo-log-writer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { ClientLogStoreRequest } from "@/modules/client-logs/client-log";
import { ILogWriter, LogWriterContext } from "@/modules/client-logs/log-writer";
import { ILogsRepository } from "@/modules/client-logs/logs-repository";

export class DynamoDbLogWriter implements ILogWriter {
constructor(
private repo: ILogsRepository,
private context: LogWriterContext,
) {
if (!repo) {
throw new Error("Repository is nullish");
}
}

writeLog = async (log: ClientLogStoreRequest): Promise<void> => {
await this.repo.writeLog({
appId: this.context.appId,
saleorApiUrl: this.context.saleorApiUrl,
clientLogRequest: log,
});
};
}
9 changes: 3 additions & 6 deletions apps/avatax/src/modules/client-logs/log-writer-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@ import {
createLogsDocumentClient,
createLogsDynamoClient,
} from "@/modules/client-logs/dynamo-client";
import { DynamoDbLogWriter } from "@/modules/client-logs/dynamo-log-writer";
import { ClientLogDynamoEntityFactory, LogsTable } from "@/modules/client-logs/dynamo-schema";
import {
DynamoDbLogWriter,
ILogWriter,
LogWriterContext,
NoopLogWriter,
} from "@/modules/client-logs/log-writer";
import { ILogWriter, LogWriterContext } from "@/modules/client-logs/log-writer";
import { LogsRepositoryDynamodb } from "@/modules/client-logs/logs-repository";
import { NoopLogWriter } from "@/modules/client-logs/noop-log-writer";

export interface ILogWriterFactory {
createWriter(context: LogWriterContext): ILogWriter;
Expand Down
29 changes: 0 additions & 29 deletions apps/avatax/src/modules/client-logs/log-writer.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,7 @@
import { ClientLogStoreRequest } from "@/modules/client-logs/client-log";
import { ILogsRepository } from "@/modules/client-logs/logs-repository";

export type LogWriterContext = { appId: string; saleorApiUrl: string };

export interface ILogWriter {
writeLog(log: ClientLogStoreRequest): Promise<void>;
}

export class DynamoDbLogWriter implements ILogWriter {
constructor(
private repo: ILogsRepository,
private context: LogWriterContext,
) {
if (!repo) {
throw new Error("Repository is nullish");
}
}

writeLog = async (log: ClientLogStoreRequest): Promise<void> => {
await this.repo.writeLog({
appId: this.context.appId,
saleorApiUrl: this.context.saleorApiUrl,
clientLogRequest: log,
});
};
}

/**
* Just no-op. For testing or if feature is disabled
*/
export class NoopLogWriter implements ILogWriter {
async writeLog(log: ClientLogStoreRequest): Promise<void> {
return;
}
}
11 changes: 11 additions & 0 deletions apps/avatax/src/modules/client-logs/noop-log-writer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { ClientLogStoreRequest } from "@/modules/client-logs/client-log";
import { ILogWriter } from "@/modules/client-logs/log-writer";

/**
* Just no-op. For testing or if feature is disabled
*/
export class NoopLogWriter implements ILogWriter {
async writeLog(log: ClientLogStoreRequest): Promise<void> {
return;
}
}
13 changes: 8 additions & 5 deletions apps/avatax/src/pages/api/webhooks/checkout-calculate-taxes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ import { SubscriptionPayloadErrorChecker } from "@/lib/error-utils";
import { createLogger } from "@/logger";
import { loggerContext } from "@/logger-context";
import { CalculateTaxesUseCase } from "@/modules/calculate-taxes/use-case/calculate-taxes.use-case";
import { clientLogsFeatureConfig } from "@/modules/client-logs/client-logs-feature-config";
import { DynamoDbLogWriter, ILogWriter, NoopLogWriter } from "@/modules/client-logs/log-writer";
import { LogWriterFactory } from "@/modules/client-logs/log-writer-factory";
import { LogsRepositoryDynamodb } from "@/modules/client-logs/logs-repository";
import { ILogWriter, LogWriterContext } from "@/modules/client-logs/log-writer";
import { NoopLogWriter } from "@/modules/client-logs/noop-log-writer";
import { AvataxInvalidAddressError } from "@/modules/taxes/tax-error";
import { checkoutCalculateTaxesSyncWebhook } from "@/modules/webhooks/definitions/checkout-calculate-taxes";

Expand All @@ -31,7 +29,12 @@ const withMetadataCache = wrapWithMetadataCache(metadataCache);
const subscriptionErrorChecker = new SubscriptionPayloadErrorChecker(logger, captureException);
const useCase = new CalculateTaxesUseCase({
configExtractor: new AppConfigExtractor(),
logWriterFactory: new LogWriterFactory(),
logWriterFactory: {
createWriter(context: LogWriterContext): ILogWriter {
// temp - until we fix
return new NoopLogWriter();
},
},
});

/**
Expand Down
Loading