Skip to content

Commit 40b90cd

Browse files
committed
feat(api): include deviceId
1 parent 3d96b5a commit 40b90cd

File tree

9 files changed

+2571
-15887
lines changed

9 files changed

+2571
-15887
lines changed

devices/publicDevicesRepo.spec.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ void describe('getById()', () => {
229229

230230
assert.deepEqual('device' in res && toPublic(res.device), {
231231
id,
232+
deviceId: 'some-device',
232233
model: 'thingy91x',
233234
})
234235
})
@@ -249,11 +250,8 @@ void describe('toPublic()', () => {
249250
})
250251
assert.deepEqual(record, {
251252
id,
253+
deviceId: 'some-device',
252254
model: ModelID.Thingy91x,
253255
})
254-
assert.equal(
255-
Object.values(record as Record<string, any>).includes('some-device'),
256-
false,
257-
)
258256
})
259257
})

devices/publicDevicesRepo.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,8 @@ export const publicDevicesRepo = ({
269269

270270
export const toPublic = (
271271
device: PublicDeviceRecord,
272-
): Pick<PublicDeviceRecord, 'id' | 'model'> => ({
272+
): Pick<PublicDeviceRecord, 'id' | 'deviceId' | 'model'> => ({
273273
id: device.id,
274+
deviceId: device.deviceId,
274275
model: device.model,
275276
})

features/JWT.feature.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ public device id in `publicDeviceId`
2121

2222
## Retrieve the JWT
2323

24-
When I `GET` to `${API}/device/${publicDeviceId}/jwt`
24+
When I `GET` to `${API}/device/${publicDeviceId} `
2525

26-
Then I should receive a `https://github.com/hello-nrfcloud/proto-map/jwt`
26+
Then I should receive a `https://github.com/hello-nrfcloud/proto-map/device-jwt`
2727
response
2828

2929
And I store `jwt` of the last response into `jwt`

features/OOBMapShare.feature.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,16 @@ And the last response should match
7575
```json
7676
{
7777
"id": "${publicDeviceId}",
78+
"deviceId": "${deviceId}",
7879
"model": "thingy91x"
7980
}
8081
```
8182

8283
## The sharing status of a device can be checked using the fingerprint
8384

84-
> Users should be able to determine whether a certain device is sharing data
85+
> Users should be able to determine whether a certain device is sharing data.
86+
>
87+
> This uses the fingerprint so it's not possible to just enumerate device IDs.
8588
8689
When I `GET` to `${API}/share/status?fingerprint=${fingerprint}`
8790

@@ -93,6 +96,7 @@ And the last response should match
9396
```json
9497
{
9598
"id": "${publicDeviceId}",
99+
"deviceId": "${deviceId}",
96100
"model": "thingy91x"
97101
}
98102
```

lambda/apiHealthCheck.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1+
import { fromEnv } from '@bifravst/from-env'
12
import { aResponse } from '@hello.nrfcloud.com/lambda-helpers/aResponse'
23
import { addVersionHeader } from '@hello.nrfcloud.com/lambda-helpers/addVersionHeader'
34
import { corsOPTIONS } from '@hello.nrfcloud.com/lambda-helpers/corsOPTIONS'
45
import { Context } from '@hello.nrfcloud.com/proto-map/api'
56
import middy from '@middy/core'
6-
import { fromEnv } from '@bifravst/from-env'
77
import { type APIGatewayProxyResultV2 } from 'aws-lambda'
88

99
const { version } = fromEnv({
1010
version: 'VERSION',
1111
})(process.env)
1212

13-
const h = async (): Promise<APIGatewayProxyResultV2> => {
14-
return aResponse(200, {
15-
'@context': Context.named('api/health'),
13+
const h = async (): Promise<APIGatewayProxyResultV2> =>
14+
aResponse(200, {
15+
'@context': Context.apiHealth,
1616
version,
1717
})
18-
}
1918

2019
export const handler = middy()
2120
.use(addVersionHeader(version))

lambda/deviceJwt.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ const h = async (
6969
return aResponse(
7070
200,
7171
{
72-
'@context': Context.named('jwt'),
72+
'@context': Context.deviceJWT,
7373
id: maybeSharedDevice.device.id,
7474
deviceId: maybeSharedDevice.device.deviceId,
7575
model: maybeSharedDevice.device.model,

lambda/devicesData.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ const h = async (
123123

124124
const devices: Array<{
125125
id: string
126+
deviceId: string
126127
model: string
127128
state?: Array<LwM2MObjectInstance>
128129
}> = (
@@ -137,6 +138,7 @@ const h = async (
137138
)
138139
return {
139140
id,
141+
deviceId,
140142
model,
141143
state:
142144
shadow.payload === undefined
@@ -151,7 +153,7 @@ const h = async (
151153
} else {
152154
console.error(err)
153155
}
154-
return { id, model }
156+
return { id, deviceId, model }
155157
}
156158
}),
157159
)

0 commit comments

Comments
 (0)