Skip to content

feat!: injectable HTTP client, contract-first IClient & authup-owned oauth2 layer - #3114

Merged
tada5hi merged 9 commits into
masterfrom
feat/injectable-http-client-ssr-tests
Jun 12, 2026
Merged

tada5hi merged 9 commits into
masterfrom
feat/injectable-http-client-ssr-tests

Conversation

@tada5hi

@tada5hi tada5hi commented Jun 11, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Three layered changes (one commit each):

1. Injectable HTTP client for the SSR'd auth workflow UI (+ testing kit)

  • @authup/core-http-kit/testing: in-memory route-matching FakeClient for tests.
  • apps/server-core: HTTPInjectionKey.UIHttpClientFactory — a per-request factory handed through renderUIPage into the embedded SSR app. A factory, not an instance: the auth hook writes per-user Authorization state onto attached clients, so a shared instance across concurrent renders would leak tokens between sessions. Production registers nothing.
  • First HTTP-level tests for the SSR'd workflow pages (ui-pages.spec.ts).

2. Contract-first interfaces (new codebase convention, recorded in .agents/conventions.md)

  • Every interface is I-prefixed; interface is reserved for class-implemented contracts; contracts are written explicitly, never inferred from implementations.
  • Explicit I*API interface per domain (IRealmAPI, IUserAPI, …), implemented by the API classes; EntityAPI/EntityAPISlim → IEntityAPI/IEntityAPISlim, payload-parameterized (IEntityAPI<T, TCreate, TUpdate>) so contracts no longer advertise Partial<T> while implementations expect narrower payloads.
  • Aggregate IClient implemented by Client; all consumers (client-web-kit http-client/store/auth-hook, SSR client factory, ui app) are typed against it — any conforming test double substitutes.

3. HTTP-client redesign (transport port + OAuth2 contracts)

  • BaseAPI depends on a minimal ApiTransport type (readonly, setClient removed) — the domain layer is http-library-agnostic; hapic remains the default implementation at a documented structural boundary (ClientBase).
  • OAuth2 sub-APIs: authup owns the contract, hapic owns the implementation — OAuth2TokenAPI extends TokenAPI implements IOAuth2TokenAPI (same for authorize/user-info). Parameter/response types are authup-owned (@authup/specs), and the implements check verifies on every build that @hapic/oauth2 (same author) still satisfies the contract — no duplicated protocol code, drift caught at compile time.

Breaking changes

  • @authup/core-http-kit no longer re-exports @hapic/oauth2 types (it stays as the implementation dependency); EntityAPI/EntityAPISlim renamed; BaseAPI.setClient removed; OAuth2 parameter types are authup-owned (OAuth2Token*GrantParameters / OAuth2TokenRequestOptions / OAuth2AuthorizeParameters).

Test plan

  • apps/server-core — 89 files / 868 tests pass (all OAuth2 grants — password, client_credentials, robot_credentials, authorization_code+PKCE, refresh — run through the new authup-owned token layer against Docker services)
  • packages/core-http-kit — 19 tests pass (creator spec migrated to spy on OAuth2TokenAPI)
  • Builds green: core-http-kit, client-web-kit, client-web-nuxt, all server-adapter packages, server-core, client-web, authup CLI
  • ESLint clean; lockfile refreshed (singa gone earlier, @hapic/oauth2 removed from core-http-kit)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Inject a custom HTTP client into server-side rendered UI for testable SSR flows.
    • Provide an in-memory fake HTTP client for deterministic, network-free testing.
  • Documentation

    • Expanded testing guides covering SSR HTTP injection and fake client usage.
  • Tests

    • Added unit tests validating SSR UI hydration, redirects, and fake-client matcher behavior.
  • Refactor

    • Strengthened public API typings for HTTP client and domain APIs.

Post-review hardening: 13 getOne() implementations now honor the record? query param their interface advertises; plugin Options.httpClient typed IClient; FakeClient normalizes urlencoded bodies; stale doc refs fixed; OAuth2 parameter types are now one-line aliases over @hapic/oauth2's exports (single source for the shapes); @hapic/oauth2 correctly sits in dependencies (devDeps get bundled by tsdown, which broke prototype spies and would have broken the published package); isApiTransport checks all five transport members; branch merged with master after #3113 landed.

- @authup/core-http-kit: new `./testing` subpath export with an
  in-memory, route-matching fake Client for tests.
- @authup/client-web-kit: store & http-client install accept a
  pre-built client (httpClient option) instead of always constructing
  one from baseURL.
- apps/server-core: optional HTTPInjectionKey.UIHttpClient container
  binding flows per-request through renderUIPage into the embedded SSR
  app (UI_HTTP_CLIENT_STORE_KEY handoff, same mechanism as
  VITE_SERVER_STORE_KEY); production registers nothing. Unblocks
  HTTP-level tests for the SSR'd workflow pages (ui-pages.spec.ts).
Copilot AI review requested due to automatic review settings June 11, 2026 17:51

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Jun 11, 2026 •

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds request-scoped UI HTTP client injection and fake HTTP client utilities; wires injected client into SSR rendering and client-web-kit; refactors core-http-kit to use a structural ApiTransport/IClient contract and explicit per-entity API interfaces; adds tests and docs for SSR testing and fake client usage.

Changes

Combined Change Cohort

Layer / File(s) Summary
All changes (single checkpoint)
all modified files in PR
Includes SSR middleware and DI token for per-request UI httpClient, SSR render and UI app wiring to accept injected httpClient, client-web-kit wiring to accept optional httpClient, core-http-kit transport/interface refactor (ApiTransport, IClient, BaseAPI changes), per-entity I* API interface additions and updated getOne signatures, OAuth2 local workflow types and token response typing changes, testing matcher/fake client implementation and tests, docs/site sidebar and testing documentation updates, and small type/tsconfig/package build edits.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~75 minutes

Possibly related PRs

  • authup/authup#3111: Modifies SSR rendering in renderUIPage; related to injected httpClient wiring.
  • authup/authup#3011: Introduced SSR testing guidance wiring createFakeClient into SSR flow; overlaps testing approach and injection.
  • authup/authup#2945: DI/token and middleware registration changes for HTTP injection flow; related constants/mounting changes.

Poem

"I'm a rabbit in the code, nose twitching at each line,
I stash a fake client in the store, per-request and fine.
I hop through renders, sniffing payloads clear,
Interfaces and tokens now parade without fear.
Tests hum softly — all injections align."

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/injectable-http-client-ssr-tests

@pkg-pr-new

pkg-pr-new Bot commented Jun 11, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

authup

npm i https://pkg.pr.new/authup@3114

@authup/client-web

npm i https://pkg.pr.new/@authup/client-web@3114

@authup/server-core

npm i https://pkg.pr.new/@authup/server-core@3114

@authup/access

npm i https://pkg.pr.new/@authup/access@3114

@authup/client-web-kit

npm i https://pkg.pr.new/@authup/client-web-kit@3114

@authup/client-web-kit-theme

npm i https://pkg.pr.new/@authup/client-web-kit-theme@3114

@authup/client-web-nuxt

npm i https://pkg.pr.new/@authup/client-web-nuxt@3114

@authup/client-web-theme

npm i https://pkg.pr.new/@authup/client-web-theme@3114

@authup/core-http-kit

npm i https://pkg.pr.new/@authup/core-http-kit@3114

@authup/core-kit

npm i https://pkg.pr.new/@authup/core-kit@3114

@authup/core-realtime-kit

npm i https://pkg.pr.new/@authup/core-realtime-kit@3114

@authup/errors

npm i https://pkg.pr.new/@authup/errors@3114

@authup/i18n

npm i https://pkg.pr.new/@authup/i18n@3114

@authup/kit

npm i https://pkg.pr.new/@authup/kit@3114

@authup/server-adapter-kit

npm i https://pkg.pr.new/@authup/server-adapter-kit@3114

@authup/server-adapter-node

npm i https://pkg.pr.new/@authup/server-adapter-node@3114

@authup/server-adapter-socket-io

npm i https://pkg.pr.new/@authup/server-adapter-socket-io@3114

@authup/server-adapter-web

npm i https://pkg.pr.new/@authup/server-adapter-web@3114

@authup/server-kit

npm i https://pkg.pr.new/@authup/server-kit@3114

@authup/server-test-kit

npm i https://pkg.pr.new/@authup/server-test-kit@3114

@authup/specs

npm i https://pkg.pr.new/@authup/specs@3114

commit: 5735fd1

tada5hi added 2 commits June 12, 2026 10:14
… override

A shared Client instance across concurrent SSR renders would be a
cross-request hazard: client-web-kit's authentication hook writes
per-user Authorization state onto the client it attaches to, so two
parallel renders could leak tokens between sessions. The DI token is
now a factory (() => Client) that renderUIPage invokes per render —
per-request isolation is structural instead of conventional.
…uth2 layer

Interfaces & types convention (also recorded in .agents/conventions.md):
every interface is I-prefixed, the interface keyword is reserved for
contracts a class implements, and contracts are written explicitly —
never inferred from implementations.

- Every domain API gets an explicit interface in its types.ts
  (IRealmAPI, IUserAPI, IPolicyAPI, ...) with precise payload types;
  classes declare `implements I*API`. EntityAPI/EntityAPISlim are
  renamed to IEntityAPI/IEntityAPISlim and payload-parameterized
  (IEntityAPI<T, TCreate, TUpdate>) so interfaces no longer advertise
  Partial<T> while implementations expect narrower payloads.
- New aggregate IClient contract implemented by Client; consumers
  (client-web-kit http-client/store/auth-hook, server-core SSR client
  factory, ui app) are typed against IClient instead of the class.
  The hapic base surface is mirrored structurally (ClientBase) — the
  one sanctioned implementation-derived type, at the third-party
  boundary.
- Transport port: BaseAPI now depends on a minimal ApiTransport type
  (get/post/put/delete/getBaseURL) instead of hapic's Client class and
  holds it readonly (mutable setClient removed) — the domain layer is
  http-library-agnostic.
- OAuth2 layer is authup-owned: OAuth2TokenAPI / OAuth2AuthorizeAPI /
  OAuth2UserInfoAPI no longer extend @hapic/oauth2 classes; grant,
  revoke, introspect and userinfo logic is implemented in-package
  (faithful port: urlencoded bodies, client-credential headers,
  parameter extension) against IOAuth2*API interfaces with
  authup-owned parameter types; responses are typed by @authup/specs
  (OAuth2TokenGrantResponse — now also carrying
  refresh_token_expires_in). @hapic/oauth2 dependency dropped.

BREAKING CHANGE: @authup/core-http-kit no longer re-exports
@hapic/oauth2 types; EntityAPI/EntityAPISlim are renamed to
IEntityAPI/IEntityAPISlim; BaseAPI.setClient removed; OAuth2 parameter
types are now authup-owned (OAuth2Token*GrantParameters,
OAuth2TokenRequestOptions, OAuth2AuthorizeParameters).
@tada5hi tada5hi changed the title feat: injectable HTTP client for SSR'd auth workflow UI & core-http-kit testing utilities feat!: injectable HTTP client, contract-first IClient & authup-owned oauth2 layer Jun 12, 2026
- 13 entity APIs declared getOne(id, record?) via IEntityAPISlim but
  ignored the query argument — callers' BuildInput was silently
  dropped. The implementations now append buildQuery(record).
- client-web-kit plugin Options.httpClient is typed IClient (was the
  concrete Client class, blocking test doubles at the top-level
  install seam the sub-installers already accept).
- FakeClient normalizes URLSearchParams bodies to plain objects in
  recorded requests so token-endpoint handler assertions stay
  ergonomic.
- Refresh stale HTTPInjectionKey.UIHttpClient references in
  .agents docs (token is UIHttpClientFactory).

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (1)
packages/core-http-kit/src/client/module.ts (1)

104-110: ⚡ Quick win

Consider refactoring to avoid type-safety escape hatch.

The cast (options as Record<string, any>)[key] at line 108 bypasses TypeScript's type checking to mutate the options object. This pattern is fragile because:

  • It assumes all OAuth2APIOptions properties are URL strings that need normalization
  • Future non-URL properties added to OAuth2APIOptions would incorrectly pass through this loop
  • The cast undermines the type safety benefits of the interface refactoring
♻️ Recommended refactor to preserve type safety

Create a new object instead of mutating:

 const baseURL = this.getBaseURL();

 if (typeof baseURL === 'string') {
-    const keys = Object.keys(options) as (keyof OAuth2APIOptions)[];
-    for (const key of keys) {
-        const value = options[key];
-        if (typeof value === 'string') {
-            (options as Record<string, any>)[key] = new URL(value, baseURL).href;
-        }
-    }
+    const normalizedOptions: OAuth2APIOptions = {
+        authorizationEndpoint: typeof options.authorizationEndpoint === 'string' 
+            ? new URL(options.authorizationEndpoint, baseURL).href 
+            : options.authorizationEndpoint,
+        introspectionEndpoint: typeof options.introspectionEndpoint === 'string'
+            ? new URL(options.introspectionEndpoint, baseURL).href
+            : options.introspectionEndpoint,
+        tokenEndpoint: typeof options.tokenEndpoint === 'string'
+            ? new URL(options.tokenEndpoint, baseURL).href
+            : options.tokenEndpoint,
+        userinfoEndpoint: typeof options.userinfoEndpoint === 'string'
+            ? new URL(options.userinfoEndpoint, baseURL).href
+            : options.userinfoEndpoint,
+    };
+    
+    this.authorize = new OAuth2AuthorizeAPI({
+        client: this,
+        options: normalizedOptions, 
+    });
+    // ... use normalizedOptions in subsequent API constructors
 }
-
-this.authorize = new OAuth2AuthorizeAPI({
-    client: this,
-    options, 
-});

Alternatively, if OAuth2APIOptions is guaranteed to only contain URL-string properties, document this invariant explicitly in the type definition and add a comment explaining the cast.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/core-http-kit/src/client/module.ts` around lines 104 - 110, The
current loop mutates options using a type-escape cast at the line with (options
as Record<string, any>)[key], which bypasses TypeScript safety and assumes every
OAuth2APIOptions property is a URL string; instead create a new object (e.g.,
normalizedOptions: OAuth2APIOptions) and populate it without casting: copy
non-string fields directly and only normalize known URL-string fields (use an
explicit whitelist of keys or narrow the key type) by doing new URL(value,
baseURL).href for those keys, then use normalizedOptions in place of options;
update the code around the existing keys/for loop and remove the unsafe cast.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.agents/testing.md:
- Around line 146-148: The registered value currently constructs a singleton
Fake HTTP client by calling createFakeHTTPClient(...) directly; change the
registration to provide a per-request factory function instead (i.e., set
useValue to a function that returns createFakeHTTPClient({ handlers: { 'GET
/identity-providers': () => ({ data: [], meta: { total: 0 } }) } })). Update the
code where useValue is assigned so it returns a new createFakeHTTPClient
instance on each invocation to prevent cross-request token leakage.

In `@packages/client-web-kit/src/types.ts`:
- Line 8: The public Options type incorrectly uses the concrete Client type;
update the Options definition to accept the interface IClient instead of Client
so it matches downstream contracts; locate the exported Options/type in
packages/client-web-kit/src/types.ts (the httpClient property) and change its
type from Client to IClient (importing IClient from '`@authup/core-http-kit`' if
necessary) so injectable test/fake implementations conform to the public API.

In `@packages/core-http-kit/src/domains/base.ts`:
- Around line 12-16: The type guard isApiTransport is incomplete and only checks
get/post; update it to verify all ApiTransport members by ensuring
isObject(input) and that getBaseURL, get, post, put, and delete exist and are
functions so BaseAPI (and callers like RobotAPI and IdentityProviderAPI) won't
crash at runtime when they call any of those methods.

---

Nitpick comments:
In `@packages/core-http-kit/src/client/module.ts`:
- Around line 104-110: The current loop mutates options using a type-escape cast
at the line with (options as Record<string, any>)[key], which bypasses
TypeScript safety and assumes every OAuth2APIOptions property is a URL string;
instead create a new object (e.g., normalizedOptions: OAuth2APIOptions) and
populate it without casting: copy non-string fields directly and only normalize
known URL-string fields (use an explicit whitelist of keys or narrow the key
type) by doing new URL(value, baseURL).href for those keys, then use
normalizedOptions in place of options; update the code around the existing
keys/for loop and remove the unsafe cast.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d4df67ae-6f1f-41c6-9492-9edd06afae08

📥 Commits

Reviewing files that changed from the base of the PR and between 2654d03 and 372b7ef.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (91)
  • .agents/architecture.md
  • .agents/conventions.md
  • .agents/testing.md
  • apps/server-core/src/adapters/http/middleware/built-in/index.ts
  • apps/server-core/src/adapters/http/middleware/built-in/ui-http-client.ts
  • apps/server-core/src/adapters/http/ui/render.ts
  • apps/server-core/src/app/modules/http/constants.ts
  • apps/server-core/src/app/modules/http/modules/middleware.ts
  • apps/server-core/test/unit/http/controllers/workflows/ui-pages.spec.ts
  • apps/server-core/ui/src/app.ts
  • apps/server-core/ui/src/server.ts
  • docs/src/.vitepress/config.mjs
  • docs/src/sdks/javascript/core-http-kit/testing.md
  • packages/client-web-kit/src/components/utility/entity/AEntityDelete.ts
  • packages/client-web-kit/src/components/utility/entity/collection/module.ts
  • packages/client-web-kit/src/components/utility/entity/record/module.ts
  • packages/client-web-kit/src/core/http-client/authentication-hook/install.ts
  • packages/client-web-kit/src/core/http-client/authentication-hook/types.ts
  • packages/client-web-kit/src/core/http-client/install.ts
  • packages/client-web-kit/src/core/http-client/singleton.ts
  • packages/client-web-kit/src/core/http-client/types.ts
  • packages/client-web-kit/src/core/store/create.ts
  • packages/client-web-kit/src/core/store/install.ts
  • packages/client-web-kit/src/core/store/types.ts
  • packages/client-web-kit/src/module.ts
  • packages/client-web-kit/src/types.ts
  • packages/core-http-kit/package.json
  • packages/core-http-kit/src/client/module.ts
  • packages/core-http-kit/src/client/type.ts
  • packages/core-http-kit/src/domains/base.ts
  • packages/core-http-kit/src/domains/entities/client-permission/module.ts
  • packages/core-http-kit/src/domains/entities/client-permission/types.ts
  • packages/core-http-kit/src/domains/entities/client-role/module.ts
  • packages/core-http-kit/src/domains/entities/client-role/types.ts
  • packages/core-http-kit/src/domains/entities/client-scope/module.ts
  • packages/core-http-kit/src/domains/entities/client-scope/types.ts
  • packages/core-http-kit/src/domains/entities/client/module.ts
  • packages/core-http-kit/src/domains/entities/client/types.ts
  • packages/core-http-kit/src/domains/entities/identity-provider-role-mapping/module.ts
  • packages/core-http-kit/src/domains/entities/identity-provider-role-mapping/types.ts
  • packages/core-http-kit/src/domains/entities/identity-provider/module.ts
  • packages/core-http-kit/src/domains/entities/identity-provider/types.ts
  • packages/core-http-kit/src/domains/entities/permission-policy/module.ts
  • packages/core-http-kit/src/domains/entities/permission-policy/types.ts
  • packages/core-http-kit/src/domains/entities/permission/module.ts
  • packages/core-http-kit/src/domains/entities/permission/types.ts
  • packages/core-http-kit/src/domains/entities/policy/module.ts
  • packages/core-http-kit/src/domains/entities/policy/types.ts
  • packages/core-http-kit/src/domains/entities/realm/module.ts
  • packages/core-http-kit/src/domains/entities/realm/types.ts
  • packages/core-http-kit/src/domains/entities/robot-permission/module.ts
  • packages/core-http-kit/src/domains/entities/robot-permission/types.ts
  • packages/core-http-kit/src/domains/entities/robot-role/module.ts
  • packages/core-http-kit/src/domains/entities/robot-role/types.ts
  • packages/core-http-kit/src/domains/entities/robot/module.ts
  • packages/core-http-kit/src/domains/entities/robot/types.ts
  • packages/core-http-kit/src/domains/entities/role-attribute/module.ts
  • packages/core-http-kit/src/domains/entities/role-attribute/types.ts
  • packages/core-http-kit/src/domains/entities/role-permission/module.ts
  • packages/core-http-kit/src/domains/entities/role-permission/types.ts
  • packages/core-http-kit/src/domains/entities/role/module.ts
  • packages/core-http-kit/src/domains/entities/role/types.ts
  • packages/core-http-kit/src/domains/entities/scope/module.ts
  • packages/core-http-kit/src/domains/entities/scope/types.ts
  • packages/core-http-kit/src/domains/entities/user-attribute/module.ts
  • packages/core-http-kit/src/domains/entities/user-attribute/types.ts
  • packages/core-http-kit/src/domains/entities/user-permission/module.ts
  • packages/core-http-kit/src/domains/entities/user-permission/types.ts
  • packages/core-http-kit/src/domains/entities/user-role/module.ts
  • packages/core-http-kit/src/domains/entities/user-role/types.ts
  • packages/core-http-kit/src/domains/entities/user/module.ts
  • packages/core-http-kit/src/domains/entities/user/types.ts
  • packages/core-http-kit/src/domains/types-base.ts
  • packages/core-http-kit/src/domains/workflows/oauth2/authorize/module.ts
  • packages/core-http-kit/src/domains/workflows/oauth2/base.ts
  • packages/core-http-kit/src/domains/workflows/oauth2/index.ts
  • packages/core-http-kit/src/domains/workflows/oauth2/token/module.ts
  • packages/core-http-kit/src/domains/workflows/oauth2/types.ts
  • packages/core-http-kit/src/domains/workflows/oauth2/user-info/module.ts
  • packages/core-http-kit/src/domains/workflows/status/module.ts
  • packages/core-http-kit/src/domains/workflows/status/types.ts
  • packages/core-http-kit/src/hook/module.ts
  • packages/core-http-kit/src/hook/types.ts
  • packages/core-http-kit/src/testing/index.ts
  • packages/core-http-kit/src/testing/matcher.ts
  • packages/core-http-kit/src/testing/module.ts
  • packages/core-http-kit/src/testing/types.ts
  • packages/core-http-kit/src/token-creator/type.ts
  • packages/core-http-kit/test/unit/creator.spec.ts
  • packages/core-http-kit/test/unit/fake-client.spec.ts
  • packages/core-http-kit/tsdown.config.ts

Comment thread .agents/testing.md Resolved
Comment thread packages/client-web-kit/src/types.ts Resolved
…lementation

Keep the authup-owned IOAuth2{Token,Authorize,UserInfo}API contracts
and parameter/response types, but drop the in-package protocol
reimplementation: the OAuth2 classes extend @hapic/oauth2 again and
declare `implements I*API`, so hapic (same author) stays the single
implementation while the compiler verifies it satisfies authup's
contract on every build. Removes ~300 duplicated lines of
security-sensitive grant/header/encoding logic.

Also: convert CookieOptions & LoggerLevelFn to type aliases per the
interface convention (not class-implemented), and annotate the
httpClient-fallback sites as IClient so the Client/IClient union stays
callable.
@tada5hi

tada5hi commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator Author

@coderabbitai pause

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/client-web-kit/src/types.ts (1)

105-124: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Make baseURL conditional when httpClient is provided.

Options still requires baseURL, but installHTTPClient() only uses it when httpClient is absent. That leaves the new injectable-client path type-incorrect for consumers unless they pass a fake URL. Model this as a union so callers provide either a prebuilt httpClient or a baseURL.

Suggested shape
-export type Options = {
-    baseURL: string,
+export type Options = ({
+    baseURL: string,
+    httpClient?: undefined,
+} | {
+    baseURL?: string,
+    httpClient: IClient,
+}) & {
     /**
      * Pre-built HTTP client used instead of constructing one from baseURL.
      * Covers the store, the authentication hook and the provided client.
      */
-    httpClient?: IClient,
-
     realtime?: boolean,
     realtimeURL?: string,
 
     components?: boolean | string[],
     translatorLocale?: string,
@@
     cookieGet?: CookieGetFn,
 
     pinia?: Pinia,
     isServer?: boolean
-};
+};
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/client-web-kit/src/types.ts` around lines 105 - 124, The Options
type currently requires baseURL even when a prebuilt httpClient is provided;
update the Options definition to be a discriminated union so callers must
provide either a prebuilt httpClient or a baseURL (not both). Specifically,
refactor the exported type Options into two variants (one with httpClient:
IClient and no baseURL, and one with baseURL: string and no httpClient) while
keeping the shared fields (realtime, components, translatorLocale,
cookieSet/unset/get, pinia, isServer) common to both; adjust installs that
reference installHTTPClient() to accept the new union type if necessary. Ensure
unique symbols referenced: Options and installHTTPClient so type-checks now
prevent passing a fake baseURL when using a prebuilt httpClient.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@packages/client-web-kit/src/types.ts`:
- Around line 105-124: The Options type currently requires baseURL even when a
prebuilt httpClient is provided; update the Options definition to be a
discriminated union so callers must provide either a prebuilt httpClient or a
baseURL (not both). Specifically, refactor the exported type Options into two
variants (one with httpClient: IClient and no baseURL, and one with baseURL:
string and no httpClient) while keeping the shared fields (realtime, components,
translatorLocale, cookieSet/unset/get, pinia, isServer) common to both; adjust
installs that reference installHTTPClient() to accept the new union type if
necessary. Ensure unique symbols referenced: Options and installHTTPClient so
type-checks now prevent passing a fake baseURL when using a prebuilt httpClient.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 61289a4c-9643-462a-97b3-5b9c29725628

📥 Commits

Reviewing files that changed from the base of the PR and between 372b7ef and 607bbe5.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (25)
  • .agents/testing.md
  • packages/client-web-kit/src/core/http-client/authentication-hook/install.ts
  • packages/client-web-kit/src/core/http-client/install.ts
  • packages/client-web-kit/src/core/store/create.ts
  • packages/client-web-kit/src/types.ts
  • packages/core-http-kit/package.json
  • packages/core-http-kit/src/domains/entities/client-role/module.ts
  • packages/core-http-kit/src/domains/entities/client-scope/module.ts
  • packages/core-http-kit/src/domains/entities/identity-provider-role-mapping/module.ts
  • packages/core-http-kit/src/domains/entities/permission-policy/module.ts
  • packages/core-http-kit/src/domains/entities/realm/module.ts
  • packages/core-http-kit/src/domains/entities/robot-role/module.ts
  • packages/core-http-kit/src/domains/entities/role-attribute/module.ts
  • packages/core-http-kit/src/domains/entities/role-permission/module.ts
  • packages/core-http-kit/src/domains/entities/role/module.ts
  • packages/core-http-kit/src/domains/entities/scope/module.ts
  • packages/core-http-kit/src/domains/entities/user-attribute/module.ts
  • packages/core-http-kit/src/domains/entities/user-permission/module.ts
  • packages/core-http-kit/src/domains/entities/user-role/module.ts
  • packages/core-http-kit/src/domains/workflows/oauth2/authorize/module.ts
  • packages/core-http-kit/src/domains/workflows/oauth2/index.ts
  • packages/core-http-kit/src/domains/workflows/oauth2/token/module.ts
  • packages/core-http-kit/src/domains/workflows/oauth2/user-info/module.ts
  • packages/core-http-kit/src/testing/module.ts
  • packages/server-kit/src/logger/types.ts
💤 Files with no reviewable changes (1)
  • packages/core-http-kit/src/domains/workflows/oauth2/index.ts
✅ Files skipped from review due to trivial changes (2)
  • packages/server-kit/src/logger/types.ts
  • .agents/testing.md
🚧 Files skipped from review as they are similar to previous changes (5)
  • packages/client-web-kit/src/core/store/create.ts
  • packages/client-web-kit/src/core/http-client/authentication-hook/install.ts
  • packages/core-http-kit/package.json
  • packages/core-http-kit/src/domains/entities/scope/module.ts
  • packages/core-http-kit/src/testing/module.ts

@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown
✅ Action performed

Reviews paused.

tada5hi added 3 commits June 12, 2026 13:02
- @hapic/oauth2 was re-added under devDependencies, so tsdown bundled
  a private copy of TokenAPI into the dist — prototype spies in
  server-adapter-kit's verifier spec no longer intercepted introspect
  and a real fetch escaped (CI 'Test Packages' failure). Moved to
  dependencies so the import stays external and class identity is
  shared.
- isApiTransport now checks all five ApiTransport members
  (getBaseURL/get/post/put/delete) instead of get/post only, so an
  incomplete transport is rejected at construction rather than
  crashing on first put/delete call (review feedback).
The grant/revoke/introspect/authorize parameter shapes were still
re-declared verbatim after the implementation went back to hapic.
They are now type aliases over @hapic/oauth2's exports — single source
of truth for the shapes, authup keeps only its naming convention and
the IOAuth2*API contracts (whose responses stay typed by
@authup/specs).
…client override

The hand-rolled TypedToken<() => IClient> duplicated what the DI
container already provides: HTTPInjectionKey.UIHttpClient is typed
IClient again and registered with a useFactory provider +
lifetime: 'transient', so each resolve yields a fresh client. The
wiring passes a resolve-thunk into the (DI-agnostic) middleware;
renderUIPage still resolves lazily per render.
@tada5hi

tada5hi commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 12, 2026 •

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
packages/core-http-kit/src/domains/workflows/oauth2/types.ts (1)

29-34: 💤 Low value

Consider clarifying the dependency model in the comment.

The comment states consumers won't depend on @hapic/oauth2 directly. While this is true for imports (consumers import from @authup/core-http-kit), TypeScript still requires @hapic/oauth2 as a transitive dependency for type resolution since these are type aliases, not re-declarations. Consider rephrasing to: "without consumers importing from @hapic/oauth2 directly" to be more precise about the dependency model.

📝 Suggested clarification
 /**
  * The OAuth2 protocol mechanics (and their parameter shapes) are owned
- * by `@hapic/oauth2` — authup only re-exposes them under its naming
- * convention so the contracts below stay expressible without consumers
- * depending on `@hapic/oauth2` directly.
+ * by `@hapic/oauth2` — authup re-exposes them under its naming convention
+ * so consumers can use these contracts without importing from
+ * `@hapic/oauth2` directly (though it remains a transitive dependency).
  */
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/core-http-kit/src/domains/workflows/oauth2/types.ts` around lines 29
- 34, Update the top comment in
packages/core-http-kit/src/domains/workflows/oauth2/types.ts to clarify the
dependency model by changing "consumers won't depend on `@hapic/oauth2`
directly" to something like "without consumers importing from `@hapic/oauth2`
directly" so it accurately distinguishes import usage from TypeScript's
transitive type resolution; keep the surrounding explanation about re-exposing
parameter shapes intact.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@packages/core-http-kit/src/domains/workflows/oauth2/types.ts`:
- Around line 29-34: Update the top comment in
packages/core-http-kit/src/domains/workflows/oauth2/types.ts to clarify the
dependency model by changing "consumers won't depend on `@hapic/oauth2`
directly" to something like "without consumers importing from `@hapic/oauth2`
directly" so it accurately distinguishes import usage from TypeScript's
transitive type resolution; keep the surrounding explanation about re-exposing
parameter shapes intact.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 87cdc360-8c9b-4024-b074-fce7bf523755

📥 Commits

Reviewing files that changed from the base of the PR and between 607bbe5 and 5735fd1.

📒 Files selected for processing (9)
  • .agents/conventions.md
  • .agents/testing.md
  • apps/server-core/src/adapters/http/middleware/built-in/ui-http-client.ts
  • apps/server-core/src/app/modules/http/constants.ts
  • apps/server-core/src/app/modules/http/modules/middleware.ts
  • apps/server-core/test/unit/http/controllers/workflows/ui-pages.spec.ts
  • packages/core-http-kit/package.json
  • packages/core-http-kit/src/domains/base.ts
  • packages/core-http-kit/src/domains/workflows/oauth2/types.ts
✅ Files skipped from review due to trivial changes (2)
  • .agents/conventions.md
  • .agents/testing.md
🚧 Files skipped from review as they are similar to previous changes (4)
  • apps/server-core/src/app/modules/http/modules/middleware.ts
  • packages/core-http-kit/src/domains/base.ts
  • apps/server-core/test/unit/http/controllers/workflows/ui-pages.spec.ts
  • apps/server-core/src/adapters/http/middleware/built-in/ui-http-client.ts

@tada5hi
tada5hi merged commit ab06f38 into master Jun 12, 2026
15 checks passed
@tada5hi
tada5hi deleted the feat/injectable-http-client-ssr-tests branch June 12, 2026 12:52
@github-actions github-actions Bot mentioned this pull request Jun 12, 2026
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.

2 participants