diff --git a/server/src/queue/initSqs.ts b/server/src/queue/initSqs.ts index 9eb2d78f6..018ccbf60 100644 --- a/server/src/queue/initSqs.ts +++ b/server/src/queue/initSqs.ts @@ -1,7 +1,29 @@ import { SQSClient } from "@aws-sdk/client-sqs"; +/** + * Extracts the AWS region from a given SQS queue URL. + * Returns undefined if the URL is empty or invalid. + */ +export function extractRegionFromQueueUrl({ + queueUrl, +}: { + queueUrl: string; +}): string | undefined { + if (!queueUrl) return undefined; + // SQS URL format: https://sqs..amazonaws.com// + const match = queueUrl.match( + /^https:\/\/sqs\.([a-z0-9-]+)\.amazonaws\.com\//, + ); + return match ? match[1] : undefined; +} + export const sqs = new SQSClient({ - region: process.env.NODE_ENV === "production" ? "us-west-2" : "eu-west-2", + region: + process.env.NODE_ENV === "production" + ? "us-west-2" + : extractRegionFromQueueUrl({ + queueUrl: process.env.SQS_QUEUE_URL || "", + }), credentials: { accessKeyId: process.env.AWS_ACCESS_KEY_ID || "", secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY || "", diff --git a/shared/utils/productV2Utils/productV2ToProperties.ts b/shared/utils/productV2Utils/productV2ToProperties.ts index 9cab69964..12e31c505 100644 --- a/shared/utils/productV2Utils/productV2ToProperties.ts +++ b/shared/utils/productV2Utils/productV2ToProperties.ts @@ -2,7 +2,7 @@ import type { ApiProduct, ApiProductProperties, } from "../../api/products/previousVersions/apiProduct.js"; -import type { BillingInterval } from "../../models/productModels/intervals/billingInterval.js"; +import { BillingInterval } from "../../models/productModels/intervals/billingInterval.js"; import { UsageModel } from "../../models/productV2Models/productItemModels/productItemModels.js"; import type { ProductV2 } from "../../models/productV2Models/productV2Models.js"; import { productV2ToBasePrice } from "../productV3Utils/productItemUtils/productV3ItemUtils.js"; @@ -38,7 +38,11 @@ export const productV2ToProperties = ({ }); let intervalGroup: BillingInterval | undefined; if (basePriceItem) { - intervalGroup = itemToBillingInterval({ item: basePriceItem }); + const billingInterval = itemToBillingInterval({ item: basePriceItem }); + + if (billingInterval !== BillingInterval.OneOff) { + intervalGroup = billingInterval; + } } // Updateable