Add ETag Support to HackMD API Client#31
Merged
Yukaii merged 4 commits intohackmdio:developfrom May 27, 2025
Merged
Conversation
- Remove test.only to run all tests
- Create dedicated client instance with retry disabled for rate limit tests
- Fix Jest exit issues with proper cleanup
- Remove debug console.log statements
- Update axios from 0.25.0 to 1.8.4 - Update msw from 1.0.1 to 2.7.3 - Refactor mock server implementation to use MSW v2 API - Update API client to use new axios types - Fix type issues in headers handling
- Add etag field to RequestOptions type - Implement conditional requests with If-None-Match header - Add proper handling of 304 Not Modified responses - Extract etag from response headers - Include etag in response data when requested - Add comprehensive test coverage for etag functionality
* Add etag support to createNote method * Add etag support to updateNoteContent method * Add etag support to updateNote method * Organize tests by API method * Improve test naming for clarity
There was a problem hiding this comment.
Pull Request Overview
This PR adds optional ETag support to the HackMD API client, enabling conditional requests and response caching for user note operations. Key changes include updating the API methods to optionally include ETag headers and accept 304 responses, modifying test mocks to use the new msw http API, and upgrading dependencies to support these changes.
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| nodejs/tests/mock/index.ts | Updated mock server setup to use new msw http API for GET handlers. |
| nodejs/tests/mock/handlers.ts | Converted REST handlers to use the new msw http API. |
| nodejs/tests/etag.spec.ts | Added comprehensive tests validating ETag functionality. |
| nodejs/tests/api.spec.ts | Updated API tests including error handling and cleanup adjustments. |
| nodejs/src/index.ts | Modified API class to support ETag functionality with conditional GET and header handling. |
| nodejs/package.json | Upgraded msw and axios dependencies. |
Comments suppressed due to low confidence (2)
nodejs/src/index.ts:150
- [nitpick] The configuration in getNote that allows a 304 status via validateStatus is appropriate for ETag support; ensure that this does not inadvertently accept other non-successful responses that should be handled differently.
const config = options.etag ? { headers: { 'If-None-Match': options.etag }, validateStatus: (status: number) => (status >= 200 && status < 300) || status === 304 } : undefined
nodejs/src/index.ts:54
- Using config.headers.set may cause runtime errors if the headers object does not support the set method. Consider verifying that Axios' header implementation in v1.8.4 supports this pattern or revert to direct object assignment (e.g. config.headers['Authorization'] = ...).
config.headers.set('Authorization', `Bearer ${accessToken}`)
Yukaii
approved these changes
May 27, 2025
Member
|
Thanks for your contirbution, @bagnier ! |
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.
Add ETag Support to HackMD API Client
Summary
This PR implements ETag support for HackMD API client operations, enabling conditional requests and response caching.
Technical Details
getNote,createNote,updateNote, andupdateNoteContentLimitations
Implementation Approach
Security