Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
Address PR review: disable commit during preview load; drop client-controlled prorationDate
Tre Dubrava5eeebbff99f7
diff --git a/backend/src/ee/routes/v1/license-v2-router.ts b/backend/src/ee/routes/v1/license-v2-router.tsindex 2eda6882ea..d54ec17712 100644--- a/backend/src/ee/routes/v1/license-v2-router.ts+++ b/backend/src/ee/routes/v1/license-v2-router.ts@@ -317,7 +317,6 @@ export const registerLicenseV2Router = async (server: FastifyZodProvider) => {},schema: {params: z.object({ organizationId: z.string().trim(), productId: z.string().trim() }),- querystring: z.object({ prorationDate: z.coerce.number().optional() }),response: {200: BillingV2MutationResultSchema}@@ -327,8 +326,7 @@ export const registerLicenseV2Router = async (server: FastifyZodProvider) => {return server.services.licenseV2.removeProduct({orgId: req.params.organizationId,actor: buildActor(req.permission),- productId: req.params.productId,- prorationDate: req.query.prorationDate+ productId: req.params.productId});}});diff --git a/backend/src/ee/services/license-v2/license-v2-service.ts b/backend/src/ee/services/license-v2/license-v2-service.tsindex 2a7f8971ec..97aac08bfc 100644--- a/backend/src/ee/services/license-v2/license-v2-service.ts+++ b/backend/src/ee/services/license-v2/license-v2-service.ts@@ -552,10 +552,10 @@ export const licenseV2ServiceFactory = ({};// Remove a single product from a multi-product subscription, the operation the Stripe Customer- // Portal cannot do. prorationDate pins the proration to the previewed value when provided.- const removeProduct = async ({ orgId, actor, productId, prorationDate }: TRemoveBillingV2ProductDTO) => {+ // Portal cannot do. The license server prorates at commit time (Stripe default = now).+ const removeProduct = async ({ orgId, actor, productId }: TRemoveBillingV2ProductDTO) => {await ensureManageBilling(orgId, actor);- const result = await licenseClient.removeSubscriptionItem(orgId, productId, prorationDate);+ const result = await licenseClient.removeSubscriptionItem(orgId, productId);await licenseClient.invalidateEntitlements(orgId);return { subscriptionId: result.subscriptionId };};diff --git a/backend/src/ee/services/license-v2/license-v2-types.ts b/backend/src/ee/services/license-v2/license-v2-types.tsindex 04482ed479..ae46d5e033 100644--- a/backend/src/ee/services/license-v2/license-v2-types.ts+++ b/backend/src/ee/services/license-v2/license-v2-types.ts@@ -152,7 +152,6 @@ export type TRemoveBillingV2ProductDTO = {orgId: string;actor: OrgServiceActor;productId: string;- prorationDate?: number;};export type TBillingV2SubscriptionLifecycleDTO = {diff --git a/backend/src/services/license-client/license-client-backends.ts b/backend/src/services/license-client/license-client-backends.tsindex 87577e86fe..07f413a089 100644--- a/backend/src/services/license-client/license-client-backends.ts+++ b/backend/src/services/license-client/license-client-backends.ts@@ -233,16 +233,9 @@ export const licenseServerBackend = (return checkoutResultSchema.parse(body);},- removeSubscriptionItem: async (- orgId: string,- productId: string,- prorationDate?: number- ): Promise<TCheckoutResult> => {+ removeSubscriptionItem: async (orgId: string, productId: string): Promise<TCheckoutResult> => {const url = new URL(`${SUBSCRIPTION_ITEMS_PATH}/${encodeURIComponent(productId)}`, serverUrl);url.searchParams.set("org_id", orgId);- if (prorationDate !== undefined) {- url.searchParams.set("prorationDate", String(prorationDate));- }const res = await fetch(url, {method: "DELETE",headers: { Authorization: `Bearer ${mintServiceToken(signingKey)}` },diff --git a/backend/src/services/license-client/license-client-types.ts b/backend/src/services/license-client/license-client-types.tsindex becd27831b..2672ef9d1c 100644--- a/backend/src/services/license-client/license-client-types.ts+++ b/backend/src/services/license-client/license-client-types.ts@@ -121,7 +121,7 @@ export const checkoutResultSchema = z// Proration preview for an add/remove against an existing subscription. prorationAmount is signed:// positive is charged now (an add), negative is a credit toward the next invoice (a removal).-// prorationDate is echoed so the follow-up change can reproduce the same numbers.+// prorationDate is the timestamp the preview was computed at.const subscriptionPreviewLineSchema = z.object({description: z.string(),@@ -242,7 +242,7 @@ export type TLicenseClientBackend = {createPortalSession: (orgId: string, payload: TCreatePortalPayload) => Promise<TSessionResponse>;previewSubscriptionChange: (orgId: string, payload: TSubscriptionPreviewPayload) => Promise<TSubscriptionPreview>;addSubscriptionItems: (orgId: string, payload: TAddSubscriptionItemsPayload) => Promise<TCheckoutResult>;- removeSubscriptionItem: (orgId: string, productId: string, prorationDate?: number) => Promise<TCheckoutResult>;+ removeSubscriptionItem: (orgId: string, productId: string) => Promise<TCheckoutResult>;cancelSubscription: (orgId: string) => Promise<TCheckoutResult>;resumeSubscription: (orgId: string) => Promise<TCheckoutResult>;};diff --git a/backend/src/services/license-client/license-client.test.ts b/backend/src/services/license-client/license-client.test.tsindex 5744549ab0..43b47526a0 100644--- a/backend/src/services/license-client/license-client.test.ts+++ b/backend/src/services/license-client/license-client.test.ts@@ -34,6 +34,10 @@ const createFakeKeyStore = () => {setItemWithExpiry: async (key: string, _ttl: number | string, value: string | number | Buffer) => {store.set(key, String(value));return "OK" as const;+ },+ deleteItem: async (key: string) => {+ const existed = store.delete(key);+ return existed ? 1 : 0;}};};diff --git a/backend/src/services/license-client/license-client.ts b/backend/src/services/license-client/license-client.tsindex f85fbbf3b5..617b619f75 100644--- a/backend/src/services/license-client/license-client.ts+++ b/backend/src/services/license-client/license-client.ts@@ -131,11 +131,11 @@ export const licenseClientFactory = ({ envConfig, keyStore }: TLicenseClientFactreturn backend.addSubscriptionItems(orgId, payload);};- const removeSubscriptionItem = async (orgId: string, productId: string, prorationDate?: number) => {+ const removeSubscriptionItem = async (orgId: string, productId: string) => {if (!backend) {throw new Error("license client backend is not configured");}- return backend.removeSubscriptionItem(orgId, productId, prorationDate);+ return backend.removeSubscriptionItem(orgId, productId);};const cancelSubscription = async (orgId: string) => {diff --git a/frontend/src/hooks/api/billingV2/mutations.tsx b/frontend/src/hooks/api/billingV2/mutations.tsxindex 42d54c8fa5..49fd4ceac7 100644--- a/frontend/src/hooks/api/billingV2/mutations.tsx+++ b/frontend/src/hooks/api/billingV2/mutations.tsx@@ -102,10 +102,9 @@ export const useAddBillingV2Product = () => {export const useRemoveBillingV2Product = () => {const queryClient = useQueryClient();return useMutation({- mutationFn: async ({ orgId, productId, prorationDate }: TRemoveBillingV2ProductDTO) => {- const params = prorationDate === undefined ? "" : `?prorationDate=${prorationDate}`;+ mutationFn: async ({ orgId, productId }: TRemoveBillingV2ProductDTO) => {const { data } = await apiRequest.delete<BillingV2MutationResult>(- `/api/v1/organizations/${orgId}/billing/v2/subscription/items/${encodeURIComponent(productId)}${params}`+ `/api/v1/organizations/${orgId}/billing/v2/subscription/items/${encodeURIComponent(productId)}`);return data;diff --git a/frontend/src/hooks/api/billingV2/types.ts b/frontend/src/hooks/api/billingV2/types.tsindex a05c9c10cc..3776720532 100644--- a/frontend/src/hooks/api/billingV2/types.ts+++ b/frontend/src/hooks/api/billingV2/types.ts@@ -118,7 +118,7 @@ export type BillingV2PreviewLine = {};// prorationAmount is signed: positive is charged now (an add), negative is a credit toward the next-// invoice (a removal). prorationDate is echoed so the follow-up change reproduces the same numbers.+// invoice (a removal). prorationDate is the timestamp the preview was computed at, for display only.export type BillingV2Preview = {currency: string;prorationAmount: number;@@ -148,7 +148,6 @@ export type TAddBillingV2ProductDTO = {export type TRemoveBillingV2ProductDTO = {orgId: string;productId: string;- prorationDate?: number;};export type TBillingV2LifecycleDTO = {diff --git a/frontend/src/pages/organization/BillingV2Page/components/AddProductModal.tsx b/frontend/src/pages/organization/BillingV2Page/components/AddProductModal.tsxindex f29871802e..8bc00bd8b3 100644--- a/frontend/src/pages/organization/BillingV2Page/components/AddProductModal.tsx+++ b/frontend/src/pages/organization/BillingV2Page/components/AddProductModal.tsx@@ -54,6 +54,10 @@ export const AddProductModal = ({ orgId, product, cadence, onClose }: Props) =>const dueToday = preview.data ? Math.max(preview.data.prorationAmount, 0) : 0;+ // Only let the user commit a charge once the prorated cost has rendered; a still-loading or+ // failed preview keeps the confirm disabled so nobody pays without seeing the amount.+ const canConfirm = Boolean(preview.data);+return (<AlertDialogopen@@ -103,7 +107,11 @@ export const AddProductModal = ({ orgId, product, cadence, onClose }: Props) =></div><AlertDialogFooter><AlertDialogCancel>Cancel</AlertDialogCancel>- <AlertDialogAction variant="org" isDisabled={addProduct.isPending} onClick={handleAdd}>+ <AlertDialogAction+ variant="org"+ isDisabled={addProduct.isPending || !canConfirm}+ onClick={handleAdd}+ >Add {product.name}</AlertDialogAction></AlertDialogFooter>diff --git a/frontend/src/pages/organization/BillingV2Page/components/RemoveProductModal.tsx b/frontend/src/pages/organization/BillingV2Page/components/RemoveProductModal.tsxindex ae9dcd1ae4..e57a3f7377 100644--- a/frontend/src/pages/organization/BillingV2Page/components/RemoveProductModal.tsx+++ b/frontend/src/pages/organization/BillingV2Page/components/RemoveProductModal.tsx@@ -39,11 +39,7 @@ export const RemoveProductModal = ({ orgId, product, onClose }: Props) => {const handleRemove = async () => {try {- await removeProduct.mutateAsync({- orgId,- productId: product.id,- prorationDate: preview.data?.prorationDate- });+ await removeProduct.mutateAsync({ orgId, productId: product.id });createNotification({type: "success",text: `${product.name} will be removed. It may take a moment to update here.`@@ -56,6 +52,10 @@ export const RemoveProductModal = ({ orgId, product, onClose }: Props) => {const credit = preview.data ? Math.abs(preview.data.prorationAmount) : 0;+ // Block while the credit preview is still in flight; a failed preview keeps the graceful+ // fallback enabled because a removal only ever credits the customer.+ const previewLoading = !preview.data && !preview.isError;+return (<AlertDialogopen@@ -104,7 +104,11 @@ export const RemoveProductModal = ({ orgId, product, onClose }: Props) => {</div><AlertDialogFooter><AlertDialogCancel>Keep product</AlertDialogCancel>- <AlertDialogAction variant="danger" isDisabled={removeProduct.isPending} onClick={handleRemove}>+ <AlertDialogAction+ variant="danger"+ isDisabled={removeProduct.isPending || previewLoading}+ onClick={handleRemove}+ >Remove {product.name}</AlertDialogAction></AlertDialogFooter>