-
Notifications
You must be signed in to change notification settings - Fork 37
Project factory tenant id fix #1779
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -94,7 +94,7 @@ const config = { | |
| contextPath: process.env.CONTEXT_PATH || "/project-factory", | ||
| logLevel: process.env.APP_LOG_LEVEL || "debug", | ||
| debugLogCharLimit: process.env.APP_MAX_DEBUG_CHAR ? Number(process.env.APP_MAX_DEBUG_CHAR) : 1000, | ||
| defaultTenantId: process.env.DEFAULT_TENANT_ID || "mz", | ||
| defaultTenantId: process.env.DEFAULT_TENANT_ID , | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainAudit usages of defaultTenantId; it may now be undefined Since there’s no fallback, ensure no code depends on a non-empty default. Prefer explicit tenantId everywhere; otherwise, add boot-time validation or remove fallbacks. Run to find usages relying on defaultTenantId: 🏁 Script executed: #!/bin/bash
rg -n -C2 --type=ts --type=tsx --type=js --type=jsx '\bdefaultTenantId\b'Length of output: 27 🏁 Script executed: #!/bin/bash
rg -n -C2 'defaultTenantId'Length of output: 1556 🏁 Script executed: #!/bin/bash
# Get context around coreApis.ts:15
echo "=== coreApis.ts context ==="
sed -n '1,30p' health-services/project-factory/src/server/api/coreApis.ts
echo -e "\n=== campaignApis.ts context around 1542 ==="
sed -n '1535,1550p' health-services/project-factory/src/server/api/campaignApis.tsLength of output: 1601 🏁 Script executed: #!/bin/bash
# Check if there's any git history showing what changed on line 97
echo "=== Checking git log for config/index.ts ==="
cd health-services/project-factory && git log -p --follow -S 'defaultTenantId' -- src/server/config/index.ts 2>/dev/null | head -50
echo -e "\n=== Searching for DEFAULT_TENANT_ID in .env or docs ==="
find . -name ".env*" -o -name "*.md" | xargs grep -l "DEFAULT_TENANT_ID" 2>/dev/null || echo "No env file references found"
echo -e "\n=== Checking produceModifiedMessages signature ==="
rg -n -A5 'function produceModifiedMessages|const produceModifiedMessages|export.*produceModifiedMessages' | head -30Length of output: 1033 Enforce a non-empty DEFAULT_TENANT_ID or restore a fallback
🤖 Prompt for AI Agents |
||
| incomingRequestPayloadLimit: process.env.INCOMING_REQUEST_PAYLOAD_LIMIT || "2mb", | ||
| maxInFlight: process.env.MAX_INFLIGHT || "15", | ||
| maxEventLoopLagMs: process.env.MAX_EVENT_LOOP_LAG_MS || "100", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1262,6 +1262,10 @@ async function validateForRetry(request: any) { | |
|
|
||
| async function validateProductVariant(request: any) { | ||
| const deliveryRules = request?.body?.CampaignDetails?.deliveryRules; | ||
| const tenantId = request?.body?.CampaignDetails?.tenantId; | ||
| if(tenantId === undefined){ | ||
| logger.error("tenantId is undefined"); | ||
| } | ||
|
|
||
|
Comment on lines
+1265
to
1269
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainRequire tenantId for product-variant validation; validate at both levels Logging when tenantId is undefined but continuing leads to invalid downstream calls. Enforce presence and propagate explicitly. - const tenantId = request?.body?.CampaignDetails?.tenantId;
- if(tenantId === undefined){
- logger.error("tenantId is undefined");
- }
+ const tenantId = request?.body?.CampaignDetails?.tenantId;
+ if (!tenantId) {
+ throwError("COMMON", 400, "VALIDATION_ERROR", "tenantId is required to validate product variants");
+ }
...
- await validatePvarIds(pvarIds as string[] ,tenantId);
+ await validatePvarIds(pvarIds as string[], tenantId);Also guard inside validatePvarIds: -async function validatePvarIds(pvarIds: string[] , tenantId?: string) {
+async function validatePvarIds(pvarIds: string[] , tenantId?: string) {
+ if (!tenantId) {
+ throwError("COMMON", 400, "VALIDATION_ERROR", "tenantId is required to validate product variants");
+ }
if (!pvarIds?.length || pvarIds.some((id:any) => !id)) {
throwError("COMMON", 400, "VALIDATION_ERROR", "productVariantId is required in every delivery rule's resources");
}
- const allProductVariants = await fetchProductVariants(pvarIds ,tenantId);
+ const allProductVariants = await fetchProductVariants(pvarIds, tenantId);Check for any other call sites that still use the old signature: Also applies to: 1281-1283, 1285-1293 🏁 Script executed: #!/bin/bash
rg -n -C2 --type=ts --type=tsx '\bvalidatePvarIds\s*\('Length of output: 27 |
||
| if (!Array.isArray(deliveryRules)) { | ||
| throwError("COMMON", 400, "VALIDATION_ERROR", "deliveryRules must be an array"); | ||
|
|
@@ -1274,18 +1278,18 @@ async function validateProductVariant(request: any) { | |
| } | ||
| }); | ||
| const pvarIds= getPvarIds(request?.body); | ||
| await validatePvarIds(pvarIds as string[]); | ||
| await validatePvarIds(pvarIds as string[] ,tenantId); | ||
| logger.info("Validated product variants successfully"); | ||
| } | ||
|
|
||
| async function validatePvarIds(pvarIds: string[]) { | ||
| async function validatePvarIds(pvarIds: string[] , tenantId?: string) { | ||
| // Validate that pvarIds is not null, undefined, or empty, and that no element is null or undefined | ||
| if (!pvarIds?.length || pvarIds.some((id:any) => !id)) { | ||
| throwError("COMMON", 400, "VALIDATION_ERROR", "productVariantId is required in every delivery rule's resources"); | ||
| } | ||
|
|
||
| // Fetch product variants using the fetchProductVariants function | ||
| const allProductVariants = await fetchProductVariants(pvarIds); | ||
| const allProductVariants = await fetchProductVariants(pvarIds ,tenantId); | ||
|
|
||
| // Extract the ids of the fetched product variants | ||
| const fetchedIds = new Set(allProductVariants.map((pvar: any) => pvar?.id)); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Enforce tenantId; avoid sending undefined in query params
Passing
tenantId: undefinedcan generate invalid requests. Fail fast if tenantId is missing.🤖 Prompt for AI Agents