From 10cccb0dcff4e5c55b81bfd411f29eaf5de74f9f Mon Sep 17 00:00:00 2001 From: John Yeo Date: Fri, 13 Mar 2026 15:18:47 +0000 Subject: [PATCH] addressed code review changes, fix check --- server/src/internal/api/check/handleCheck.ts | 3 ++- server/src/internal/api/check/runCheckWithTrack.ts | 12 +++++++++--- shared/api/entities/entityOpModels.ts | 1 + .../requestChanges/V1.2_EntityQueryChange.ts | 6 ++---- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/server/src/internal/api/check/handleCheck.ts b/server/src/internal/api/check/handleCheck.ts index 348471345..c1c985abb 100644 --- a/server/src/internal/api/check/handleCheck.ts +++ b/server/src/internal/api/check/handleCheck.ts @@ -91,7 +91,8 @@ export const handleCheck = createRoute({ targetVersion: ctx.apiVersion, resource: AffectedResource.Check, legacyData: { - noCusEnts: checkData.apiBalance === undefined, + noCusEnts: + checkData.apiBalance === undefined && checkData.apiFlag === undefined, featureToUse: checkData.featureToUse, }, ctx, diff --git a/server/src/internal/api/check/runCheckWithTrack.ts b/server/src/internal/api/check/runCheckWithTrack.ts index b2e3b0756..f10928f95 100644 --- a/server/src/internal/api/check/runCheckWithTrack.ts +++ b/server/src/internal/api/check/runCheckWithTrack.ts @@ -4,7 +4,6 @@ import { CheckResponseV3Schema, ErrCode, FeatureType, - type FullCustomer, featureUtils, InsufficientBalanceError, InternalError, @@ -52,6 +51,14 @@ export const runCheckWithTrack = async ({ }); } + if (checkData.originalFeature.type === FeatureType.Boolean) { + throw new RecaseError({ + message: "Not allowed to pass in send_event: true for a boolean feature", + code: ErrCode.InvalidRequest, + statusCode: 400, + }); + } + const featureDeductions = getTrackFeatureDeductions({ ctx, featureId: body.feature_id, @@ -71,7 +78,6 @@ export const runCheckWithTrack = async ({ }; let allowed = true; - let fullCustomer: FullCustomer | undefined; try { // Use V2_1 to get ApiBalanceV1 format internally @@ -135,7 +141,7 @@ export const runCheckWithTrack = async ({ entity_id: checkData.entityId, required_balance: requiredBalance, balance: checkData.apiBalance ?? null, - // lock_id: body.lock?.lock_id, + flag: checkData.apiFlag ?? null, }); return checkResponse; diff --git a/shared/api/entities/entityOpModels.ts b/shared/api/entities/entityOpModels.ts index a4099d9b8..c1e457336 100644 --- a/shared/api/entities/entityOpModels.ts +++ b/shared/api/entities/entityOpModels.ts @@ -12,6 +12,7 @@ export const GetEntityQuerySchema = z.object({ CustomerExpand.SubscriptionsPlan, CustomerExpand.PurchasesPlan, CustomerExpand.BalancesFeature, + CustomerExpand.FlagsFeature, ]), ).default([]), skip_cache: z.boolean().optional(), diff --git a/shared/api/entities/requestChanges/V1.2_EntityQueryChange.ts b/shared/api/entities/requestChanges/V1.2_EntityQueryChange.ts index d991e76c9..3558976e9 100644 --- a/shared/api/entities/requestChanges/V1.2_EntityQueryChange.ts +++ b/shared/api/entities/requestChanges/V1.2_EntityQueryChange.ts @@ -6,10 +6,7 @@ import { import type { z } from "zod/v4"; import type { SharedContext } from "../../../types/sharedContext"; import { CustomerExpand } from "../../customers/components/customerExpand/customerExpand"; -import { - type GetEntityQuery, - GetEntityQuerySchema, -} from "../entityOpModels"; +import { type GetEntityQuery, GetEntityQuerySchema } from "../entityOpModels"; /** * V1_2_EntityQueryChange: Transforms entity query TO latest format @@ -60,6 +57,7 @@ export const V1_2_EntityQueryChange = defineVersionChange({ ...existingExpand, CustomerExpand.SubscriptionsPlan, CustomerExpand.BalancesFeature, + CustomerExpand.FlagsFeature, CustomerExpand.PurchasesPlan, ] as GetEntityQuery["expand"];