Repository navigation
Save movements via the app API on lsze test - #922
Merged
Merged
Conversation
New app API routes (movement writes via the API) need one error
format, traceable requests and token auth that yields an actor.
functions/api/http/ adds an ApiError with the {error:{code,message,
details}} envelope and its status mapping, an X-Request-Id middleware,
an async route wrapper that logs internal errors without leaking them,
and appAuth, which verifies the ID token (checkRevoked) and answers
401 for rejected tokens but 500 for infrastructure faults such as
unreachable signing keys. Existing routes are not wired to it.
The new specs run in the node environment, so the root jest setup
only sets the language in localStorage where localStorage exists.
Pure CommonJS core in functions/movements/domain that mirrors the movement write rules of the Realtime Database: a tenant policy built from the generated functions config, validateMovement (fields, formats, enums, conditional rules), checkWriteAccess (ownership and movement lock) and prepareWrite (update merge, server-derived negativeTimestamp, createdBy and order key). negativeTimestamp is always derived from dateTime, closing the backdated-lock bypass. The generator now emits the fields the policy needs and the new movementWritesViaApi flag (set in no project yet). It refuses per-environment values the rules cannot see. Own "__proto__" keys and Object.prototype field names are handled as data. A parity suite runs the shared cases against the built rules in the emulator. The functions config loader now uses the generated config when any feature flag is set, not only reportApiEnabled.
POST /app/movements/:type creates and PATCH /app/movements/:type/:key updates a departure or arrival (also under /api), registered only when the functions config has movementWritesViaApi. The route authenticates the app user, loads the movement and write settings, runs the domain core (prepareWrite, validateMovement, checkWriteAccess) and writes via the RTDB REST API with auth_variable_override set to the caller, so the database rules still apply as a second line of defence. A rules rejection after the domain accepted is logged and answered as 500. Only JSON object bodies up to 64 KB, 100 fields and 8 levels deep are accepted, also behind the Cloud Functions body parsers, so malformed input gets a 400 instead of a 500 or an oversized error list. The client does not use the endpoint yet.
With the new movementWritesViaApi flag, remote.saveMovement sends creates (POST) and updates incl. the payment method (PATCH) to the app API with the user's ID token instead of writing to the Realtime Database. Errors carry status, code, reason and validation errors from the envelope, so the existing commit failure dialog shows them. With the flag off the database path is unchanged. Because a create through the API is slow and not idempotent, further saves are ignored while one is running, a lost response is reported as "unknown whether saved", and the checkout redirect waits for a pending payment method write. A token refresh that fails offline is reported as a network error, not as signed out. The flag is switched on in lsze test only, to try the API there before other aerodromes. Configuration.md documents the differences and how to switch the flag on and off.
rzueger
force-pushed
the
claude/mcp-api-feasibility-93xd5a
branch
from
November 19, 2026 17:28
f375428 to
16fc2ca
Compare
The movement specs only covered direct database writes. CI now runs them a second time with the app built with movementWritesViaApi (npm run cy:test:api), against the same cypress-testing project. projects/cypress-testing-api.json extends cypress-testing and only switches the flag on; projects.load() now supports "extends" (top level replaced, environments merged by name). deploy:cypress builds the functions config from it, so the cypress-testing functions serve the movement routes while the default run keeps writing directly. New specs in cypress/integration/movements_api, run only with the flag: create and edit go through the API, a validation error of the API is shown and nothing is stored, and a double click saves once.
rzueger
force-pushed
the
claude/mcp-api-feasibility-93xd5a
branch
from
November 19, 2026 20:34
1212cd9 to
32fc23a
Compare
This was referenced Nov 20, 2026
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.
Summary
The first small step towards an API layer between the clients and the
Realtime Database. With the new per-project flag
movementWritesViaApi,the web app creates and updates departures and arrivals through
POST/PATCH /api/app/movements/...instead of writing to the RTDBdirectly.
The flag is on only in lsze test and in the Cypress API run.
Production and all other aerodromes behave as before.
Commits
functions/api/http/:ApiErrorwith{error:{code,message,details}};X-Request-Id;them;
appAuth, which verifies the ID token withcheckRevoked.Rejected tokens get 401, infrastructure faults get 500.
pure code in
functions/movements/domainthat mirrors the movementwrite rules: field validation, ownership, movement lock, merge
semantics.
negativeTimestampis always derived fromdateTime,which closes the bypass of the lock with a backdated date. The
functions config loader now uses the generated config when any
feature flag is set.
application / adapters / http). Writes go through the RTDB REST API
with
auth_variable_overrideset to the caller, so the existingdatabase rules still check every write. If the domain accepts a
write and the rules reject it, the mismatch is logged as an error
and the caller gets a 500. Body limits: 64 KB, 100 fields, 8 levels
deep.
remote.saveMovementdelegates to
remoteApi.tswhen the flag is on.takeLeading).(
npm run cy:test:api), against the samecypress-testingproject.
projects/cypress-testing-api.jsonextendscypress-testingandonly switches the flag on;
projects.load()now supportsextends.deploy:cypressbuilds the functions config from it, so thecypress-testingfunctions serve the routes.cypress/integration/movements_api, run only withthe flag:
Before CI can pass
The Cypress API run needs the new routes in the
cypress-testingfunctions. They are deployed manually from this branch:
cd functions && npm run deploy:cypress.Unchanged
firebase-rules-template.json,tasks/processFirebaseRules.js). Direct client writes are stillallowed everywhere, including lsze test.
still use the RTDB directly.
Test plan
npm test,npm run typecheckandnpm run test:functionson its own. At the last commit:352 / 7756 root tests and 107 / 4526 functions tests.
npm run test:rulesin the database emulator:lszt (572), lspv (572) and lsze with
lockOnDateTime(590).auth.token.email.sagas (not the forms) ran with the lsze test
__CONF__againstthe real API app:
404 on the new routes and keep writing to the RTDB directly.
npm run build --project=cypress-testing-apibuilds the app withthe flag compiled in.
deploy:cypress. Not run locally:the Cypress binary could not be downloaded in the dev environment.
by another pilot (should fail), and check the logs.
Known issues / notes
computeArrivalFeeswritesaircraftDataSourceonto arrivals, which the rules (and so thedomain) don't allow. Arrivals with computed fees therefore can't be
edited, either directly or through the API. A separate fix is
needed.
firebase-hosting-dev.yml, hosting andfunctions deploy in parallel. If the bundle goes live before the
functions, lsze-test saves get 404 until the functions are up.
projects/Configuration.md):can create a duplicate.
🤖 Generated with Claude Code
https://claude.ai/code/session_01EsQwcjvDCVeFpizmLUnv9B