feat: add TypeScript SDK source and build configuration#5
Conversation
Set up the TypeScript SDK build infrastructure, aligned with AOSSIE npm package standards (IndexedDB-Import-Export reference): - package.json: dual ESM/CJS, type:module, publishConfig for npm, bugs/homepage URLs, GPL-3.0 license, eslint + prettier deps - tsconfig.json: strict mode with noUncheckedIndexedAccess, noUnusedLocals, noUnusedParameters - tsup.config.ts: ESM + CJS output, sourcemaps, ES2020 target - eslint.config.js: flat config with typescript-eslint - .prettierrc: AOSSIE standard formatting rules - vitest.config.ts: test runner configuration
Add the core SDK implementation — a zero-dependency TypeScript client
for the ThruBox Server relay:
- src/client.ts: RelayClient class with send, receive, delete, poll,
health. Automatic retry with exponential backoff on
5xx/network errors. Configurable timeout via
AbortController.
- src/types.ts: Message, CreateMessageParams, ClientOptions,
HealthResponse type definitions.
- src/errors.ts: Typed error hierarchy (RelayError, NetworkError,
HttpError, RateLimitError, PayloadTooLargeError,
NotFoundError).
- src/index.ts: Public API barrel export.
|
Warning Review limit reached
Next review available in: 43 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (4)
WalkthroughAdds a typed AOSSIE Relay client SDK with message operations, polling, retries, timeouts, typed errors, public exports, package metadata, build settings, and development tooling. ChangesRelay SDK
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Caller
participant RelayClient
participant RelayServer
Caller->>RelayClient: Send or poll messages
RelayClient->>RelayServer: HTTP request with optional API key
RelayServer-->>RelayClient: JSON response or HTTP error
RelayClient-->>Caller: Result, callback, or typed error
Suggested labels: Poem
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
There was a problem hiding this comment.
Actionable comments posted: 10
🤖 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 `@src/client.ts`:
- Around line 138-145: Update the polling flow around receive and callback
execution so only the request in receive is handled by the catch, reporting
failures through the existing typed error handler instead of silently ignoring
them. Move callback(messages) outside that catch so user callback exceptions
propagate normally, while preserving the stopped check.
- Around line 55-56: Validate the option assignments in the client
initialization and the polling configuration around the referenced code: require
timeout and interval values to be finite and strictly positive, and require
retries to be a finite non-negative integer. Reject invalid values before
storing or using them, while preserving the existing defaults when options are
omitted.
- Around line 180-189: Update the retry loop in the client send flow around
fetch so non-idempotent POST requests are not automatically retried after
timeout or failure. Restrict retries to idempotent HTTP methods, or use a
server-supported idempotency key for sends; preserve existing retry behavior for
safe methods and ensure the logic also covers the corresponding handling around
lines 230-257.
- Around line 182-199: Update the fetch attempt in the client method containing
the AbortController and response body parsing so the timeout remains active
through json()/text() consumption. Wrap the complete fetch, status handling, and
body-reading flow in try/finally, and clear timeoutId only in the finally block
so rejected fetches and body-read failures always clean up the timer.
- Around line 148-151: Update the polling flow around doPoll and intervalId to
prevent concurrent async requests: replace the recurring setInterval scheduling
with a self-scheduling setTimeout that starts the next poll only after doPoll()
settles, while preserving the immediate first poll and existing polling
interval.
- Around line 51-53: Update the Client constructor to parse baseUrl once with
URL, reject malformed values and any protocol other than http: or https:, and
store the normalized URL. In the request-building logic near the additional
occurrence, construct paths with new URL(path, baseUrl) rather than string
concatenation or direct interpolation, ensuring user input is not inserted
directly into URLs.
- Around line 170-172: Update the headers construction in the client request
flow to include Content-Type only when a JSON body is present. Ensure GET and
DELETE requests without bodies omit this header while preserving
application/json for requests that send JSON.
- Around line 216-221: Update the 429 handling near RelayRateLimitError to parse
Retry-After as either numeric delta-seconds or an HTTP-date converted to a
numeric delay in seconds. Use the existing 60-second fallback only when the
header is missing or invalid, ensuring retryAfter is always numeric.
In `@vitest.config.ts`:
- Around line 4-8: Update the test workflow associated with the Vitest
configuration so coverage collection is explicitly enabled, since
test.coverage.reporter only selects report formats. Modify the existing test
script or add a dedicated coverage script to invoke Vitest with the coverage
flag, ensuring CI runs generate the configured text and lcov reports.
- Around line 6-8: Add a supported Vitest coverage provider dependency and
configure the coverage settings in the Vitest configuration to use it, ensuring
the existing text and lcov reporters continue to work when running vitest
--coverage. Alternatively, remove the coverage block if coverage is not intended
to be supported.
🪄 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: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: b55a54bb-071f-4b15-ac4e-b02b72d33cfb
📒 Files selected for processing (10)
.prettierrceslint.config.jspackage.jsonsrc/client.tssrc/errors.tssrc/index.tssrc/types.tstsconfig.jsontsup.config.tsvitest.config.ts
🔗 Linked repositories identified
CodeRabbit considers these linked repositories for cross-repo context during reviews:
AOSSIE-Org/ThruBox-Server(manual)
- client.ts: Validated and normalized baseUrl using URL parser - client.ts: Rejected invalid timeout, retry, and polling values - client.ts: Added onError callback to PollOptions to prevent swallowing errors - client.ts: Used recursive setTimeout for polling to prevent overlapping requests - client.ts: Fixed headers to only send application/json for POST/PUT/PATCH - client.ts: Disabled automatic retries for non-idempotent POST requests - client.ts: Wrapped fetch in try/finally to ensure timeout is cleared during body consumption - client.ts: Added proper HTTP-date parsing for Retry-After headers - vitest.config.ts / package.json: Added @vitest/coverage-v8 provider and coverage script
ca091a6 to
6cda706
Compare
Addressed Issues:
Fixes #(issue number)
Initializes the complete TypeScript SDK source code, build tooling, and project configuration aligned with AOSSIE npm package standards.
Screenshots/Recordings:
Additional Notes:
Commit 1 Build tooling & config:
package.json: Dual ESM/CJS,type: "module",publishConfigfor npm, GPL-3.0 licensetsconfig.json: Strict mode withnoUncheckedIndexedAccess,noUnusedLocals,noUnusedParameterstsup.config.ts: ESM + CJS output, sourcemaps, ES2020 targeteslint.config.js: Flat config with typescript-eslint (matches IndexedDB-Import-Export).prettierrc: AOSSIE standard formatting rulesvitest.config.ts: Test runner configurationCommit 2 SDK source code:
src/client.ts:RelayClientclass (native fetch, auto-retry with exponential backoff)src/errors.ts: Typed error hierarchy (RelayError,RateLimitError,PayloadTooLargeError, etc.)src/types.ts: Message, ClientOptions, HealthResponse type definitionssrc/index.ts: Public API barrel exportZero runtime dependencies. Works in Node.js 18+ and modern browsers.
Checklist
We encourage contributors to use AI tools responsibly when creating Pull Requests. While AI can be a valuable aid, it is essential to ensure that your contributions meet the task requirements, build successfully, include relevant tests, and pass all linters. Submissions that do not meet these standards may be closed without warning to maintain the quality and integrity of the project. Please take the time to understand the changes you are proposing and their impact.
Summary by CodeRabbit