Skip to content

fix(resources): apply bare-response and pageinate fixes to all resources#3

Merged
asachs01 merged 1 commit intomainfrom
fix/all-resources-bare-response
May 7, 2026
Merged

fix(resources): apply bare-response and pageinate fixes to all resources#3
asachs01 merged 1 commit intomainfrom
fix/all-resources-bare-response

Conversation

@asachs01
Copy link
Copy Markdown
Member

@asachs01 asachs01 commented May 7, 2026

Summary

The two HaloPSA quirks fixed in #2 (bare-vs-wrapped single GET response shape, and the pageinate=true requirement for page_size/page_no) existed in every resource, not just tickets/actions. This PR sweeps them across the SDK.

  • New shared helpers in src/resources/utils.ts:
    • unwrapSingle<T>(response, listKey) — accepts either bare entity or wrapped list shape
    • addPageinate(params) — adds the literal pageinate: true flag when paging is requested
    • buildListParams(params) — camelCase→snake_case conversion + addPageinate
  • 26 .get() methods (across 16 resource files including reference's nested classes) now use unwrapSingle
  • Resource-local buildListParams methods delegate to the shared helper
  • Net −33 lines despite adding the helper

Resources covered

actions, agents, appointments, assets (incl. AssetType), clients, contacts, contracts, invoices, items, opportunities, projects, quotes, reference (ticket types, statuses, priorities, categories, SLAs, custom fields, user roles, KB articles, recurring invoices, reports, software licences), sites, suppliers, teams, tickets.

Test plan

  • npm run build
  • npm test (79 tests pass — added 10 new tests for the helpers)
  • Smoke test a handful of .get() calls on a real HaloPSA tenant after release

Sweeps the same two HaloPSA quirks across every resource — not just
tickets/actions:

1. Single-resource GET endpoints (`GET /<Entity>/{id}`) sometimes return
   the entity bare and sometimes wrap it in a list-style envelope
   (`{ entities: [{...}] }`). 26 `.get()` methods were unwrapping
   unconditionally and would crash with "Cannot read properties of
   undefined (reading '0')" against any tenant returning the bare shape.

2. HaloPSA silently ignores `page_size`/`page_no` unless `pageinate=true`
   is sent alongside, so caller-supplied page sizes were capped at the
   server default of 50 across every list endpoint.

Both behaviors are now centralized in `src/resources/utils.ts`
(`unwrapSingle`, `addPageinate`, `buildListParams`); resources delegate
to the shared helpers so future endpoints inherit the fix automatically.

Covers: actions, agents, appointments, assets, clients, contacts,
contracts, invoices, items, opportunities, projects, quotes, reference
(ticket types, statuses, priorities, categories, SLAs, custom fields,
user roles, KB articles, recurring invoices, reports, software
licences), sites, suppliers, teams, tickets.
@asachs01 asachs01 merged commit 46af9cb into main May 7, 2026
3 checks passed
@asachs01 asachs01 deleted the fix/all-resources-bare-response branch May 7, 2026 18:27
github-actions Bot pushed a commit that referenced this pull request May 7, 2026
## [1.0.3](v1.0.2...v1.0.3) (2026-05-07)

### Bug Fixes

* **resources:** apply bare-response and pageinate fixes to all resources ([#3](#3)) ([46af9cb](46af9cb))
asachs01 added a commit to wyre-technology/halopsa-mcp that referenced this pull request May 7, 2026
Picks up the SDK-wide bare-response and pageinate fixes from
wyre-technology/node-halopsa#3 — every resource's `.get()` and list
endpoint now handles HaloPSA's quirks consistently, not just tickets
and actions.
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