Skip to content

build(deps): move to ts-client 7, with typed API calls and checked request bodies - #346

Merged
MrYuion merged 10 commits into
developfrom
work/migrate-ts-client-v7
Nov 23, 2026
Merged

MrYuion merged 10 commits into
developfrom
work/migrate-ts-client-v7

Conversation

@MrYuion

@MrYuion MrYuion commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

Backoffice used @placeos/ts-client 6.x. Version 7 replaces the global session and the raw HTTP helpers with a generated, typed client. It also rejects request bodies that have fields the schema does not know.

This PR moves backoffice to ^7.0.0-next.2.

How

  • common/placeos.ts creates the auth session, the API client and the realtime client. It also gives newItem and toBody, so request bodies contain only the fields in the schema.
  • Calls use the compat helpers orThrow and orThrowPage. A failed call still rejects, as in 6.x.
  • Each item type has one save path: the forms call ACTIONS.<type>.save.
  • activeOf types the active item. withEmptyLists gives [] where v7 gives null for a list the server leaves out, as the 6.x classes did.
  • oauth-resp.html now comes from the package root. Before this change, a clean build did not have it, and the silent frame login failed.
  • Build jobs use /api/engine/v2/build/*.
  • The driver update body sends only the commit. A failed recompile shows the compiler output from the plain-text error body.
  • Metadata details that the API sends as JSON text are parsed, as 6.x did.
  • Server error text does not go to Sentry. The debug log removes it, failed calls go to Sentry with only the kind and status, and Sentry no longer records console output.

next.1 had three client problems that needed workarounds here (PlaceOS/ts-client#37). next.2 fixes them, so the second commit removes the workarounds.

Local stack e2e tests

e2e/src/local/ now has specs for the main user stories: zones, systems, users, groups, domains, triggers, admin, repositories, drivers and modules. Each test makes its own data through the API, checks the result through the API, and removes the data with the new cleanup fixture. e2e/README.md lists the coverage and the stories that the local stack cannot run (no core, build service or upload store).

Bugs the new tests found

These were also on develop.

  • object-list-field sent a value in a new row to the row with the field's index. Tenant booking limits and SAML attribute mappings were lost.
  • A new SAML source sent name_identifier_format: '', and the API refused it with a 422. A new source now leaves out empty values, so the API gives its defaults. The attribute and runtime parameter maps also updated 200 ms after a change, so a quick save lost them. They now update at once.
  • The API keeps the email of a saved user, but the form let the admin change it and showed success. The field is now read-only for a saved user.
  • The API key edit form did not show the assigned user.
  • The module header status did not change after start or stop, because the item changed in place.
  • Edge "Last seen" read the time in seconds as milliseconds ("56 years ago"). It now shows the correct time, or "Never" for a new edge.
  • An extension with no conditions broke the extensions list.
  • The broker edit button said "New MQTT Broker" (en-US, en-GB, fr). It now says "Edit MQTT Broker" and has an accessible name.

Behaviour changes

  • v7 keeps tokens in memory unless the app is trusted. Each page load signs in again through the hidden frame.
  • A new module gets port 1 when no port is given, also from the module form. The server default is 0, and port 0 does not fall back to the driver port.
  • Sentry events no longer have console breadcrumbs. Click, navigation and request breadcrumbs stay.
  • A cascade delete plan fails when a list does not move to its next page. Before, the plan could be short with no error.
  • Adding or removing a zone trigger sends only triggers, so other edits to the zone stay.
  • When the item counts and the metadata tab load at the same time, they share one metadata request.
  • The email of a saved user cannot be edited.

Testing

  • tsc and ngc: 0 errors. The spec type check has the same 10 errors as develop.
  • Vitest: 1084 tests pass.
  • Mock e2e on chromium and mobile-chrome: all pass. AC-ADM-011-4 sometimes fails and then passes on retry (3 in 10 on develop too): its helper presses ArrowDown before the debounced user search starts.
  • Local stack e2e (e2e/stack): 175 pass, setup included. The specs I changed for these fixes also passed twice in a row.
  • Not tested on a real server: module exec, live bindings, driver compile, uploads and build jobs. The local stack does not have those services.

Five rounds of multi-model review checked the first commit. All blockers are fixed. The later commits (the workaround removal, the review fixes, two cleanup passes, the e2e specs and the bug fixes) had no council review.

Created with Claude Opus 5.5 in Claude Code, with review by gpt-6.2-sol.

🤖 Generated with Claude Code

Replace the 6.x session globals and raw HTTP helpers with the v7
typed client, session and realtime API. Calls keep the 6.x reject-on-error
behaviour through the compat helpers.

- common/placeos.ts holds the auth session, client and realtime
- request bodies keep only schema fields (newItem, toBody)
- serve oauth-resp.html from the package root for the frame login
- build jobs use /api/engine/v2/build
- driver recompile and reload read text responses
- server error text no longer reaches the console or Sentry

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@greptile-apps

greptile-apps Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[High impact] The changes since the previous review appear safe to merge.

Summary

Moves Backoffice to @placeos/ts-client 7 with typed calls, checked request bodies, and local-stack tests.

  • Backoffice uses typed client calls and schema-shaped item data.
  • Sign-in, credentialed requests, and error reports use the new client session.
  • Admin pages use typed calls for build jobs, cluster status, and cascade plans.
  • Several admin forms and detail views keep their data and labels in sync.
  • Local-stack tests cover more Backoffice stories and clean up their test data.

Reviews (9) · Last reviewed commit: "fix(triggers): a new trigger gets POST a..." · Reviewed by Greptile

Comment thread src/app/admin/staff-api.component.ts Resolved
ts-client now reads the driver recompile and reload replies as text,
keeps a plain-text error body in the http error, and navigates only to
http and https URLs. Remove the local operations, the error text reader
and the navigate hook that did this in backoffice.

readError shows a plain-text error body, and the debug log leaves out
the new error text.

Refs PlaceOS/ts-client#37

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread src/app/common/errors.ts Resolved
MrYuion and others added 3 commits November 22, 2026 19:40
…e out of Sentry

- extensions and the history comparison get parsed metadata details, as
  6.x gave them
- history version dates use milliseconds, so they no longer show 1970
- Sentry does not record console output, where error toasts put the
  message of the server

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- one collectPages in common/types, used by cascade delete and the zone
  export. A next() that gives null now fails the cascade plan instead of
  giving a short list
- httpError, settingsLevels and toUser replace repeated code
- remove cleanObject calls around toBody, which drops null already
- remove apiClient, the binding directive ngOnInit and unused types
- derive the signage AI provider type from the API type
- the debug log copies nothing while window.debug is off

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… on load

- forms save through ACTIONS.<type>.save, and a crudActions factory
  builds the plain item actions
- zone trigger links send only `triggers`, so other edits stay
- activeOf types the active item with its settings, so state services
  need no casts
- withEmptyLists gives `[]` for null value lists of the active item and
  settings keys, so reads need no guards
- the item counts and the metadata tab share one metadata load
- errors.ts reads the parsed CallError, with no raw Response branches
- form models and the chip-list use readonly arrays
- cluster task names load nodes without their status

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread src/app/common/placeos.ts Resolved
MrYuion and others added 2 commits November 23, 2026 00:45
- object-list-field: a value in a new row went to the row with the field's
  index, so tenant booking limits and SAML attribute mappings were lost
- SAML: a new source leaves out empty values, so the API gives its defaults
  and does not refuse an empty name identifier format. The attribute and
  runtime parameter maps update without a delay, so a quick save keeps them
- users: the email of a saved user is read-only, as the API keeps it
- API keys: the edit form shows the assigned user
- modules: the header status follows start and stop
- edges: "Last seen" reads the time in seconds, and shows "Never" for a
  new edge
- extensions: an extension with no conditions no longer breaks the list
- brokers: the edit button says "Edit MQTT Broker" and has an accessible name

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Specs for zones, systems, users, groups, domains, triggers, admin,
repositories, drivers and modules against the local PlaceOS stack. Each
test makes its own data through the API, checks the result through the
API, and removes the data with the new `cleanup` fixture.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread src/app/modules/module-state.service.ts Resolved
- A module start or stop reply changes the active item only when the same
  module is still active, and it copies the current item. Before, a reply
  after a move to another section made the old module the active item there
- `loadMetadataBlocks` shares only a load that is still running. A finished
  load is not used again, so a metadata write from an extension or the user
  settings is seen at once. `forgetMetadataBlocks` is removed

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@MrYuion MrYuion left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note

🤖 Claude Opus 5.5 responding on behalf of Alex

Review of 5dc98e68 against develop: 3 regressions from 6.x and 2 nits, inline below.

I checked the 5 "Fixed in" replies against the code. All are true: parseMetadataDetails is used for the extension reply and the history diff, both history selectors multiply updated_at by 1000, Sentry drops the Console integration, toggleModuleState reads active_item again before replaceItem, and loadMetadataBlocks shares only a running load. The secret_expiry answer matches the 6.x behaviour.

Checks on this head: bun run test:ci passes (129 files, 1079 tests). bun run lint passes. tsc -p tsconfig.app.json passes. tsc -p tsconfig.spec.json gives 10 errors (Promise.withResolvers lib target, mock types). CI does not run that check, and the lines with the errors are not changed by this PR.

I compared with the @placeos/ts-client@6.11.0 source and dropped findings where 6.x did the same thing. For example, the bulk import spread a PlaceModule into a plain object, so toJSON never removed control_system_id.

Comment thread src/app/ui/guards/authorised.guard.ts Resolved
Comment thread src/app/triggers/triggers.utilities.ts Resolved
Comment thread src/app/common/types.ts Resolved
…ty webhook methods

- An extension `load` of a block that does not exist gives `{}` again.
- The route guard waits for the connection with no time limit, as 6.x did.
  Only the user load has the 60 s limit.
- A saved trigger with no webhook methods keeps the empty list. Only a new
  trigger gets `POST`. The server always sends the list.
- A new metadata block shows no update time until it is saved.
- The `mapPage` doc comment is above `mapPage`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread src/app/triggers/triggers.utilities.ts Resolved
The create flow gives the form `newItem(Trigger)`, so the form always has
a trigger and the `POST` default did not apply. Now a saved trigger keeps
its list, also when it is empty. A copy keeps its list. An unsaved trigger
with an empty list gets `POST`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@MrYuion
MrYuion merged commit 3cc46f0 into develop Nov 23, 2026
6 checks passed
@MrYuion
MrYuion deleted the work/migrate-ts-client-v7 branch November 23, 2026 01:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant