Skip to content

Add @enonic-types/lib-http-client types package #226#227

Open
rymsha wants to merge 1 commit into
masterfrom
add-types-package-226
Open

Add @enonic-types/lib-http-client types package #226#227
rymsha wants to merge 1 commit into
masterfrom
add-types-package-226

Conversation

@rymsha

@rymsha rymsha commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Publishes a TypeScript types package for lib-http-client so consumers stop hand-maintaining local /lib/http-client declarations (e.g. app-features currently ships its own copy).

Changes

  • types/index.d.ts — ambient module declaration for /lib/http-client (single request(params) export). Types verified against the JS bridge (src/main/resources/lib/http-client.js) and the Java bean (HttpRequestHandler + ResponseMapper), not blindly copied from app-features/src/main/resources/types/http-client.d.ts.
  • types/package.json@enonic-types/lib-http-client manifest (version substituted at build time, @enonic-types/core dep).
  • build.gradleassembleTypes Copy task builds build/types with project.version injected; jar.dependsOn assembleTypes (mirrors lib-mustache Bump mockito-core from 3.11.0 to 3.11.1 #66 / app-guillotine's pattern; no node build needed for a pure-JS lib).
  • .github/workflows/enonic-gradle.ymlnpmPublish: true on build-and-publish + top-level id-token: write / contents: write for OIDC trusted publishing.

Corrections vs the app-features declaration

The app-features copy was a useful starting point but had drifted from the actual API. Fixed and verified:

  • connectTimeout renamed to connectionTimeout (the JS actually reads params.connectionTimeout; connectTimeout was silently ignored).
  • connectionTimeout / readTimeout narrowed from number | string to number (Java setter is Long).
  • params.body widened from string to string | ByteSource (postImageRequest in the request-test proves stream input works).
  • Response cookies retyped from Record<string, string> to HttpResponseCookie[] with the actual per-cookie shape { name, value, path, domain, expires, secure, httpOnly } (see ResponseMapper.serializeCookies + Utils.calculateCookieExpires).
  • Response headers retyped from Record<string, string> to Record<string, string | string[]> (repeated headers serialize as arrays — ResponseMapper.serializeHeaders).
  • Added previously-missing options: queryParams, disableHttp2, multipart (with proper HttpRequestMultipartPart shape), followRedirects, certificates, clientCertificate.
  • Added previously-missing response field: bodyStream (typed ByteSource).
  • Response body and contentType typed as string | null (matches Java behaviour when content-type isn't text).

Typed exports

The lib has a single JS export: exports.request. It is typed. Also exported for consumer convenience: HttpRequestParams, HttpRequestAuth, HttpRequestProxy, HttpRequestMultipartPart, HttpResponse, HttpResponseCookie.

Verification

  • ./gradlew build green; build/types/ contains index.d.ts + a package.json with the version substituted to 4.1.0-SNAPSHOT.
  • .d.ts type-checks under TS 5.6 strict mode against @enonic-types/core@^8 (verified locally with a smoke .ts covering every option and every response field, plus a fail-checked companion that confirmed the corrections above are actually enforced by the type system).

Notes

Closes #226

Adds a published TypeScript types package for lib-http-client so consumers
no longer hand-maintain local declarations for /lib/http-client.

- types/index.d.ts: ambient module declaration for /lib/http-client
  (single request() export). Types verified against the JS bridge and the
  Java bean; corrects a handful of drifts from the app-features copy
  (connectTimeout -> connectionTimeout, readTimeout number, body accepts
  ByteSource, response cookies as an array of cookie objects, headers as
  string|string[], plus previously-missing queryParams, disableHttp2,
  multipart, followRedirects, certificates, clientCertificate, bodyStream).
- types/package.json: @enonic-types/lib-http-client manifest.
- build.gradle: assembleTypes Copy task -> build/types (version substituted
  from project.version); jar.dependsOn assembleTypes.
- workflow: npmPublish: true on build-and-publish + id-token permission for
  OIDC trusted publishing.

Closes #226

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.42%. Comparing base (4cfc31f) to head (d1a8c9c).

Additional details and impacted files
@@            Coverage Diff            @@
##             master     #227   +/-   ##
=========================================
  Coverage     91.42%   91.42%           
  Complexity      156      156           
=========================================
  Files             9        9           
  Lines           513      513           
  Branches         58       58           
=========================================
  Hits            469      469           
  Misses           23       23           
  Partials         21       21           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

Pull request overview

Adds a publishable TypeScript declaration package (@enonic-types/lib-http-client) so downstream XP apps can rely on shared, versioned typings for /lib/http-client instead of maintaining local copies.

Changes:

  • Introduces types/index.d.ts with an ambient declare module "/lib/http-client" (typed request(params) plus related request/response shapes).
  • Adds types/package.json and a Gradle assembleTypes task to materialize build/types/ with the project version injected for CI publishing.
  • Updates the GitHub Actions workflow to enable npm publishing via OIDC trusted publishing (npmPublish: true + required permissions).

Reviewed changes

Copilot reviewed 2 out of 4 changed files in this pull request and generated 1 comment.

File Description
types/package.json Defines the new @enonic-types/lib-http-client types package metadata and dependency on @enonic-types/core.
types/index.d.ts Adds the ambient module declaration and exported request/response types for /lib/http-client.
build.gradle Adds assembleTypes Copy task to build build/types with version substitution and wires it into jar.
.github/workflows/enonic-gradle.yml Enables npm publish in CI and adds required GitHub token/OIDC permissions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +5 to +8
permissions:
id-token: write # Required for npm OIDC / trusted publishing
contents: write

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.

Create @enonic-types/lib-http-client types package

2 participants