UNPKG

@softchef/cdk-iot-device-management

Version:

IoT device management is composed of things, thing types, thing groups, jobs, files API services. The constructs can be used independently, that are based on full-managed service to create an API Gateway & Lambda function.

1,111 lines (1,110 loc) 47.9 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.deserializeAws_restJson1UpdateThingShadowCommand = exports.deserializeAws_restJson1PublishCommand = exports.deserializeAws_restJson1ListRetainedMessagesCommand = exports.deserializeAws_restJson1ListNamedShadowsForThingCommand = exports.deserializeAws_restJson1GetThingShadowCommand = exports.deserializeAws_restJson1GetRetainedMessageCommand = exports.deserializeAws_restJson1DeleteThingShadowCommand = exports.serializeAws_restJson1UpdateThingShadowCommand = exports.serializeAws_restJson1PublishCommand = exports.serializeAws_restJson1ListRetainedMessagesCommand = exports.serializeAws_restJson1ListNamedShadowsForThingCommand = exports.serializeAws_restJson1GetThingShadowCommand = exports.serializeAws_restJson1GetRetainedMessageCommand = exports.serializeAws_restJson1DeleteThingShadowCommand = void 0; const protocol_http_1 = require("@aws-sdk/protocol-http"); const smithy_client_1 = require("@aws-sdk/smithy-client"); const serializeAws_restJson1DeleteThingShadowCommand = async (input, context) => { const { hostname, protocol = "https", port, path: basePath } = await context.endpoint(); const headers = {}; let resolvedPath = `${(basePath === null || basePath === void 0 ? void 0 : basePath.endsWith("/")) ? basePath.slice(0, -1) : basePath || ""}` + "/things/{thingName}/shadow"; if (input.thingName !== undefined) { const labelValue = input.thingName; if (labelValue.length <= 0) { throw new Error("Empty value provided for input HTTP label: thingName."); } resolvedPath = resolvedPath.replace("{thingName}", smithy_client_1.extendedEncodeURIComponent(labelValue)); } else { throw new Error("No value provided for input HTTP label: thingName."); } const query = { ...(input.shadowName !== undefined && { name: input.shadowName }), }; let body; return new protocol_http_1.HttpRequest({ protocol, hostname, port, method: "DELETE", headers, path: resolvedPath, query, body, }); }; exports.serializeAws_restJson1DeleteThingShadowCommand = serializeAws_restJson1DeleteThingShadowCommand; const serializeAws_restJson1GetRetainedMessageCommand = async (input, context) => { const { hostname, protocol = "https", port, path: basePath } = await context.endpoint(); const headers = {}; let resolvedPath = `${(basePath === null || basePath === void 0 ? void 0 : basePath.endsWith("/")) ? basePath.slice(0, -1) : basePath || ""}` + "/retainedMessage/{topic}"; if (input.topic !== undefined) { const labelValue = input.topic; if (labelValue.length <= 0) { throw new Error("Empty value provided for input HTTP label: topic."); } resolvedPath = resolvedPath.replace("{topic}", smithy_client_1.extendedEncodeURIComponent(labelValue)); } else { throw new Error("No value provided for input HTTP label: topic."); } let body; return new protocol_http_1.HttpRequest({ protocol, hostname, port, method: "GET", headers, path: resolvedPath, body, }); }; exports.serializeAws_restJson1GetRetainedMessageCommand = serializeAws_restJson1GetRetainedMessageCommand; const serializeAws_restJson1GetThingShadowCommand = async (input, context) => { const { hostname, protocol = "https", port, path: basePath } = await context.endpoint(); const headers = {}; let resolvedPath = `${(basePath === null || basePath === void 0 ? void 0 : basePath.endsWith("/")) ? basePath.slice(0, -1) : basePath || ""}` + "/things/{thingName}/shadow"; if (input.thingName !== undefined) { const labelValue = input.thingName; if (labelValue.length <= 0) { throw new Error("Empty value provided for input HTTP label: thingName."); } resolvedPath = resolvedPath.replace("{thingName}", smithy_client_1.extendedEncodeURIComponent(labelValue)); } else { throw new Error("No value provided for input HTTP label: thingName."); } const query = { ...(input.shadowName !== undefined && { name: input.shadowName }), }; let body; return new protocol_http_1.HttpRequest({ protocol, hostname, port, method: "GET", headers, path: resolvedPath, query, body, }); }; exports.serializeAws_restJson1GetThingShadowCommand = serializeAws_restJson1GetThingShadowCommand; const serializeAws_restJson1ListNamedShadowsForThingCommand = async (input, context) => { const { hostname, protocol = "https", port, path: basePath } = await context.endpoint(); const headers = {}; let resolvedPath = `${(basePath === null || basePath === void 0 ? void 0 : basePath.endsWith("/")) ? basePath.slice(0, -1) : basePath || ""}` + "/api/things/shadow/ListNamedShadowsForThing/{thingName}"; if (input.thingName !== undefined) { const labelValue = input.thingName; if (labelValue.length <= 0) { throw new Error("Empty value provided for input HTTP label: thingName."); } resolvedPath = resolvedPath.replace("{thingName}", smithy_client_1.extendedEncodeURIComponent(labelValue)); } else { throw new Error("No value provided for input HTTP label: thingName."); } const query = { ...(input.nextToken !== undefined && { nextToken: input.nextToken }), ...(input.pageSize !== undefined && { pageSize: input.pageSize.toString() }), }; let body; return new protocol_http_1.HttpRequest({ protocol, hostname, port, method: "GET", headers, path: resolvedPath, query, body, }); }; exports.serializeAws_restJson1ListNamedShadowsForThingCommand = serializeAws_restJson1ListNamedShadowsForThingCommand; const serializeAws_restJson1ListRetainedMessagesCommand = async (input, context) => { const { hostname, protocol = "https", port, path: basePath } = await context.endpoint(); const headers = {}; const resolvedPath = `${(basePath === null || basePath === void 0 ? void 0 : basePath.endsWith("/")) ? basePath.slice(0, -1) : basePath || ""}` + "/retainedMessage"; const query = { ...(input.nextToken !== undefined && { nextToken: input.nextToken }), ...(input.maxResults !== undefined && { maxResults: input.maxResults.toString() }), }; let body; return new protocol_http_1.HttpRequest({ protocol, hostname, port, method: "GET", headers, path: resolvedPath, query, body, }); }; exports.serializeAws_restJson1ListRetainedMessagesCommand = serializeAws_restJson1ListRetainedMessagesCommand; const serializeAws_restJson1PublishCommand = async (input, context) => { const { hostname, protocol = "https", port, path: basePath } = await context.endpoint(); const headers = { "content-type": "application/octet-stream", }; let resolvedPath = `${(basePath === null || basePath === void 0 ? void 0 : basePath.endsWith("/")) ? basePath.slice(0, -1) : basePath || ""}` + "/topics/{topic}"; if (input.topic !== undefined) { const labelValue = input.topic; if (labelValue.length <= 0) { throw new Error("Empty value provided for input HTTP label: topic."); } resolvedPath = resolvedPath.replace("{topic}", smithy_client_1.extendedEncodeURIComponent(labelValue)); } else { throw new Error("No value provided for input HTTP label: topic."); } const query = { ...(input.qos !== undefined && { qos: input.qos.toString() }), ...(input.retain !== undefined && { retain: input.retain.toString() }), }; let body; if (input.payload !== undefined) { body = input.payload; } return new protocol_http_1.HttpRequest({ protocol, hostname, port, method: "POST", headers, path: resolvedPath, query, body, }); }; exports.serializeAws_restJson1PublishCommand = serializeAws_restJson1PublishCommand; const serializeAws_restJson1UpdateThingShadowCommand = async (input, context) => { const { hostname, protocol = "https", port, path: basePath } = await context.endpoint(); const headers = { "content-type": "application/octet-stream", }; let resolvedPath = `${(basePath === null || basePath === void 0 ? void 0 : basePath.endsWith("/")) ? basePath.slice(0, -1) : basePath || ""}` + "/things/{thingName}/shadow"; if (input.thingName !== undefined) { const labelValue = input.thingName; if (labelValue.length <= 0) { throw new Error("Empty value provided for input HTTP label: thingName."); } resolvedPath = resolvedPath.replace("{thingName}", smithy_client_1.extendedEncodeURIComponent(labelValue)); } else { throw new Error("No value provided for input HTTP label: thingName."); } const query = { ...(input.shadowName !== undefined && { name: input.shadowName }), }; let body; if (input.payload !== undefined) { body = input.payload; } return new protocol_http_1.HttpRequest({ protocol, hostname, port, method: "POST", headers, path: resolvedPath, query, body, }); }; exports.serializeAws_restJson1UpdateThingShadowCommand = serializeAws_restJson1UpdateThingShadowCommand; const deserializeAws_restJson1DeleteThingShadowCommand = async (output, context) => { if (output.statusCode !== 200 && output.statusCode >= 300) { return deserializeAws_restJson1DeleteThingShadowCommandError(output, context); } const contents = { $metadata: deserializeMetadata(output), payload: undefined, }; const data = await collectBody(output.body, context); contents.payload = data; return Promise.resolve(contents); }; exports.deserializeAws_restJson1DeleteThingShadowCommand = deserializeAws_restJson1DeleteThingShadowCommand; const deserializeAws_restJson1DeleteThingShadowCommandError = async (output, context) => { 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.iotdataplane#InternalFailureException": response = { ...(await deserializeAws_restJson1InternalFailureExceptionResponse(parsedOutput, context)), name: errorCode, $metadata: deserializeMetadata(output), }; break; case "InvalidRequestException": case "com.amazonaws.iotdataplane#InvalidRequestException": response = { ...(await deserializeAws_restJson1InvalidRequestExceptionResponse(parsedOutput, context)), name: errorCode, $metadata: deserializeMetadata(output), }; break; case "MethodNotAllowedException": case "com.amazonaws.iotdataplane#MethodNotAllowedException": response = { ...(await deserializeAws_restJson1MethodNotAllowedExceptionResponse(parsedOutput, context)), name: errorCode, $metadata: deserializeMetadata(output), }; break; case "ResourceNotFoundException": case "com.amazonaws.iotdataplane#ResourceNotFoundException": response = { ...(await deserializeAws_restJson1ResourceNotFoundExceptionResponse(parsedOutput, context)), name: errorCode, $metadata: deserializeMetadata(output), }; break; case "ServiceUnavailableException": case "com.amazonaws.iotdataplane#ServiceUnavailableException": response = { ...(await deserializeAws_restJson1ServiceUnavailableExceptionResponse(parsedOutput, context)), name: errorCode, $metadata: deserializeMetadata(output), }; break; case "ThrottlingException": case "com.amazonaws.iotdataplane#ThrottlingException": response = { ...(await deserializeAws_restJson1ThrottlingExceptionResponse(parsedOutput, context)), name: errorCode, $metadata: deserializeMetadata(output), }; break; case "UnauthorizedException": case "com.amazonaws.iotdataplane#UnauthorizedException": response = { ...(await deserializeAws_restJson1UnauthorizedExceptionResponse(parsedOutput, context)), name: errorCode, $metadata: deserializeMetadata(output), }; break; case "UnsupportedDocumentEncodingException": case "com.amazonaws.iotdataplane#UnsupportedDocumentEncodingException": response = { ...(await deserializeAws_restJson1UnsupportedDocumentEncodingExceptionResponse(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), }; } const message = response.message || response.Message || errorCode; response.message = message; delete response.Message; return Promise.reject(Object.assign(new Error(message), response)); }; const deserializeAws_restJson1GetRetainedMessageCommand = async (output, context) => { if (output.statusCode !== 200 && output.statusCode >= 300) { return deserializeAws_restJson1GetRetainedMessageCommandError(output, context); } const contents = { $metadata: deserializeMetadata(output), lastModifiedTime: undefined, payload: undefined, qos: undefined, topic: undefined, }; const data = smithy_client_1.expectNonNull(smithy_client_1.expectObject(await parseBody(output.body, context)), "body"); if (data.lastModifiedTime !== undefined && data.lastModifiedTime !== null) { contents.lastModifiedTime = smithy_client_1.expectLong(data.lastModifiedTime); } if (data.payload !== undefined && data.payload !== null) { contents.payload = context.base64Decoder(data.payload); } if (data.qos !== undefined && data.qos !== null) { contents.qos = smithy_client_1.expectInt32(data.qos); } if (data.topic !== undefined && data.topic !== null) { contents.topic = smithy_client_1.expectString(data.topic); } return Promise.resolve(contents); }; exports.deserializeAws_restJson1GetRetainedMessageCommand = deserializeAws_restJson1GetRetainedMessageCommand; const deserializeAws_restJson1GetRetainedMessageCommandError = async (output, context) => { 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.iotdataplane#InternalFailureException": response = { ...(await deserializeAws_restJson1InternalFailureExceptionResponse(parsedOutput, context)), name: errorCode, $metadata: deserializeMetadata(output), }; break; case "InvalidRequestException": case "com.amazonaws.iotdataplane#InvalidRequestException": response = { ...(await deserializeAws_restJson1InvalidRequestExceptionResponse(parsedOutput, context)), name: errorCode, $metadata: deserializeMetadata(output), }; break; case "MethodNotAllowedException": case "com.amazonaws.iotdataplane#MethodNotAllowedException": response = { ...(await deserializeAws_restJson1MethodNotAllowedExceptionResponse(parsedOutput, context)), name: errorCode, $metadata: deserializeMetadata(output), }; break; case "ResourceNotFoundException": case "com.amazonaws.iotdataplane#ResourceNotFoundException": response = { ...(await deserializeAws_restJson1ResourceNotFoundExceptionResponse(parsedOutput, context)), name: errorCode, $metadata: deserializeMetadata(output), }; break; case "ServiceUnavailableException": case "com.amazonaws.iotdataplane#ServiceUnavailableException": response = { ...(await deserializeAws_restJson1ServiceUnavailableExceptionResponse(parsedOutput, context)), name: errorCode, $metadata: deserializeMetadata(output), }; break; case "ThrottlingException": case "com.amazonaws.iotdataplane#ThrottlingException": response = { ...(await deserializeAws_restJson1ThrottlingExceptionResponse(parsedOutput, context)), name: errorCode, $metadata: deserializeMetadata(output), }; break; case "UnauthorizedException": case "com.amazonaws.iotdataplane#UnauthorizedException": response = { ...(await deserializeAws_restJson1UnauthorizedExceptionResponse(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), }; } const message = response.message || response.Message || errorCode; response.message = message; delete response.Message; return Promise.reject(Object.assign(new Error(message), response)); }; const deserializeAws_restJson1GetThingShadowCommand = async (output, context) => { if (output.statusCode !== 200 && output.statusCode >= 300) { return deserializeAws_restJson1GetThingShadowCommandError(output, context); } const contents = { $metadata: deserializeMetadata(output), payload: undefined, }; const data = await collectBody(output.body, context); contents.payload = data; return Promise.resolve(contents); }; exports.deserializeAws_restJson1GetThingShadowCommand = deserializeAws_restJson1GetThingShadowCommand; const deserializeAws_restJson1GetThingShadowCommandError = async (output, context) => { 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.iotdataplane#InternalFailureException": response = { ...(await deserializeAws_restJson1InternalFailureExceptionResponse(parsedOutput, context)), name: errorCode, $metadata: deserializeMetadata(output), }; break; case "InvalidRequestException": case "com.amazonaws.iotdataplane#InvalidRequestException": response = { ...(await deserializeAws_restJson1InvalidRequestExceptionResponse(parsedOutput, context)), name: errorCode, $metadata: deserializeMetadata(output), }; break; case "MethodNotAllowedException": case "com.amazonaws.iotdataplane#MethodNotAllowedException": response = { ...(await deserializeAws_restJson1MethodNotAllowedExceptionResponse(parsedOutput, context)), name: errorCode, $metadata: deserializeMetadata(output), }; break; case "ResourceNotFoundException": case "com.amazonaws.iotdataplane#ResourceNotFoundException": response = { ...(await deserializeAws_restJson1ResourceNotFoundExceptionResponse(parsedOutput, context)), name: errorCode, $metadata: deserializeMetadata(output), }; break; case "ServiceUnavailableException": case "com.amazonaws.iotdataplane#ServiceUnavailableException": response = { ...(await deserializeAws_restJson1ServiceUnavailableExceptionResponse(parsedOutput, context)), name: errorCode, $metadata: deserializeMetadata(output), }; break; case "ThrottlingException": case "com.amazonaws.iotdataplane#ThrottlingException": response = { ...(await deserializeAws_restJson1ThrottlingExceptionResponse(parsedOutput, context)), name: errorCode, $metadata: deserializeMetadata(output), }; break; case "UnauthorizedException": case "com.amazonaws.iotdataplane#UnauthorizedException": response = { ...(await deserializeAws_restJson1UnauthorizedExceptionResponse(parsedOutput, context)), name: errorCode, $metadata: deserializeMetadata(output), }; break; case "UnsupportedDocumentEncodingException": case "com.amazonaws.iotdataplane#UnsupportedDocumentEncodingException": response = { ...(await deserializeAws_restJson1UnsupportedDocumentEncodingExceptionResponse(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), }; } const message = response.message || response.Message || errorCode; response.message = message; delete response.Message; return Promise.reject(Object.assign(new Error(message), response)); }; const deserializeAws_restJson1ListNamedShadowsForThingCommand = async (output, context) => { if (output.statusCode !== 200 && output.statusCode >= 300) { return deserializeAws_restJson1ListNamedShadowsForThingCommandError(output, context); } const contents = { $metadata: deserializeMetadata(output), nextToken: undefined, results: undefined, timestamp: undefined, }; const data = smithy_client_1.expectNonNull(smithy_client_1.expectObject(await parseBody(output.body, context)), "body"); if (data.nextToken !== undefined && data.nextToken !== null) { contents.nextToken = smithy_client_1.expectString(data.nextToken); } if (data.results !== undefined && data.results !== null) { contents.results = deserializeAws_restJson1NamedShadowList(data.results, context); } if (data.timestamp !== undefined && data.timestamp !== null) { contents.timestamp = smithy_client_1.expectLong(data.timestamp); } return Promise.resolve(contents); }; exports.deserializeAws_restJson1ListNamedShadowsForThingCommand = deserializeAws_restJson1ListNamedShadowsForThingCommand; const deserializeAws_restJson1ListNamedShadowsForThingCommandError = async (output, context) => { 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.iotdataplane#InternalFailureException": response = { ...(await deserializeAws_restJson1InternalFailureExceptionResponse(parsedOutput, context)), name: errorCode, $metadata: deserializeMetadata(output), }; break; case "InvalidRequestException": case "com.amazonaws.iotdataplane#InvalidRequestException": response = { ...(await deserializeAws_restJson1InvalidRequestExceptionResponse(parsedOutput, context)), name: errorCode, $metadata: deserializeMetadata(output), }; break; case "MethodNotAllowedException": case "com.amazonaws.iotdataplane#MethodNotAllowedException": response = { ...(await deserializeAws_restJson1MethodNotAllowedExceptionResponse(parsedOutput, context)), name: errorCode, $metadata: deserializeMetadata(output), }; break; case "ResourceNotFoundException": case "com.amazonaws.iotdataplane#ResourceNotFoundException": response = { ...(await deserializeAws_restJson1ResourceNotFoundExceptionResponse(parsedOutput, context)), name: errorCode, $metadata: deserializeMetadata(output), }; break; case "ServiceUnavailableException": case "com.amazonaws.iotdataplane#ServiceUnavailableException": response = { ...(await deserializeAws_restJson1ServiceUnavailableExceptionResponse(parsedOutput, context)), name: errorCode, $metadata: deserializeMetadata(output), }; break; case "ThrottlingException": case "com.amazonaws.iotdataplane#ThrottlingException": response = { ...(await deserializeAws_restJson1ThrottlingExceptionResponse(parsedOutput, context)), name: errorCode, $metadata: deserializeMetadata(output), }; break; case "UnauthorizedException": case "com.amazonaws.iotdataplane#UnauthorizedException": response = { ...(await deserializeAws_restJson1UnauthorizedExceptionResponse(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), }; } const message = response.message || response.Message || errorCode; response.message = message; delete response.Message; return Promise.reject(Object.assign(new Error(message), response)); }; const deserializeAws_restJson1ListRetainedMessagesCommand = async (output, context) => { if (output.statusCode !== 200 && output.statusCode >= 300) { return deserializeAws_restJson1ListRetainedMessagesCommandError(output, context); } const contents = { $metadata: deserializeMetadata(output), nextToken: undefined, retainedTopics: undefined, }; const data = smithy_client_1.expectNonNull(smithy_client_1.expectObject(await parseBody(output.body, context)), "body"); if (data.nextToken !== undefined && data.nextToken !== null) { contents.nextToken = smithy_client_1.expectString(data.nextToken); } if (data.retainedTopics !== undefined && data.retainedTopics !== null) { contents.retainedTopics = deserializeAws_restJson1RetainedMessageList(data.retainedTopics, context); } return Promise.resolve(contents); }; exports.deserializeAws_restJson1ListRetainedMessagesCommand = deserializeAws_restJson1ListRetainedMessagesCommand; const deserializeAws_restJson1ListRetainedMessagesCommandError = async (output, context) => { 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.iotdataplane#InternalFailureException": response = { ...(await deserializeAws_restJson1InternalFailureExceptionResponse(parsedOutput, context)), name: errorCode, $metadata: deserializeMetadata(output), }; break; case "InvalidRequestException": case "com.amazonaws.iotdataplane#InvalidRequestException": response = { ...(await deserializeAws_restJson1InvalidRequestExceptionResponse(parsedOutput, context)), name: errorCode, $metadata: deserializeMetadata(output), }; break; case "MethodNotAllowedException": case "com.amazonaws.iotdataplane#MethodNotAllowedException": response = { ...(await deserializeAws_restJson1MethodNotAllowedExceptionResponse(parsedOutput, context)), name: errorCode, $metadata: deserializeMetadata(output), }; break; case "ServiceUnavailableException": case "com.amazonaws.iotdataplane#ServiceUnavailableException": response = { ...(await deserializeAws_restJson1ServiceUnavailableExceptionResponse(parsedOutput, context)), name: errorCode, $metadata: deserializeMetadata(output), }; break; case "ThrottlingException": case "com.amazonaws.iotdataplane#ThrottlingException": response = { ...(await deserializeAws_restJson1ThrottlingExceptionResponse(parsedOutput, context)), name: errorCode, $metadata: deserializeMetadata(output), }; break; case "UnauthorizedException": case "com.amazonaws.iotdataplane#UnauthorizedException": response = { ...(await deserializeAws_restJson1UnauthorizedExceptionResponse(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), }; } const message = response.message || response.Message || errorCode; response.message = message; delete response.Message; return Promise.reject(Object.assign(new Error(message), response)); }; const deserializeAws_restJson1PublishCommand = async (output, context) => { if (output.statusCode !== 200 && output.statusCode >= 300) { return deserializeAws_restJson1PublishCommandError(output, context); } const contents = { $metadata: deserializeMetadata(output), }; await collectBody(output.body, context); return Promise.resolve(contents); }; exports.deserializeAws_restJson1PublishCommand = deserializeAws_restJson1PublishCommand; const deserializeAws_restJson1PublishCommandError = async (output, context) => { 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.iotdataplane#InternalFailureException": response = { ...(await deserializeAws_restJson1InternalFailureExceptionResponse(parsedOutput, context)), name: errorCode, $metadata: deserializeMetadata(output), }; break; case "InvalidRequestException": case "com.amazonaws.iotdataplane#InvalidRequestException": response = { ...(await deserializeAws_restJson1InvalidRequestExceptionResponse(parsedOutput, context)), name: errorCode, $metadata: deserializeMetadata(output), }; break; case "MethodNotAllowedException": case "com.amazonaws.iotdataplane#MethodNotAllowedException": response = { ...(await deserializeAws_restJson1MethodNotAllowedExceptionResponse(parsedOutput, context)), name: errorCode, $metadata: deserializeMetadata(output), }; break; case "UnauthorizedException": case "com.amazonaws.iotdataplane#UnauthorizedException": response = { ...(await deserializeAws_restJson1UnauthorizedExceptionResponse(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), }; } const message = response.message || response.Message || errorCode; response.message = message; delete response.Message; return Promise.reject(Object.assign(new Error(message), response)); }; const deserializeAws_restJson1UpdateThingShadowCommand = async (output, context) => { if (output.statusCode !== 200 && output.statusCode >= 300) { return deserializeAws_restJson1UpdateThingShadowCommandError(output, context); } const contents = { $metadata: deserializeMetadata(output), payload: undefined, }; const data = await collectBody(output.body, context); contents.payload = data; return Promise.resolve(contents); }; exports.deserializeAws_restJson1UpdateThingShadowCommand = deserializeAws_restJson1UpdateThingShadowCommand; const deserializeAws_restJson1UpdateThingShadowCommandError = async (output, context) => { const parsedOutput = { ...output, body: await parseBody(output.body, context), }; let response; let errorCode = "UnknownError"; errorCode = loadRestJsonErrorCode(output, parsedOutput.body); switch (errorCode) { case "ConflictException": case "com.amazonaws.iotdataplane#ConflictException": response = { ...(await deserializeAws_restJson1ConflictExceptionResponse(parsedOutput, context)), name: errorCode, $metadata: deserializeMetadata(output), }; break; case "InternalFailureException": case "com.amazonaws.iotdataplane#InternalFailureException": response = { ...(await deserializeAws_restJson1InternalFailureExceptionResponse(parsedOutput, context)), name: errorCode, $metadata: deserializeMetadata(output), }; break; case "InvalidRequestException": case "com.amazonaws.iotdataplane#InvalidRequestException": response = { ...(await deserializeAws_restJson1InvalidRequestExceptionResponse(parsedOutput, context)), name: errorCode, $metadata: deserializeMetadata(output), }; break; case "MethodNotAllowedException": case "com.amazonaws.iotdataplane#MethodNotAllowedException": response = { ...(await deserializeAws_restJson1MethodNotAllowedExceptionResponse(parsedOutput, context)), name: errorCode, $metadata: deserializeMetadata(output), }; break; case "RequestEntityTooLargeException": case "com.amazonaws.iotdataplane#RequestEntityTooLargeException": response = { ...(await deserializeAws_restJson1RequestEntityTooLargeExceptionResponse(parsedOutput, context)), name: errorCode, $metadata: deserializeMetadata(output), }; break; case "ServiceUnavailableException": case "com.amazonaws.iotdataplane#ServiceUnavailableException": response = { ...(await deserializeAws_restJson1ServiceUnavailableExceptionResponse(parsedOutput, context)), name: errorCode, $metadata: deserializeMetadata(output), }; break; case "ThrottlingException": case "com.amazonaws.iotdataplane#ThrottlingException": response = { ...(await deserializeAws_restJson1ThrottlingExceptionResponse(parsedOutput, context)), name: errorCode, $metadata: deserializeMetadata(output), }; break; case "UnauthorizedException": case "com.amazonaws.iotdataplane#UnauthorizedException": response = { ...(await deserializeAws_restJson1UnauthorizedExceptionResponse(parsedOutput, context)), name: errorCode, $metadata: deserializeMetadata(output), }; break; case "UnsupportedDocumentEncodingException": case "com.amazonaws.iotdataplane#UnsupportedDocumentEncodingException": response = { ...(await deserializeAws_restJson1UnsupportedDocumentEncodingExceptionResponse(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), }; } const message = response.message || response.Message || errorCode; response.message = message; delete response.Message; return Promise.reject(Object.assign(new Error(message), response)); }; const deserializeAws_restJson1ConflictExceptionResponse = async (parsedOutput, context) => { const contents = { name: "ConflictException", $fault: "client", $metadata: deserializeMetadata(parsedOutput), message: undefined, }; const data = parsedOutput.body; if (data.message !== undefined && data.message !== null) { contents.message = smithy_client_1.expectString(data.message); } return contents; }; const deserializeAws_restJson1InternalFailureExceptionResponse = async (parsedOutput, context) => { const contents = { name: "InternalFailureException", $fault: "server", $metadata: deserializeMetadata(parsedOutput), message: undefined, }; const data = parsedOutput.body; if (data.message !== undefined && data.message !== null) { contents.message = smithy_client_1.expectString(data.message); } return contents; }; const deserializeAws_restJson1InvalidRequestExceptionResponse = async (parsedOutput, context) => { const contents = { name: "InvalidRequestException", $fault: "client", $metadata: deserializeMetadata(parsedOutput), message: undefined, }; const data = parsedOutput.body; if (data.message !== undefined && data.message !== null) { contents.message = smithy_client_1.expectString(data.message); } return contents; }; const deserializeAws_restJson1MethodNotAllowedExceptionResponse = async (parsedOutput, context) => { const contents = { name: "MethodNotAllowedException", $fault: "client", $metadata: deserializeMetadata(parsedOutput), message: undefined, }; const data = parsedOutput.body; if (data.message !== undefined && data.message !== null) { contents.message = smithy_client_1.expectString(data.message); } return contents; }; const deserializeAws_restJson1RequestEntityTooLargeExceptionResponse = async (parsedOutput, context) => { const contents = { name: "RequestEntityTooLargeException", $fault: "client", $metadata: deserializeMetadata(parsedOutput), message: undefined, }; const data = parsedOutput.body; if (data.message !== undefined && data.message !== null) { contents.message = smithy_client_1.expectString(data.message); } return contents; }; const deserializeAws_restJson1ResourceNotFoundExceptionResponse = async (parsedOutput, context) => { const contents = { name: "ResourceNotFoundException", $fault: "client", $metadata: deserializeMetadata(parsedOutput), message: undefined, }; const data = parsedOutput.body; if (data.message !== undefined && data.message !== null) { contents.message = smithy_client_1.expectString(data.message); } return contents; }; const deserializeAws_restJson1ServiceUnavailableExceptionResponse = async (parsedOutput, context) => { const contents = { name: "ServiceUnavailableException", $fault: "server", $metadata: deserializeMetadata(parsedOutput), message: undefined, }; const data = parsedOutput.body; if (data.message !== undefined && data.message !== null) { contents.message = smithy_client_1.expectString(data.message); } return contents; }; const deserializeAws_restJson1ThrottlingExceptionResponse = async (parsedOutput, context) => { const contents = { name: "ThrottlingException", $fault: "client", $metadata: deserializeMetadata(parsedOutput), message: undefined, }; const data = parsedOutput.body; if (data.message !== undefined && data.message !== null) { contents.message = smithy_client_1.expectString(data.message); } return contents; }; const deserializeAws_restJson1UnauthorizedExceptionResponse = async (parsedOutput, context) => { const contents = { name: "UnauthorizedException", $fault: "client", $metadata: deserializeMetadata(parsedOutput), message: undefined, }; const data = parsedOutput.body; if (data.message !== undefined && data.message !== null) { contents.message = smithy_client_1.expectString(data.message); } return contents; }; const deserializeAws_restJson1UnsupportedDocumentEncodingExceptionResponse = async (parsedOutput, context) => { const contents = { name: "UnsupportedDocumentEncodingException", $fault: "client", $metadata: deserializeMetadata(parsedOutput), message: undefined, }; const data = parsedOutput.body; if (data.message !== undefined && data.message !== null) { contents.message = smithy_client_1.expectString(data.message); } return contents; }; const deserializeAws_restJson1NamedShadowList = (output, context) => { return (output || []) .filter((e) => e != null) .map((entry) => { if (entry === null) { return null; } return smithy_client_1.expectString(entry); }); }; const deserializeAws_restJson1RetainedMessageList = (output, context) => { return (output || []) .filter((e) => e != null) .map((entry) => { if (entry === null) { return null; } return deserializeAws_restJson1RetainedMessageSummary(entry, context); }); }; const deserializeAws_restJson1RetainedMessageSummary = (output, context) => { return { lastModifiedTime: smithy_client_1.expectLong(output.lastModifiedTime), payloadSize: smithy_client_1.expectLong(output.payloadSize), qos: smithy_client_1.expectInt32(output.qos), topic: smithy_client_1.expectString(output.topic), }; }; const deserializeMetadata = (output) => { var _a; return ({ httpStatusCode: output.statusCode, requestId: (_a = output.headers["x-amzn-requestid"]) !== null && _a !== void 0 ? _a : 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) => { if (streamBody instanceof Uint8Array) { return Promise.resolve(streamBody); } return context.streamCollector(streamBody) || Promise.resolve(new Uint8Array()); }; const collectBodyString = (streamBody, context) => collectBody(streamBody, context).then((body) => context.utf8Encoder(body)); const isSerializableHeaderValue = (value) => 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) => collectBodyString(streamBody, context).then((encoded) => { if (encoded.length) { return JSON.parse(encoded); } return {}; }); const loadRestJsonErrorCode = (output, data) => { const findKey = (object, key) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); const sanitizeErrorCode = (rawValue) => { 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 ""; };