import { HttpRequest as __HttpRequest , HttpResponse as __HttpResponse } from "@aws-sdk/protocol-http" ; import { expectBoolean as __expectBoolean , expectInt32 as __expectInt32 , expectNonNull as __expectNonNull , expectObject as __expectObject , expectString as __expectString , extendedEncodeURIComponent as __extendedEncodeURIComponent , limitedParseDouble as __limitedParseDouble , } from "@aws-sdk/smithy-client" ; import { Endpoint as __Endpoint , MetadataBearer as __MetadataBearer , ResponseMetadata as __ResponseMetadata , SerdeContext as __SerdeContext , SmithyException as __SmithyException , } from "@aws-sdk/types" ; import { ClaimDevicesByClaimCodeCommandInput , ClaimDevicesByClaimCodeCommandOutput , } from "../commands/ClaimDevicesByClaimCodeCommand" ; import { DescribeDeviceCommandInput , DescribeDeviceCommandOutput } from "../commands/DescribeDeviceCommand" ; import { FinalizeDeviceClaimCommandInput , FinalizeDeviceClaimCommandOutput , } from "../commands/FinalizeDeviceClaimCommand" ; import { GetDeviceMethodsCommandInput , GetDeviceMethodsCommandOutput } from "../commands/GetDeviceMethodsCommand" ; import { InitiateDeviceClaimCommandInput , InitiateDeviceClaimCommandOutput , } from "../commands/InitiateDeviceClaimCommand" ; import { InvokeDeviceMethodCommandInput , InvokeDeviceMethodCommandOutput } from "../commands/InvokeDeviceMethodCommand" ; import { ListDeviceEventsCommandInput , ListDeviceEventsCommandOutput } from "../commands/ListDeviceEventsCommand" ; import { ListDevicesCommandInput , ListDevicesCommandOutput } from "../commands/ListDevicesCommand" ; import { ListTagsForResourceCommandInput , ListTagsForResourceCommandOutput , } from "../commands/ListTagsForResourceCommand" ; import { TagResourceCommandInput , TagResourceCommandOutput } from "../commands/TagResourceCommand" ; import { UnclaimDeviceCommandInput , UnclaimDeviceCommandOutput } from "../commands/UnclaimDeviceCommand" ; import { UntagResourceCommandInput , UntagResourceCommandOutput } from "../commands/UntagResourceCommand" ; import { UpdateDeviceStateCommandInput , UpdateDeviceStateCommandOutput } from "../commands/UpdateDeviceStateCommand" ; import { Attributes , Device , DeviceDescription , DeviceEvent , DeviceMethod , ForbiddenException , InternalFailureException , InvalidRequestException , PreconditionFailedException , RangeNotSatisfiableException , ResourceConflictException , ResourceNotFoundException , } from "../models/models_0" ; export const serializeAws_restJson1ClaimDevicesByClaimCodeCommand = async ( input , context ) : Promise < __HttpRequest > => { const { hostname , protocol = "https" , port , path : basePath } = await context . endpoint ( ) ; const headers = { } ; let resolvedPath = `${ basePath ?. endsWith ( "/" ) ? basePath . slice ( 0 , - 1 ) : basePath || "" }` + "/claims/{ClaimCode}" ; if ( input . ClaimCode !== undefined ) { const labelValue = input . ClaimCode ; if ( labelValue . length <= 0 ) { throw new Error ( "Empty value provided for input HTTP label: ClaimCode." ) ; } resolvedPath = resolvedPath . replace ( "{ClaimCode}" , __extendedEncodeURIComponent ( labelValue ) ) ; } else { throw new Error ( "No value provided for input HTTP label: ClaimCode." ) ; } let body ; return new __HttpRequest ( { protocol , hostname , port , method : "PUT" , headers , path : resolvedPath , body , } ) ; } ; export const serializeAws_restJson1DescribeDeviceCommand = async ( input , context ) : Promise < __HttpRequest > => { const { hostname , protocol = "https" , port , path : basePath } = await context . endpoint ( ) ; const headers = { } ; let resolvedPath = `${ basePath ?. endsWith ( "/" ) ? basePath . slice ( 0 , - 1 ) : basePath || "" }` + "/devices/{DeviceId}" ; if ( input . DeviceId !== undefined ) { const labelValue = input . DeviceId ; if ( labelValue . length <= 0 ) { throw new Error ( "Empty value provided for input HTTP label: DeviceId." ) ; } resolvedPath = resolvedPath . replace ( "{DeviceId}" , __extendedEncodeURIComponent ( labelValue ) ) ; } else { throw new Error ( "No value provided for input HTTP label: DeviceId." ) ; } let body ; return new __HttpRequest ( { protocol , hostname , port , method : "GET" , headers , path : resolvedPath , body , } ) ; } ; export const serializeAws_restJson1FinalizeDeviceClaimCommand = async ( input , context ) : Promise < __HttpRequest > => { const { hostname , protocol = "https" , port , path : basePath } = await context . endpoint ( ) ; const headers = { "content-type" : "application/json" , } ; let resolvedPath = `${ basePath ?. endsWith ( "/" ) ? basePath . slice ( 0 , - 1 ) : basePath || "" }` + "/devices/{DeviceId}/finalize-claim" ; if ( input . DeviceId !== undefined ) { const labelValue = input . DeviceId ; if ( labelValue . length <= 0 ) { throw new Error ( "Empty value provided for input HTTP label: DeviceId." ) ; } resolvedPath = resolvedPath . replace ( "{DeviceId}" , __extendedEncodeURIComponent ( labelValue ) ) ; } else { throw new Error ( "No value provided for input HTTP label: DeviceId." ) ; } let body ; body = JSON . stringify ( { ... ( input . Tags !== undefined && input . Tags !== null && { tags : serializeAws_restJson1__mapOf__string ( input . Tags , context ) } ) , } ) ; return new __HttpRequest ( { protocol , hostname , port , method : "PUT" , headers , path : resolvedPath , body , } ) ; } ; export const serializeAws_restJson1GetDeviceMethodsCommand = async ( input , context ) : Promise < __HttpRequest > => { const { hostname , protocol = "https" , port , path : basePath } = await context . endpoint ( ) ; const headers = { } ; let resolvedPath = `${ basePath ?. endsWith ( "/" ) ? basePath . slice ( 0 , - 1 ) : basePath || "" }` + "/devices/{DeviceId}/methods" ; if ( input . DeviceId !== undefined ) { const labelValue = input . DeviceId ; if ( labelValue . length <= 0 ) { throw new Error ( "Empty value provided for input HTTP label: DeviceId." ) ; } resolvedPath = resolvedPath . replace ( "{DeviceId}" , __extendedEncodeURIComponent ( labelValue ) ) ; } else { throw new Error ( "No value provided for input HTTP label: DeviceId." ) ; } let body ; return new __HttpRequest ( { protocol , hostname , port , method : "GET" , headers , path : resolvedPath , body , } ) ; } ; export const serializeAws_restJson1InitiateDeviceClaimCommand = async ( input , context ) : Promise < __HttpRequest > => { const { hostname , protocol = "https" , port , path : basePath } = await context . endpoint ( ) ; const headers = { } ; let resolvedPath = `${ basePath ?. endsWith ( "/" ) ? basePath . slice ( 0 , - 1 ) : basePath || "" }` + "/devices/{DeviceId}/initiate-claim" ; if ( input . DeviceId !== undefined ) { const labelValue = input . DeviceId ; if ( labelValue . length <= 0 ) { throw new Error ( "Empty value provided for input HTTP label: DeviceId." ) ; } resolvedPath = resolvedPath . replace ( "{DeviceId}" , __extendedEncodeURIComponent ( labelValue ) ) ; } else { throw new Error ( "No value provided for input HTTP label: DeviceId." ) ; } let body ; return new __HttpRequest ( { protocol , hostname , port , method : "PUT" , headers , path : resolvedPath , body , } ) ; } ; export const serializeAws_restJson1InvokeDeviceMethodCommand = async ( input , context ) : Promise < __HttpRequest > => { const { hostname , protocol = "https" , port , path : basePath } = await context . endpoint ( ) ; const headers = { "content-type" : "application/json" , } ; let resolvedPath = `${ basePath ?. endsWith ( "/" ) ? basePath . slice ( 0 , - 1 ) : basePath || "" }` + "/devices/{DeviceId}/methods" ; if ( input . DeviceId !== undefined ) { const labelValue = input . DeviceId ; if ( labelValue . length <= 0 ) { throw new Error ( "Empty value provided for input HTTP label: DeviceId." ) ; } resolvedPath = resolvedPath . replace ( "{DeviceId}" , __extendedEncodeURIComponent ( labelValue ) ) ; } else { throw new Error ( "No value provided for input HTTP label: DeviceId." ) ; } let body ; body = JSON . stringify ( { ... ( input . DeviceMethod !== undefined && input . DeviceMethod !== null && { deviceMethod : serializeAws_restJson1DeviceMethod ( input . DeviceMethod , context ) } ) , ... ( input . DeviceMethodParameters !== undefined && input . DeviceMethodParameters !== null && { deviceMethodParameters : input . DeviceMethodParameters } ) , } ) ; return new __HttpRequest ( { protocol , hostname , port , method : "POST" , headers , path : resolvedPath , body , } ) ; } ; export const serializeAws_restJson1ListDeviceEventsCommand = async ( input , context ) : Promise < __HttpRequest > => { const { hostname , protocol = "https" , port , path : basePath } = await context . endpoint ( ) ; const headers = { } ; let resolvedPath = `${ basePath ?. endsWith ( "/" ) ? basePath . slice ( 0 , - 1 ) : basePath || "" }` + "/devices/{DeviceId}/events" ; if ( input . DeviceId !== undefined ) { const labelValue = input . DeviceId ; if ( labelValue . length <= 0 ) { throw new Error ( "Empty value provided for input HTTP label: DeviceId." ) ; } resolvedPath = resolvedPath . replace ( "{DeviceId}" , __extendedEncodeURIComponent ( labelValue ) ) ; } else { throw new Error ( "No value provided for input HTTP label: DeviceId." ) ; } const query = { ... ( input . FromTimeStamp !== undefined && { fromTimeStamp : ( input . FromTimeStamp . toISOString ( ) . split ( "." ) [ 0 ] + "Z" ) . toString ( ) , } ) , ... ( input . MaxResults !== undefined && { maxResults : input . MaxResults . toString ( ) } ) , ... ( input . NextToken !== undefined && { nextToken : input . NextToken } ) , ... ( input . ToTimeStamp !== undefined && { toTimeStamp : ( input . ToTimeStamp . toISOString ( ) . split ( "." ) [ 0 ] + "Z" ) . toString ( ) , } ) , } ; let body ; return new __HttpRequest ( { protocol , hostname , port , method : "GET" , headers , path : resolvedPath , query , body , } ) ; } ; export const serializeAws_restJson1ListDevicesCommand = async ( input , context ) : Promise < __HttpRequest > => { const { hostname , protocol = "https" , port , path : basePath } = await context . endpoint ( ) ; const headers = { } ; const resolvedPath = `${ basePath ?. endsWith ( "/" ) ? basePath . slice ( 0 , - 1 ) : basePath || "" }` + "/devices" ; const query = { ... ( input . DeviceType !== undefined && { deviceType : input . DeviceType } ) , ... ( input . MaxResults !== undefined && { maxResults : input . MaxResults . toString ( ) } ) , ... ( input . NextToken !== undefined && { nextToken : input . NextToken } ) , } ; let body ; return new __HttpRequest ( { protocol , hostname , port , method : "GET" , headers , path : resolvedPath , query , body , } ) ; } ; export const serializeAws_restJson1ListTagsForResourceCommand = async ( input , context ) : Promise < __HttpRequest > => { const { hostname , protocol = "https" , port , path : basePath } = await context . endpoint ( ) ; const headers = { } ; let resolvedPath = `${ basePath ?. endsWith ( "/" ) ? basePath . slice ( 0 , - 1 ) : basePath || "" }` + "/tags/{ResourceArn}" ; if ( input . ResourceArn !== undefined ) { const labelValue = input . ResourceArn ; if ( labelValue . length <= 0 ) { throw new Error ( "Empty value provided for input HTTP label: ResourceArn." ) ; } resolvedPath = resolvedPath . replace ( "{ResourceArn}" , __extendedEncodeURIComponent ( labelValue ) ) ; } else { throw new Error ( "No value provided for input HTTP label: ResourceArn." ) ; } let body ; return new __HttpRequest ( { protocol , hostname , port , method : "GET" , headers , path : resolvedPath , body , } ) ; } ; export const serializeAws_restJson1TagResourceCommand = async ( input , context ) : Promise < __HttpRequest > => { const { hostname , protocol = "https" , port , path : basePath } = await context . endpoint ( ) ; const headers = { "content-type" : "application/json" , } ; let resolvedPath = `${ basePath ?. endsWith ( "/" ) ? basePath . slice ( 0 , - 1 ) : basePath || "" }` + "/tags/{ResourceArn}" ; if ( input . ResourceArn !== undefined ) { const labelValue = input . ResourceArn ; if ( labelValue . length <= 0 ) { throw new Error ( "Empty value provided for input HTTP label: ResourceArn." ) ; } resolvedPath = resolvedPath . replace ( "{ResourceArn}" , __extendedEncodeURIComponent ( labelValue ) ) ; } else { throw new Error ( "No value provided for input HTTP label: ResourceArn." ) ; } let body ; body = JSON . stringify ( { ... ( input . Tags !== undefined && input . Tags !== null && { tags : serializeAws_restJson1__mapOf__string ( input . Tags , context ) } ) , } ) ; return new __HttpRequest ( { protocol , hostname , port , method : "POST" , headers , path : resolvedPath , body , } ) ; } ; export const serializeAws_restJson1UnclaimDeviceCommand = async ( input , context ) : Promise < __HttpRequest > => { const { hostname , protocol = "https" , port , path : basePath } = await context . endpoint ( ) ; const headers = { } ; let resolvedPath = `${ basePath ?. endsWith ( "/" ) ? basePath . slice ( 0 , - 1 ) : basePath || "" }` + "/devices/{DeviceId}/unclaim" ; if ( input . DeviceId !== undefined ) { const labelValue = input . DeviceId ; if ( labelValue . length <= 0 ) { throw new Error ( "Empty value provided for input HTTP label: DeviceId." ) ; } resolvedPath = resolvedPath . replace ( "{DeviceId}" , __extendedEncodeURIComponent ( labelValue ) ) ; } else { throw new Error ( "No value provided for input HTTP label: DeviceId." ) ; } let body ; return new __HttpRequest ( { protocol , hostname , port , method : "PUT" , headers , path : resolvedPath , body , } ) ; } ; export const serializeAws_restJson1UntagResourceCommand = async ( input , context ) : Promise < __HttpRequest > => { const { hostname , protocol = "https" , port , path : basePath } = await context . endpoint ( ) ; const headers = { } ; let resolvedPath = `${ basePath ?. endsWith ( "/" ) ? basePath . slice ( 0 , - 1 ) : basePath || "" }` + "/tags/{ResourceArn}" ; if ( input . ResourceArn !== undefined ) { const labelValue = input . ResourceArn ; if ( labelValue . length <= 0 ) { throw new Error ( "Empty value provided for input HTTP label: ResourceArn." ) ; } resolvedPath = resolvedPath . replace ( "{ResourceArn}" , __extendedEncodeURIComponent ( labelValue ) ) ; } else { throw new Error ( "No value provided for input HTTP label: ResourceArn." ) ; } const query = { ... ( input . TagKeys !== undefined && { tagKeys : ( input . TagKeys || [ ] ) . map ( ( _entry ) => _entry as any ) } ) , } ; let body ; return new __HttpRequest ( { protocol , hostname , port , method : "DELETE" , headers , path : resolvedPath , query , body , } ) ; } ; export const serializeAws_restJson1UpdateDeviceStateCommand = async ( input , context ) : Promise < __HttpRequest > => { const { hostname , protocol = "https" , port , path : basePath } = await context . endpoint ( ) ; const headers = { "content-type" : "application/json" , } ; let resolvedPath = `${ basePath ?. endsWith ( "/" ) ? basePath . slice ( 0 , - 1 ) : basePath || "" }` + "/devices/{DeviceId}/state" ; if ( input . DeviceId !== undefined ) { const labelValue = input . DeviceId ; if ( labelValue . length <= 0 ) { throw new Error ( "Empty value provided for input HTTP label: DeviceId." ) ; } resolvedPath = resolvedPath . replace ( "{DeviceId}" , __extendedEncodeURIComponent ( labelValue ) ) ; } else { throw new Error ( "No value provided for input HTTP label: DeviceId." ) ; } let body ; body = JSON . stringify ( { ... ( input . Enabled !== undefined && input . Enabled !== null && { enabled : input . Enabled } ) , } ) ; return new __HttpRequest ( { protocol , hostname , port , method : "PUT" , headers , path : resolvedPath , body , } ) ; } ; export const deserializeAws_restJson1ClaimDevicesByClaimCodeCommand = async ( output , context ) : Promise < ClaimDevicesByClaimCodeCommandOutput > => { if ( output . statusCode !== 200 && output . statusCode >= 300 ) { return deserializeAws_restJson1ClaimDevicesByClaimCodeCommandError ( output , context ) ; } const contents = { $metadata : deserializeMetadata ( output ) , ClaimCode : undefined , Total : undefined , } ; const data = __expectNonNull ( __expectObject ( await parseBody ( output . body , context ) ) , "body" ) ; if ( data . claimCode !== undefined && data . claimCode !== null ) { contents . ClaimCode = __expectString ( data . claimCode ) ; } if ( data . total !== undefined && data . total !== null ) { contents . Total = __expectInt32 ( data . total ) ; } return Promise . resolve ( contents ) ; } ; const deserializeAws_restJson1ClaimDevicesByClaimCodeCommandError = async ( output , context ) : Promise < ClaimDevicesByClaimCodeCommandOutput > => { const parsedOutput = { ... output , body : await parseBody ( output . body , context ) , } ; let response ; let errorCode = "UnknownError" ; errorCode = loadRestJsonErrorCode ( output , parsedOutput . body ) ; switch ( errorCode ) { case "ForbiddenException" : case "com.amazonaws.iot1clickdevicesservice#ForbiddenException" : response = { ... ( await deserializeAws_restJson1ForbiddenExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "InternalFailureException" : case "com.amazonaws.iot1clickdevicesservice#InternalFailureException" : response = { ... ( await deserializeAws_restJson1InternalFailureExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "InvalidRequestException" : case "com.amazonaws.iot1clickdevicesservice#InvalidRequestException" : response = { ... ( await deserializeAws_restJson1InvalidRequestExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; default : const parsedBody = parsedOutput . body ; errorCode = parsedBody . code || parsedBody . Code || errorCode ; response = { ... parsedBody , name : `${ errorCode }` , message : parsedBody . message || parsedBody . Message || errorCode , $fault : "client" , $metadata : deserializeMetadata ( output ) , } as any ; } const message = response . message || response . Message || errorCode ; response . message = message ; delete response . Message ; return Promise . reject ( Object . assign ( new Error ( message ) , response ) ) ; } ; export const deserializeAws_restJson1DescribeDeviceCommand = async ( output , context ) : Promise < DescribeDeviceCommandOutput > => { if ( output . statusCode !== 200 && output . statusCode >= 300 ) { return deserializeAws_restJson1DescribeDeviceCommandError ( output , context ) ; } const contents = { $metadata : deserializeMetadata ( output ) , DeviceDescription : undefined , } ; const data = __expectNonNull ( __expectObject ( await parseBody ( output . body , context ) ) , "body" ) ; if ( data . deviceDescription !== undefined && data . deviceDescription !== null ) { contents . DeviceDescription = deserializeAws_restJson1DeviceDescription ( data . deviceDescription , context ) ; } return Promise . resolve ( contents ) ; } ; const deserializeAws_restJson1DescribeDeviceCommandError = async ( output , context ) : Promise < DescribeDeviceCommandOutput > => { const parsedOutput = { ... output , body : await parseBody ( output . body , context ) , } ; let response ; let errorCode = "UnknownError" ; errorCode = loadRestJsonErrorCode ( output , parsedOutput . body ) ; switch ( errorCode ) { case "InternalFailureException" : case "com.amazonaws.iot1clickdevicesservice#InternalFailureException" : response = { ... ( await deserializeAws_restJson1InternalFailureExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "InvalidRequestException" : case "com.amazonaws.iot1clickdevicesservice#InvalidRequestException" : response = { ... ( await deserializeAws_restJson1InvalidRequestExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "ResourceNotFoundException" : case "com.amazonaws.iot1clickdevicesservice#ResourceNotFoundException" : response = { ... ( await deserializeAws_restJson1ResourceNotFoundExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; default : const parsedBody = parsedOutput . body ; errorCode = parsedBody . code || parsedBody . Code || errorCode ; response = { ... parsedBody , name : `${ errorCode }` , message : parsedBody . message || parsedBody . Message || errorCode , $fault : "client" , $metadata : deserializeMetadata ( output ) , } as any ; } const message = response . message || response . Message || errorCode ; response . message = message ; delete response . Message ; return Promise . reject ( Object . assign ( new Error ( message ) , response ) ) ; } ; export const deserializeAws_restJson1FinalizeDeviceClaimCommand = async ( output , context ) : Promise < FinalizeDeviceClaimCommandOutput > => { if ( output . statusCode !== 200 && output . statusCode >= 300 ) { return deserializeAws_restJson1FinalizeDeviceClaimCommandError ( output , context ) ; } const contents = { $metadata : deserializeMetadata ( output ) , State : undefined , } ; const data = __expectNonNull ( __expectObject ( await parseBody ( output . body , context ) ) , "body" ) ; if ( data . state !== undefined && data . state !== null ) { contents . State = __expectString ( data . state ) ; } return Promise . resolve ( contents ) ; } ; const deserializeAws_restJson1FinalizeDeviceClaimCommandError = async ( output , context ) : Promise < FinalizeDeviceClaimCommandOutput > => { const parsedOutput = { ... output , body : await parseBody ( output . body , context ) , } ; let response ; let errorCode = "UnknownError" ; errorCode = loadRestJsonErrorCode ( output , parsedOutput . body ) ; switch ( errorCode ) { case "InternalFailureException" : case "com.amazonaws.iot1clickdevicesservice#InternalFailureException" : response = { ... ( await deserializeAws_restJson1InternalFailureExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "InvalidRequestException" : case "com.amazonaws.iot1clickdevicesservice#InvalidRequestException" : response = { ... ( await deserializeAws_restJson1InvalidRequestExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "PreconditionFailedException" : case "com.amazonaws.iot1clickdevicesservice#PreconditionFailedException" : response = { ... ( await deserializeAws_restJson1PreconditionFailedExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "ResourceConflictException" : case "com.amazonaws.iot1clickdevicesservice#ResourceConflictException" : response = { ... ( await deserializeAws_restJson1ResourceConflictExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "ResourceNotFoundException" : case "com.amazonaws.iot1clickdevicesservice#ResourceNotFoundException" : response = { ... ( await deserializeAws_restJson1ResourceNotFoundExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; default : const parsedBody = parsedOutput . body ; errorCode = parsedBody . code || parsedBody . Code || errorCode ; response = { ... parsedBody , name : `${ errorCode }` , message : parsedBody . message || parsedBody . Message || errorCode , $fault : "client" , $metadata : deserializeMetadata ( output ) , } as any ; } const message = response . message || response . Message || errorCode ; response . message = message ; delete response . Message ; return Promise . reject ( Object . assign ( new Error ( message ) , response ) ) ; } ; export const deserializeAws_restJson1GetDeviceMethodsCommand = async ( output , context ) : Promise < GetDeviceMethodsCommandOutput > => { if ( output . statusCode !== 200 && output . statusCode >= 300 ) { return deserializeAws_restJson1GetDeviceMethodsCommandError ( output , context ) ; } const contents = { $metadata : deserializeMetadata ( output ) , DeviceMethods : undefined , } ; const data = __expectNonNull ( __expectObject ( await parseBody ( output . body , context ) ) , "body" ) ; if ( data . deviceMethods !== undefined && data . deviceMethods !== null ) { contents . DeviceMethods = deserializeAws_restJson1__listOfDeviceMethod ( data . deviceMethods , context ) ; } return Promise . resolve ( contents ) ; } ; const deserializeAws_restJson1GetDeviceMethodsCommandError = async ( output , context ) : Promise < GetDeviceMethodsCommandOutput > => { const parsedOutput = { ... output , body : await parseBody ( output . body , context ) , } ; let response ; let errorCode = "UnknownError" ; errorCode = loadRestJsonErrorCode ( output , parsedOutput . body ) ; switch ( errorCode ) { case "InternalFailureException" : case "com.amazonaws.iot1clickdevicesservice#InternalFailureException" : response = { ... ( await deserializeAws_restJson1InternalFailureExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "InvalidRequestException" : case "com.amazonaws.iot1clickdevicesservice#InvalidRequestException" : response = { ... ( await deserializeAws_restJson1InvalidRequestExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "ResourceNotFoundException" : case "com.amazonaws.iot1clickdevicesservice#ResourceNotFoundException" : response = { ... ( await deserializeAws_restJson1ResourceNotFoundExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; default : const parsedBody = parsedOutput . body ; errorCode = parsedBody . code || parsedBody . Code || errorCode ; response = { ... parsedBody , name : `${ errorCode }` , message : parsedBody . message || parsedBody . Message || errorCode , $fault : "client" , $metadata : deserializeMetadata ( output ) , } as any ; } const message = response . message || response . Message || errorCode ; response . message = message ; delete response . Message ; return Promise . reject ( Object . assign ( new Error ( message ) , response ) ) ; } ; export const deserializeAws_restJson1InitiateDeviceClaimCommand = async ( output , context ) : Promise < InitiateDeviceClaimCommandOutput > => { if ( output . statusCode !== 200 && output . statusCode >= 300 ) { return deserializeAws_restJson1InitiateDeviceClaimCommandError ( output , context ) ; } const contents = { $metadata : deserializeMetadata ( output ) , State : undefined , } ; const data = __expectNonNull ( __expectObject ( await parseBody ( output . body , context ) ) , "body" ) ; if ( data . state !== undefined && data . state !== null ) { contents . State = __expectString ( data . state ) ; } return Promise . resolve ( contents ) ; } ; const deserializeAws_restJson1InitiateDeviceClaimCommandError = async ( output , context ) : Promise < InitiateDeviceClaimCommandOutput > => { const parsedOutput = { ... output , body : await parseBody ( output . body , context ) , } ; let response ; let errorCode = "UnknownError" ; errorCode = loadRestJsonErrorCode ( output , parsedOutput . body ) ; switch ( errorCode ) { case "InternalFailureException" : case "com.amazonaws.iot1clickdevicesservice#InternalFailureException" : response = { ... ( await deserializeAws_restJson1InternalFailureExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "InvalidRequestException" : case "com.amazonaws.iot1clickdevicesservice#InvalidRequestException" : response = { ... ( await deserializeAws_restJson1InvalidRequestExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "ResourceConflictException" : case "com.amazonaws.iot1clickdevicesservice#ResourceConflictException" : response = { ... ( await deserializeAws_restJson1ResourceConflictExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "ResourceNotFoundException" : case "com.amazonaws.iot1clickdevicesservice#ResourceNotFoundException" : response = { ... ( await deserializeAws_restJson1ResourceNotFoundExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; default : const parsedBody = parsedOutput . body ; errorCode = parsedBody . code || parsedBody . Code || errorCode ; response = { ... parsedBody , name : `${ errorCode }` , message : parsedBody . message || parsedBody . Message || errorCode , $fault : "client" , $metadata : deserializeMetadata ( output ) , } as any ; } const message = response . message || response . Message || errorCode ; response . message = message ; delete response . Message ; return Promise . reject ( Object . assign ( new Error ( message ) , response ) ) ; } ; export const deserializeAws_restJson1InvokeDeviceMethodCommand = async ( output , context ) : Promise < InvokeDeviceMethodCommandOutput > => { if ( output . statusCode !== 200 && output . statusCode >= 300 ) { return deserializeAws_restJson1InvokeDeviceMethodCommandError ( output , context ) ; } const contents = { $metadata : deserializeMetadata ( output ) , DeviceMethodResponse : undefined , } ; const data = __expectNonNull ( __expectObject ( await parseBody ( output . body , context ) ) , "body" ) ; if ( data . deviceMethodResponse !== undefined && data . deviceMethodResponse !== null ) { contents . DeviceMethodResponse = __expectString ( data . deviceMethodResponse ) ; } return Promise . resolve ( contents ) ; } ; const deserializeAws_restJson1InvokeDeviceMethodCommandError = async ( output , context ) : Promise < InvokeDeviceMethodCommandOutput > => { const parsedOutput = { ... output , body : await parseBody ( output . body , context ) , } ; let response ; let errorCode = "UnknownError" ; errorCode = loadRestJsonErrorCode ( output , parsedOutput . body ) ; switch ( errorCode ) { case "InternalFailureException" : case "com.amazonaws.iot1clickdevicesservice#InternalFailureException" : response = { ... ( await deserializeAws_restJson1InternalFailureExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "InvalidRequestException" : case "com.amazonaws.iot1clickdevicesservice#InvalidRequestException" : response = { ... ( await deserializeAws_restJson1InvalidRequestExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "PreconditionFailedException" : case "com.amazonaws.iot1clickdevicesservice#PreconditionFailedException" : response = { ... ( await deserializeAws_restJson1PreconditionFailedExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "RangeNotSatisfiableException" : case "com.amazonaws.iot1clickdevicesservice#RangeNotSatisfiableException" : response = { ... ( await deserializeAws_restJson1RangeNotSatisfiableExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "ResourceConflictException" : case "com.amazonaws.iot1clickdevicesservice#ResourceConflictException" : response = { ... ( await deserializeAws_restJson1ResourceConflictExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "ResourceNotFoundException" : case "com.amazonaws.iot1clickdevicesservice#ResourceNotFoundException" : response = { ... ( await deserializeAws_restJson1ResourceNotFoundExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; default : const parsedBody = parsedOutput . body ; errorCode = parsedBody . code || parsedBody . Code || errorCode ; response = { ... parsedBody , name : `${ errorCode }` , message : parsedBody . message || parsedBody . Message || errorCode , $fault : "client" , $metadata : deserializeMetadata ( output ) , } as any ; } const message = response . message || response . Message || errorCode ; response . message = message ; delete response . Message ; return Promise . reject ( Object . assign ( new Error ( message ) , response ) ) ; } ; export const deserializeAws_restJson1ListDeviceEventsCommand = async ( output , context ) : Promise < ListDeviceEventsCommandOutput > => { if ( output . statusCode !== 200 && output . statusCode >= 300 ) { return deserializeAws_restJson1ListDeviceEventsCommandError ( output , context ) ; } const contents = { $metadata : deserializeMetadata ( output ) , Events : undefined , NextToken : undefined , } ; const data = __expectNonNull ( __expectObject ( await parseBody ( output . body , context ) ) , "body" ) ; if ( data . events !== undefined && data . events !== null ) { contents . Events = deserializeAws_restJson1__listOfDeviceEvent ( data . events , context ) ; } if ( data . nextToken !== undefined && data . nextToken !== null ) { contents . NextToken = __expectString ( data . nextToken ) ; } return Promise . resolve ( contents ) ; } ; const deserializeAws_restJson1ListDeviceEventsCommandError = async ( output , context ) : Promise < ListDeviceEventsCommandOutput > => { const parsedOutput = { ... output , body : await parseBody ( output . body , context ) , } ; let response ; let errorCode = "UnknownError" ; errorCode = loadRestJsonErrorCode ( output , parsedOutput . body ) ; switch ( errorCode ) { case "InternalFailureException" : case "com.amazonaws.iot1clickdevicesservice#InternalFailureException" : response = { ... ( await deserializeAws_restJson1InternalFailureExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "InvalidRequestException" : case "com.amazonaws.iot1clickdevicesservice#InvalidRequestException" : response = { ... ( await deserializeAws_restJson1InvalidRequestExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "RangeNotSatisfiableException" : case "com.amazonaws.iot1clickdevicesservice#RangeNotSatisfiableException" : response = { ... ( await deserializeAws_restJson1RangeNotSatisfiableExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "ResourceNotFoundException" : case "com.amazonaws.iot1clickdevicesservice#ResourceNotFoundException" : response = { ... ( await deserializeAws_restJson1ResourceNotFoundExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; default : const parsedBody = parsedOutput . body ; errorCode = parsedBody . code || parsedBody . Code || errorCode ; response = { ... parsedBody , name : `${ errorCode }` , message : parsedBody . message || parsedBody . Message || errorCode , $fault : "client" , $metadata : deserializeMetadata ( output ) , } as any ; } const message = response . message || response . Message || errorCode ; response . message = message ; delete response . Message ; return Promise . reject ( Object . assign ( new Error ( message ) , response ) ) ; } ; export const deserializeAws_restJson1ListDevicesCommand = async ( output , context ) : Promise < ListDevicesCommandOutput > => { if ( output . statusCode !== 200 && output . statusCode >= 300 ) { return deserializeAws_restJson1ListDevicesCommandError ( output , context ) ; } const contents = { $metadata : deserializeMetadata ( output ) , Devices : undefined , NextToken : undefined , } ; const data = __expectNonNull ( __expectObject ( await parseBody ( output . body , context ) ) , "body" ) ; if ( data . devices !== undefined && data . devices !== null ) { contents . Devices = deserializeAws_restJson1__listOfDeviceDescription ( data . devices , context ) ; } if ( data . nextToken !== undefined && data . nextToken !== null ) { contents . NextToken = __expectString ( data . nextToken ) ; } return Promise . resolve ( contents ) ; } ; const deserializeAws_restJson1ListDevicesCommandError = async ( output , context ) : Promise < ListDevicesCommandOutput > => { const parsedOutput = { ... output , body : await parseBody ( output . body , context ) , } ; let response ; let errorCode = "UnknownError" ; errorCode = loadRestJsonErrorCode ( output , parsedOutput . body ) ; switch ( errorCode ) { case "InternalFailureException" : case "com.amazonaws.iot1clickdevicesservice#InternalFailureException" : response = { ... ( await deserializeAws_restJson1InternalFailureExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "InvalidRequestException" : case "com.amazonaws.iot1clickdevicesservice#InvalidRequestException" : response = { ... ( await deserializeAws_restJson1InvalidRequestExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "RangeNotSatisfiableException" : case "com.amazonaws.iot1clickdevicesservice#RangeNotSatisfiableException" : response = { ... ( await deserializeAws_restJson1RangeNotSatisfiableExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; default : const parsedBody = parsedOutput . body ; errorCode = parsedBody . code || parsedBody . Code || errorCode ; response = { ... parsedBody , name : `${ errorCode }` , message : parsedBody . message || parsedBody . Message || errorCode , $fault : "client" , $metadata : deserializeMetadata ( output ) , } as any ; } const message = response . message || response . Message || errorCode ; response . message = message ; delete response . Message ; return Promise . reject ( Object . assign ( new Error ( message ) , response ) ) ; } ; export const deserializeAws_restJson1ListTagsForResourceCommand = async ( output , context ) : Promise < ListTagsForResourceCommandOutput > => { if ( output . statusCode !== 200 && output . statusCode >= 300 ) { return deserializeAws_restJson1ListTagsForResourceCommandError ( output , context ) ; } const contents = { $metadata : deserializeMetadata ( output ) , Tags : undefined , } ; const data = __expectNonNull ( __expectObject ( await parseBody ( output . body , context ) ) , "body" ) ; if ( data . tags !== undefined && data . tags !== null ) { contents . Tags = deserializeAws_restJson1__mapOf__string ( data . tags , context ) ; } return Promise . resolve ( contents ) ; } ; const deserializeAws_restJson1ListTagsForResourceCommandError = async ( output , context ) : Promise < ListTagsForResourceCommandOutput > => { const parsedOutput = { ... output , body : await parseBody ( output . body , context ) , } ; let response ; let errorCode = "UnknownError" ; errorCode = loadRestJsonErrorCode ( output , parsedOutput . body ) ; switch ( errorCode ) { case "InternalFailureException" : case "com.amazonaws.iot1clickdevicesservice#InternalFailureException" : response = { ... ( await deserializeAws_restJson1InternalFailureExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "ResourceNotFoundException" : case "com.amazonaws.iot1clickdevicesservice#ResourceNotFoundException" : response = { ... ( await deserializeAws_restJson1ResourceNotFoundExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; default : const parsedBody = parsedOutput . body ; errorCode = parsedBody . code || parsedBody . Code || errorCode ; response = { ... parsedBody , name : `${ errorCode }` , message : parsedBody . message || parsedBody . Message || errorCode , $fault : "client" , $metadata : deserializeMetadata ( output ) , } as any ; } const message = response . message || response . Message || errorCode ; response . message = message ; delete response . Message ; return Promise . reject ( Object . assign ( new Error ( message ) , response ) ) ; } ; export const deserializeAws_restJson1TagResourceCommand = async ( output , context ) : Promise < TagResourceCommandOutput > => { if ( output . statusCode !== 204 && output . statusCode >= 300 ) { return deserializeAws_restJson1TagResourceCommandError ( output , context ) ; } const contents = { $metadata : deserializeMetadata ( output ) , } ; await collectBody ( output . body , context ) ; return Promise . resolve ( contents ) ; } ; const deserializeAws_restJson1TagResourceCommandError = async ( output , context ) : Promise < TagResourceCommandOutput > => { const parsedOutput = { ... output , body : await parseBody ( output . body , context ) , } ; let response ; let errorCode = "UnknownError" ; errorCode = loadRestJsonErrorCode ( output , parsedOutput . body ) ; switch ( errorCode ) { case "InternalFailureException" : case "com.amazonaws.iot1clickdevicesservice#InternalFailureException" : response = { ... ( await deserializeAws_restJson1InternalFailureExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "InvalidRequestException" : case "com.amazonaws.iot1clickdevicesservice#InvalidRequestException" : response = { ... ( await deserializeAws_restJson1InvalidRequestExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "ResourceNotFoundException" : case "com.amazonaws.iot1clickdevicesservice#ResourceNotFoundException" : response = { ... ( await deserializeAws_restJson1ResourceNotFoundExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; default : const parsedBody = parsedOutput . body ; errorCode = parsedBody . code || parsedBody . Code || errorCode ; response = { ... parsedBody , name : `${ errorCode }` , message : parsedBody . message || parsedBody . Message || errorCode , $fault : "client" , $metadata : deserializeMetadata ( output ) , } as any ; } const message = response . message || response . Message || errorCode ; response . message = message ; delete response . Message ; return Promise . reject ( Object . assign ( new Error ( message ) , response ) ) ; } ; export const deserializeAws_restJson1UnclaimDeviceCommand = async ( output , context ) : Promise < UnclaimDeviceCommandOutput > => { if ( output . statusCode !== 200 && output . statusCode >= 300 ) { return deserializeAws_restJson1UnclaimDeviceCommandError ( output , context ) ; } const contents = { $metadata : deserializeMetadata ( output ) , State : undefined , } ; const data = __expectNonNull ( __expectObject ( await parseBody ( output . body , context ) ) , "body" ) ; if ( data . state !== undefined && data . state !== null ) { contents . State = __expectString ( data . state ) ; } return Promise . resolve ( contents ) ; } ; const deserializeAws_restJson1UnclaimDeviceCommandError = async ( output , context ) : Promise < UnclaimDeviceCommandOutput > => { const parsedOutput = { ... output , body : await parseBody ( output . body , context ) , } ; let response ; let errorCode = "UnknownError" ; errorCode = loadRestJsonErrorCode ( output , parsedOutput . body ) ; switch ( errorCode ) { case "InternalFailureException" : case "com.amazonaws.iot1clickdevicesservice#InternalFailureException" : response = { ... ( await deserializeAws_restJson1InternalFailureExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "InvalidRequestException" : case "com.amazonaws.iot1clickdevicesservice#InvalidRequestException" : response = { ... ( await deserializeAws_restJson1InvalidRequestExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "ResourceNotFoundException" : case "com.amazonaws.iot1clickdevicesservice#ResourceNotFoundException" : response = { ... ( await deserializeAws_restJson1ResourceNotFoundExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; default : const parsedBody = parsedOutput . body ; errorCode = parsedBody . code || parsedBody . Code || errorCode ; response = { ... parsedBody , name : `${ errorCode }` , message : parsedBody . message || parsedBody . Message || errorCode , $fault : "client" , $metadata : deserializeMetadata ( output ) , } as any ; } const message = response . message || response . Message || errorCode ; response . message = message ; delete response . Message ; return Promise . reject ( Object . assign ( new Error ( message ) , response ) ) ; } ; export const deserializeAws_restJson1UntagResourceCommand = async ( output , context ) : Promise < UntagResourceCommandOutput > => { if ( output . statusCode !== 204 && output . statusCode >= 300 ) { return deserializeAws_restJson1UntagResourceCommandError ( output , context ) ; } const contents = { $metadata : deserializeMetadata ( output ) , } ; await collectBody ( output . body , context ) ; return Promise . resolve ( contents ) ; } ; const deserializeAws_restJson1UntagResourceCommandError = async ( output , context ) : Promise < UntagResourceCommandOutput > => { const parsedOutput = { ... output , body : await parseBody ( output . body , context ) , } ; let response ; let errorCode = "UnknownError" ; errorCode = loadRestJsonErrorCode ( output , parsedOutput . body ) ; switch ( errorCode ) { case "InternalFailureException" : case "com.amazonaws.iot1clickdevicesservice#InternalFailureException" : response = { ... ( await deserializeAws_restJson1InternalFailureExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "InvalidRequestException" : case "com.amazonaws.iot1clickdevicesservice#InvalidRequestException" : response = { ... ( await deserializeAws_restJson1InvalidRequestExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "ResourceNotFoundException" : case "com.amazonaws.iot1clickdevicesservice#ResourceNotFoundException" : response = { ... ( await deserializeAws_restJson1ResourceNotFoundExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; default : const parsedBody = parsedOutput . body ; errorCode = parsedBody . code || parsedBody . Code || errorCode ; response = { ... parsedBody , name : `${ errorCode }` , message : parsedBody . message || parsedBody . Message || errorCode , $fault : "client" , $metadata : deserializeMetadata ( output ) , } as any ; } const message = response . message || response . Message || errorCode ; response . message = message ; delete response . Message ; return Promise . reject ( Object . assign ( new Error ( message ) , response ) ) ; } ; export const deserializeAws_restJson1UpdateDeviceStateCommand = async ( output , context ) : Promise < UpdateDeviceStateCommandOutput > => { if ( output . statusCode !== 200 && output . statusCode >= 300 ) { return deserializeAws_restJson1UpdateDeviceStateCommandError ( output , context ) ; } const contents = { $metadata : deserializeMetadata ( output ) , } ; await collectBody ( output . body , context ) ; return Promise . resolve ( contents ) ; } ; const deserializeAws_restJson1UpdateDeviceStateCommandError = async ( output , context ) : Promise < UpdateDeviceStateCommandOutput > => { const parsedOutput = { ... output , body : await parseBody ( output . body , context ) , } ; let response ; let errorCode = "UnknownError" ; errorCode = loadRestJsonErrorCode ( output , parsedOutput . body ) ; switch ( errorCode ) { case "InternalFailureException" : case "com.amazonaws.iot1clickdevicesservice#InternalFailureException" : response = { ... ( await deserializeAws_restJson1InternalFailureExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "InvalidRequestException" : case "com.amazonaws.iot1clickdevicesservice#InvalidRequestException" : response = { ... ( await deserializeAws_restJson1InvalidRequestExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "ResourceNotFoundException" : case "com.amazonaws.iot1clickdevicesservice#ResourceNotFoundException" : response = { ... ( await deserializeAws_restJson1ResourceNotFoundExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; default : const parsedBody = parsedOutput . body ; errorCode = parsedBody . code || parsedBody . Code || errorCode ; response = { ... parsedBody , name : `${ errorCode }` , message : parsedBody . message || parsedBody . Message || errorCode , $fault : "client" , $metadata : deserializeMetadata ( output ) , } as any ; } const message = response . message || response . Message || errorCode ; response . message = message ; delete response . Message ; return Promise . reject ( Object . assign ( new Error ( message ) , response ) ) ; } ; const deserializeAws_restJson1ForbiddenExceptionResponse = async ( parsedOutput , context ) : Promise < ForbiddenException > => { const contents = { name : "ForbiddenException" , $fault : "client" , $metadata : deserializeMetadata ( parsedOutput ) , Code : undefined , Message : undefined , } ; const data = parsedOutput . body ; if ( data . code !== undefined && data . code !== null ) { contents . Code = __expectString ( data . code ) ; } if ( data . message !== undefined && data . message !== null ) { contents . Message = __expectString ( data . message ) ; } return contents ; } ; const deserializeAws_restJson1InternalFailureExceptionResponse = async ( parsedOutput , context ) : Promise < InternalFailureException > => { const contents = { name : "InternalFailureException" , $fault : "server" , $metadata : deserializeMetadata ( parsedOutput ) , Code : undefined , Message : undefined , } ; const data = parsedOutput . body ; if ( data . code !== undefined && data . code !== null ) { contents . Code = __expectString ( data . code ) ; } if ( data . message !== undefined && data . message !== null ) { contents . Message = __expectString ( data . message ) ; } return contents ; } ; const deserializeAws_restJson1InvalidRequestExceptionResponse = async ( parsedOutput , context ) : Promise < InvalidRequestException > => { const contents = { name : "InvalidRequestException" , $fault : "client" , $metadata : deserializeMetadata ( parsedOutput ) , Code : undefined , Message : undefined , } ; const data = parsedOutput . body ; if ( data . code !== undefined && data . code !== null ) { contents . Code = __expectString ( data . code ) ; } if ( data . message !== undefined && data . message !== null ) { contents . Message = __expectString ( data . message ) ; } return contents ; } ; const deserializeAws_restJson1PreconditionFailedExceptionResponse = async ( parsedOutput , context ) : Promise < PreconditionFailedException > => { const contents = { name : "PreconditionFailedException" , $fault : "client" , $metadata : deserializeMetadata ( parsedOutput ) , Code : undefined , Message : undefined , } ; const data = parsedOutput . body ; if ( data . code !== undefined && data . code !== null ) { contents . Code = __expectString ( data . code ) ; } if ( data . message !== undefined && data . message !== null ) { contents . Message = __expectString ( data . message ) ; } return contents ; } ; const deserializeAws_restJson1RangeNotSatisfiableExceptionResponse = async ( parsedOutput , context ) : Promise < RangeNotSatisfiableException > => { const contents = { name : "RangeNotSatisfiableException" , $fault : "client" , $metadata : deserializeMetadata ( parsedOutput ) , Code : undefined , Message : undefined , } ; const data = parsedOutput . body ; if ( data . code !== undefined && data . code !== null ) { contents . Code = __expectString ( data . code ) ; } if ( data . message !== undefined && data . message !== null ) { contents . Message = __expectString ( data . message ) ; } return contents ; } ; const deserializeAws_restJson1ResourceConflictExceptionResponse = async ( parsedOutput , context ) : Promise < ResourceConflictException > => { const contents = { name : "ResourceConflictException" , $fault : "client" , $metadata : deserializeMetadata ( parsedOutput ) , Code : undefined , Message : undefined , } ; const data = parsedOutput . body ; if ( data . code !== undefined && data . code !== null ) { contents . Code = __expectString ( data . code ) ; } if ( data . message !== undefined && data . message !== null ) { contents . Message = __expectString ( data . message ) ; } return contents ; } ; const deserializeAws_restJson1ResourceNotFoundExceptionResponse = async ( parsedOutput , context ) : Promise < ResourceNotFoundException > => { const contents = { name : "ResourceNotFoundException" , $fault : "client" , $metadata : deserializeMetadata ( parsedOutput ) , Code : undefined , Message : undefined , } ; const data = parsedOutput . body ; if ( data . code !== undefined && data . code !== null ) { contents . Code = __expectString ( data . code ) ; } if ( data . message !== undefined && data . message !== null ) { contents . Message = __expectString ( data . message ) ; } return contents ; } ; const serializeAws_restJson1__mapOf__string = ( input , context ) : any => { return Object . entries ( input ) . reduce ( ( acc , [ key , value ] ) => { if ( value === null ) { return acc ; } return { ... acc , [ key ] : value , } ; } , { } ) ; } ; const serializeAws_restJson1DeviceMethod = ( input , context ) : any => { return { ... ( input . DeviceType !== undefined && input . DeviceType !== null && { deviceType : input . DeviceType } ) , ... ( input . MethodName !== undefined && input . MethodName !== null && { methodName : input . MethodName } ) , } ; } ; const deserializeAws_restJson1__listOfDeviceDescription = ( output , context ) : DeviceDescription [ ] => { return ( output || [ ] ) . filter ( ( e ) => e != null ) . map ( ( entry ) => { if ( entry === null ) { return null as any ; } return deserializeAws_restJson1DeviceDescription ( entry , context ) ; } ) ; } ; const deserializeAws_restJson1__listOfDeviceEvent = ( output , context ) : DeviceEvent [ ] => { return ( output || [ ] ) . filter ( ( e ) => e != null ) . map ( ( entry ) => { if ( entry === null ) { return null as any ; } return deserializeAws_restJson1DeviceEvent ( entry , context ) ; } ) ; } ; const deserializeAws_restJson1__listOfDeviceMethod = ( output , context ) : DeviceMethod [ ] => { return ( output || [ ] ) . filter ( ( e ) => e != null ) . map ( ( entry ) => { if ( entry === null ) { return null as any ; } return deserializeAws_restJson1DeviceMethod ( entry , context ) ; } ) ; } ; const deserializeAws_restJson1__mapOf__string = ( output , context ) : { [ key ] : string ; } => { return Object . entries ( output ) . reduce ( ( acc , [ key , value ] ) => { if ( value === null ) { return acc ; } return { ... acc , [ key ] : __expectString ( value ) as any , } ; } , { } ) ; } ; const deserializeAws_restJson1Attributes = ( output , context ) : Attributes => { return { } as any ; } ; const deserializeAws_restJson1Device = ( output , context ) : Device => { return { Attributes : output . attributes !== undefined && output . attributes !== null ? deserializeAws_restJson1Attributes ( output . attributes , context ) : undefined , DeviceId : __expectString ( output . deviceId ) , Type : __expectString ( output . type ) , } as any ; } ; const deserializeAws_restJson1DeviceAttributes = ( output , context ) : { [ key ] : string ; } => { return Object . entries ( output ) . reduce ( ( acc , [ key , value ] ) => { if ( value === null ) { return acc ; } return { ... acc , [ key ] : __expectString ( value ) as any , } ; } , { } ) ; } ; const deserializeAws_restJson1DeviceDescription = ( output , context ) : DeviceDescription => { return { Arn : __expectString ( output . arn ) , Attributes : output . attributes !== undefined && output . attributes !== null ? deserializeAws_restJson1DeviceAttributes ( output . attributes , context ) : undefined , DeviceId : __expectString ( output . deviceId ) , Enabled : __expectBoolean ( output . enabled ) , RemainingLife : __limitedParseDouble ( output . remainingLife ) , Tags : output . tags !== undefined && output . tags !== null ? deserializeAws_restJson1__mapOf__string ( output . tags , context ) : undefined , Type : __expectString ( output . type ) , } as any ; } ; const deserializeAws_restJson1DeviceEvent = ( output , context ) : DeviceEvent => { return { Device : output . device !== undefined && output . device !== null ? deserializeAws_restJson1Device ( output . device , context ) : undefined , StdEvent : __expectString ( output . stdEvent ) , } as any ; } ; const deserializeAws_restJson1DeviceMethod = ( output , context ) : DeviceMethod => { return { DeviceType : __expectString ( output . deviceType ) , MethodName : __expectString ( output . methodName ) , } as any ; } ; const deserializeMetadata = ( output ) : __ResponseMetadata => ( { httpStatusCode : output . statusCode , requestId : output . headers [ "x-amzn-requestid" ] ?? output . headers [ "x-amzn-request-id" ] , extendedRequestId : output . headers [ "x-amz-id-2" ] , cfId : output . headers [ "x-amz-cf-id" ] , } ) ; const collectBody = ( streamBody = new Uint8Array ( ) , context ) : Promise < Uint8Array > => { if ( streamBody instanceof Uint8Array ) { return Promise . resolve ( streamBody ) ; } return context . streamCollector ( streamBody ) || Promise . resolve ( new Uint8Array ( ) ) ; } ; const collectBodyString = ( streamBody , context ) : Promise < string > => collectBody ( streamBody , context ) . then ( ( body ) => context . utf8Encoder ( body ) ) ; const isSerializableHeaderValue = ( value ) : boolean => value !== undefined && value !== null && value !== "" && ( ! Object . getOwnPropertyNames ( value ) . includes ( "length" ) || value . length != 0 ) && ( ! Object . getOwnPropertyNames ( value ) . includes ( "size" ) || value . size != 0 ) ; const parseBody = ( streamBody , context ) : any => collectBodyString ( streamBody , context ) . then ( ( encoded ) => { if ( encoded . length ) { return JSON . parse ( encoded ) ; } return { } ; } ) ; /**
 * Load an error code for the aws.rest-json-1.1 protocol.
 */ const loadRestJsonErrorCode = ( output , data ) : string => { const findKey = ( object , key ) => Object . keys ( object ) . find ( ( k ) => k . toLowerCase ( ) === key . toLowerCase ( ) ) ; const sanitizeErrorCode = ( rawValue ) : string => { let cleanValue = rawValue ; if ( cleanValue . indexOf ( ":" ) >= 0 ) { cleanValue = cleanValue . split ( ":" ) [ 0 ] ; } if ( cleanValue . indexOf ( "#" ) >= 0 ) { cleanValue = cleanValue . split ( "#" ) [ 1 ] ; } return cleanValue ; } ; const headerKey = findKey ( output . headers , "x-amzn-errortype" ) ; if ( headerKey !== undefined ) { return sanitizeErrorCode ( output . headers [ headerKey ] ) ; } if ( data . code !== undefined ) { return sanitizeErrorCode ( data . code ) ; } if ( data [ "__type" ] !== undefined ) { return sanitizeErrorCode ( data [ "__type" ] ) ; } return "" ; } ;