Add @enonic-types/lib-http-client types package #226#227
Open
rymsha wants to merge 1 commit into
Open
Conversation
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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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.tswith an ambientdeclare module "/lib/http-client"(typedrequest(params)plus related request/response shapes). - Adds
types/package.jsonand a GradleassembleTypestask to materializebuild/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 | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Publishes a TypeScript types package for lib-http-client so consumers stop hand-maintaining local
/lib/http-clientdeclarations (e.g. app-features currently ships its own copy).Changes
types/index.d.ts— ambient module declaration for/lib/http-client(singlerequest(params)export). Types verified against the JS bridge (src/main/resources/lib/http-client.js) and the Java bean (HttpRequestHandler+ResponseMapper), not blindly copied fromapp-features/src/main/resources/types/http-client.d.ts.types/package.json—@enonic-types/lib-http-clientmanifest (version substituted at build time,@enonic-types/coredep).build.gradle—assembleTypesCopy task buildsbuild/typeswithproject.versioninjected;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.yml—npmPublish: trueonbuild-and-publish+ top-levelid-token: write/contents: writefor 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:
connectTimeoutrenamed toconnectionTimeout(the JS actually readsparams.connectionTimeout;connectTimeoutwas silently ignored).connectionTimeout/readTimeoutnarrowed fromnumber | stringtonumber(Java setter isLong).params.bodywidened fromstringtostring | ByteSource(postImageRequestin the request-test proves stream input works).cookiesretyped fromRecord<string, string>toHttpResponseCookie[]with the actual per-cookie shape{ name, value, path, domain, expires, secure, httpOnly }(seeResponseMapper.serializeCookies+Utils.calculateCookieExpires).headersretyped fromRecord<string, string>toRecord<string, string | string[]>(repeated headers serialize as arrays —ResponseMapper.serializeHeaders).queryParams,disableHttp2,multipart(with properHttpRequestMultipartPartshape),followRedirects,certificates,clientCertificate.bodyStream(typedByteSource).bodyandcontentTypetyped asstring | 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 buildgreen;build/types/containsindex.d.ts+ apackage.jsonwith the version substituted to4.1.0-SNAPSHOT..d.tstype-checks under TS 5.6 strict mode against@enonic-types/core@^8(verified locally with a smoke.tscovering every option and every response field, plus a fail-checked companion that confirmed the corrections above are actually enforced by the type system).Notes
@enonic-types/lib-http-clientneeds the npm trusted-publisher / package access configured org-side.npmPublish) — merged.Closes #226