@@ -125,7 +125,10 @@ export const read: ReadActionRequest = (id: string, include?: string[]) => {
125125 return {
126126 [ RSAA ] : {
127127 endpoint : `/api/v1/devices/${ id } ?${ inclusions } ` ,
128- headers : JSONAPI_HEADERS ,
128+ headers : ( state : RootState ) => ( {
129+ ...JSONAPI_HEADERS ,
130+ Authorization : `Bearer ${ state . auth . access_token } ` ,
131+ } ) ,
129132 method : "GET" ,
130133 types : [
131134 DevicesActionTypes . READ_REQUEST ,
@@ -182,7 +185,10 @@ export const push: PushActionRequest = (id: string | number) => {
182185 return {
183186 [ RSAA ] : {
184187 endpoint : `/api/v1/devices/${ id } /push` ,
185- headers : JSON_HEADERS ,
188+ headers : ( state : RootState ) => ( {
189+ ...JSONAPI_HEADERS ,
190+ Authorization : `Bearer ${ state . auth . access_token } ` ,
191+ } ) ,
186192 method : "POST" ,
187193 types : [
188194 DevicesActionTypes . PUSH_REQUEST ,
@@ -205,7 +211,10 @@ export const restart: RestartActionRequest = (deviceId: string | number) => {
205211 return {
206212 [ RSAA ] : {
207213 endpoint : `/api/v1/devices/${ deviceId } /restart` ,
208- headers : JSON_HEADERS ,
214+ headers : ( state : RootState ) => ( {
215+ ...JSONAPI_HEADERS ,
216+ Authorization : `Bearer ${ state . auth . access_token } ` ,
217+ } ) ,
209218 method : "POST" ,
210219 types : [
211220 DevicesActionTypes . RESTART_REQUEST ,
@@ -233,7 +242,10 @@ export const shutdown: ShutdownActionRequest = (id: string | number) => {
233242 return {
234243 [ RSAA ] : {
235244 endpoint : `/api/v1/devices/${ id } /shutdown` ,
236- headers : JSON_HEADERS ,
245+ headers : ( state : RootState ) => ( {
246+ ...JSONAPI_HEADERS ,
247+ Authorization : `Bearer ${ state . auth . access_token } ` ,
248+ } ) ,
237249 method : "POST" ,
238250 types : [
239251 DevicesActionTypes . SHUTDOWN_REQUEST ,
@@ -261,7 +273,10 @@ export const erase: EraseActionRequest = (id: string | number) => {
261273 return {
262274 [ RSAA ] : {
263275 endpoint : `/api/v1/devices/${ id } /erase` ,
264- headers : JSON_HEADERS ,
276+ headers : ( state : RootState ) => ( {
277+ ...JSONAPI_HEADERS ,
278+ Authorization : `Bearer ${ state . auth . access_token } ` ,
279+ } ) ,
265280 method : "POST" ,
266281 types : [
267282 DevicesActionTypes . ERASE_REQUEST ,
@@ -294,7 +309,10 @@ export const lock: LockActionRequest = (deviceId: string | number, pin?: string,
294309 pin,
295310 } ) ,
296311 endpoint : `/api/v1/devices/${ deviceId } /lock` ,
297- headers : JSON_HEADERS ,
312+ headers : ( state : RootState ) => ( {
313+ ...JSONAPI_HEADERS ,
314+ Authorization : `Bearer ${ state . auth . access_token } ` ,
315+ } ) ,
298316 method : "POST" ,
299317 types : [
300318 DevicesActionTypes . LOCK_REQUEST ,
@@ -322,7 +340,10 @@ export const clearPasscode: ClearPasscodeActionRequest = (id: string | number) =
322340 return {
323341 [ RSAA ] : {
324342 endpoint : `/api/v1/devices/${ id } /clear_passcode` ,
325- headers : JSON_HEADERS ,
343+ headers : ( state : RootState ) => ( {
344+ ...JSONAPI_HEADERS ,
345+ Authorization : `Bearer ${ state . auth . access_token } ` ,
346+ } ) ,
326347 method : "POST" ,
327348 types : [
328349 DevicesActionTypes . CLEARPASSCODE_REQUEST ,
@@ -349,7 +370,10 @@ export const inventory: InventoryActionRequest = (id: string | number) => {
349370 return {
350371 [ RSAA ] : {
351372 endpoint : `/api/v1/devices/inventory/${ id } ` ,
352- headers : JSON_HEADERS ,
373+ headers : ( state : RootState ) => ( {
374+ ...JSONAPI_HEADERS ,
375+ Authorization : `Bearer ${ state . auth . access_token } ` ,
376+ } ) ,
353377 method : "GET" ,
354378 types : [
355379 DevicesActionTypes . INVENTORY_REQUEST ,
@@ -377,7 +401,10 @@ export const test: TestActionRequest = (id: string | number) => {
377401 return {
378402 [ RSAA ] : {
379403 endpoint : `/api/v1/devices/test/${ id } ` ,
380- headers : JSON_HEADERS ,
404+ headers : ( state : RootState ) => ( {
405+ ...JSONAPI_HEADERS ,
406+ Authorization : `Bearer ${ state . auth . access_token } ` ,
407+ } ) ,
381408 method : "POST" ,
382409 types : [
383410 TEST_REQUEST ,
@@ -400,7 +427,10 @@ export const commands = encodeJSONAPIChildIndexParameters((deviceId: string, que
400427 return ( {
401428 [ RSAA ] : {
402429 endpoint : `/api/v1/devices/${ deviceId } /commands?${ queryParameters . join ( "&" ) } ` ,
403- headers : JSONAPI_HEADERS ,
430+ headers : ( state : RootState ) => ( {
431+ ...JSONAPI_HEADERS ,
432+ Authorization : `Bearer ${ state . auth . access_token } ` ,
433+ } ) ,
404434 method : "GET" ,
405435 types : [
406436 DevicesActionTypes . COMMANDS_REQUEST ,
@@ -433,7 +463,10 @@ export const patch: PatchActionRequest = (deviceId: string, values: Device) => {
433463 } ,
434464 } ) ,
435465 endpoint : `/api/v1/devices/${ deviceId } ` ,
436- headers : JSONAPI_HEADERS ,
466+ headers : ( state : RootState ) => ( {
467+ ...JSONAPI_HEADERS ,
468+ Authorization : `Bearer ${ state . auth . access_token } ` ,
469+ } ) ,
437470 method : "PATCH" ,
438471 types : [
439472 DevicesActionTypes . PATCH_REQUEST ,
@@ -457,7 +490,10 @@ export const postRelationship: PostRelationshipActionRequest = (id: string, rela
457490 [ RSAA ] : {
458491 body : JSON . stringify ( { data } ) ,
459492 endpoint : `/api/v1/devices/${ id } /relationships/${ relationship } ` ,
460- headers : JSONAPI_HEADERS ,
493+ headers : ( state : RootState ) => ( {
494+ ...JSONAPI_HEADERS ,
495+ Authorization : `Bearer ${ state . auth . access_token } ` ,
496+ } ) ,
461497 method : "POST" ,
462498 types : [
463499 DevicesActionTypes . REL_POST_REQUEST ,
@@ -478,7 +514,10 @@ export type RCPOST_FAILURE = typeof RCPOST_FAILURE;
478514export type PostRelatedActionRequest = < TRelated > ( parentId : string , relationship : DeviceRelationship , data : TRelated ) => RSAAction < RCPOST_REQUEST , RCPOST_SUCCESS , RCPOST_FAILURE > ;
479515export type PostRelatedActionResponse = RSAAReadActionResponse < RCPOST_REQUEST , RCPOST_SUCCESS , RCPOST_FAILURE , JSONAPIDetailResponse < any , undefined > > ;
480516
481- export const postRelated : PostRelatedActionRequest = < TRelated > ( parentId : string , relationship : DeviceRelationship , data : TRelated ) : RSAAction < RCPOST_REQUEST , RCPOST_SUCCESS , RCPOST_FAILURE > => {
517+ export const postRelated : PostRelatedActionRequest = < TRelated > (
518+ parentId : string ,
519+ relationship : DeviceRelationship ,
520+ data : TRelated ) : RSAAction < RCPOST_REQUEST , RCPOST_SUCCESS , RCPOST_FAILURE > => {
482521 return {
483522 [ RSAA ] : {
484523 body : JSON . stringify ( { data : {
@@ -496,7 +535,10 @@ export const postRelated: PostRelatedActionRequest = <TRelated>(parentId: string
496535 type : relationship ,
497536 } } ) ,
498537 endpoint : `/api/v1/devices/${ parentId } /${ relationship } ` ,
499- headers : JSONAPI_HEADERS ,
538+ headers : ( state : RootState ) => ( {
539+ ...JSONAPI_HEADERS ,
540+ Authorization : `Bearer ${ state . auth . access_token } ` ,
541+ } ) ,
500542 method : "POST" ,
501543 types : [
502544 RCPOST_REQUEST ,
@@ -514,15 +556,24 @@ export type RPATCH_SUCCESS = typeof RPATCH_SUCCESS;
514556export const RPATCH_FAILURE = "devices/RPATCH_FAILURE" ;
515557export type RPATCH_FAILURE = typeof RPATCH_FAILURE ;
516558
517- export type PatchRelationshipActionRequest = ( parentId : string , relationship : DeviceRelationship , data : JSONAPIRelationship [ ] ) => RSAAction < RPATCH_REQUEST , RPATCH_SUCCESS , RPATCH_FAILURE > ;
518- export type PatchRelationshipActionResponse = RSAAReadActionResponse < RPATCH_REQUEST , RPATCH_SUCCESS , RPATCH_FAILURE , JSONAPIDetailResponse < Device , undefined > > ;
559+ export type PatchRelationshipActionRequest = (
560+ parentId : string ,
561+ relationship : DeviceRelationship ,
562+ data : JSONAPIRelationship [ ] ) => RSAAction < RPATCH_REQUEST , RPATCH_SUCCESS , RPATCH_FAILURE > ;
519563
520- export const patchRelationship : PatchRelationshipActionRequest = ( id : string , relationship : DeviceRelationship , data : JSONAPIRelationship [ ] ) => {
564+ export type PatchRelationshipActionResponse = RSAAReadActionResponse <
565+ RPATCH_REQUEST , RPATCH_SUCCESS , RPATCH_FAILURE , JSONAPIDetailResponse < Device , undefined > > ;
566+
567+ export const patchRelationship : PatchRelationshipActionRequest = (
568+ id : string , relationship : DeviceRelationship , data : JSONAPIRelationship [ ] ) => {
521569 return {
522570 [ RSAA ] : {
523571 body : JSON . stringify ( { data } ) ,
524572 endpoint : `/api/v1/devices/${ id } /relationships/${ relationship } ` ,
525- headers : JSONAPI_HEADERS ,
573+ headers : ( state : RootState ) => ( {
574+ ...JSONAPI_HEADERS ,
575+ Authorization : `Bearer ${ state . auth . access_token } ` ,
576+ } ) ,
526577 method : "PATCH" ,
527578 types : [
528579 RPATCH_REQUEST ,
0 commit comments