Skip to content

feat: move to the typed ts-client 7, so bad API data fails at once - #755

Merged
MrYuion merged 25 commits into
developfrom
feat/migrate-ts-client-v7
Dec 3, 2026
Merged

MrYuion merged 25 commits into
developfrom
feat/migrate-ts-client-v7

Conversation

@MrYuion

@MrYuion MrYuion commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

The apps use @placeos/ts-client 6.x, which has no types for the API and no checks on what the apps send or get. This moves every app and lib to the typed 7.x client (7.0.0-next.6). Requests and responses are now checked against the API schemas, so a wrong field fails at once and does not reach the server.

How

  • One client layer in libs/common:
    • place-client.ts: the login session, realtime, token(), authority() and placeFetch().
    • realtime.ts: getModule(), with the 6.x call and binding shape.
    • json.ts: shared JSON helpers.
  • Generated operations: they replace the raw get/post calls. placeFetch is used only for endpoints that have no operation.
  • Mock data: it matches the 7.x schemas. libs/mocks/src/tests/mock-schemas.spec.ts keeps it that way.
  • Teams tabs and the Outlook task pane: they are trusted, so their tokens stay over a reload. They keep the tokens in their session storage, so the app outside Teams or Outlook, which shares the local storage, does not get them.
  • Paste-token shortcut: it keeps a pasted refresh token, with the new session.useRefreshToken.
  • Signage manager: it sends include_child_data again.
  • Code from develop: remote debugging and payments now use the 7.x client.

ts-client changes for this PR, already released on next:

Fixes from the review (see below):

  • Events: a recurring event read no clashes, because Staff API sends them as system_id, event_start and event_end.
  • Settings: a save waits for the stored settings, and does not replace them when they did not load.
  • Catering: a save keeps the stored fields that the app does not read.
  • Startup: the device settings of the URL and the visitor kiosk token apply before the first request.
  • Errors and logs: a failed call shows its message, not [object Object], and logs keep only its kind and status.
  • Signage: a trigger that is already on when the display binds does not replay its playlist.
  • Public events: when one tab changes the remembered guest, the other open tabs forget it too.
  • Outlook: single sign-on stops when the sign-in dialog opens, so it cannot open a second prompt or replace the token of the dialog.

Checks

  • Type check, lint and e2e type check: clean.
  • Production builds: all 19 apps build with their budgets. On develop, Workplace fails its 1000 kB initial budget at 1.15 MB, and the migration added about 29 kB. Two fixes take it to 912 kB: the payments service and its checkout modal now load on use, and provideValueAccessor moved out of the @placeos/common index, to @placeos/common/value-accessor, so @angular/forms loads only with the form fields. CI builds with --configuration=feat, which has no budgets.
  • Unit tests: all 31 projects pass.
  • E2E in mock mode, after the rebase:
    • Workplace: 57 of 57 pass.
    • Signage Manager: 43 pass, 2 fail. Both also fail on develop: US-SGM-005, and the child-group toggle in the folder view.
  • E2E against a local PlaceOS stack, before the rebase:
    • Stagehand: 22 of 22 pass.
    • Workplace: 149 pass, 8 fail.
    • Concierge: 38 pass, 17 fail.
    • Each failure also fails on develop. They come from the login redirect setup, the Microsoft 365 credentials that the stack does not have, and the state of the stack data.
  • Unit tests under load: all 31 projects passed in two full parallel runs.

Known gaps

  • Teams and Outlook tokens: a token from the Teams sign-in window still does not refresh when it expires. Reload the tab to sign in again. See docs/teams-app.md.
  • Remote debugging filter: 7.x does not log realtime calls. Remote debugging now filters only the binding-change lines of its own driver.

Sentry

Fixes PLACEOS-DEV-N5. In 7.x, a mock module is a plain object with no call method, so the 6.x mod.call.bind(mod) wrap in persistSystem failed at mock start-up. This PR wraps the $ functions in its place.

Council review

Rounds: 6 with gpt-6.2-sol on high. Verdict: approved

Aspect Round 1 Round 2 Round 3 Round 4 Round 5 Round 6
Correctness 6/10 9/10 8/10 7/10 9/10 9/10
Simplicity 7/10 8/10 — — — —
Readability 8/10 9/10 — — — —
Coverage 8/10 8/10 8/10 9/10 — —
Security 7/10 8/10 8/10 8/10 9/10 —
Privacy 7/10 7/10 8/10 8/10 9/10 —
Compatibility 6/10 8/10 9/10 — — —
Errors 6/10 9/10 — — — —
Concurrency 6/10 8/10 8/10 8/10 8/10 9/10
Data integrity 7/10 8/10 8/10 9/10 8/10 9/10
Test quality 8/10 9/10 — — — —
Determinism 7/10 9/10 — — — —

Created with Claude Opus 5.5 in Claude Code (T3 Code). Subagents on Claude Opus 5.5 wrote parts of the tests and follow-ups. The council reviewers ran on gpt-6.2-sol.

🤖 Generated with Claude Code

@greptile-apps

greptile-apps Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5 · No confirmed new issue blocks merging this PR.RetriggerView in GreptileConfidence Score: 5/5

[High impact] No confirmed new issue blocks merging this PR.

Summary

Moves the apps to @placeos/ts-client 7 and adds a shared layer for login, requests, and realtime calls.

  • PlaceOS apps use typed API operations for their requests and responses.
  • Apps share login and realtime setup, with trusted tabs keeping their tokens in session storage.
  • Booking, asset, and settings flows adapt their data to the typed API.
  • Event, signage, guest, and sign-in flows use the new client behavior.

MrYuion documents the missing refresh for Teams sign-in-window tokens as a known gap; reloading signs the user in again.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
    Apps[Apps and libraries] --> Common[Shared PlaceOS client]
    Common --> Session[Login session]
    Common --> Realtime[Realtime connection]
    Apps --> Operations[Typed API operations]
    Session --> Operations
    Operations --> Checks[Request and response checks]
    Checks --> API[PlaceOS API]
    Operations --> Mocks[Mock replies]
Loading

Reviews (12) · Last reviewed commit: "fix: move the new code from develop to t..." · Reviewed by Greptile

Comment thread libs/events/src/lib/calendar.fn.ts Resolved
Comment thread libs/assets/src/lib/assets.fn.ts Resolved
Comment thread libs/assets/src/lib/assets.fn.ts Resolved

@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 MrYuion

Review of the behavior changes at 3bd5868. I checked the client layer in libs/common, the asset, booking, event and explore functions, and the signage manager services. Inline comments:

  1. Blocking. Against a live server, the staff event schema cuts event.system down to { id }. Mock mode and the mock schema spec do not show this.
  2. queryBookings no longer sends include_parent_bookings, so asset requests on a parent booking go missing from the concierge asset manager.
  3. Minor: the display zones still come from one page of 500 group zones, and the doc comment above that query is now wrong.

I found no problems in the login session, placeFetch, realtime, pagination (loadAllPages, queryAllPages) or the request body helpers.

Comment thread libs/events/src/lib/events.fn.ts Resolved
Comment thread libs/bookings/src/lib/bookings.fn.ts Resolved
Comment thread libs/bookings/src/lib/bookings.fn.ts Resolved

@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 MrYuion

I re-reviewed 77943042a4..47d00b293a, the five commits added after the review at 3bd5868. The rebase did not change the first three commits, and git range-diff shows them as identical. I found no new issues.

The fixes in the replies are correct:

  • event.system: 7.0.0-next.5 parses a response union as the variant that knows the most of the given keys, and arrays add up the counts of their items (core/schema.js, knownKeys). A full system now parses as ControlSystem if it has update_triggers.
  • include_parent_bookings: bookingQuery sends it and the as any cast is gone. No other queryBookings caller passes a field that bookingQuery drops.
  • Display zones: queryAll follows next from orThrowPage, stops after 50 pages, and still decodes the entity names. Thus removing .map(decodeEntityNames) loses nothing.
  • Ignored booking IDs: both sides are compared as strings in queryResourceAvailability and queryGroupAvailability.

Lazy loading: no app or library code imports payment-checkout-modal.component directly. Only the @placeos/payments index exports it, and payments.service.ts loads it with await import() before dialog.open. The hosted page window still opens in the click handler of the modal, so the deferred import does not cause popup blocking. No file imports provideValueAccessor from the @placeos/common index now. All build and test checks pass on 47d00b2.

Not blocking: Workplace still gets PAYMENT_CHECKOUT from the @placeos/payments index, which also exports the modal. The bundle stays small only because of tree shaking. A @placeos/payments/checkout path, like @placeos/common/value-accessor, would make this explicit. This is optional.

@MrYuion
MrYuion force-pushed the feat/migrate-ts-client-v7 branch from 47d00b2 to ec35d0f Compare November 25, 2026 02:17
Comment thread apps/concierge/src/app/metadata.ts Resolved
@MrYuion
MrYuion force-pushed the feat/migrate-ts-client-v7 branch from 49abe29 to 4c12678 Compare November 25, 2026 23:24

@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 MrYuion

I re-reviewed the changes after 49abe29c and found no new issues.

git range-diff 442eeb0c..49abe29c 2f225605..4c126788 shows 18 of the 19 commits as identical. Only ba8d3a07f2, the ts-client 7 migration commit, changed. The rebase onto develop picked up #759 and #760, and this commit now moves the #759 test to the 7.x client. The test "should keep the selected desk in the form when the save fails" mocks bookings.create with httpFailure(504, ...) instead of mocking ts_client.post through an as any cast. It fails when I revert the { ...this.model() } copy in postForm, so it still checks the #759 fix.

The source from #759 and #760 works with 7.x as merged. desk-flow-confirm.component.ts and sentry.ts did not need changes.

The fixes in the replies are correct at 4c126788:

  • Deals: deals.service.ts:39 defaults the missing entry to { details: [] }. explore-poi.service.ts:41 and explore-search.service.ts:263 default to { details: {} }. The other metadata.show callers that I checked use ?. or a .catch.
  • Public guest: PublicEventsComponent opens /guest-details when authenticated() changes from true to false. It sends the same query as the route check.
  • The fixes from the earlier reviews are still in place. These are the calendar mock system, the asset category pages, include_parent_bookings, the display zone pages and the string comparison of ignored booking IDs.

One question on a resolved thread. The Greptile finding on apps/concierge/src/app/metadata.ts about saved desks is resolved, but it has no reply and no change. ts-client 6.13 parsed string details with JSON.parse in src/metadata/metadata.ts:42-45. floorplanDetails in apps/map-studio/src/app/data/placeos.service.ts says that 7.x gives the string, and it parses it. The concierge showMetadata and the jsonList and jsonRecord helpers do not parse strings. So protected-ids.ts:57 reads a level whose desks details are a JSON string as a level with no desks. If the API stores only floorplans as strings, a reply on that thread would close this.

Checks:

  • nx test bookings --include=libs/bookings/src/test/booking-form.service.spec.ts: 129 passed.
  • nx test workplace --include=apps/workplace/src/tests/book/desk-flow/desk-flow-confirm.component.spec.ts: 20 passed.
  • nx test common --include=libs/common/src/tests/sentry.spec.ts: 12 passed.
  • tsc --noEmit for the bookings lib and spec, the workplace app and spec, and the common spec: no errors.

@MrYuion
MrYuion force-pushed the feat/migrate-ts-client-v7 branch from 4c12678 to 0231d4d Compare November 28, 2026 04:24

@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 MrYuion

I reviewed the changes after 4c126788. The branch was rebased onto develop (d780f499). git range-diff 2f225605..4c126788 d780f499..0231d4d8 shows 17 of the 19 earlier commits as identical. Commit 1 now moves the new develop code (assigned bookings, signage reports) to 7.x. Commit 15 moves its updateBooking change to the new assigned-booking.ts. Commit 0231d4d8 is new.

The 7.x changes in 0231d4d8 look correct. Module calls pass { timeout_ms }, order saves use playlist.media and updateMedia with orThrow, and updateBooking sends PATCH, which staff.bookings.update expects. Inline comments:

  1. The content report reads playlist.enabled on raw 7.x rows, where the field is nullable. The 6.x class set it to true when it was missing.
  2. Nit: commits 1–19 do not type-check without 0231d4d8.

I also found one issue outside the range while I checked the nullable fields. survey-responses.component.ts:279 calls survey.pages.forEach(...). In 7.x, Survey.pages is nullable(array(SurveyPage)) (generated/staff/schemas.ts:1484), and the survey comes raw from surveys.show(...).then(orThrow). A survey with pages: null makes the paged_responses computed throw. new-survey.service.ts:72 already uses survey.pages ?? [], and the same guard fits here.

I did not run the type check or the tests, because this worktree has no node_modules. I read the 7.0.0-next.6 and 6.x client sources from other local installs.

@MrYuion
MrYuion force-pushed the feat/migrate-ts-client-v7 branch from 0231d4d to 390523f Compare December 2, 2026 02:02
@MrYuion

MrYuion commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator Author

Note

🤖 Claude Opus 5.5 responding on behalf of MrYuion

Replies to the two items in the review at 0231d4d that were not in a thread:

  • survey.pages can be null. Fixed in 5d3cb99. paged_responses reads survey.pages ?? []. New test: a survey with pages: null gives no pages. It fails without the fix.
  • Concierge metadata given as a JSON string (the resolved Greptile thread on apps/concierge/src/app/metadata.ts). Also fixed in 5d3cb99. ts-client 6.13 parsed a string details with JSON.parse and kept the string when the parse failed (PlaceMetadata, dist/index.es.js:2761). The concierge showMetadata now does the same, so protected-ids.ts and the desk save read a string desk list as desks, not as an empty level. New test in protected-ids.spec.ts: a desk list given as a JSON string is read. It fails without the fix.

All concierge and signage-manager tests pass, and tsc passes for both apps and their specs.

@MrYuion
MrYuion force-pushed the feat/migrate-ts-client-v7 branch from 5d3cb99 to eab00a2 Compare December 3, 2026 04:05
@MrYuion

MrYuion commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator Author

Note

🤖 Claude Opus 5.5 responding on behalf of MrYuion

Rebased onto develop at b1bb346 (after #785, #786 and #787). The head is now eab00a2.

Conflicts:

New develop code moved to 7.x (in the migration commit):

  • libs/wayfinding/src/lib/metadata.ts: metadata.childrenMetadata and metadata.update with orThrow, in place of listChildMetadata and updateMetadata. Its specs in concierge and explore use mockReply.
  • apps/control/src/app/exec-command.ts: getModule from @placeos/common. Its spec uses startTestPlaceClient.
  • The enrolment spec checks session.useToken, and the desk row key spec uses mockData(Zone, …).

Checks:

  • tsc --noEmit passes for every app, spec and e2e config.
  • Unit tests pass for all 33 projects.
  • oxlint and eslint report nothing.

Move every app and lib from the 6.x client to the typed 7.x client
(7.0.0-next.4). Generated operations return a Result, request bodies and
responses are checked against the API schemas, and login and realtime use
createAuthSession and createRealtime.

- libs/common: place-client.ts (session, realtime, token, placeFetch),
  realtime.ts (getModule), json.ts (shared JSON helpers)
- Mock data matches the 7.x schemas, with a spec that keeps it that way
- Remote debugging and payments from develop use the 7.x client too
- Teams tabs and the Outlook add-in are trusted, so tokens stay over a
  reload; the paste shortcut keeps a pasted refresh token with
  useRefreshToken
- Signage manager sends include_child_data again
- The mock availability and free/busy replies now give `id` and
  `system`, as the v7 schema has them. The app found no rooms in
  mock mode before.
- `queryAssetGroupsExtended` uses `queryAssetTypes`, so types of
  hidden categories, such as desks, do not reach the asset report
  and asset availability.
The visible category check read only the first page of categories.
Types in a visible category on a later page were left out of the asset
groups, the asset report and asset availability. The check now reads
all pages, with the bounded loop that the asset query already used.
- `queryBookings` sends `include_parent_bookings` again. The concierge
  asset manager needs it to show asset requests on a parent booking.
  The query type has the field now, so the `as any` cast is gone.
- The zones of a signage display come from all pages of the group
  zones, not only the first 500.
7.0.0-next.5 parses a response union as the variant that knows the most
fields. Before, the staff event `system` lost all fields but `id` on a
live server (PlaceOS/ts-client#40).
Workplace provides `PAYMENT_CHECKOUT` at start-up. The token was in
`payments.service.ts`, so the import loaded the service, `MatDialog`
and the checkout modal with the Material checkbox and radio into the
initial bundle. The production build failed its 1000 kB budget at
1.18 MB, as it does on `develop` at 1.15 MB.

- The token, the checkout errors, the options and `openPaymentWindow`
  are in the new `payment-checkout.ts`.
- The service loads the checkout modal when it opens it.

The initial bundle of Workplace is 958.78 kB.
`provideValueAccessor` was in the `@placeos/common` index. The index is
in the initial bundle of each app, so `@angular/forms` (58 kB) was too.
It is now imported as `@placeos/common/value-accessor`.

The initial bundle of Workplace goes from 958.78 kB to 910.46 kB.
Concierge, Signage Manager, Visitor Kiosk, Map Kiosk and Stagehand
also get smaller.
The ID of a `Booking` from the 7.x API is a number. A booking event
keeps it, so editing a room booking with `app.events.use_bookings`
passed a numeric `ignore` to `queryResourceAvailability`. The check
compared it with a string, never matched, and the booking clashed
with itself.

`queryResourceAvailability` and `queryGroupAvailability` now compare
the ignored IDs and the booking IDs as strings.
7.0.0-next.6 (PlaceOS/ts-client#41) decodes metadata `details` that the
server keeps as JSON text, as 6.x did, and gives each value of a realtime
variable in a batch.

With each value, a signage trigger that is already true when the display
binds gave its first value as a change and replayed its playlist. A new
binding does not know its value yet, so its first value is now the start
state.
- The Outlook task pane and the Teams tab and sign-in window keep their
  trust flag and tokens in their session storage. Other windows share the
  local storage and no longer get them. Other windows keep no tokens, as
  in 6.x.
- setupPlace keeps the device settings of the URL (x-api-key, trust,
  trusted, fixed_device) and the visitor kiosk token before the first
  request, so that request does not use an old key or no token.
- A save of the user settings waits for the stored settings. When they do
  not load, or are text that is not JSON, the changes stay in the app and
  the save does not replace them. Only the latest waiting save sends.
- notifyError shows and logs only text, so a failed 7.x call no longer
  shows "[object Object]" or logs its response body. loggableError gives
  only the kind and status of a failed call for other logs.
- A realtime listener that throws no longer stops the other listeners of
  its batch.
- httpFailure moves to @placeos/common/tests, in place of the copies.
- The remote setup tests wait for the binding values, not for 10 ms.
- The work location tests wait for the user reload of a save, so it does
  not run in the next test.
With include_clash_time, Staff API gives each event clash as system_id,
event_start and event_end. The mapper expected booking fields and dropped
every row, so a recurring event saved over its clashes. The mock now
sends the same shape. A failed space list logs only the kind and status.
A save kept only the fields the app reads, and removed the others, as the
parsers dropped them. They now stay. Rules that are text and not JSON
show an error, and the editor does not open over them.
The pages of the group zones now get the abort signal, so a lookup stops
when the display or the group changes. The tests check failed results
through orThrow, load the edit modal before they start, and wait for the
service instead of a fixed time.
The API has one update action, so the method argument of updateBooking,
updateBookingInstance and updateEvent did nothing. toBookingClash is no
longer exported.
All tabs share a remembered guest in the local storage. When one tab
changes the guest, the other open tabs kept the old guest and used its
token until it expired. A tab now listens for the storage change and
forgets that guest too. A guest of one tab only does not change.
A retry of the user load could start single sign-on again while the
dialog was open, which could open a second Microsoft prompt. An attempt
that started before the dialog could also replace the token of the
dialog. After the dialog opens, single sign-on gives no token for the
rest of the load.
metadata.show succeeds without an entry for a name that the zone does
not have, so `data[name]` is undefined. The deals page then threw before
it cleared `loading`, and the points of interest and the emergency
contacts of explore threw too. These now default to empty details, as
the 6.x showMetadata did.
The events page checked the guest only when the route changed, so a tab
whose guest another tab forgot stayed on an empty page with no way to
sign in again. It now opens the guest details form, with the same system
and event.
When ts-client 7 rejected the zones response as invalid, the app tried
the load again without end. Boot now fails with a message. Network and
offline errors still try again.
ts-client 7 takes a list for the in parameter of findByEmail. The lookup
now sends a list, and does not run when there is no calendar.
The host lookup for booking rules gave a user with no groups, so group
rules did not apply. It now reads the engine user, and uses the email and
name when that read fails.
The fakes now use integer booking and guest ids, an id on notify
messages, a token request on each page load, the trust flag for stored
tokens, and v7 response shapes (v7-fixtures.ts).
…d value as enabled

7.x gives the raw playlist, in which enabled can be null. The 6.x class
set it to true. The report now counts a playlist as disabled only when
enabled is false.
6.x parsed metadata details that the API gave as a JSON string, and 7.x
gives the string. showMetadata now parses it, so a level with desks in a
string does not read as empty, and a save does not overwrite them.

7.x gives Survey.pages as nullable. The responses page now reads null as
no pages.
@MrYuion
MrYuion force-pushed the feat/migrate-ts-client-v7 branch from eab00a2 to 3fa2b50 Compare December 3, 2026 06:00
@MrYuion
MrYuion merged commit 0882def into develop Dec 3, 2026
3 checks passed
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