@@ -3,14 +3,16 @@ import { IoTDataPlaneClient } from '@aws-sdk/client-iot-data-plane'
33import { validateInput } from '@hello.nrfcloud.com/lambda-helpers/validateInput'
44import middy from '@middy/core'
55import inputOutputLogger from '@middy/input-output-logger'
6- import { Type } from '@sinclair/typebox'
76import type {
87 APIGatewayProxyEventV2 ,
98 APIGatewayProxyResultV2 ,
109} from 'aws-lambda'
11- import { processNrplusMessagesAndUpdateThingShadow } from '../nordicNRPlus/processNrplusMessagesAndUpdateThingShadow.ts'
10+ import { ensureThingExists } from '../nordicNRPlus/ensureThingExists.ts'
11+ import {
12+ inputSchemaLwm2mMessage ,
13+ processNrplusMessagesAndUpdateThingShadow ,
14+ } from '../nordicNRPlus/processNrplusMessagesAndUpdateThingShadow.ts'
1215import { thingExists } from '../nordicNRPlus/thingExists.ts'
13- import { ensureThingExists } from './ensureThingExists.ts'
1416import { updateShadow } from './updateShadow.ts'
1517
1618export const iotData = new IoTDataPlaneClient ( { } )
@@ -19,90 +21,6 @@ const iotClient = new IoTClient({})
1921const u = updateShadow ( iotData )
2022const ensureThing = ensureThingExists ( iotClient , thingExists )
2123
22- const neighborsInputSchema = Type . Object ( {
23- 0 : Type . Number ( ) ,
24- 1 : Type . Number ( ) ,
25- 99 : Type . Number ( ) ,
26- } )
27- const neighborsObjectSchema = Type . Record ( Type . String ( ) , neighborsInputSchema )
28-
29- const networkInputSchema = Type . Object ( {
30- 0 : Type . Number ( ) ,
31- 1 : Type . Number ( ) ,
32- 2 : Type . String ( ) ,
33- 99 : Type . Number ( ) ,
34- } )
35- const networkObjectSchema = Type . Record ( Type . String ( ) , networkInputSchema )
36-
37- const buttonPressInputSchema = Type . Object ( {
38- 99 : Type . Number ( ) ,
39- } )
40- const buttonPressObjectSchema = Type . Record (
41- Type . String ( ) ,
42- buttonPressInputSchema ,
43- )
44-
45- const lwm2mSchema = Type . Object ( {
46- '14502:1.0' : Type . Optional ( neighborsObjectSchema ) ,
47- '14503:1.0' : Type . Optional ( networkObjectSchema ) ,
48- '14220:1.0' : Type . Optional ( buttonPressObjectSchema ) ,
49- } )
50-
51- const shadowMessageSchema = Type . Object ( {
52- previous : Type . Optional (
53- Type . Object ( {
54- state : Type . Object ( {
55- desired : Type . Optional ( Type . Any ( ) ) ,
56- reported : Type . Optional (
57- Type . Object ( { lwm2m : Type . Optional ( lwm2mSchema ) } ) ,
58- ) ,
59- } ) ,
60- } ) ,
61- ) ,
62- current : Type . Optional (
63- Type . Object ( {
64- state : Type . Object ( {
65- desired : Type . Optional ( Type . Any ( ) ) ,
66- reported : Type . Optional (
67- Type . Object ( { lwm2m : Type . Optional ( lwm2mSchema ) } ) ,
68- ) ,
69- } ) ,
70- } ) ,
71- ) ,
72- } )
73-
74- const coapMessageSchema = Type . Object ( {
75- request : Type . Object ( {
76- body : Type . String ( ) , // base64
77- } ) ,
78- response : Type . Optional (
79- Type . Object ( {
80- body : Type . Optional ( Type . String ( ) ) ,
81- } ) ,
82- ) ,
83- } )
84-
85- const messageSchema = Type . Union ( [
86- shadowMessageSchema ,
87- coapMessageSchema ,
88- Type . Any ( ) ,
89- ] )
90-
91- export const inputSchemaLwm2mMessage = Type . Object ( {
92- type : Type . Literal ( 'device.messages' ) ,
93- messages : Type . Array (
94- Type . Object ( {
95- teamId : Type . String ( ) ,
96- deviceId : Type . String ( ) ,
97- messageId : Type . String ( ) ,
98- topic : Type . Optional ( Type . String ( ) ) ,
99- coapRequestUrl : Type . Optional ( Type . String ( ) ) ,
100- receivedAt : Type . Optional ( Type . String ( ) ) ,
101- message : messageSchema ,
102- } ) ,
103- ) ,
104- timestamp : Type . String ( ) ,
105- } )
10624const handle = processNrplusMessagesAndUpdateThingShadow ( {
10725 ensureThing,
10826 updateShadow : u ,
0 commit comments