File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -7,3 +7,4 @@ export * from './getAccountInfo.js'
7
7
export * from './deleteAccountDevice.js'
8
8
export * from './getDeviceShadow.js'
9
9
export * from './DeviceShadow.js'
10
+ export * from './updateDeviceShadow.js'
Original file line number Diff line number Diff line change
1
+ import { slashless } from './slashless.js'
2
+
3
+ export const updateDeviceShadow =
4
+ (
5
+ {
6
+ endpoint,
7
+ apiKey,
8
+ } : {
9
+ endpoint : URL
10
+ apiKey : string
11
+ } ,
12
+ fetchImplementation ?: typeof fetch ,
13
+ ) =>
14
+ async (
15
+ deviceId : string ,
16
+ state : {
17
+ desired ?: Record < string , any >
18
+ reported ?: Record < string , any >
19
+ } ,
20
+ ) : Promise < void > => {
21
+ await ( fetchImplementation ?? fetch ) (
22
+ new URL (
23
+ `${ slashless ( endpoint ) } /v1/devices/${ encodeURIComponent (
24
+ deviceId ,
25
+ ) } /state`,
26
+ ) ,
27
+ {
28
+ method : 'PATCH' ,
29
+ headers : {
30
+ 'Content-Type' : 'application/json' ,
31
+ Authorization : `Bearer ${ apiKey } ` ,
32
+ } ,
33
+ body : JSON . stringify ( state ) ,
34
+ } ,
35
+ )
36
+ }
You can’t perform that action at this time.
0 commit comments