Skip to content

Commit b624597

Browse files
committed
fix: use proper model for device credentials
1 parent 43f9e2e commit b624597

File tree

3 files changed

+311
-214
lines changed

3 files changed

+311
-214
lines changed

lambda/createCredentials.ts

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ import { metricsForComponent } from '@hello.nrfcloud.com/lambda-helpers/metrics'
1919
import { MetricUnit } from '@aws-lambda-powertools/metrics'
2020
import { NRF_CLOUD_ACCOUNT } from '../settings/account.js'
2121
import { addVersionHeader } from '@hello.nrfcloud.com/lambda-helpers/addVersionHeader'
22+
import {
23+
Context,
24+
type DeviceCredentials,
25+
} from '@hello.nrfcloud.com/proto-map/api'
26+
import type { Static } from '@sinclair/typebox'
2227

2328
const {
2429
backendStackName,
@@ -103,14 +108,15 @@ const h = async (
103108
).Payload?.transformToString() ?? '',
104109
)
105110

106-
const registration = await client.register([
107-
{
108-
deviceId,
109-
subType: 'map',
110-
tags: ['map'],
111-
certPem: certificate,
112-
},
113-
])
111+
const registrationArgs = {
112+
deviceId,
113+
subType: 'map-custom',
114+
tags: ['map-custom'],
115+
certPem: certificate,
116+
}
117+
console.debug(`Registering`, JSON.stringify(registrationArgs))
118+
119+
const registration = await client.register([registrationArgs])
114120

115121
if ('error' in registration) {
116122
console.error(
@@ -129,16 +135,21 @@ const h = async (
129135

130136
track('credentialsCreated', MetricUnit.Count, 1)
131137

138+
const res: Static<typeof DeviceCredentials> = {
139+
'@context': Context.deviceCredentials.toString(),
140+
id: maybePublicDevice.device.id,
141+
deviceId,
142+
credentials: {
143+
privateKey,
144+
certificate,
145+
},
146+
}
147+
132148
return aResponse(
133149
200,
134150
{
135-
'@context': new URL(
136-
'https://github.com/hello-nrfcloud/proto-map/device-credentials',
137-
),
138-
credentials: {
139-
privateKey,
140-
certificate,
141-
},
151+
...res,
152+
'@context': Context.deviceCredentials,
142153
},
143154
0,
144155
{

0 commit comments

Comments
 (0)