fix: plan properties

This commit is contained in:
John Yeo
2025-12-04 09:41:57 +00:00
parent c67d1ab2ef
commit 60fbd2b6dc
2 changed files with 29 additions and 3 deletions

View File

@@ -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.<region>.amazonaws.com/<account>/<queueName>
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 || "",

View File

@@ -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