@bikefinder/sdk 0.12.0 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/README.md +47 -128
  2. package/dist/chunk-HTKUP56M.js +786 -0
  3. package/dist/index.d.ts +17753 -39
  4. package/dist/index.js +385 -65
  5. package/dist/schemas.d.ts +17882 -0
  6. package/dist/schemas.js +174 -0
  7. package/package.json +20 -23
  8. package/dist/acquisition-schema.d.ts +0 -177
  9. package/dist/acquisition-schema.js +0 -250
  10. package/dist/device-schema.d.ts +0 -9095
  11. package/dist/device-schema.js +0 -10734
  12. package/dist/generated/client/client.gen.d.ts +0 -2
  13. package/dist/generated/client/client.gen.js +0 -217
  14. package/dist/generated/client/index.d.ts +0 -10
  15. package/dist/generated/client/index.js +0 -6
  16. package/dist/generated/client/types.gen.d.ts +0 -120
  17. package/dist/generated/client/types.gen.js +0 -2
  18. package/dist/generated/client/utils.gen.d.ts +0 -37
  19. package/dist/generated/client/utils.gen.js +0 -231
  20. package/dist/generated/client.gen.d.ts +0 -12
  21. package/dist/generated/client.gen.js +0 -3
  22. package/dist/generated/core/auth.gen.d.ts +0 -25
  23. package/dist/generated/core/auth.gen.js +0 -14
  24. package/dist/generated/core/bodySerializer.gen.d.ts +0 -25
  25. package/dist/generated/core/bodySerializer.gen.js +0 -57
  26. package/dist/generated/core/params.gen.d.ts +0 -43
  27. package/dist/generated/core/params.gen.js +0 -112
  28. package/dist/generated/core/pathSerializer.gen.d.ts +0 -33
  29. package/dist/generated/core/pathSerializer.gen.js +0 -114
  30. package/dist/generated/core/queryKeySerializer.gen.d.ts +0 -18
  31. package/dist/generated/core/queryKeySerializer.gen.js +0 -99
  32. package/dist/generated/core/serverSentEvents.gen.d.ts +0 -71
  33. package/dist/generated/core/serverSentEvents.gen.js +0 -136
  34. package/dist/generated/core/types.gen.d.ts +0 -83
  35. package/dist/generated/core/types.gen.js +0 -2
  36. package/dist/generated/core/utils.gen.d.ts +0 -19
  37. package/dist/generated/core/utils.gen.js +0 -87
  38. package/dist/generated/index.d.ts +0 -2
  39. package/dist/generated/index.js +0 -2
  40. package/dist/generated/sdk.gen.d.ts +0 -136
  41. package/dist/generated/sdk.gen.js +0 -1347
  42. package/dist/generated/types.gen.d.ts +0 -12633
  43. package/dist/generated/types.gen.js +0 -2
  44. package/dist/generated/zod.gen.d.ts +0 -40667
  45. package/dist/generated/zod.gen.js +0 -13757
  46. package/dist/signalr/BikeFinder.Api.Commands.d.ts +0 -1
  47. package/dist/signalr/BikeFinder.Api.Commands.js +0 -1
  48. package/dist/signalr/BikeFinder.Api.Firestore.d.ts +0 -1
  49. package/dist/signalr/BikeFinder.Api.Firestore.js +0 -1
  50. package/dist/signalr/BikeFinder.Api.Http.d.ts +0 -7
  51. package/dist/signalr/BikeFinder.Api.Http.js +0 -4
  52. package/dist/signalr/BikeFinder.Api.Observations.d.ts +0 -1
  53. package/dist/signalr/BikeFinder.Api.Observations.js +0 -1
  54. package/dist/signalr/BikeFinder.Api.Settings.d.ts +0 -1
  55. package/dist/signalr/BikeFinder.Api.Settings.js +0 -1
  56. package/dist/signalr/BikeFinder.Api.Trackers.d.ts +0 -22
  57. package/dist/signalr/BikeFinder.Api.Trackers.js +0 -4
  58. package/dist/signalr/BikeFinder.DeviceConfiguration.d.ts +0 -1
  59. package/dist/signalr/BikeFinder.DeviceConfiguration.js +0 -1
  60. package/dist/signalr/BikeFinder.Nucleus.Commands.d.ts +0 -1
  61. package/dist/signalr/BikeFinder.Nucleus.Commands.js +0 -1
  62. package/dist/signalr/BikeFinder.Observations.Model.d.ts +0 -1
  63. package/dist/signalr/BikeFinder.Observations.Model.js +0 -1
  64. package/dist/signalr/TypedSignalR.Client/BikeFinder.Api.Trackers.d.ts +0 -91
  65. package/dist/signalr/TypedSignalR.Client/BikeFinder.Api.Trackers.js +0 -1
  66. package/dist/signalr/TypedSignalR.Client/index.d.ts +0 -18
  67. package/dist/signalr/TypedSignalR.Client/index.js +0 -89
  68. package/openapi/api.json +0 -52163
package/README.md CHANGED
@@ -1,144 +1,63 @@
1
1
  # @bikefinder/sdk
2
2
 
3
- Generated REST and SignalR clients for the [API service](../../services/api/README.md). Hey API generates named HTTP methods, types and Zod validation from OpenAPI. TypedSignalR.Client.TypeScript generates hub proxies from C# interfaces implemented by the server. The official `@microsoft/signalr` client owns streaming and connection management.
4
-
5
- Firmware receipts include the server's `jobId` so clients can match device progress to the exact update and execution.
6
-
7
- This package remains prelaunch. It replaces the experimental
8
- `@bikefinder/api-client` package so **1.0.0** can mark the eventual stable launch.
9
- Pin exact versions during development. Existing consumers of the old package
10
- continue to work; renaming the package does not change the API's `/v1` paths.
11
-
12
- Staff can explicitly query Com4 with
13
- `requests.getStaffTrackerCom4SimStatus({ path: { id: trackerId } })`. The server
14
- resolves the tracker's ICCID and returns only its provider status and check time.
15
- This call does not activate or suspend a SIM, and provisioning status does not
16
- establish tracker connectivity.
17
-
18
- Tracker audit responses model the existing log types separately: field changes
19
- carry typed `old`/`new` values, messages carry `message`, and operator actions,
20
- effect failures and historical operation batches retain their own fields. Map
21
- changes are partial diffs. Unknown event types keep their envelope and include a
22
- `readIssues` warning; stored payloads are never forwarded as arbitrary JSON.
3
+ Typed customer HTTP and WebSocket client for the [API](../../README.md).
4
+ Version 0.23 replaces the previous generated REST methods and custom realtime
5
+ protocol with native oRPC contracts, validation and async iterators. Staff tools
6
+ use [@bikefinder/staff-sdk](../staff-sdk/README.md).
23
7
 
24
8
  ```ts
25
- import { createBikeFinderClient } from "@bikefinder/sdk";
9
+ import { createBikeFinderClient, ORPCError } from '@bikefinder/sdk';
26
10
 
27
- const api = createBikeFinderClient({
28
- baseUrl: "https://api.example.com",
29
- getToken: () => auth0.getAccessTokenSilently(),
11
+ const client = createBikeFinderClient({
12
+ baseUrl: 'https://api.prod.bikefinder.com',
13
+ accessToken: () => session.getAccessToken(),
14
+ onReconnect: () => restartActiveViews(),
30
15
  });
31
16
 
32
- const result = await api.requests.getTracker({ path: { id: trackerId } });
33
- if (result.error) showProblem(result.error);
34
- else render(result.data.data);
35
-
36
- await api.realtime.connection.start();
37
- const subscription = api.realtime.hub.watchTracker(trackerId).subscribe({
38
- next: (document) => render(document.data),
39
- error: (error) => showSubscriptionError(error),
40
- complete: () => showSubscriptionEnded(),
41
- });
17
+ const tracker = await client.api.trackers.get({ id: trackerId });
18
+ const controller = new AbortController();
19
+ const changes = await client.api.trackers.watch(
20
+ { id: trackerId },
21
+ { signal: controller.signal },
22
+ );
23
+ for await (const tracker of changes) updateTracker(tracker);
42
24
 
43
- // Cancel this native SignalR stream and its server-side Firestore listener.
44
- subscription.dispose();
45
- // On sign-out/account change, discard account data and dispose this client.
46
- await api.dispose();
25
+ controller.abort();
26
+ client.dispose();
47
27
  ```
48
28
 
49
- Use `staffRealtime.connection` and `staffRealtime.hub` for staff operations. Connections are created without starting; start only the ones the application uses. Paged streams accept one query object, for example `api.realtime.hub.watchTrackers({limit: 50})`. Pass the returned `nextCursor` as `cursor` for another page.
50
-
51
- Both connections use native SignalR stateful reconnect. Temporary WebSocket interruptions can resume the existing connection and stream subscriptions, with buffered messages replayed by SignalR. Negotiation is enabled and realtime requests include cookies for load-balancer task affinity. Both the API and SDK must support stateful reconnect; each side uses SignalR's default 100,000-byte buffer.
52
-
53
- The application owns subscription sharing, retained data and account scope. Subscribe to native `connection.onreconnecting`, `onreconnected` and `onclose` events to update its UI. Stateful recovery preserves subscriptions without a new hub connection or an `onreconnected` event. If recovery fails, automatic reconnect can establish a new connection: recreate subscriptions in `onreconnected`. Server restarts and authentication-expiry closures can require new connections. Initial `start()` failures still require application retries, and a terminated stream is finished. There is no custom watch-state or subscription coordinator, and history queries remain necessary to recover gaps after a new connection.
54
-
55
- The application's Auth0 SDK supplies tokens and handles refresh. Create a new client for a new account session. `dispose()` aborts HTTP requests and stops both connections. REST requests use bearer authentication, omit cookies and reject redirects. Realtime requests also use bearer authentication and allow affinity cookies. Network/validation failures reject; HTTP Problem Details are available as `result.error` by default. Writes are never automatically retried; a `503 operation_unconfirmed` may already have committed.
56
-
57
- REST calls automatically validate response structure without transforming response JSON. The API uses native Firestore mapping and narrow field converters before responding. Malformed known values fail with `stored_data_invalid`; ordinary document responses no longer carry partial-data `readIssues`. Stream values use the native SignalR decoder; import `zTrackerDocument` from `@bikefinder/sdk/schemas` and call `.parse(value)` for the same runtime boundary check on a stream message. Both transports reference the same generated payload types. Firestore responses come from the actual C# DTOs in `Firestore/TrackerData.cs` and `Firestore/ResourceData.cs`. Unmodeled storage fields are ignored, never forwarded into response extensions. Server-serialized response fixtures are validated by both API and generated-client tests. IDs are exact Firestore IDs.
29
+ Ordinary procedures use HTTP under `/rpc/customer`. Event iterators share one
30
+ API Gateway WebSocket connection. The SDK obtains a fresh, single-use connection
31
+ ticket over authenticated HTTP; access tokens never appear in the WebSocket URL
32
+ or application frames. The application's Auth0 SDK owns login and token refresh.
33
+ HTTP requests omit cookies, disable caching and refuse redirects.
58
34
 
59
- Other native resources expose their known fields through resource-specific document types. Their C# contracts expose only interpreted fields; unrelated stored fields stay inside the API. Tracker reports and statistics have concrete models, and access-code storage is omitted from responses. Observation values use the shared generated union: narrow observation.type before reading its typed value. Current readings expose a nullable typed observation.
35
+ `baseUrl` accepts HTTPS, including an optional stage path. Plain HTTP is limited
36
+ to loopback development endpoints. Each procedure accepts an optional second
37
+ argument containing `signal`. `dispose()` cancels requests, uploads and the
38
+ shared socket. Typed failures use `ORPCError` with `code`, `status` and `data`.
60
39
 
61
- The handwritten entry point only configures clients, authentication and disposal. Hub methods, wire names and streaming signatures are generated. A generated type-only bridge reuses OpenAPI payload definitions instead of publishing a second set of models. There is no RxJS or MQTT dependency.
40
+ Full reconnects end existing subscriptions. Use `onReconnect` to explicitly
41
+ subscribe again. The SDK does not replay events or retry writes automatically.
42
+ Retain the original request ID when explicitly retrying an uncertain mutation.
62
43
 
63
- Hey API owns all settings and observation value types. The public `DeviceSettings` export is the generated request type; `ObservationFact` combines catalog-defined metric names/IDs with the generated `Observation` value for that metric. Its known fields stay typed while read models allow additive fields. `generate-device-sdk.mjs` emits protocol schema/catalog data and workflow descriptors; it does not compile another set of settings or observation interfaces. No second schema-to-TypeScript compiler is required.
44
+ Photos use the normal typed HTTP API for authorization and metadata. The upload
45
+ helper sends JPEG bytes directly to private staging storage, then asks the API
46
+ to sanitize and publish the image:
64
47
 
65
- Staff diagnostics use the same tracker inventory ID as `getStaffTracker`. Use `requests.readStaffTrackerObservations({path: {id}, body: {series: [{definitionId, subject?}]}})` for current values, `getStaffTrackerSettings` to read settings, and `updateStaffTrackerSettings` to patch typed settings with an expected version. Current observation reads use POST with the same JSON selection as their realtime subscriptions; account batches use GET with `readStaffAccounts({query: {ids}})`. `getStaffTrackerCommandCatalog` returns definitions and availability together. The generated `staffRealtime.hub.watchObservations`, `watchCommand(id, operationId)` and `watchSettings` methods return native SignalR streams. Staff tracker pages accept `StaffTrackerPageRequest` with an optional exact `selection`, matching REST filters. See the [tracker diagnostics map](../../docs/api/diagnostics.md) for database, identity and acceptance semantics.
66
-
67
- Command and firmware acceptance returns `202` with a `Location` status URL. Recover a command with `getStaffTrackerCommand({path: {id, operationId}})` using the original caller-generated UUID; its numeric hardware request ID is receipt evidence. Do not allocate a new UUID after an uncertain write. SDK 0.2 introduced the tracker resource layout; SDK 0.3 standardizes legacy LTE states (`queued`, `dispatched`, `expired`) and request kinds (`queue`, `cancel`) on lower-case strings. Firmware enum inputs accept strings, with numeric inputs rejected. Consumers must pin the matching prelaunch release.
68
-
69
- The runtime requires standard Fetch, Request, Blob, AbortController and `AbortSignal.any`/`throwIfAborted`, plus a WebSocket implementation supported by SignalR. Supply the relevant platform polyfills before creating a client when needed.
70
-
71
- ## Regenerate and build
72
-
73
- The [protocol ownership guide](../../protocol/README.md) identifies the source
74
- for each contract and the upstream generation steps. Edit those sources before
75
- regenerating this client. `openapi/api.json`, `src/generated`, `src/signalr`,
76
- `src/device-schema.ts` and `src/acquisition-schema.ts` are generated outputs required
77
- by the client build and consumers.
78
-
79
- From the repository root:
80
-
81
- ```powershell
82
- dotnet tool restore
83
- dotnet restore services/api/src/Api.csproj --locked-mode
84
- npm ci --ignore-scripts
85
- npm run contract --workspace @bikefinder/sdk
86
- npm run generate --workspace @bikefinder/sdk
87
- npm run check --workspace @bikefinder/sdk
88
- npm test --workspace @bikefinder/sdk
89
- npm run build --workspace @bikefinder/sdk
48
+ ```ts
49
+ const result = await client.uploadPhoto({
50
+ id: trackerId,
51
+ requestId: crypto.randomUUID(),
52
+ kind: 'bike',
53
+ body: jpegBlob,
54
+ });
55
+ const download = await client.api.trackers.photos.download({
56
+ id: trackerId,
57
+ photoId: result.photoId,
58
+ });
90
59
  ```
91
60
 
92
- The pinned .NET tool is configured in `.config/dotnet-tools.json`. Contract export uses Microsoft's build-time generator with a mock server and inert configuration; no cloud credentials or listening HTTP server are needed. Ordinary builds do not export the contract. Generation fails if either generator fails. Generated source is committed and must be regenerated together. `tsc-alias` resolves generated extensionless imports when compiling the ESM package. The focused tests cover authentication, typed payloads, binary writes, uncertain write responses, native proxy invocation/cancellation and disposal.
93
-
94
- SignalR generation clears its owned output directory first so removed namespaces cannot remain in the source or next package. The payload bridges are rebuilt with the generated proxies.
95
-
96
- ## Publish
97
-
98
- Bump this package's version and the root lockfile. Generate, check, test and build locally, then publish with `npm publish --workspace @bikefinder/sdk --access public` when release is authorized. Use the existing local npm authentication; never put a token in the repository. Publishing the package does not deploy the API.
99
-
100
- The optional **Publish API client** workflow (`publish-client.yml`) uses GitHub OIDC when Actions minutes are available. Local releases do not depend on that workflow.
101
-
102
- The npm package's trusted publisher must name organization `bikefinder`,
103
- repository `aws_cloud`, workflow `publish-client.yml`, with direct `npm publish`
104
- allowed and no environment name. This account setup is performed once in the
105
- package's npm settings. See [npm trusted publishing](https://docs.npmjs.com/trusted-publishers/).
106
-
107
- Command HTTP reads return `TrackerCommand`; command subscriptions return `CommandUpdate` with a command or an explicit read issue. Requests, broker publication and `execution.completed` are distinct stages on that resource. A completion includes its outcome, unavailable observation names and authenticated receipt time. Command output values are separate typed observations delivered through the observation endpoints and streams.
108
-
109
- Version **0.7.0** reads selected current observations with a typed JSON body instead of repeated URL parameters. Pass `{path: {id}, body: {series: [{definitionId, subject?}]}}` to `readStaffTrackerObservations`. All registered observations, including request-scoped command events, support latest-value reads and streams. Observation `requestId` metadata is retained when recorded; older facts may lack it.
110
-
111
- Version **0.6.0** aligned command receipts and independent domain observations. Consumers upgrading from 0.5 must read command output from the observation stream instead of a nested response-data union. `execution.accepted` is removed; use `publishedAt` for broker publication and `execution.completed` for the terminal device result.
112
-
113
- ## Observation timestamps
114
-
115
- Observation history exposes `measuredAt` and `receivedAt`. Current readings expose these on `reading.observation`, which is null when no current value exists.
116
- Observation IDs are opaque server-generated references. They carry no boot or
117
- sequence information. Distinct rows can have identical capture timestamps;
118
- clients must not infer physical ordering from their IDs. History can contain
119
- separate rows for an at-least-once delivery of the same reading.
120
-
121
- Settings responses use the API-owned `SettingsSnapshot` for HTTP and SignalR: read typed `desired`, `reported`, `application`, capabilities and schema/version evidence directly. `readIssues` identifies stored values the API could not interpret. The resource does not expose the underlying AWS shadow document or its independent owners. Settings fields and bounds come from the same protocol registry as the firmware.
122
-
123
- Command reads validate stored identity, catalog arguments, artifacts, and execution evidence. A malformed single-command read returns `command_unreadable`; command pages keep valid items and attach per-request `readIssues`. Both command streams emit `CommandUpdate` with either a validated `command` or a `readIssue`, allowing subsequent events to continue.
124
-
125
- ## Current API contract
126
-
127
- Version **0.12.0** enables native SignalR stateful reconnect on customer and staff connections. Temporary transport interruptions retain existing subscriptions when the original server connection survives. Negotiation and affinity cookies are enabled; a new connection still requires new subscriptions. Generated observation types also include the deployed `power.idleState` observation.
128
-
129
- Version **0.11.0** adds `listStaffTrackerCommandObservations({path: {id, operationId}, query: {limit, cursor}})`. It returns a typed `ObservationPage` scoped to that tracker and command, including cached readings and later resolved locations. Subscribe to observation events and match both `deviceId` and `requestId` for live results.
130
-
131
- Version **0.9.0** removes the separate positioning request/schedule APIs and
132
- retires their device command. Request WiFi, LTE and GPS observations through
133
- normal `requestObservations` commands. Fresh radio observations are geolocated
134
- automatically; no workflow registration or automatic fallback is involved.
135
-
136
- Generate HTTP methods and response schemas from the API-owned OpenAPI contract. Use the same explicit models for HTTP and SignalR: `TrackerCommand`, `CommandUpdate`, `ObservationSelection`, `SettingsSnapshot` and `FirmwareArtifact`. Deploy the matching API before updating consumers to a changed contract.
137
-
138
- WiFi, LTE and GPS requests use normal observation commands. Fresh radio observations are geolocated automatically. Movement-alert preferences have their own typed request contract. The protocol registry owns settings fields and bounds; the runtime schema endpoints expose the deployed definitions. Firmware mode selectors, per-mode timers and command-listening settings are retired.
139
-
140
- Observation history and events use the catalog-discriminated `Observation` union. Current readings identify a selected series and a nullable typed `CurrentObservation`; null means that no current reading exists. Request validation is strict. Response validation checks known fields while preserving additions.
141
-
142
- Contract export uses `Microsoft.Extensions.ApiDescription.Server` through the contract script. It executes startup with inert configuration and disables cloud event workers; it opens no listening HTTP server and needs no cloud credentials. Ordinary builds do not rewrite the checked-in contract.
143
-
144
- Run generation, type checks, runtime contract tests and the build before release. Publishing the SDK and deploying the API are separate operations; generated code does neither.
61
+ Uploads are limited to 10 MiB. Download URLs expire after two minutes; request a
62
+ fresh reference if one expires. Photo bytes do not travel over WebSockets.
63
+ Runtime schemas are available from `@bikefinder/sdk/schemas`.