Skip to content

Commit 08a7917

Browse files
committed
fix: update dependencies
Closes #213 Closes #214
1 parent 5487886 commit 08a7917

File tree

14 files changed

+313
-250
lines changed

14 files changed

+313
-250
lines changed

lambda/apiHealthCheck.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ import { fromEnv } from '@bifravst/from-env'
22
import { aResponse } from '@hello.nrfcloud.com/lambda-helpers/aResponse'
33
import { addVersionHeader } from '@hello.nrfcloud.com/lambda-helpers/addVersionHeader'
44
import { corsOPTIONS } from '@hello.nrfcloud.com/lambda-helpers/corsOPTIONS'
5+
import { problemResponse } from '@hello.nrfcloud.com/lambda-helpers/problemResponse'
6+
import { requestLogger } from '@hello.nrfcloud.com/lambda-helpers/requestLogger'
57
import { Context } from '@hello.nrfcloud.com/proto-map/api'
68
import middy from '@middy/core'
79
import { type APIGatewayProxyResultV2 } from 'aws-lambda'
8-
import { requestLogger } from '@hello.nrfcloud.com/lambda-helpers/requestLogger'
910

1011
const { version } = fromEnv({
1112
version: 'VERSION',
@@ -21,4 +22,5 @@ export const handler = middy()
2122
.use(addVersionHeader(version))
2223
.use(corsOPTIONS('POST'))
2324
.use(requestLogger())
25+
.use(problemResponse())
2426
.handler(h)

lambda/createDevice.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import { InvokeCommand, LambdaClient } from '@aws-sdk/client-lambda'
55
import { SSMClient } from '@aws-sdk/client-ssm'
66
import { fromEnv } from '@bifravst/from-env'
77
import { addVersionHeader } from '@hello.nrfcloud.com/lambda-helpers/addVersionHeader'
8-
import { aProblem } from '@hello.nrfcloud.com/lambda-helpers/aProblem'
98
import { aResponse } from '@hello.nrfcloud.com/lambda-helpers/aResponse'
109
import { corsOPTIONS } from '@hello.nrfcloud.com/lambda-helpers/corsOPTIONS'
1110
import { metricsForComponent } from '@hello.nrfcloud.com/lambda-helpers/metrics'
11+
import { problemResponse } from '@hello.nrfcloud.com/lambda-helpers/problemResponse'
1212
import { requestLogger } from '@hello.nrfcloud.com/lambda-helpers/requestLogger'
1313
import {
1414
validateInput,
@@ -102,10 +102,7 @@ const h = async (
102102
})
103103
if ('error' in maybePublished) {
104104
console.error(maybePublished.error)
105-
return aProblem({
106-
title: `Failed to share device: ${maybePublished.error.message}`,
107-
status: 500,
108-
})
105+
throw new Error(`Failed to share device: ${maybePublished.error.message}`)
109106
}
110107

111108
const { privateKey, certificate } = JSON.parse(
@@ -138,10 +135,7 @@ const h = async (
138135
`registration failed`,
139136
JSON.stringify(registration.error),
140137
)
141-
return aProblem({
142-
title: `Registration failed: ${registration.error.message}`,
143-
status: 500,
144-
})
138+
throw new Error(`Registration failed: ${registration.error.message}`)
145139
}
146140

147141
console.log(deviceId, `Registered devices with nRF Cloud`)
@@ -185,4 +179,5 @@ export const handler = middy()
185179
),
186180
}),
187181
)
182+
.use(problemResponse())
188183
.handler(h)

lambda/deviceJwt.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import { DynamoDBClient } from '@aws-sdk/client-dynamodb'
22
import { SSMClient } from '@aws-sdk/client-ssm'
33
import { fromEnv } from '@bifravst/from-env'
4-
import { aProblem } from '@hello.nrfcloud.com/lambda-helpers/aProblem'
54
import { aResponse } from '@hello.nrfcloud.com/lambda-helpers/aResponse'
65
import { addVersionHeader } from '@hello.nrfcloud.com/lambda-helpers/addVersionHeader'
76
import { corsOPTIONS } from '@hello.nrfcloud.com/lambda-helpers/corsOPTIONS'
7+
import {
8+
ProblemDetailError,
9+
problemResponse,
10+
} from '@hello.nrfcloud.com/lambda-helpers/problemResponse'
811
import { requestLogger } from '@hello.nrfcloud.com/lambda-helpers/requestLogger'
912
import {
1013
validateInput,
@@ -47,7 +50,7 @@ const h = async (
4750
const maybeSharedDevice = await devicesRepo.getById(context.validInput.id)
4851

4952
if ('error' in maybeSharedDevice) {
50-
return aProblem({
53+
throw new ProblemDetailError({
5154
title: `Device with id ${context.validInput.id} not shared: ${maybeSharedDevice.error}`,
5255
status: 404,
5356
})
@@ -71,4 +74,5 @@ export const handler = middy()
7174
.use(corsOPTIONS('GET'))
7275
.use(requestLogger())
7376
.use(validateInput(InputSchema))
77+
.use(problemResponse())
7478
.handler(h)

lambda/devicesData.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { fromEnv } from '@bifravst/from-env'
1313
import { aResponse } from '@hello.nrfcloud.com/lambda-helpers/aResponse'
1414
import { addVersionHeader } from '@hello.nrfcloud.com/lambda-helpers/addVersionHeader'
1515
import { corsOPTIONS } from '@hello.nrfcloud.com/lambda-helpers/corsOPTIONS'
16+
import { problemResponse } from '@hello.nrfcloud.com/lambda-helpers/problemResponse'
1617
import { requestLogger } from '@hello.nrfcloud.com/lambda-helpers/requestLogger'
1718
import {
1819
validateInput,
@@ -164,4 +165,5 @@ export const handler = middy()
164165
return qs
165166
}),
166167
)
168+
.use(problemResponse())
167169
.handler(h)

lambda/jwks.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { SSMClient } from '@aws-sdk/client-ssm'
22
import { fromEnv } from '@bifravst/from-env'
33
import { addVersionHeader } from '@hello.nrfcloud.com/lambda-helpers/addVersionHeader'
4+
import { problemResponse } from '@hello.nrfcloud.com/lambda-helpers/problemResponse'
5+
import { requestLogger } from '@hello.nrfcloud.com/lambda-helpers/requestLogger'
46
import middy from '@middy/core'
57
import type { APIGatewayProxyResultV2 } from 'aws-lambda'
68
import { getSettings } from '../settings/jwt.js'
7-
import { requestLogger } from '@hello.nrfcloud.com/lambda-helpers/requestLogger'
89

910
const { version, stackName } = fromEnv({
1011
version: 'VERSION',
@@ -36,4 +37,5 @@ const h = async (): Promise<APIGatewayProxyResultV2> => ({
3637
export const handler = middy()
3738
.use(addVersionHeader(version))
3839
.use(requestLogger())
40+
.use(problemResponse())
3941
.handler(h)

lambda/middleware/withUser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { aProblem } from '@hello.nrfcloud.com/lambda-helpers/aProblem'
1+
import { ProblemDetailError } from '@hello.nrfcloud.com/lambda-helpers/problemResponse'
22
import { HttpStatusCode } from '@hello.nrfcloud.com/proto/hello'
33
import type { MiddlewareObj } from '@middy/core'
44
import type {
@@ -23,7 +23,7 @@ export const withUser = ({
2323
)
2424
if ('error' in maybeValidJWT) {
2525
console.error(`[withUser:jwt]`, maybeValidJWT.error)
26-
return aProblem({
26+
throw new ProblemDetailError({
2727
title: `Failed to validate JWT!`,
2828
detail: maybeValidJWT.error.message,
2929
status: HttpStatusCode.BAD_REQUEST,

lambda/openSSL.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import fs from 'node:fs/promises'
2-
import os from 'node:os'
3-
import path from 'node:path'
41
import run from '@bifravst/run'
52
import { createCA } from '@hello.nrfcloud.com/certificate-helpers/ca'
63
import { createDeviceCertificate } from '@hello.nrfcloud.com/certificate-helpers/device'
7-
import middy from '@middy/core'
4+
import { problemResponse } from '@hello.nrfcloud.com/lambda-helpers/problemResponse'
85
import { requestLogger } from '@hello.nrfcloud.com/lambda-helpers/requestLogger'
6+
import middy from '@middy/core'
7+
import fs from 'node:fs/promises'
8+
import os from 'node:os'
9+
import path from 'node:path'
910

1011
/**
1112
* Allows to use OpenSSL
@@ -52,4 +53,7 @@ const h = async (event: {
5253
}
5354
}
5455

55-
export const handler = middy().use(requestLogger()).handler(h)
56+
export const handler = middy()
57+
.use(requestLogger())
58+
.use(problemResponse())
59+
.handler(h)

lambda/requestToken.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ import {
66
} from '@aws-sdk/client-dynamodb'
77
import { SESClient } from '@aws-sdk/client-ses'
88
import { fromEnv } from '@bifravst/from-env'
9-
import { aProblem } from '@hello.nrfcloud.com/lambda-helpers/aProblem'
109
import { aResponse } from '@hello.nrfcloud.com/lambda-helpers/aResponse'
1110
import { addVersionHeader } from '@hello.nrfcloud.com/lambda-helpers/addVersionHeader'
1211
import { corsOPTIONS } from '@hello.nrfcloud.com/lambda-helpers/corsOPTIONS'
1312
import { metricsForComponent } from '@hello.nrfcloud.com/lambda-helpers/metrics'
13+
import {
14+
ProblemDetailError,
15+
problemResponse,
16+
} from '@hello.nrfcloud.com/lambda-helpers/problemResponse'
1417
import { requestLogger } from '@hello.nrfcloud.com/lambda-helpers/requestLogger'
1518
import {
1619
validateInput,
@@ -68,16 +71,13 @@ const h = async (
6871
})
6972
if ('error' in maybeToken) {
7073
if (maybeToken.error instanceof ConditionalCheckFailedException) {
71-
return aProblem({
74+
throw new ProblemDetailError({
7275
title: `Failed to request token: ${maybeToken.error.message}`,
7376
status: 409,
7477
})
7578
}
7679
console.error(maybeToken.error)
77-
return aProblem({
78-
title: `Failed to request token: ${maybeToken.error.message}`,
79-
status: 500,
80-
})
80+
throw new Error(`Failed to request token: ${maybeToken.error.message}`)
8181
}
8282

8383
track('tokenCreated', MetricUnit.Count, 1)
@@ -99,4 +99,5 @@ export const handler = middy()
9999
.use(logMetrics(metrics))
100100
.use(requestLogger())
101101
.use(validateInput(InputSchema))
102+
.use(problemResponse())
102103
.handler(h)

lambda/shareDevice.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ import {
66
} from '@aws-sdk/client-dynamodb'
77
import { SSMClient } from '@aws-sdk/client-ssm'
88
import { fromEnv } from '@bifravst/from-env'
9-
import { aProblem } from '@hello.nrfcloud.com/lambda-helpers/aProblem'
109
import { aResponse } from '@hello.nrfcloud.com/lambda-helpers/aResponse'
1110
import { addVersionHeader } from '@hello.nrfcloud.com/lambda-helpers/addVersionHeader'
1211
import { corsOPTIONS } from '@hello.nrfcloud.com/lambda-helpers/corsOPTIONS'
1312
import { metricsForComponent } from '@hello.nrfcloud.com/lambda-helpers/metrics'
13+
import {
14+
ProblemDetailError,
15+
problemResponse,
16+
} from '@hello.nrfcloud.com/lambda-helpers/problemResponse'
1417
import { requestLogger } from '@hello.nrfcloud.com/lambda-helpers/requestLogger'
1518
import {
1619
validateInput,
@@ -81,7 +84,7 @@ const h = async (
8184
context.validInput.fingerprint,
8285
)
8386
if ('error' in maybeDevice) {
84-
return aProblem(maybeDevice.error)
87+
throw new ProblemDetailError(maybeDevice.error)
8588
}
8689
const { id: deviceId } = maybeDevice.result
8790
return publish({
@@ -107,16 +110,13 @@ const publish = async ({
107110
})
108111
if ('error' in maybePublished) {
109112
if (maybePublished.error instanceof ConditionalCheckFailedException) {
110-
return aProblem({
113+
throw new ProblemDetailError({
111114
title: `Failed to share device: ${maybePublished.error.message}`,
112115
status: 409,
113116
})
114117
}
115118
console.error(maybePublished.error)
116-
return aProblem({
117-
title: `Failed to share device: ${maybePublished.error.message}`,
118-
status: 500,
119-
})
119+
throw new Error(`Failed to share device: ${maybePublished.error.message}`)
120120
}
121121

122122
track('deviceShared', MetricUnit.Count, 1)
@@ -148,4 +148,5 @@ export const handler = middy()
148148
),
149149
}),
150150
)
151+
.use(problemResponse())
151152
.handler(h)

lambda/sharingStatus.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import { DynamoDBClient } from '@aws-sdk/client-dynamodb'
22
import { fromEnv } from '@bifravst/from-env'
3-
import { aProblem } from '@hello.nrfcloud.com/lambda-helpers/aProblem'
43
import { aResponse } from '@hello.nrfcloud.com/lambda-helpers/aResponse'
54
import { addVersionHeader } from '@hello.nrfcloud.com/lambda-helpers/addVersionHeader'
65
import { corsOPTIONS } from '@hello.nrfcloud.com/lambda-helpers/corsOPTIONS'
6+
import {
7+
ProblemDetailError,
8+
problemResponse,
9+
} from '@hello.nrfcloud.com/lambda-helpers/problemResponse'
710
import { requestLogger } from '@hello.nrfcloud.com/lambda-helpers/requestLogger'
811
import {
912
validateInput,
@@ -42,7 +45,7 @@ const h = async (
4245
console.log(JSON.stringify(maybeDevice))
4346

4447
if ('error' in maybeDevice) {
45-
return aProblem({
48+
throw new ProblemDetailError({
4649
title: `Device ${context.validInput.id} not shared: ${maybeDevice.error}`,
4750
status: 404,
4851
})
@@ -63,4 +66,5 @@ export const handler = middy()
6366
.use(corsOPTIONS('GET'))
6467
.use(requestLogger())
6568
.use(validateInput(InputSchema))
69+
.use(problemResponse())
6670
.handler(h)

0 commit comments

Comments
 (0)