Skip to content

Commit

Permalink
fix: update dependencies
Browse files Browse the repository at this point in the history
Closes #1066
Closes #1054
Closes #1048
Closes #1047
  • Loading branch information
coderbyheart committed Nov 24, 2024
1 parent 2dff12b commit 480a04d
Show file tree
Hide file tree
Showing 14 changed files with 165 additions and 399 deletions.
2 changes: 1 addition & 1 deletion Memfault/MemfaultReboots.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { validateWithTypeBox } from '@hello.nrfcloud.com/proto'
import assert from 'node:assert'
import { describe, it } from 'node:test'
import { MemfaultReboots } from './MemfaultReboots.js'
import res from './reboots.json'
import res from './reboots.json' assert { type: 'json' }

void describe('MemfaultReboots()', () => {
void it('should validate a response', () => {
Expand Down
16 changes: 8 additions & 8 deletions cdk/BackendStack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,22 +94,22 @@ export class BackendStack extends Stack {
layerVersionName: `${Stack.of(this).stackName}-baseLayer`,
code: new LambdaSource(this, {
id: 'baseLayer',
zipFile: baseLayer.layerZipFile,
zipFilePath: baseLayer.layerZipFilePath,
hash: baseLayer.hash,
}).code,
compatibleArchitectures: [Lambda.Architecture.ARM_64],
compatibleRuntimes: [Lambda.Runtime.NODEJS_20_X],
compatibleRuntimes: [Lambda.Runtime.NODEJS_22_X],
})

const jwtLayerVersion = new Lambda.LayerVersion(this, 'jwtLayer', {
layerVersionName: `${Stack.of(this).stackName}-jwtLayer`,
code: new LambdaSource(this, {
id: 'jwtLayer',
zipFile: jwtLayer.layerZipFile,
zipFilePath: jwtLayer.layerZipFilePath,
hash: jwtLayer.hash,
}).code,
compatibleArchitectures: [Lambda.Architecture.ARM_64],
compatibleRuntimes: [Lambda.Runtime.NODEJS_20_X],
compatibleRuntimes: [Lambda.Runtime.NODEJS_22_X],
})

const healthCheckLayerVersion = new Lambda.LayerVersion(
Expand All @@ -118,11 +118,11 @@ export class BackendStack extends Stack {
{
code: new LambdaSource(this, {
id: 'healthcheckLayer',
zipFile: healthCheckLayer.layerZipFile,
zipFilePath: healthCheckLayer.layerZipFilePath,
hash: healthCheckLayer.hash,
}).code,
compatibleArchitectures: [Lambda.Architecture.ARM_64],
compatibleRuntimes: [Lambda.Runtime.NODEJS_20_X],
compatibleRuntimes: [Lambda.Runtime.NODEJS_22_X],
},
)

Expand Down Expand Up @@ -175,11 +175,11 @@ export class BackendStack extends Stack {
const cdkLayerVersion = new Lambda.LayerVersion(this, 'cdkLayer', {
code: new LambdaSource(this, {
id: 'cdkLayer',
zipFile: cdkLayer.layerZipFile,
zipFilePath: cdkLayer.layerZipFilePath,
hash: cdkLayer.hash,
}).code,
compatibleArchitectures: [Lambda.Architecture.ARM_64],
compatibleRuntimes: [Lambda.Runtime.NODEJS_20_X],
compatibleRuntimes: [Lambda.Runtime.NODEJS_22_X],
})
const domain = new APICustomDomain(this, {
api,
Expand Down
2 changes: 1 addition & 1 deletion cdk/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { ensureCA } from '../bridge/ensureCA.js'
import { ensureMQTTBridgeCredentials } from '../bridge/ensureMQTTBridgeCredentials.js'
import { mqttBridgeCertificateLocation } from '../bridge/mqttBridgeCertificateLocation.js'
import { debug, type logFn } from '../cli/log.js'
import pJSON from '../package.json'
import pJSON from '../package.json' assert { type: 'json' }
import { ScopeContexts, type ScopeContext } from '../settings/scope.js'
import { BackendApp } from './BackendApp.js'
import { restoreCertificateFromSSM } from './helpers/certificates/restoreCertificateFromSSM.js'
Expand Down
9 changes: 6 additions & 3 deletions cdk/helpers/lambda/packGo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const packGo = async (
lambdaFolder: string,
distFolder: string = join(process.cwd(), 'dist/lambda'),
): Promise<PackedLambda> => {
const zipFile = join(distFolder, `${id}.zip`)
const zipFilePath = join(distFolder, `${id}.zip`)
const absLambdaFolder = join(process.cwd(), lambdaFolder)
await run({
command: 'go',
Expand All @@ -49,14 +49,17 @@ export const packGo = async (
GOCACHE: join(distFolder, 'gocache'),
},
})
await zipBinary(await readFile(join(absLambdaFolder, 'bootstrap')), zipFile)
await zipBinary(
await readFile(join(absLambdaFolder, 'bootstrap')),
zipFilePath,
)

return {
handler: 'bootstrap',
hash: await checkSumOfFiles(
(await readdir(absLambdaFolder)).map((f) => join(absLambdaFolder, f)),
),
zipFile,
zipFilePath,
id,
}
}
2 changes: 1 addition & 1 deletion cdk/layers/baseLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
packLayer,
type PackedLayer,
} from '@bifravst/aws-cdk-lambda-helpers/layer'
import type pJson from '../../package.json'
import pJson from '../../package.json' assert { type: 'json' }

const dependencies: Array<keyof (typeof pJson)['dependencies']> = [
'@bifravst/from-env',
Expand Down
2 changes: 1 addition & 1 deletion cdk/layers/cdkLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
packLayer,
type PackedLayer,
} from '@bifravst/aws-cdk-lambda-helpers/layer'
import type pJson from '../../package.json'
import pJson from '../../package.json' assert { type: 'json' }

const dependencies: Array<keyof (typeof pJson)['devDependencies']> = [
'cfn-response',
Expand Down
2 changes: 1 addition & 1 deletion cdk/layers/healthCheckLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
packLayer,
type PackedLayer,
} from '@bifravst/aws-cdk-lambda-helpers/layer'
import type pJson from '../../package.json'
import pJson from '../../package.json' assert { type: 'json' }

const dependencies: Array<keyof (typeof pJson)['dependencies']> = [
'mqtt',
Expand Down
2 changes: 1 addition & 1 deletion cdk/layers/jwtLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
packLayer,
type PackedLayer,
} from '@bifravst/aws-cdk-lambda-helpers/layer'
import type pJson from '../../package.json'
import pJson from '../../package.json' assert { type: 'json' }

const dependencies: Array<keyof (typeof pJson)['dependencies']> = [
'jsonwebtoken',
Expand Down
122 changes: 53 additions & 69 deletions cdk/packBackendLambdas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
packLambdaFromPath,
type PackedLambda,
} from '@bifravst/aws-cdk-lambda-helpers'
import path from 'node:path'
import { packGo } from './helpers/lambda/packGo.js'

export type BackendLambdas = {
Expand Down Expand Up @@ -54,7 +55,21 @@ export type BackendLambdas = {
}
}

const pack = async (id: string) => packLambdaFromPath(id, `lambda/${id}.ts`)
const pack = async (id: string) =>
packLambdaFromPath({ id, sourceFilePath: path.join(`lambda`, `${id}.ts`) })

const packFromFolder =
(folder: string) =>
async (id: string, lambda = id) =>
packLambdaFromPath({
id,
sourceFilePath: path.join(`lambda`, folder, `${lambda}.ts`),
})

const packLocationHistory = packFromFolder('location-history')
const packFOTA = packFromFolder('fota')
const packMultiBundleFOTA = packFromFolder('fota/multi-bundle-flow')
const packMemfault = packFromFolder('memfault')

export const packBackendLambdas = async (): Promise<BackendLambdas> => ({
authorizer: await pack('authorizer'),
Expand Down Expand Up @@ -83,99 +98,68 @@ export const packBackendLambdas = async (): Promise<BackendLambdas> => ({
queryLwM2MHistory: await pack('queryLwM2MHistory'),
apiHealthCheck: await pack('apiHealthCheck'),
onNrfCloudDeviceMessage: await pack('onNrfCloudDeviceMessage'),
scheduleFetchLocationHistory: await packLambdaFromPath(
scheduleFetchLocationHistory: await packLocationHistory(
'scheduleFetchLocationHistory',
'lambda/location-history/scheduleFetchLocationHistory.ts',
),
fetchLocationHistory: await packLambdaFromPath(
'fetchLocationHistory',
'lambda/location-history/fetchLocationHistory.ts',
),
queryLocationHistory: await packLambdaFromPath(
'queryLocationHistory',
'lambda/location-history/queryLocationHistory.ts',
),
scheduleFOTAJobStatusUpdate: await packLambdaFromPath(
'scheduleFOTAJobStatusUpdate',
`lambda/fota/scheduleFOTAJobStatusUpdate.ts`,
),
getFOTAJobStatus: await packLambdaFromPath(
'getFOTAJobStatus',
`lambda/fota/getFOTAJobStatus.ts`,
),
updateFOTAJobStatus: await packLambdaFromPath(
'updateFOTAJobStatus',
`lambda/fota/updateFOTAJobStatus.ts`,
),
notifyFOTAJobStatus: await packLambdaFromPath(
'notifyFOTAJobStatus',
`lambda/fota/notifyFOTAJobStatus.ts`,
),
listFOTABundles: await packLambdaFromPath(
'listFOTABundles',
`lambda/fota/listFOTABundles.ts`,
),
scheduleFetchMemfaultReboots: await packLambdaFromPath(
fetchLocationHistory: await packLocationHistory('fetchLocationHistory'),
queryLocationHistory: await packLocationHistory('queryLocationHistory'),
scheduleFOTAJobStatusUpdate: await packFOTA('scheduleFOTAJobStatusUpdate'),
getFOTAJobStatus: await packFOTA('getFOTAJobStatus'),
updateFOTAJobStatus: await packFOTA('updateFOTAJobStatus'),
notifyFOTAJobStatus: await packFOTA('notifyFOTAJobStatus'),
listFOTABundles: await packFOTA('listFOTABundles'),
scheduleFetchMemfaultReboots: await packMemfault(
'scheduleFetchMemfaultReboots',
'lambda/memfault/scheduleFetchReboots.ts',
'scheduleFetchReboots',
),
fetchMemfaultReboots: await packLambdaFromPath(
fetchMemfaultReboots: await packMemfault(
'fetchMemfaultReboots',
'lambda/memfault/fetchReboots.ts',
'fetchReboots',
),
queryMemfaultReboots: await packLambdaFromPath(
queryMemfaultReboots: await packMemfault(
'queryMemfaultReboots',
'lambda/memfault/queryReboots.ts',
'queryReboots',
),
hideDataBefore: await pack('hideDataBefore'),
createCNAMERecord: await packLambdaFromPath(
'createCNAMERecord',
'cdk/resources/api/createCNAMERecord.ts',
),
createCNAMERecord: await packLambdaFromPath({
id: 'createCNAMERecord',
sourceFilePath: 'cdk/resources/api/createCNAMERecord.ts',
}),
multiBundleFOTAFlow: {
start: await packLambdaFromPath(
'multiBundleFOTAFlowStart',
'lambda/fota/multi-bundle-flow/start.ts',
),
abort: await packLambdaFromPath(
'multiBundleFOTAFlowAbort',
'lambda/fota/multi-bundle-flow/abort.ts',
),
onFail: await packLambdaFromPath(
'multiBundleFOTAFlowOnFail',
'lambda/fota/multi-bundle-flow/onFail.ts',
),
getDeviceFirmwareDetails: await packLambdaFromPath(
start: await packMultiBundleFOTA('multiBundleFOTAFlowStart', 'start'),
abort: await packMultiBundleFOTA('multiBundleFOTAFlowAbort', 'abort'),
onFail: await packMultiBundleFOTA('multiBundleFOTAFlowOnFail', 'onFail'),
getDeviceFirmwareDetails: await packMultiBundleFOTA(
'multiBundleFOTAFlowGetDeviceFirmareDetails',
'lambda/fota/multi-bundle-flow/getDeviceFirmwareDetails.ts',
'getDeviceFirmwareDetails',
),
getNextBundle: await packLambdaFromPath(
getNextBundle: await packMultiBundleFOTA(
'multiBundleFOTAFlowGetNextBundle',
'lambda/fota/multi-bundle-flow/getNextBundle.ts',
'getNextBundle',
),
createFOTAJob: await packLambdaFromPath(
createFOTAJob: await packMultiBundleFOTA(
'multiBundleFOTAFlowCreateFOTAJob',
'lambda/fota/multi-bundle-flow/createFOTAJob.ts',
'createFOTAJob',
),
cancelFOTAJob: await packLambdaFromPath(
cancelFOTAJob: await packMultiBundleFOTA(
'multiBundleFOTAFlowCancelFOTAJob',
'lambda/fota/multi-bundle-flow/cancelFOTAJob.ts',
'cancelFOTAJob',
),
WaitForFOTAJobCompletionCallback: await packLambdaFromPath(
WaitForFOTAJobCompletionCallback: await packMultiBundleFOTA(
'multiBundleFOTAFlowWaitForFOTAJobCompletionCallback',
'lambda/fota/multi-bundle-flow/waitForFOTAJobCompletionCallback.ts',
'waitForFOTAJobCompletionCallback',
),
waitForFOTAJobCompletion: await packLambdaFromPath(
waitForFOTAJobCompletion: await packMultiBundleFOTA(
'multiBundleFOTAFlowWaitForFOTAJobCompletion',
'lambda/fota/multi-bundle-flow/waitForFOTAJobCompletion.ts',
'waitForFOTAJobCompletion',
),
waitForUpdateAppliedCallback: await packLambdaFromPath(
waitForUpdateAppliedCallback: await packMultiBundleFOTA(
'multiBundleFOTAFlowWaitForUpdateAppliedCallback',
'lambda/fota/multi-bundle-flow/waitForUpdateAppliedCallback.ts',
'waitForUpdateAppliedCallback',
),
WaitForUpdateApplied: await packLambdaFromPath(
WaitForUpdateApplied: await packMultiBundleFOTA(
'multiBundleFOTAFlowWaitForUpdateApplied',
'lambda/fota/multi-bundle-flow/waitForUpdateApplied.ts',
'waitForUpdateApplied',
),
},
})
2 changes: 1 addition & 1 deletion cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { env } from '../aws/env.js'
import { getIoTEndpoint } from '../aws/getIoTEndpoint.js'
import type { StackOutputs } from '../cdk/BackendStack.js'
import { STACK_NAME } from '../cdk/stackConfig.js'
import psjon from '../package.json'
import psjon from '../package.json' assert { type: 'json' }
import { buildContainersCommand } from './commands/build-container.js'
import { cleanBackupCertificates } from './commands/clean-backup-certificates.js'
import type { CommandDefinition } from './commands/CommandDefinition.js'
Expand Down
8 changes: 6 additions & 2 deletions cli/commands/update-lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,11 @@ export const updateLambda = ({

switch (fnInfo.Configuration?.Runtime) {
case 'nodejs20.x':
res = await packLambdaFromPath(id, `lambda/${sourceFile ?? id}.ts`)
case 'nodejs22.x':
res = await packLambdaFromPath({
id,
sourceFilePath: `lambda/${sourceFile ?? id}.ts`,
})
break
case 'provided.al2023':
if (id !== 'healthCheckForCoAPClient')
Expand All @@ -120,7 +124,7 @@ export const updateLambda = ({
const updateResult = await lambda.send(
new UpdateFunctionCodeCommand({
FunctionName: functionToUpdate.PhysicalResourceId,
ZipFile: new Uint8Array(await readFile(res.zipFile)),
ZipFile: new Uint8Array(await readFile(res.zipFilePath)),
}),
)

Expand Down
2 changes: 1 addition & 1 deletion nrfCloud/converter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
import assert from 'node:assert/strict'
import { describe, it } from 'node:test'
import { converter } from './converter.js'
import GNSS from './examples/GNSS.json'
import GNSS from './examples/GNSS.json' assert { type: 'json' }

void describe('convert()', () => {
void describe('should convert devices messages to LwM2M objects', () => {
Expand Down
Loading

0 comments on commit 480a04d

Please sign in to comment.