@bikefinder/sdk 0.0.0-stage → 0.1.1
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.
- package/README.md +139 -2
- package/dist/device-schema.d.ts +9462 -0
- package/dist/device-schema.js +9397 -0
- package/dist/generated/client/client.gen.d.ts +2 -0
- package/dist/generated/client/client.gen.js +217 -0
- package/dist/generated/client/index.d.ts +10 -0
- package/dist/generated/client/index.js +6 -0
- package/dist/generated/client/types.gen.d.ts +120 -0
- package/dist/generated/client/types.gen.js +2 -0
- package/dist/generated/client/utils.gen.d.ts +37 -0
- package/dist/generated/client/utils.gen.js +231 -0
- package/dist/generated/client.gen.d.ts +12 -0
- package/dist/generated/client.gen.js +3 -0
- package/dist/generated/core/auth.gen.d.ts +25 -0
- package/dist/generated/core/auth.gen.js +14 -0
- package/dist/generated/core/bodySerializer.gen.d.ts +25 -0
- package/dist/generated/core/bodySerializer.gen.js +57 -0
- package/dist/generated/core/params.gen.d.ts +43 -0
- package/dist/generated/core/params.gen.js +112 -0
- package/dist/generated/core/pathSerializer.gen.d.ts +33 -0
- package/dist/generated/core/pathSerializer.gen.js +114 -0
- package/dist/generated/core/queryKeySerializer.gen.d.ts +18 -0
- package/dist/generated/core/queryKeySerializer.gen.js +99 -0
- package/dist/generated/core/serverSentEvents.gen.d.ts +71 -0
- package/dist/generated/core/serverSentEvents.gen.js +136 -0
- package/dist/generated/core/types.gen.d.ts +83 -0
- package/dist/generated/core/types.gen.js +2 -0
- package/dist/generated/core/utils.gen.d.ts +19 -0
- package/dist/generated/core/utils.gen.js +87 -0
- package/dist/generated/index.d.ts +2 -0
- package/dist/generated/index.js +2 -0
- package/dist/generated/sdk.gen.d.ts +133 -0
- package/dist/generated/sdk.gen.js +2132 -0
- package/dist/generated/types.gen.d.ts +11444 -0
- package/dist/generated/types.gen.js +2 -0
- package/dist/generated/zod.gen.d.ts +39797 -0
- package/dist/generated/zod.gen.js +13163 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +69 -0
- package/dist/signalr/BikeFinder.Api.Aws.d.ts +1 -0
- package/dist/signalr/BikeFinder.Api.Aws.js +1 -0
- package/dist/signalr/BikeFinder.Api.Firestore.d.ts +1 -0
- package/dist/signalr/BikeFinder.Api.Firestore.js +1 -0
- package/dist/signalr/BikeFinder.Api.Trackers.d.ts +7 -0
- package/dist/signalr/BikeFinder.Api.Trackers.js +4 -0
- package/dist/signalr/BikeFinder.DeviceConfiguration.d.ts +1 -0
- package/dist/signalr/BikeFinder.DeviceConfiguration.js +1 -0
- package/dist/signalr/BikeFinder.Nucleus.Commands.d.ts +1 -0
- package/dist/signalr/BikeFinder.Nucleus.Commands.js +1 -0
- package/dist/signalr/TypedSignalR.Client/BikeFinder.Api.Trackers.d.ts +87 -0
- package/dist/signalr/TypedSignalR.Client/BikeFinder.Api.Trackers.js +1 -0
- package/dist/signalr/TypedSignalR.Client/index.d.ts +18 -0
- package/dist/signalr/TypedSignalR.Client/index.js +89 -0
- package/dist/workflow-schema.d.ts +198 -0
- package/dist/workflow-schema.js +297 -0
- package/openapi/api.json +47014 -0
- package/package.json +53 -4
package/README.md
CHANGED
|
@@ -1,3 +1,140 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @bikefinder/sdk
|
|
2
2
|
|
|
3
|
-
|
|
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
|
+
This package starts at **0.1.0** and remains prelaunch. It replaces the experimental
|
|
6
|
+
`@bikefinder/api-client` package so **1.0.0** can mark the eventual stable launch.
|
|
7
|
+
Pin exact versions during development. Existing consumers of the old package
|
|
8
|
+
continue to work; renaming the package does not change the API's `/v1` paths.
|
|
9
|
+
|
|
10
|
+
Staff can explicitly query Com4 with
|
|
11
|
+
`requests.getStaffTrackerCom4SimStatus({ path: { id: trackerId } })`. The server
|
|
12
|
+
resolves the tracker's ICCID and returns only its provider status and check time.
|
|
13
|
+
This call does not activate or suspend a SIM, and provisioning status does not
|
|
14
|
+
establish tracker connectivity.
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import { createBikeFinderClient } from "@bikefinder/sdk";
|
|
18
|
+
|
|
19
|
+
const api = createBikeFinderClient({
|
|
20
|
+
baseUrl: "https://api.example.com",
|
|
21
|
+
getToken: () => auth0.getAccessTokenSilently(),
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const result = await api.requests.getTracker({ path: { id: trackerId } });
|
|
25
|
+
if (result.error) showProblem(result.error);
|
|
26
|
+
else render(result.data.data);
|
|
27
|
+
|
|
28
|
+
await api.realtime.connection.start();
|
|
29
|
+
const subscription = api.realtime.hub.watchTracker(trackerId).subscribe({
|
|
30
|
+
next: (document) => render(document.data),
|
|
31
|
+
error: (error) => showSubscriptionError(error),
|
|
32
|
+
complete: () => showSubscriptionEnded(),
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// Cancel this native SignalR stream and its server-side Firestore listener.
|
|
36
|
+
subscription.dispose();
|
|
37
|
+
// On sign-out/account change, discard account data and dispose this client.
|
|
38
|
+
await api.dispose();
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
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.
|
|
42
|
+
|
|
43
|
+
The application owns subscription sharing, retained data and account scope. Subscribe to native `connection.onreconnecting`, `onreconnected` and `onclose` events to update its UI. Automatic reconnect is configured on each connection, but does not retry an initial `start()` failure or restore stream invocations: recreate subscriptions after reconnect. A terminated stream is finished. There is no custom watch-state or subscription coordinator.
|
|
44
|
+
|
|
45
|
+
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. Requests use bearer authentication, omit cookies and reject redirects. 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.
|
|
46
|
+
|
|
47
|
+
REST responses use generated Zod validation. Stream values have generated static types and use the native SignalR decoder; for runtime validation, import `zTrackerDocument` from `@bikefinder/sdk/schemas` and call `.parse(value)`. Both transports reference the same generated payload types. Firestore responses come from the actual C# DTOs in `Firestore/TrackerData.cs` and `Firestore/ResourceData.cs`. The API converts stored data before responding; `readIssues` identifies unusable stored fields. Additional metadata remains in explicit JSON extension fields. Server-serialized response fixtures are validated by both API and generated-client tests. IDs are exact Firestore IDs.
|
|
48
|
+
|
|
49
|
+
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 are generated unions: after `observation.definitionId === 5`, `observation.value.percent` is a number. Current readings expose the same discriminator; check `observationId !== null` before using a present reading. Device settings, the built-in workflow descriptor and command argument tuples are generated from the canonical protocol JSON contracts. Bike and preference patches expose supported properties and distinguish omission from explicit null. Response validators preserve additional API fields while checking known values, required properties and enums. Request models retain their declared constraints and closed objects reject unknown write fields. Shared payloads have generated read variants so a tolerant response never weakens a request schema.
|
|
50
|
+
|
|
51
|
+
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.
|
|
52
|
+
|
|
53
|
+
AWS staff methods deal with general observation, command and settings resources. Use `requests.readAwsObservations` to select current observation series, `getAwsSettings` to read the singleton settings shadow, and `updateAwsSettings` to patch typed settings with an expected version. The generated `staffRealtime.hub.watchAwsObservations`, `watchAwsCommand` and `watchAwsSettings` methods return native SignalR streams. See the [AWS resource map](../../docs/api/aws.md) for database and command-acceptance semantics.
|
|
54
|
+
|
|
55
|
+
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.
|
|
56
|
+
|
|
57
|
+
## Regenerate and build
|
|
58
|
+
|
|
59
|
+
The [protocol ownership guide](../../protocol/README.md) identifies the source
|
|
60
|
+
for each contract and the upstream generation steps. Edit those sources before
|
|
61
|
+
regenerating this client. `openapi/api.json`, `src/generated`, `src/signalr`,
|
|
62
|
+
`src/device-schema.ts` and `src/workflow-schema.ts` are generated outputs required
|
|
63
|
+
by the client build and consumers.
|
|
64
|
+
|
|
65
|
+
From the repository root:
|
|
66
|
+
|
|
67
|
+
```powershell
|
|
68
|
+
dotnet tool restore
|
|
69
|
+
dotnet restore services/api/src/Api.csproj --locked-mode
|
|
70
|
+
dotnet build services/api/src/Api.csproj --no-restore
|
|
71
|
+
npm ci --ignore-scripts
|
|
72
|
+
npm run contract --workspace @bikefinder/sdk
|
|
73
|
+
npm run generate --workspace @bikefinder/sdk
|
|
74
|
+
npm run check --workspace @bikefinder/sdk
|
|
75
|
+
npm test --workspace @bikefinder/sdk
|
|
76
|
+
npm run build --workspace @bikefinder/sdk
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
The pinned .NET tool is configured in `.config/dotnet-tools.json`. Contract export runs the built service locally to retrieve OpenAPI; no Firebase credentials or live requests are needed. 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, document fidelity, binary writes, uncertain write responses, native proxy invocation/cancellation and disposal.
|
|
80
|
+
|
|
81
|
+
## Publish
|
|
82
|
+
|
|
83
|
+
Bump this package's version and the root lockfile. **Publish API client**
|
|
84
|
+
(`publish-client.yml`) runs when the package manifest changes on `main`; it can also be run manually. The workflow checks the generated schemas, runs
|
|
85
|
+
the SDK tests, builds and publishes using GitHub OIDC. It does not deploy AWS
|
|
86
|
+
services and requires no npm token or per-release browser approval.
|
|
87
|
+
|
|
88
|
+
The npm package's trusted publisher must name organization `bikefinder`,
|
|
89
|
+
repository `aws_cloud`, workflow `publish-client.yml`, with direct `npm publish`
|
|
90
|
+
allowed and no environment name. This account setup is performed once in the
|
|
91
|
+
package's npm settings. See [npm trusted publishing](https://docs.npmjs.com/trusted-publishers/).
|
|
92
|
+
|
|
93
|
+
Command HTTP and SignalR methods return `AwsCommand`. Requests, broker publication and `execution.accepted`/`execution.completed` are distinct stages on that resource. The client no longer joins command-result observations or exposes a separate results endpoint. A completion includes a typed response data union and authenticated receipt time.
|
|
94
|
+
|
|
95
|
+
## Observation timestamps
|
|
96
|
+
|
|
97
|
+
Observation history and current readings expose `measuredAt` and `receivedAt`.
|
|
98
|
+
Observation IDs are opaque server-generated references. They carry no boot or
|
|
99
|
+
sequence information. Distinct rows can have identical capture timestamps;
|
|
100
|
+
clients must not infer physical ordering from their IDs. History can contain
|
|
101
|
+
separate rows for an at-least-once delivery of the same reading.
|
|
102
|
+
|
|
103
|
+
The source contract has changed after SDK 1.0.14. Before deploying consumers,
|
|
104
|
+
publish the next SDK release and update their registry dependency and lockfile.
|
|
105
|
+
Local validation can use the newly built SDK; keep that temporary override out
|
|
106
|
+
of committed consumer dependencies.
|
|
107
|
+
|
|
108
|
+
Settings responses use the API-owned `AwsSettingsSnapshot` 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.
|
|
109
|
+
|
|
110
|
+
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 `AwsCommandUpdate` with either a validated `command` or a `readIssue`, allowing subsequent events to continue.
|
|
111
|
+
|
|
112
|
+
## Supported API consumers
|
|
113
|
+
|
|
114
|
+
SDK 2.0.0 is the supported baseline after the explicitly approved pre-launch mode
|
|
115
|
+
alignment. It replaces the experimental `powerSaving`/`precision` mode names and
|
|
116
|
+
their timing setting names with `standard`/`security`. Earlier clients require a
|
|
117
|
+
one-time upgrade for these AWS resources. The tolerant response policy introduced
|
|
118
|
+
in 1.0.27 remains in place. Mode availability is an ID list, and selected mode IDs
|
|
119
|
+
are open strings validated against each tracker's cloud catalog. Adding or removing
|
|
120
|
+
catalog choices does not require another SDK release.
|
|
121
|
+
|
|
122
|
+
API CI installs the oldest supported immutable npm release selected in
|
|
123
|
+
`tools/check-api-compatibility.mjs`. It validates freshly server-serialized
|
|
124
|
+
Firestore, command and settings fixtures with that published reader, exercises
|
|
125
|
+
its HTTP transformer and stream-message schema, and checks additions at envelope
|
|
126
|
+
and nested-settings levels. The package includes its exported OpenAPI contract
|
|
127
|
+
under `@bikefinder/sdk/openapi` for the comparison.
|
|
128
|
+
|
|
129
|
+
The `compatibility` job runs oasdiff against that published contract, applying the
|
|
130
|
+
same tolerant-read policy to both documents. Request validation stays strict.
|
|
131
|
+
The gate rejects removed endpoints or response fields, incompatible types and
|
|
132
|
+
bounds, newly required inputs, and incompatible enum changes. Add a separate API
|
|
133
|
+
version for breaking changes and retain the supported v1 routes. Raising the
|
|
134
|
+
oldest supported SDK version is an explicit retirement decision, not a routine
|
|
135
|
+
way to pass CI. Dev deployment and production promotion both require this job.
|
|
136
|
+
|
|
137
|
+
Runtime validation still rejects malformed known data. Applications should retain
|
|
138
|
+
last valid stream messages and isolate failures per resource. When patching
|
|
139
|
+
settings, send only changed supported fields; preserve unfamiliar response fields
|
|
140
|
+
and do not copy a full response into a write payload.
|