1- import { models } from '@hello.nrfcloud.com/proto-map'
2- import { DeviceId } from '@hello.nrfcloud.com/proto-map/api'
3- import type { ProblemDetail } from '@hello.nrfcloud.com/proto/hello'
4- import { Type , type Static } from '@sinclair/typebox'
5- import { typedFetch } from './typedFetch.js'
6-
7- const Model = Type . Union (
8- Object . keys ( models ) . map ( ( model ) => Type . Literal ( model ) ) ,
9- )
1+ import {
2+ DeviceIdentity ,
3+ typedFetch ,
4+ type TypedFetchResponse ,
5+ } from '@hello.nrfcloud.com/proto/hello'
106
117export const helloApi = ( {
128 endpoint,
@@ -15,29 +11,21 @@ export const helloApi = ({
1511 endpoint : URL
1612 fetchImplementation ?: typeof fetch
1713} ) : {
18- getDeviceByFingerprint : ( fingerprint : string ) => Promise <
19- | {
20- error : Omit < Static < typeof ProblemDetail > , '@context' >
21- }
22- | {
23- result : {
24- id : string
25- model : Static < typeof Model >
26- }
27- }
28- >
29- } => ( {
30- getDeviceByFingerprint : async ( fingerprint : string ) =>
31- typedFetch ( {
32- url : new URL (
33- `./device?${ new URLSearchParams ( { fingerprint } ) . toString ( ) } ` ,
34- endpoint ,
14+ getDeviceByFingerprint : (
15+ fingerprint : string ,
16+ ) => Promise < TypedFetchResponse < typeof DeviceIdentity > >
17+ } => {
18+ const getDeviceByFingerprintRequest = typedFetch ( {
19+ responseBodySchema : DeviceIdentity ,
20+ fetchImplementation,
21+ } )
22+ return {
23+ getDeviceByFingerprint : async ( fingerprint : string ) =>
24+ getDeviceByFingerprintRequest (
25+ new URL (
26+ `./device?${ new URLSearchParams ( { fingerprint } ) . toString ( ) } ` ,
27+ endpoint ,
28+ ) ,
3529 ) ,
36- RequestBodySchema : Type . Undefined ( ) ,
37- ResponseBodySchema : Type . Object ( {
38- id : DeviceId ,
39- model : Model ,
40- } ) ,
41- fetchImplementation,
42- } ) ( ) ,
43- } )
30+ }
31+ }
0 commit comments