import { HttpRequest as __HttpRequest , HttpResponse as __HttpResponse } from "@aws-sdk/protocol-http" ; import { expectString as __expectString , LazyJsonString as __LazyJsonString } from "@aws-sdk/smithy-client" ; import { Endpoint as __Endpoint , HeaderBag as __HeaderBag , MetadataBearer as __MetadataBearer , ResponseMetadata as __ResponseMetadata , SerdeContext as __SerdeContext , SmithyException as __SmithyException , } from "@aws-sdk/types" ; import { DescribeServicesCommandInput , DescribeServicesCommandOutput } from "../commands/DescribeServicesCommand" ; import { GetAttributeValuesCommandInput , GetAttributeValuesCommandOutput } from "../commands/GetAttributeValuesCommand" ; import { GetProductsCommandInput , GetProductsCommandOutput } from "../commands/GetProductsCommand" ; import { AttributeValue , DescribeServicesRequest , DescribeServicesResponse , ExpiredNextTokenException , Filter , GetAttributeValuesRequest , GetAttributeValuesResponse , GetProductsRequest , GetProductsResponse , InternalErrorException , InvalidNextTokenException , InvalidParameterException , NotFoundException , Service , } from "../models/models_0" ; export const serializeAws_json1_1DescribeServicesCommand = async ( input , context ) : Promise < __HttpRequest > => { const headers = { "content-type" : "application/x-amz-json-1.1" , "x-amz-target" : "AWSPriceListService.DescribeServices" , } ; let body ; body = JSON . stringify ( serializeAws_json1_1DescribeServicesRequest ( input , context ) ) ; return buildHttpRpcRequest ( context , headers , "/" , undefined , body ) ; } ; export const serializeAws_json1_1GetAttributeValuesCommand = async ( input , context ) : Promise < __HttpRequest > => { const headers = { "content-type" : "application/x-amz-json-1.1" , "x-amz-target" : "AWSPriceListService.GetAttributeValues" , } ; let body ; body = JSON . stringify ( serializeAws_json1_1GetAttributeValuesRequest ( input , context ) ) ; return buildHttpRpcRequest ( context , headers , "/" , undefined , body ) ; } ; export const serializeAws_json1_1GetProductsCommand = async ( input , context ) : Promise < __HttpRequest > => { const headers = { "content-type" : "application/x-amz-json-1.1" , "x-amz-target" : "AWSPriceListService.GetProducts" , } ; let body ; body = JSON . stringify ( serializeAws_json1_1GetProductsRequest ( input , context ) ) ; return buildHttpRpcRequest ( context , headers , "/" , undefined , body ) ; } ; export const deserializeAws_json1_1DescribeServicesCommand = async ( output , context ) : Promise < DescribeServicesCommandOutput > => { if ( output . statusCode >= 300 ) { return deserializeAws_json1_1DescribeServicesCommandError ( output , context ) ; } const data = await parseBody ( output . body , context ) ; let contents = { } ; contents = deserializeAws_json1_1DescribeServicesResponse ( data , context ) ; const response = { $metadata : deserializeMetadata ( output ) , ... contents , } ; return Promise . resolve ( response ) ; } ; const deserializeAws_json1_1DescribeServicesCommandError = async ( output , context ) : Promise < DescribeServicesCommandOutput > => { const parsedOutput = { ... output , body : await parseBody ( output . body , context ) , } ; let response ; let errorCode = "UnknownError" ; errorCode = loadRestJsonErrorCode ( output , parsedOutput . body ) ; switch ( errorCode ) { case "ExpiredNextTokenException" : case "com.amazonaws.pricing#ExpiredNextTokenException" : response = { ... ( await deserializeAws_json1_1ExpiredNextTokenExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "InternalErrorException" : case "com.amazonaws.pricing#InternalErrorException" : response = { ... ( await deserializeAws_json1_1InternalErrorExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "InvalidNextTokenException" : case "com.amazonaws.pricing#InvalidNextTokenException" : response = { ... ( await deserializeAws_json1_1InvalidNextTokenExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "InvalidParameterException" : case "com.amazonaws.pricing#InvalidParameterException" : response = { ... ( await deserializeAws_json1_1InvalidParameterExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "NotFoundException" : case "com.amazonaws.pricing#NotFoundException" : response = { ... ( await deserializeAws_json1_1NotFoundExceptionResponse ( 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_json1_1GetAttributeValuesCommand = async ( output , context ) : Promise < GetAttributeValuesCommandOutput > => { if ( output . statusCode >= 300 ) { return deserializeAws_json1_1GetAttributeValuesCommandError ( output , context ) ; } const data = await parseBody ( output . body , context ) ; let contents = { } ; contents = deserializeAws_json1_1GetAttributeValuesResponse ( data , context ) ; const response = { $metadata : deserializeMetadata ( output ) , ... contents , } ; return Promise . resolve ( response ) ; } ; const deserializeAws_json1_1GetAttributeValuesCommandError = async ( output , context ) : Promise < GetAttributeValuesCommandOutput > => { const parsedOutput = { ... output , body : await parseBody ( output . body , context ) , } ; let response ; let errorCode = "UnknownError" ; errorCode = loadRestJsonErrorCode ( output , parsedOutput . body ) ; switch ( errorCode ) { case "ExpiredNextTokenException" : case "com.amazonaws.pricing#ExpiredNextTokenException" : response = { ... ( await deserializeAws_json1_1ExpiredNextTokenExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "InternalErrorException" : case "com.amazonaws.pricing#InternalErrorException" : response = { ... ( await deserializeAws_json1_1InternalErrorExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "InvalidNextTokenException" : case "com.amazonaws.pricing#InvalidNextTokenException" : response = { ... ( await deserializeAws_json1_1InvalidNextTokenExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "InvalidParameterException" : case "com.amazonaws.pricing#InvalidParameterException" : response = { ... ( await deserializeAws_json1_1InvalidParameterExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "NotFoundException" : case "com.amazonaws.pricing#NotFoundException" : response = { ... ( await deserializeAws_json1_1NotFoundExceptionResponse ( 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_json1_1GetProductsCommand = async ( output , context ) : Promise < GetProductsCommandOutput > => { if ( output . statusCode >= 300 ) { return deserializeAws_json1_1GetProductsCommandError ( output , context ) ; } const data = await parseBody ( output . body , context ) ; let contents = { } ; contents = deserializeAws_json1_1GetProductsResponse ( data , context ) ; const response = { $metadata : deserializeMetadata ( output ) , ... contents , } ; return Promise . resolve ( response ) ; } ; const deserializeAws_json1_1GetProductsCommandError = async ( output , context ) : Promise < GetProductsCommandOutput > => { const parsedOutput = { ... output , body : await parseBody ( output . body , context ) , } ; let response ; let errorCode = "UnknownError" ; errorCode = loadRestJsonErrorCode ( output , parsedOutput . body ) ; switch ( errorCode ) { case "ExpiredNextTokenException" : case "com.amazonaws.pricing#ExpiredNextTokenException" : response = { ... ( await deserializeAws_json1_1ExpiredNextTokenExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "InternalErrorException" : case "com.amazonaws.pricing#InternalErrorException" : response = { ... ( await deserializeAws_json1_1InternalErrorExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "InvalidNextTokenException" : case "com.amazonaws.pricing#InvalidNextTokenException" : response = { ... ( await deserializeAws_json1_1InvalidNextTokenExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "InvalidParameterException" : case "com.amazonaws.pricing#InvalidParameterException" : response = { ... ( await deserializeAws_json1_1InvalidParameterExceptionResponse ( parsedOutput , context ) ) , name : errorCode , $metadata : deserializeMetadata ( output ) , } ; break ; case "NotFoundException" : case "com.amazonaws.pricing#NotFoundException" : response = { ... ( await deserializeAws_json1_1NotFoundExceptionResponse ( 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_json1_1ExpiredNextTokenExceptionResponse = async ( parsedOutput , context ) : Promise < ExpiredNextTokenException > => { const body = parsedOutput . body ; const deserialized = deserializeAws_json1_1ExpiredNextTokenException ( body , context ) ; const contents = { name : "ExpiredNextTokenException" , $fault : "client" , $metadata : deserializeMetadata ( parsedOutput ) , ... deserialized , } ; return contents ; } ; const deserializeAws_json1_1InternalErrorExceptionResponse = async ( parsedOutput , context ) : Promise < InternalErrorException > => { const body = parsedOutput . body ; const deserialized = deserializeAws_json1_1InternalErrorException ( body , context ) ; const contents = { name : "InternalErrorException" , $fault : "server" , $metadata : deserializeMetadata ( parsedOutput ) , ... deserialized , } ; return contents ; } ; const deserializeAws_json1_1InvalidNextTokenExceptionResponse = async ( parsedOutput , context ) : Promise < InvalidNextTokenException > => { const body = parsedOutput . body ; const deserialized = deserializeAws_json1_1InvalidNextTokenException ( body , context ) ; const contents = { name : "InvalidNextTokenException" , $fault : "client" , $metadata : deserializeMetadata ( parsedOutput ) , ... deserialized , } ; return contents ; } ; const deserializeAws_json1_1InvalidParameterExceptionResponse = async ( parsedOutput , context ) : Promise < InvalidParameterException > => { const body = parsedOutput . body ; const deserialized = deserializeAws_json1_1InvalidParameterException ( body , context ) ; const contents = { name : "InvalidParameterException" , $fault : "client" , $metadata : deserializeMetadata ( parsedOutput ) , ... deserialized , } ; return contents ; } ; const deserializeAws_json1_1NotFoundExceptionResponse = async ( parsedOutput , context ) : Promise < NotFoundException > => { const body = parsedOutput . body ; const deserialized = deserializeAws_json1_1NotFoundException ( body , context ) ; const contents = { name : "NotFoundException" , $fault : "client" , $metadata : deserializeMetadata ( parsedOutput ) , ... deserialized , } ; return contents ; } ; const serializeAws_json1_1DescribeServicesRequest = ( input , context ) : any => { return { ... ( input . FormatVersion !== undefined && input . FormatVersion !== null && { FormatVersion : input . FormatVersion } ) , ... ( input . MaxResults !== undefined && input . MaxResults !== null && { MaxResults : input . MaxResults } ) , ... ( input . NextToken !== undefined && input . NextToken !== null && { NextToken : input . NextToken } ) , ... ( input . ServiceCode !== undefined && input . ServiceCode !== null && { ServiceCode : input . ServiceCode } ) , } ; } ; const serializeAws_json1_1Filter = ( input , context ) : any => { return { ... ( input . Field !== undefined && input . Field !== null && { Field : input . Field } ) , ... ( input . Type !== undefined && input . Type !== null && { Type : input . Type } ) , ... ( input . Value !== undefined && input . Value !== null && { Value : input . Value } ) , } ; } ; const serializeAws_json1_1Filters = ( input , context ) : any => { return input . filter ( ( e ) => e != null ) . map ( ( entry ) => { if ( entry === null ) { return null as any ; } return serializeAws_json1_1Filter ( entry , context ) ; } ) ; } ; const serializeAws_json1_1GetAttributeValuesRequest = ( input , context ) : any => { return { ... ( input . AttributeName !== undefined && input . AttributeName !== null && { AttributeName : input . AttributeName } ) , ... ( input . MaxResults !== undefined && input . MaxResults !== null && { MaxResults : input . MaxResults } ) , ... ( input . NextToken !== undefined && input . NextToken !== null && { NextToken : input . NextToken } ) , ... ( input . ServiceCode !== undefined && input . ServiceCode !== null && { ServiceCode : input . ServiceCode } ) , } ; } ; const serializeAws_json1_1GetProductsRequest = ( input , context ) : any => { return { ... ( input . Filters !== undefined && input . Filters !== null && { Filters : serializeAws_json1_1Filters ( input . Filters , context ) } ) , ... ( input . FormatVersion !== undefined && input . FormatVersion !== null && { FormatVersion : input . FormatVersion } ) , ... ( input . MaxResults !== undefined && input . MaxResults !== null && { MaxResults : input . MaxResults } ) , ... ( input . NextToken !== undefined && input . NextToken !== null && { NextToken : input . NextToken } ) , ... ( input . ServiceCode !== undefined && input . ServiceCode !== null && { ServiceCode : input . ServiceCode } ) , } ; } ; const deserializeAws_json1_1AttributeNameList = ( output , context ) : string [ ] => { return ( output || [ ] ) . filter ( ( e ) => e != null ) . map ( ( entry ) => { if ( entry === null ) { return null as any ; } return __expectString ( entry ) as any ; } ) ; } ; const deserializeAws_json1_1AttributeValue = ( output , context ) : AttributeValue => { return { Value : __expectString ( output . Value ) , } as any ; } ; const deserializeAws_json1_1AttributeValueList = ( output , context ) : AttributeValue [ ] => { return ( output || [ ] ) . filter ( ( e ) => e != null ) . map ( ( entry ) => { if ( entry === null ) { return null as any ; } return deserializeAws_json1_1AttributeValue ( entry , context ) ; } ) ; } ; const deserializeAws_json1_1DescribeServicesResponse = ( output , context ) : DescribeServicesResponse => { return { FormatVersion : __expectString ( output . FormatVersion ) , NextToken : __expectString ( output . NextToken ) , Services : output . Services !== undefined && output . Services !== null ? deserializeAws_json1_1ServiceList ( output . Services , context ) : undefined , } as any ; } ; const deserializeAws_json1_1ExpiredNextTokenException = ( output , context ) : ExpiredNextTokenException => { return { Message : __expectString ( output . Message ) , } as any ; } ; const deserializeAws_json1_1GetAttributeValuesResponse = ( output , context ) : GetAttributeValuesResponse => { return { AttributeValues : output . AttributeValues !== undefined && output . AttributeValues !== null ? deserializeAws_json1_1AttributeValueList ( output . AttributeValues , context ) : undefined , NextToken : __expectString ( output . NextToken ) , } as any ; } ; const deserializeAws_json1_1GetProductsResponse = ( output , context ) : GetProductsResponse => { return { FormatVersion : __expectString ( output . FormatVersion ) , NextToken : __expectString ( output . NextToken ) , PriceList : output . PriceList !== undefined && output . PriceList !== null ? deserializeAws_json1_1PriceList ( output . PriceList , context ) : undefined , } as any ; } ; const deserializeAws_json1_1InternalErrorException = ( output , context ) : InternalErrorException => { return { Message : __expectString ( output . Message ) , } as any ; } ; const deserializeAws_json1_1InvalidNextTokenException = ( output , context ) : InvalidNextTokenException => { return { Message : __expectString ( output . Message ) , } as any ; } ; const deserializeAws_json1_1InvalidParameterException = ( output , context ) : InvalidParameterException => { return { Message : __expectString ( output . Message ) , } as any ; } ; const deserializeAws_json1_1NotFoundException = ( output , context ) : NotFoundException => { return { Message : __expectString ( output . Message ) , } as any ; } ; const deserializeAws_json1_1PriceList = ( output , context ) : ( __LazyJsonString | string ) [ ] => { return ( output || [ ] ) . filter ( ( e ) => e != null ) . map ( ( entry ) => { if ( entry === null ) { return null as any ; } return new __LazyJsonString ( entry ) ; } ) ; } ; const deserializeAws_json1_1Service = ( output , context ) : Service => { return { AttributeNames : output . AttributeNames !== undefined && output . AttributeNames !== null ? deserializeAws_json1_1AttributeNameList ( output . AttributeNames , context ) : undefined , ServiceCode : __expectString ( output . ServiceCode ) , } as any ; } ; const deserializeAws_json1_1ServiceList = ( output , context ) : Service [ ] => { return ( output || [ ] ) . filter ( ( e ) => e != null ) . map ( ( entry ) => { if ( entry === null ) { return null as any ; } return deserializeAws_json1_1Service ( entry , context ) ; } ) ; } ; 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 buildHttpRpcRequest = async ( context , headers , path , resolvedHostname , body ) : Promise < __HttpRequest > => { const { hostname , protocol = "https" , port , path : basePath } = await context . endpoint ( ) ; const contents = { protocol , hostname , port , method : "POST" , path : basePath . endsWith ( "/" ) ? basePath . slice ( 0 , - 1 ) + path : basePath + path , headers , } ; if ( resolvedHostname !== undefined ) { contents . hostname = resolvedHostname ; } if ( body !== undefined ) { contents . body = body ; } return new __HttpRequest ( contents ) ; } ; 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 "" ; } ;