roboparty-rpnpm-client
v0.1.1
Published
Typed RoboParty web integration SDK for log services and robot identity.
Readme
RoboParty Web Integration SDK 0.1.1
Repository: https://github.com/Roboparty/roboparty_rpnpm_cilent
Package: roboparty-rpnpm-client (correctly spelled client; repository name retained)
License: GPL-3.0-only, following the repository LICENSE.
ES modules and TypeScript declarations. Node.js >=20; modern browsers with fetch,
ReadableStream, AbortController and Web Crypto in a secure context.
No runtime dependencies. Published on npm as roboparty-rpnpm-client.
Build and use
npm install [email protected]
For source development: npm ci npm test npm pack --pack-destination test/tmp
Install a local tarball with npm install .
Browser entry (your backend must expose an authenticated proxy):
import { RoboPartyClient } from 'roboparty-rpnpm-client'; const sdk = new RoboPartyClient({ baseUrl: new URL('/api/robot-logs/', window.location.origin).href, token: () => getScopedUserToken(), }); const page = await sdk.queryLogs({ service: 'rp_server', limit: 20 }); const next = await sdk.queryLogs({ after: page.next_after, limit: 20 });
The proxy preserves /health, /v1/logs, /v1/segments and archive routes under its prefix. It must authenticate the user and enforce allowed records and downloads, not merely forward a service token. Cookies use same-origin credentials. SDK headers do not replace backend authorization. The current Python log server has no browser CORS or per-report authorization contract; never put its read/write tokens in a browser. Direct log access is for a trusted backend.
for await (const line of sdk.exportLogsJsonl({ device_id: 'robot-1' })) { // Write JSONL incrementally to your application export destination. } const page = await sdk.listSegments({ limit: 10 }); const item = page.segments[0]; if (item) { const bytes = await sdk.downloadSegment(item.id, item.sha256); // bytes are gzip archive data; the SDK does not extract untrusted archives. }
JSONL export is bounded by maxPages (default 100). Hitting the bound throws; already emitted lines are a partial export. Use a fixed until timestamp to bound live queries; this is not a server-side transactional snapshot. Queries retain snake_case fields from the real log-server API. Limits are 1..1000 and cursors must be safe nonnegative JavaScript integers.
Server-only robot adapter:
import { RobotClient } from 'roboparty-rpnpm-client/server'; const robot = new RobotClient({ baseUrl: configuredRobotUrl }); const identity = await robot.identity(); const health = await robot.health();
The adapter only calls GET /identity and /health. Configure trusted addresses on the backend, never accept arbitrary URLs from end users. It does not discover robots, pair, acquire leases, start motion or run maintenance tasks. Serial is the board identity, not a proof of ownership or a whole-machine SN. health.version is rpserver's version, not a full installed-package inventory. Cloud-only hosts still need a reachable management channel; installing the SDK does not create it. TLS uses the platform trust store; the package never disables certificate checks. HTTP is accepted on loopback for development, or via explicit allowInsecureHttp.
Mock entry and capabilities
import { createMockClient } from 'roboparty-rpnpm-client/mock'; const sdk = createMockClient(); console.log(sdk.mode); // 'mock', never silently used as a network fallback
Run npm run build && node examples/mock.mjs. Custom fixtures can supply logs, segments and archives. No network or robot operations are performed. Mock records are schema-v1 examples, not anonymous production submissions.
Implemented: logQuery, logExport, segmentDownload. robotIdentity is available through the server-only adapter. Not implemented: remoteCollection, cloudOta, aiReports, reportAuthorization, customerAccounts. capability(name) returns availability and a reason; requireCapability(name) throws UNSUPPORTED_CAPABILITY when unavailable. These describe SDK coverage, not live backend health or the current user's permission. No speculative cloud endpoints or fabricated task-success responses are shipped. Website accounts, SN ownership, tutorials, UI, database and deployment remain the website project's responsibility. Existing MCP packages are separate products.
Failures and configuration
RoboPartyError has code, message and optional HTTP status. Codes: INVALID_ARGUMENT, HTTP_ERROR, NETWORK_ERROR, TIMEOUT, ABORTED, INVALID_RESPONSE, RESPONSE_TOO_LARGE, INTEGRITY_ERROR, UNSUPPORTED_CAPABILITY. Raw upstream errors and credentials are not attached to exceptions. No requests are retried automatically. timeoutMs defaults to 10000 and covers token resolution through body reads. maxResponseBytes defaults to 64 MiB per response. Each method accepts { signal }. Redirects are rejected. fetch may be injected for tests or a trusted adapter. Tokens are resolved for every request and never stored by the SDK.
Validation
npm test: deterministic transport, contract, mock, pagination, errors, timeout, cancellation and integrity tests. Integration with the actual Python log server can be run via test/integration.test.mjs with RP_LOG_SERVER_SOURCE set to its source-file path. This uses a loopback process and test/tmp, not a deployed robot. No real robot, public deployment, OTA, AI or browser end-to-end acceptance is claimed by passing these tests.
Next delivery
Provide the authenticated website proxy, then validate actual scoped user access. Add remote collection, OTA and AI/report adapters only when the corresponding backend contracts and authorization exist. Freeze version compatibility before adding new public entry points.
