Repository navigation
fix(api-logs): log every route that opts in to LogApiRequests and let extensions relate ids - #302
Merged
Merged
Conversation
…re or network Storefront routes are mounted under storefront/v1/, but isPublicRequest only matched v1/ since 39a6760, so LogApiRequests never logged storefront writes. Treat storefront/v1/ as public too (internal int/ routes stay excluded), and add the storefront store or network public id to the log's related column so a request can be traced back to the key that made it.
…orefront-api-requests
getSessionScope returns no scope when the request has no session. Every test request had one, so the release branch fell one statement short of the coverage floor after #300.
getCompanyUuid called $request->session() unguarded, so generateQueryCacheKey threw "Session store not set on request." before getSessionScope's hasSession check could apply. Check hasSession first and fall back to the user and request input as before. The test now covers the sessionless path through generateQueryCacheKey instead of calling getSessionScope by reflection.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## release/v1.6.69 #302 +/- ##
====================================================
Coverage 100.00% 100.00%
- Complexity 8276 8341 +65
====================================================
Files 454 454
Lines 26453 26583 +130
====================================================
+ Hits 26453 26583 +130
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…orefront-api-requests
…let extensions relate ids
Core no longer names storefront. Every route that runs LogApiRequests opted in
through its middleware group (core's public API or an extension's), so
shouldLog only skips internal routes and requests without a route, instead of
requiring the core v1/ prefix. isPublicRequest is back to v1/ only, so
storefront filters and resources are unchanged.
LogApiRequest::RELATED_ATTRIBUTE ("api_request_log_related") is a request
attribute whose ids are added to the log's related column. Extensions set it
from their middleware, for example storefront with the public id of the store
or network whose key made the request.
… methods and an unresolvable transactions manager #301 left three statements in ApiModelCache unrun, so the release branch is under the 100% coverage floor.
This was referenced Oct 13, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Storefront API write requests were never written to
api_request_logs. That is why we could not trace the abuse ofPOST storefront/v1/customers/request-creation-code, which sent about $500 of Twilio SMS.LogApiRequests::shouldLog()requiredHttp::isPublicRequest(), which only matches route URIs starting withv1/(since 39a6760, v1.6.17). Storefront addsLogApiRequeststo its ownstorefront.apigroup, but its routes arestorefront/v1/..., so they were skipped.Core stays extension-agnostic: nothing here names storefront.
Change
fleetbase.apigroup attachesLogApiRequests, and an extension attaches it to its own public group. Attaching the middleware is the opt-in, soshouldLog()now skips only internal routes (Http::isInternalRequest(), anyintsegment) and requests without a route. It no longer requires the corev1/prefix.isPublicRequest()is unchanged. It still matchesv1/only, so storefront filters, resources and validation behave as before.LogApiRequest::RELATED_ATTRIBUTE(api_request_log_related) is a request attribute.getPayload()adds its ids, skipping empty ones, to therelatedcolumn. feat(api-logs): relate logged storefront requests to the store or network whose key made them storefront#143 sets it to the store or network public id, so a row traces back to the storefront key and its company (company_uuidalready comes from the session).Also:
ApiModelCachecoverage on the release branchAfter #300 and #301 merged,
release/v1.6.69fell under the 100% coverage floor. This PR:hasSession()check togetCompanyUuid(). For a request with no session,generateQueryCacheKey()threw "Session store not set on request." before the session-scope guard ran. A test builds a key for such a request.catchwhen the transactions manager can't be resolved.ApiModelCache.phpis at 302/302 statements locally. The PR also merges the latest release branch.Tests
tests/Unit/Http/MiddlewareContractsTest.php: a POST to an extension route (storefront/v1/customers/request-creation-code) is logged with the related ids from the request attribute.storefront/int/v1writes and requests without a route are not logged. Existing tests coverv1/(logged) andint/v1/(not logged).tests/Unit/Jobs/LogApiRequestTest.php: ids from the attribute, an array or a single value, end up inrelated, and empty ids are skipped.tests/Unit/Support/ApiModelCacheTest.php: the four tests above.Validation
LogApiRequests,LogApiRequest,ApiModelCacheandHasApiModelCachetests pass: 151 tests.