@cdklabs/cdk-ecs-codedeploy 0.0.412 → 0.0.414
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.jsii +4 -4
- package/.jsii.tabl.json +1 -1
- package/lib/api-canary/code-bundling.js +1 -1
- package/lib/api-canary/index.js +2 -2
- package/lib/ecs-appspec/index.js +2 -2
- package/lib/ecs-deployment/index.js +2 -2
- package/lib/ecs-deployment-provider/is-complete.lambda.js +3 -3
- package/lib/ecs-deployment-provider/on-event.lambda.js +2 -3
- package/lib/ecs-patterns/application-load-balanced-codedeployed-fargate-service.js +2 -2
- package/node_modules/@aws-sdk/client-codedeploy/package.json +34 -34
- package/node_modules/@aws-sdk/client-sso/package.json +32 -32
- package/node_modules/@aws-sdk/core/dist-cjs/submodules/protocols/index.js +1496 -14
- package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/ConfigurableSerdeContext.js +6 -0
- package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/index.js +13 -0
- package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/AwsJson1_0Protocol.js +14 -0
- package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/AwsJson1_1Protocol.js +14 -0
- package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/AwsJsonRpcProtocol.js +84 -0
- package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/AwsRestJsonProtocol.js +118 -0
- package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/JsonCodec.js +20 -0
- package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/JsonShapeDeserializer.js +105 -0
- package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/JsonShapeSerializer.js +106 -0
- package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/jsonReplacer.js +46 -0
- package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/jsonReviver.js +18 -0
- package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/query/AwsEc2QueryProtocol.js +17 -0
- package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/query/AwsQueryProtocol.js +147 -0
- package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/query/QuerySerializerSettings.js +1 -0
- package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/query/QueryShapeSerializer.js +152 -0
- package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/xml/AwsRestXmlProtocol.js +126 -0
- package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/xml/XmlCodec.js +20 -0
- package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/xml/XmlShapeDeserializer.js +154 -0
- package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/xml/XmlShapeSerializer.js +279 -0
- package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/xml/simpleFormatXml.js +27 -0
- package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/ConfigurableSerdeContext.d.ts +8 -0
- package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/common.d.ts +2 -2
- package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/index.d.ts +13 -0
- package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/json/AwsJson1_0Protocol.d.ts +12 -0
- package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/json/AwsJson1_1Protocol.d.ts +12 -0
- package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/json/AwsJsonRpcProtocol.d.ts +18 -0
- package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/json/AwsRestJsonProtocol.d.ts +19 -0
- package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/json/JsonCodec.d.ts +19 -0
- package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/json/JsonShapeDeserializer.d.ts +13 -0
- package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/json/JsonShapeSerializer.d.ts +15 -0
- package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/json/jsonReplacer.d.ts +21 -0
- package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/json/jsonReviver.d.ts +15 -0
- package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/json/parseJsonBody.d.ts +3 -3
- package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/query/AwsEc2QueryProtocol.d.ts +20 -0
- package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/query/AwsQueryProtocol.d.ts +39 -0
- package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/query/QuerySerializerSettings.d.ts +6 -0
- package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/query/QueryShapeSerializer.d.ts +16 -0
- package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/xml/AwsRestXmlProtocol.d.ts +21 -0
- package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/xml/XmlCodec.d.ts +14 -0
- package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/xml/XmlShapeDeserializer.d.ts +20 -0
- package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/xml/XmlShapeSerializer.d.ts +21 -0
- package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/xml/simpleFormatXml.d.ts +6 -0
- package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/ConfigurableSerdeContext.d.ts +5 -0
- package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/common.d.ts +2 -2
- package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/index.d.ts +13 -0
- package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/json/AwsJson1_0Protocol.d.ts +6 -0
- package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/json/AwsJson1_1Protocol.d.ts +6 -0
- package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/json/AwsJsonRpcProtocol.d.ts +33 -0
- package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/json/AwsRestJsonProtocol.d.ts +34 -0
- package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/json/JsonCodec.d.ts +16 -0
- package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/json/JsonShapeDeserializer.d.ts +13 -0
- package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/json/JsonShapeSerializer.d.ts +15 -0
- package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/json/jsonReplacer.d.ts +7 -0
- package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/json/jsonReviver.d.ts +7 -0
- package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/json/parseJsonBody.d.ts +3 -3
- package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/query/AwsEc2QueryProtocol.d.ts +14 -0
- package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/query/AwsQueryProtocol.d.ts +55 -0
- package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/query/QuerySerializerSettings.d.ts +6 -0
- package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/query/QueryShapeSerializer.d.ts +16 -0
- package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/xml/AwsRestXmlProtocol.d.ts +39 -0
- package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/xml/XmlCodec.d.ts +17 -0
- package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/xml/XmlShapeDeserializer.d.ts +15 -0
- package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/xml/XmlShapeSerializer.d.ts +21 -0
- package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/xml/simpleFormatXml.d.ts +1 -0
- package/node_modules/@aws-sdk/core/package.json +14 -10
- package/node_modules/@aws-sdk/credential-provider-env/package.json +5 -5
- package/node_modules/@aws-sdk/credential-provider-http/package.json +10 -10
- package/node_modules/@aws-sdk/credential-provider-ini/package.json +13 -13
- package/node_modules/@aws-sdk/credential-provider-node/package.json +12 -12
- package/node_modules/@aws-sdk/credential-provider-process/package.json +6 -6
- package/node_modules/@aws-sdk/credential-provider-sso/package.json +8 -8
- package/node_modules/@aws-sdk/credential-provider-web-identity/package.json +6 -6
- package/node_modules/@aws-sdk/middleware-host-header/package.json +4 -4
- package/node_modules/@aws-sdk/middleware-logger/package.json +3 -3
- package/node_modules/@aws-sdk/middleware-recursion-detection/package.json +4 -4
- package/node_modules/@aws-sdk/middleware-user-agent/package.json +7 -7
- package/node_modules/@aws-sdk/nested-clients/package.json +32 -32
- package/node_modules/@aws-sdk/region-config-resolver/package.json +5 -5
- package/node_modules/@aws-sdk/token-providers/package.json +7 -7
- package/node_modules/@aws-sdk/types/package.json +2 -2
- package/node_modules/@aws-sdk/util-endpoints/package.json +4 -4
- package/node_modules/@aws-sdk/util-user-agent-browser/package.json +3 -3
- package/node_modules/@aws-sdk/util-user-agent-node/package.json +5 -5
- package/node_modules/@aws-sdk/xml-builder/LICENSE +201 -0
- package/node_modules/@aws-sdk/xml-builder/README.md +10 -0
- package/node_modules/@aws-sdk/xml-builder/dist-cjs/index.js +173 -0
- package/node_modules/@aws-sdk/xml-builder/dist-es/XmlNode.js +88 -0
- package/node_modules/@aws-sdk/xml-builder/dist-es/XmlText.js +10 -0
- package/node_modules/@aws-sdk/xml-builder/dist-es/escape-attribute.js +3 -0
- package/node_modules/@aws-sdk/xml-builder/dist-es/escape-element.js +12 -0
- package/node_modules/@aws-sdk/xml-builder/dist-es/index.js +2 -0
- package/node_modules/@aws-sdk/xml-builder/dist-es/stringable.js +1 -0
- package/node_modules/@aws-sdk/xml-builder/dist-types/XmlNode.d.ts +49 -0
- package/node_modules/@aws-sdk/xml-builder/dist-types/XmlText.d.ts +11 -0
- package/node_modules/@aws-sdk/xml-builder/dist-types/escape-attribute.d.ts +6 -0
- package/node_modules/@aws-sdk/xml-builder/dist-types/escape-element.d.ts +6 -0
- package/node_modules/@aws-sdk/xml-builder/dist-types/index.d.ts +8 -0
- package/node_modules/@aws-sdk/xml-builder/dist-types/stringable.d.ts +6 -0
- package/node_modules/@aws-sdk/xml-builder/dist-types/ts3.4/XmlNode.d.ts +29 -0
- package/node_modules/@aws-sdk/xml-builder/dist-types/ts3.4/XmlText.d.ts +6 -0
- package/node_modules/@aws-sdk/xml-builder/dist-types/ts3.4/escape-attribute.d.ts +1 -0
- package/node_modules/@aws-sdk/xml-builder/dist-types/ts3.4/escape-element.d.ts +1 -0
- package/node_modules/@aws-sdk/xml-builder/dist-types/ts3.4/index.d.ts +2 -0
- package/node_modules/@aws-sdk/xml-builder/dist-types/ts3.4/stringable.d.ts +3 -0
- package/node_modules/@aws-sdk/xml-builder/package.json +54 -0
- package/node_modules/@smithy/abort-controller/package.json +2 -2
- package/node_modules/@smithy/config-resolver/package.json +4 -4
- package/node_modules/@smithy/core/dist-cjs/submodules/protocols/index.js +9 -8
- package/node_modules/@smithy/core/dist-cjs/submodules/schema/index.js +4 -1
- package/node_modules/@smithy/core/dist-es/submodules/protocols/HttpBindingProtocol.js +1 -6
- package/node_modules/@smithy/core/dist-es/submodules/protocols/HttpProtocol.js +9 -2
- package/node_modules/@smithy/core/dist-es/submodules/schema/TypeRegistry.js +1 -1
- package/node_modules/@smithy/core/dist-es/submodules/schema/schemas/NormalizedSchema.js +3 -0
- package/node_modules/@smithy/core/dist-types/submodules/protocols/HttpProtocol.d.ts +4 -0
- package/node_modules/@smithy/core/dist-types/ts3.4/submodules/protocols/HttpProtocol.d.ts +4 -0
- package/node_modules/@smithy/core/package.json +6 -6
- package/node_modules/@smithy/credential-provider-imds/package.json +5 -5
- package/node_modules/@smithy/fetch-http-handler/package.json +5 -5
- package/node_modules/@smithy/hash-node/package.json +2 -2
- package/node_modules/@smithy/invalid-dependency/package.json +2 -2
- package/node_modules/@smithy/middleware-content-length/package.json +3 -3
- package/node_modules/@smithy/middleware-endpoint/package.json +8 -8
- package/node_modules/@smithy/middleware-retry/package.json +8 -8
- package/node_modules/@smithy/middleware-serde/package.json +3 -3
- package/node_modules/@smithy/middleware-stack/package.json +2 -2
- package/node_modules/@smithy/node-config-provider/package.json +4 -4
- package/node_modules/@smithy/node-http-handler/package.json +5 -5
- package/node_modules/@smithy/property-provider/package.json +2 -2
- package/node_modules/@smithy/protocol-http/package.json +2 -2
- package/node_modules/@smithy/querystring-builder/package.json +2 -2
- package/node_modules/@smithy/querystring-parser/package.json +2 -2
- package/node_modules/@smithy/service-error-classification/package.json +2 -2
- package/node_modules/@smithy/shared-ini-file-loader/package.json +2 -2
- package/node_modules/@smithy/signature-v4/package.json +4 -4
- package/node_modules/@smithy/smithy-client/package.json +7 -7
- package/node_modules/@smithy/types/dist-types/command.d.ts +5 -2
- package/node_modules/@smithy/types/dist-types/schema/schema.d.ts +2 -4
- package/node_modules/@smithy/types/dist-types/ts3.4/command.d.ts +5 -2
- package/node_modules/@smithy/types/dist-types/ts3.4/schema/schema.d.ts +2 -4
- package/node_modules/@smithy/types/package.json +1 -1
- package/node_modules/@smithy/url-parser/package.json +3 -3
- package/node_modules/@smithy/util-defaults-mode-browser/package.json +4 -4
- package/node_modules/@smithy/util-defaults-mode-node/package.json +7 -7
- package/node_modules/@smithy/util-endpoints/package.json +3 -3
- package/node_modules/@smithy/util-middleware/package.json +2 -2
- package/node_modules/@smithy/util-retry/package.json +3 -3
- package/node_modules/@smithy/util-stream/package.json +4 -4
- package/node_modules/@smithy/util-waiter/package.json +3 -3
- package/package.json +12 -11
@@ -0,0 +1,147 @@
|
|
1
|
+
import { collectBody, RpcProtocol } from "@smithy/core/protocols";
|
2
|
+
import { deref, NormalizedSchema, SCHEMA, TypeRegistry } from "@smithy/core/schema";
|
3
|
+
import { calculateBodyLength } from "@smithy/util-body-length-browser";
|
4
|
+
import { XmlShapeDeserializer } from "../xml/XmlShapeDeserializer";
|
5
|
+
import { QueryShapeSerializer } from "./QueryShapeSerializer";
|
6
|
+
export class AwsQueryProtocol extends RpcProtocol {
|
7
|
+
options;
|
8
|
+
serializer;
|
9
|
+
deserializer;
|
10
|
+
constructor(options) {
|
11
|
+
super({
|
12
|
+
defaultNamespace: options.defaultNamespace,
|
13
|
+
});
|
14
|
+
this.options = options;
|
15
|
+
const settings = {
|
16
|
+
timestampFormat: {
|
17
|
+
useTrait: true,
|
18
|
+
default: SCHEMA.TIMESTAMP_DATE_TIME,
|
19
|
+
},
|
20
|
+
httpBindings: false,
|
21
|
+
xmlNamespace: options.xmlNamespace,
|
22
|
+
serviceNamespace: options.defaultNamespace,
|
23
|
+
serializeEmptyLists: true,
|
24
|
+
};
|
25
|
+
this.serializer = new QueryShapeSerializer(settings);
|
26
|
+
this.deserializer = new XmlShapeDeserializer(settings);
|
27
|
+
}
|
28
|
+
getShapeId() {
|
29
|
+
return "aws.protocols#awsQuery";
|
30
|
+
}
|
31
|
+
setSerdeContext(serdeContext) {
|
32
|
+
this.serializer.setSerdeContext(serdeContext);
|
33
|
+
this.deserializer.setSerdeContext(serdeContext);
|
34
|
+
}
|
35
|
+
getPayloadCodec() {
|
36
|
+
throw new Error("AWSQuery protocol has no payload codec.");
|
37
|
+
}
|
38
|
+
async serializeRequest(operationSchema, input, context) {
|
39
|
+
const request = await super.serializeRequest(operationSchema, input, context);
|
40
|
+
if (!request.path.endsWith("/")) {
|
41
|
+
request.path += "/";
|
42
|
+
}
|
43
|
+
Object.assign(request.headers, {
|
44
|
+
"content-type": `application/x-www-form-urlencoded`,
|
45
|
+
});
|
46
|
+
if (deref(operationSchema.input) === "unit" || !request.body) {
|
47
|
+
request.body = "";
|
48
|
+
}
|
49
|
+
request.body = `Action=${operationSchema.name.split("#")[1]}&Version=${this.options.version}` + request.body;
|
50
|
+
if (request.body.endsWith("&")) {
|
51
|
+
request.body = request.body.slice(-1);
|
52
|
+
}
|
53
|
+
try {
|
54
|
+
request.headers["content-length"] = String(calculateBodyLength(request.body));
|
55
|
+
}
|
56
|
+
catch (e) { }
|
57
|
+
return request;
|
58
|
+
}
|
59
|
+
async deserializeResponse(operationSchema, context, response) {
|
60
|
+
const deserializer = this.deserializer;
|
61
|
+
const ns = NormalizedSchema.of(operationSchema.output);
|
62
|
+
const dataObject = {};
|
63
|
+
if (response.statusCode >= 300) {
|
64
|
+
const bytes = await collectBody(response.body, context);
|
65
|
+
if (bytes.byteLength > 0) {
|
66
|
+
Object.assign(dataObject, await deserializer.read(SCHEMA.DOCUMENT, bytes));
|
67
|
+
}
|
68
|
+
await this.handleError(operationSchema, context, response, dataObject, this.deserializeMetadata(response));
|
69
|
+
}
|
70
|
+
for (const header in response.headers) {
|
71
|
+
const value = response.headers[header];
|
72
|
+
delete response.headers[header];
|
73
|
+
response.headers[header.toLowerCase()] = value;
|
74
|
+
}
|
75
|
+
const awsQueryResultKey = ns.isStructSchema() && this.useNestedResult() ? operationSchema.name.split("#")[1] + "Result" : undefined;
|
76
|
+
const bytes = await collectBody(response.body, context);
|
77
|
+
if (bytes.byteLength > 0) {
|
78
|
+
Object.assign(dataObject, await deserializer.read(ns, bytes, awsQueryResultKey));
|
79
|
+
}
|
80
|
+
const output = {
|
81
|
+
$metadata: this.deserializeMetadata(response),
|
82
|
+
...dataObject,
|
83
|
+
};
|
84
|
+
return output;
|
85
|
+
}
|
86
|
+
useNestedResult() {
|
87
|
+
return true;
|
88
|
+
}
|
89
|
+
async handleError(operationSchema, context, response, dataObject, metadata) {
|
90
|
+
const errorIdentifier = this.loadQueryErrorCode(response, dataObject) ?? "Unknown";
|
91
|
+
let namespace = this.options.defaultNamespace;
|
92
|
+
let errorName = errorIdentifier;
|
93
|
+
if (errorIdentifier.includes("#")) {
|
94
|
+
[namespace, errorName] = errorIdentifier.split("#");
|
95
|
+
}
|
96
|
+
const errorDataSource = this.loadQueryError(dataObject);
|
97
|
+
const registry = TypeRegistry.for(namespace);
|
98
|
+
let errorSchema;
|
99
|
+
try {
|
100
|
+
errorSchema = registry.find((schema) => NormalizedSchema.of(schema).getMergedTraits().awsQueryError?.[0] === errorName);
|
101
|
+
if (!errorSchema) {
|
102
|
+
errorSchema = registry.getSchema(errorIdentifier);
|
103
|
+
}
|
104
|
+
}
|
105
|
+
catch (e) {
|
106
|
+
const baseExceptionSchema = TypeRegistry.for("smithy.ts.sdk.synthetic." + namespace).getBaseException();
|
107
|
+
if (baseExceptionSchema) {
|
108
|
+
const ErrorCtor = baseExceptionSchema.ctor;
|
109
|
+
throw Object.assign(new ErrorCtor(errorName), errorDataSource);
|
110
|
+
}
|
111
|
+
throw new Error(errorName);
|
112
|
+
}
|
113
|
+
const ns = NormalizedSchema.of(errorSchema);
|
114
|
+
const message = this.loadQueryErrorMessage(dataObject);
|
115
|
+
const exception = new errorSchema.ctor(message);
|
116
|
+
const output = {};
|
117
|
+
for (const [name, member] of ns.structIterator()) {
|
118
|
+
const target = member.getMergedTraits().xmlName ?? name;
|
119
|
+
const value = errorDataSource[target] ?? dataObject[target];
|
120
|
+
output[name] = this.deserializer.readSchema(member, value);
|
121
|
+
}
|
122
|
+
Object.assign(exception, {
|
123
|
+
$metadata: metadata,
|
124
|
+
$response: response,
|
125
|
+
$fault: ns.getMergedTraits().error,
|
126
|
+
message,
|
127
|
+
...output,
|
128
|
+
});
|
129
|
+
throw exception;
|
130
|
+
}
|
131
|
+
loadQueryErrorCode(output, data) {
|
132
|
+
const code = (data.Errors?.[0]?.Error ?? data.Errors?.Error ?? data.Error)?.Code;
|
133
|
+
if (code !== undefined) {
|
134
|
+
return code;
|
135
|
+
}
|
136
|
+
if (output.statusCode == 404) {
|
137
|
+
return "NotFound";
|
138
|
+
}
|
139
|
+
}
|
140
|
+
loadQueryError(data) {
|
141
|
+
return data.Errors?.[0]?.Error ?? data.Errors?.Error ?? data.Error;
|
142
|
+
}
|
143
|
+
loadQueryErrorMessage(data) {
|
144
|
+
const errorData = this.loadQueryError(data);
|
145
|
+
return errorData?.message ?? errorData?.Message ?? data.message ?? data.Message ?? "Unknown";
|
146
|
+
}
|
147
|
+
}
|
package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/query/QuerySerializerSettings.js
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,152 @@
|
|
1
|
+
import { determineTimestampFormat, extendedEncodeURIComponent } from "@smithy/core/protocols";
|
2
|
+
import { NormalizedSchema, SCHEMA } from "@smithy/core/schema";
|
3
|
+
import { NumericValue } from "@smithy/core/serde";
|
4
|
+
import { dateToUtcString } from "@smithy/smithy-client";
|
5
|
+
import { toBase64 } from "@smithy/util-base64";
|
6
|
+
import { SerdeContextConfig } from "../ConfigurableSerdeContext";
|
7
|
+
export class QueryShapeSerializer extends SerdeContextConfig {
|
8
|
+
settings;
|
9
|
+
buffer;
|
10
|
+
constructor(settings) {
|
11
|
+
super();
|
12
|
+
this.settings = settings;
|
13
|
+
}
|
14
|
+
write(schema, value, prefix = "") {
|
15
|
+
if (this.buffer === undefined) {
|
16
|
+
this.buffer = "";
|
17
|
+
}
|
18
|
+
const ns = NormalizedSchema.of(schema);
|
19
|
+
if (prefix && !prefix.endsWith(".")) {
|
20
|
+
prefix += ".";
|
21
|
+
}
|
22
|
+
if (ns.isBlobSchema()) {
|
23
|
+
if (typeof value === "string" || value instanceof Uint8Array) {
|
24
|
+
this.writeKey(prefix);
|
25
|
+
this.writeValue((this.serdeContext?.base64Encoder ?? toBase64)(value));
|
26
|
+
}
|
27
|
+
}
|
28
|
+
else if (ns.isBooleanSchema() || ns.isNumericSchema() || ns.isStringSchema()) {
|
29
|
+
if (value != null) {
|
30
|
+
this.writeKey(prefix);
|
31
|
+
this.writeValue(String(value));
|
32
|
+
}
|
33
|
+
}
|
34
|
+
else if (ns.isBigIntegerSchema()) {
|
35
|
+
if (value != null) {
|
36
|
+
this.writeKey(prefix);
|
37
|
+
this.writeValue(String(value));
|
38
|
+
}
|
39
|
+
}
|
40
|
+
else if (ns.isBigDecimalSchema()) {
|
41
|
+
if (value != null) {
|
42
|
+
this.writeKey(prefix);
|
43
|
+
this.writeValue(value instanceof NumericValue ? value.string : String(value));
|
44
|
+
}
|
45
|
+
}
|
46
|
+
else if (ns.isTimestampSchema()) {
|
47
|
+
if (value instanceof Date) {
|
48
|
+
this.writeKey(prefix);
|
49
|
+
const format = determineTimestampFormat(ns, this.settings);
|
50
|
+
switch (format) {
|
51
|
+
case SCHEMA.TIMESTAMP_DATE_TIME:
|
52
|
+
this.writeValue(value.toISOString().replace(".000Z", "Z"));
|
53
|
+
break;
|
54
|
+
case SCHEMA.TIMESTAMP_HTTP_DATE:
|
55
|
+
this.writeValue(dateToUtcString(value));
|
56
|
+
break;
|
57
|
+
case SCHEMA.TIMESTAMP_EPOCH_SECONDS:
|
58
|
+
this.writeValue(String(value.getTime() / 1000));
|
59
|
+
break;
|
60
|
+
}
|
61
|
+
}
|
62
|
+
}
|
63
|
+
else if (ns.isDocumentSchema()) {
|
64
|
+
throw new Error(`@aws-sdk/core/protocols - QuerySerializer unsupported document type ${ns.getName(true)}`);
|
65
|
+
}
|
66
|
+
else if (ns.isListSchema()) {
|
67
|
+
if (Array.isArray(value)) {
|
68
|
+
if (value.length === 0) {
|
69
|
+
if (this.settings.serializeEmptyLists) {
|
70
|
+
this.writeKey(prefix);
|
71
|
+
this.writeValue("");
|
72
|
+
}
|
73
|
+
}
|
74
|
+
else {
|
75
|
+
const member = ns.getValueSchema();
|
76
|
+
const flat = this.settings.flattenLists || ns.getMergedTraits().xmlFlattened;
|
77
|
+
let i = 1;
|
78
|
+
for (const item of value) {
|
79
|
+
if (item == null) {
|
80
|
+
continue;
|
81
|
+
}
|
82
|
+
const suffix = this.getKey("member", member.getMergedTraits().xmlName);
|
83
|
+
const key = flat ? `${prefix}${i}` : `${prefix}${suffix}.${i}`;
|
84
|
+
this.write(member, item, key);
|
85
|
+
++i;
|
86
|
+
}
|
87
|
+
}
|
88
|
+
}
|
89
|
+
}
|
90
|
+
else if (ns.isMapSchema()) {
|
91
|
+
if (value && typeof value === "object") {
|
92
|
+
const keySchema = ns.getKeySchema();
|
93
|
+
const memberSchema = ns.getValueSchema();
|
94
|
+
const flat = ns.getMergedTraits().xmlFlattened;
|
95
|
+
let i = 1;
|
96
|
+
for (const [k, v] of Object.entries(value)) {
|
97
|
+
if (v == null) {
|
98
|
+
continue;
|
99
|
+
}
|
100
|
+
const keySuffix = this.getKey("key", keySchema.getMergedTraits().xmlName);
|
101
|
+
const key = flat ? `${prefix}${i}.${keySuffix}` : `${prefix}entry.${i}.${keySuffix}`;
|
102
|
+
const valueSuffix = this.getKey("value", memberSchema.getMergedTraits().xmlName);
|
103
|
+
const valueKey = flat ? `${prefix}${i}.${valueSuffix}` : `${prefix}entry.${i}.${valueSuffix}`;
|
104
|
+
this.write(keySchema, k, key);
|
105
|
+
this.write(memberSchema, v, valueKey);
|
106
|
+
++i;
|
107
|
+
}
|
108
|
+
}
|
109
|
+
}
|
110
|
+
else if (ns.isStructSchema()) {
|
111
|
+
if (value && typeof value === "object") {
|
112
|
+
for (const [memberName, member] of ns.structIterator()) {
|
113
|
+
if (value[memberName] == null) {
|
114
|
+
continue;
|
115
|
+
}
|
116
|
+
const suffix = this.getKey(memberName, member.getMergedTraits().xmlName);
|
117
|
+
const key = `${prefix}${suffix}`;
|
118
|
+
this.write(member, value[memberName], key);
|
119
|
+
}
|
120
|
+
}
|
121
|
+
}
|
122
|
+
else if (ns.isUnitSchema()) {
|
123
|
+
}
|
124
|
+
else {
|
125
|
+
throw new Error(`@aws-sdk/core/protocols - QuerySerializer unrecognized schema type ${ns.getName(true)}`);
|
126
|
+
}
|
127
|
+
}
|
128
|
+
flush() {
|
129
|
+
if (this.buffer === undefined) {
|
130
|
+
throw new Error("@aws-sdk/core/protocols - QuerySerializer cannot flush with nothing written to buffer.");
|
131
|
+
}
|
132
|
+
const str = this.buffer;
|
133
|
+
delete this.buffer;
|
134
|
+
return str;
|
135
|
+
}
|
136
|
+
getKey(memberName, xmlName) {
|
137
|
+
const key = xmlName ?? memberName;
|
138
|
+
if (this.settings.capitalizeKeys) {
|
139
|
+
return key[0].toUpperCase() + key.slice(1);
|
140
|
+
}
|
141
|
+
return key;
|
142
|
+
}
|
143
|
+
writeKey(key) {
|
144
|
+
if (key.endsWith(".")) {
|
145
|
+
key = key.slice(0, key.length - 1);
|
146
|
+
}
|
147
|
+
this.buffer += `&${extendedEncodeURIComponent(key)}=`;
|
148
|
+
}
|
149
|
+
writeValue(value) {
|
150
|
+
this.buffer += extendedEncodeURIComponent(value);
|
151
|
+
}
|
152
|
+
}
|
@@ -0,0 +1,126 @@
|
|
1
|
+
import { HttpBindingProtocol, HttpInterceptingShapeDeserializer, HttpInterceptingShapeSerializer, } from "@smithy/core/protocols";
|
2
|
+
import { NormalizedSchema, SCHEMA, TypeRegistry } from "@smithy/core/schema";
|
3
|
+
import { calculateBodyLength } from "@smithy/util-body-length-browser";
|
4
|
+
import { loadRestXmlErrorCode } from "./parseXmlBody";
|
5
|
+
import { XmlCodec } from "./XmlCodec";
|
6
|
+
export class AwsRestXmlProtocol extends HttpBindingProtocol {
|
7
|
+
codec;
|
8
|
+
serializer;
|
9
|
+
deserializer;
|
10
|
+
constructor(options) {
|
11
|
+
super(options);
|
12
|
+
const settings = {
|
13
|
+
timestampFormat: {
|
14
|
+
useTrait: true,
|
15
|
+
default: SCHEMA.TIMESTAMP_DATE_TIME,
|
16
|
+
},
|
17
|
+
httpBindings: true,
|
18
|
+
xmlNamespace: options.xmlNamespace,
|
19
|
+
serviceNamespace: options.defaultNamespace,
|
20
|
+
};
|
21
|
+
this.codec = new XmlCodec(settings);
|
22
|
+
this.serializer = new HttpInterceptingShapeSerializer(this.codec.createSerializer(), settings);
|
23
|
+
this.deserializer = new HttpInterceptingShapeDeserializer(this.codec.createDeserializer(), settings);
|
24
|
+
}
|
25
|
+
getPayloadCodec() {
|
26
|
+
return this.codec;
|
27
|
+
}
|
28
|
+
getShapeId() {
|
29
|
+
return "aws.protocols#restXml";
|
30
|
+
}
|
31
|
+
async serializeRequest(operationSchema, input, context) {
|
32
|
+
const request = await super.serializeRequest(operationSchema, input, context);
|
33
|
+
const ns = NormalizedSchema.of(operationSchema.input);
|
34
|
+
const members = ns.getMemberSchemas();
|
35
|
+
request.path =
|
36
|
+
String(request.path)
|
37
|
+
.split("/")
|
38
|
+
.filter((segment) => {
|
39
|
+
return segment !== "{Bucket}";
|
40
|
+
})
|
41
|
+
.join("/") || "/";
|
42
|
+
if (!request.headers["content-type"]) {
|
43
|
+
const httpPayloadMember = Object.values(members).find((m) => {
|
44
|
+
return !!m.getMergedTraits().httpPayload;
|
45
|
+
});
|
46
|
+
if (httpPayloadMember) {
|
47
|
+
const mediaType = httpPayloadMember.getMergedTraits().mediaType;
|
48
|
+
if (mediaType) {
|
49
|
+
request.headers["content-type"] = mediaType;
|
50
|
+
}
|
51
|
+
else if (httpPayloadMember.isStringSchema()) {
|
52
|
+
request.headers["content-type"] = "text/plain";
|
53
|
+
}
|
54
|
+
else if (httpPayloadMember.isBlobSchema()) {
|
55
|
+
request.headers["content-type"] = "application/octet-stream";
|
56
|
+
}
|
57
|
+
else {
|
58
|
+
request.headers["content-type"] = "application/xml";
|
59
|
+
}
|
60
|
+
}
|
61
|
+
else if (!ns.isUnitSchema()) {
|
62
|
+
const hasBody = Object.values(members).find((m) => {
|
63
|
+
const { httpQuery, httpQueryParams, httpHeader, httpLabel, httpPrefixHeaders } = m.getMergedTraits();
|
64
|
+
return !httpQuery && !httpQueryParams && !httpHeader && !httpLabel && httpPrefixHeaders === void 0;
|
65
|
+
});
|
66
|
+
if (hasBody) {
|
67
|
+
request.headers["content-type"] = "application/xml";
|
68
|
+
}
|
69
|
+
}
|
70
|
+
}
|
71
|
+
if (request.headers["content-type"] === "application/xml") {
|
72
|
+
if (typeof request.body === "string") {
|
73
|
+
request.body = '<?xml version="1.0" encoding="UTF-8"?>' + request.body;
|
74
|
+
}
|
75
|
+
}
|
76
|
+
if (request.body) {
|
77
|
+
try {
|
78
|
+
request.headers["content-length"] = String(calculateBodyLength(request.body));
|
79
|
+
}
|
80
|
+
catch (e) { }
|
81
|
+
}
|
82
|
+
return request;
|
83
|
+
}
|
84
|
+
async deserializeResponse(operationSchema, context, response) {
|
85
|
+
return super.deserializeResponse(operationSchema, context, response);
|
86
|
+
}
|
87
|
+
async handleError(operationSchema, context, response, dataObject, metadata) {
|
88
|
+
const errorIdentifier = loadRestXmlErrorCode(response, dataObject) ?? "Unknown";
|
89
|
+
let namespace = this.options.defaultNamespace;
|
90
|
+
let errorName = errorIdentifier;
|
91
|
+
if (errorIdentifier.includes("#")) {
|
92
|
+
[namespace, errorName] = errorIdentifier.split("#");
|
93
|
+
}
|
94
|
+
const registry = TypeRegistry.for(namespace);
|
95
|
+
let errorSchema;
|
96
|
+
try {
|
97
|
+
errorSchema = registry.getSchema(errorIdentifier);
|
98
|
+
}
|
99
|
+
catch (e) {
|
100
|
+
const baseExceptionSchema = TypeRegistry.for("smithy.ts.sdk.synthetic." + namespace).getBaseException();
|
101
|
+
if (baseExceptionSchema) {
|
102
|
+
const ErrorCtor = baseExceptionSchema.ctor;
|
103
|
+
throw Object.assign(new ErrorCtor(errorName), dataObject);
|
104
|
+
}
|
105
|
+
throw new Error(errorName);
|
106
|
+
}
|
107
|
+
const ns = NormalizedSchema.of(errorSchema);
|
108
|
+
const message = dataObject.Error?.message ?? dataObject.Error?.Message ?? dataObject.message ?? dataObject.Message ?? "Unknown";
|
109
|
+
const exception = new errorSchema.ctor(message);
|
110
|
+
await this.deserializeHttpMessage(errorSchema, context, response, dataObject);
|
111
|
+
const output = {};
|
112
|
+
for (const [name, member] of ns.structIterator()) {
|
113
|
+
const target = member.getMergedTraits().xmlName ?? name;
|
114
|
+
const value = dataObject.Error?.[target] ?? dataObject[target];
|
115
|
+
output[name] = this.codec.createDeserializer().readSchema(member, value);
|
116
|
+
}
|
117
|
+
Object.assign(exception, {
|
118
|
+
$metadata: metadata,
|
119
|
+
$response: response,
|
120
|
+
$fault: ns.getMergedTraits().error,
|
121
|
+
message,
|
122
|
+
...output,
|
123
|
+
});
|
124
|
+
throw exception;
|
125
|
+
}
|
126
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import { SerdeContextConfig } from "../ConfigurableSerdeContext";
|
2
|
+
import { XmlShapeDeserializer } from "./XmlShapeDeserializer";
|
3
|
+
import { XmlShapeSerializer } from "./XmlShapeSerializer";
|
4
|
+
export class XmlCodec extends SerdeContextConfig {
|
5
|
+
settings;
|
6
|
+
constructor(settings) {
|
7
|
+
super();
|
8
|
+
this.settings = settings;
|
9
|
+
}
|
10
|
+
createSerializer() {
|
11
|
+
const serializer = new XmlShapeSerializer(this.settings);
|
12
|
+
serializer.setSerdeContext(this.serdeContext);
|
13
|
+
return serializer;
|
14
|
+
}
|
15
|
+
createDeserializer() {
|
16
|
+
const deserializer = new XmlShapeDeserializer(this.settings);
|
17
|
+
deserializer.setSerdeContext(this.serdeContext);
|
18
|
+
return deserializer;
|
19
|
+
}
|
20
|
+
}
|
@@ -0,0 +1,154 @@
|
|
1
|
+
import { FromStringShapeDeserializer } from "@smithy/core/protocols";
|
2
|
+
import { NormalizedSchema } from "@smithy/core/schema";
|
3
|
+
import { getValueFromTextNode } from "@smithy/smithy-client";
|
4
|
+
import { toUtf8 } from "@smithy/util-utf8";
|
5
|
+
import { XMLParser } from "fast-xml-parser";
|
6
|
+
import { SerdeContextConfig } from "../ConfigurableSerdeContext";
|
7
|
+
export class XmlShapeDeserializer extends SerdeContextConfig {
|
8
|
+
settings;
|
9
|
+
stringDeserializer;
|
10
|
+
constructor(settings) {
|
11
|
+
super();
|
12
|
+
this.settings = settings;
|
13
|
+
this.stringDeserializer = new FromStringShapeDeserializer(settings);
|
14
|
+
}
|
15
|
+
setSerdeContext(serdeContext) {
|
16
|
+
this.serdeContext = serdeContext;
|
17
|
+
this.stringDeserializer.setSerdeContext(serdeContext);
|
18
|
+
}
|
19
|
+
read(schema, bytes, key) {
|
20
|
+
const ns = NormalizedSchema.of(schema);
|
21
|
+
const memberSchemas = ns.getMemberSchemas();
|
22
|
+
const isEventPayload = ns.isStructSchema() &&
|
23
|
+
ns.isMemberSchema() &&
|
24
|
+
!!Object.values(memberSchemas).find((memberNs) => {
|
25
|
+
return !!memberNs.getMemberTraits().eventPayload;
|
26
|
+
});
|
27
|
+
if (isEventPayload) {
|
28
|
+
const output = {};
|
29
|
+
const memberName = Object.keys(memberSchemas)[0];
|
30
|
+
const eventMemberSchema = memberSchemas[memberName];
|
31
|
+
if (eventMemberSchema.isBlobSchema()) {
|
32
|
+
output[memberName] = bytes;
|
33
|
+
}
|
34
|
+
else {
|
35
|
+
output[memberName] = this.read(memberSchemas[memberName], bytes);
|
36
|
+
}
|
37
|
+
return output;
|
38
|
+
}
|
39
|
+
const xmlString = (this.serdeContext?.utf8Encoder ?? toUtf8)(bytes);
|
40
|
+
const parsedObject = this.parseXml(xmlString);
|
41
|
+
return this.readSchema(schema, key ? parsedObject[key] : parsedObject);
|
42
|
+
}
|
43
|
+
readSchema(_schema, value) {
|
44
|
+
const ns = NormalizedSchema.of(_schema);
|
45
|
+
const traits = ns.getMergedTraits();
|
46
|
+
const schema = ns.getSchema();
|
47
|
+
if (ns.isListSchema() && !Array.isArray(value)) {
|
48
|
+
return this.readSchema(schema, [value]);
|
49
|
+
}
|
50
|
+
if (value == null) {
|
51
|
+
return value;
|
52
|
+
}
|
53
|
+
if (typeof value === "object") {
|
54
|
+
const sparse = !!traits.sparse;
|
55
|
+
const flat = !!traits.xmlFlattened;
|
56
|
+
if (ns.isListSchema()) {
|
57
|
+
const listValue = ns.getValueSchema();
|
58
|
+
const buffer = [];
|
59
|
+
const sourceKey = listValue.getMergedTraits().xmlName ?? "member";
|
60
|
+
const source = flat ? value : (value[0] ?? value)[sourceKey];
|
61
|
+
const sourceArray = Array.isArray(source) ? source : [source];
|
62
|
+
for (const v of sourceArray) {
|
63
|
+
if (v != null || sparse) {
|
64
|
+
buffer.push(this.readSchema(listValue, v));
|
65
|
+
}
|
66
|
+
}
|
67
|
+
return buffer;
|
68
|
+
}
|
69
|
+
const buffer = {};
|
70
|
+
if (ns.isMapSchema()) {
|
71
|
+
const keyNs = ns.getKeySchema();
|
72
|
+
const memberNs = ns.getValueSchema();
|
73
|
+
let entries;
|
74
|
+
if (flat) {
|
75
|
+
entries = Array.isArray(value) ? value : [value];
|
76
|
+
}
|
77
|
+
else {
|
78
|
+
entries = Array.isArray(value.entry) ? value.entry : [value.entry];
|
79
|
+
}
|
80
|
+
const keyProperty = keyNs.getMergedTraits().xmlName ?? "key";
|
81
|
+
const valueProperty = memberNs.getMergedTraits().xmlName ?? "value";
|
82
|
+
for (const entry of entries) {
|
83
|
+
const key = entry[keyProperty];
|
84
|
+
const value = entry[valueProperty];
|
85
|
+
if (value != null || sparse) {
|
86
|
+
buffer[key] = this.readSchema(memberNs, value);
|
87
|
+
}
|
88
|
+
}
|
89
|
+
return buffer;
|
90
|
+
}
|
91
|
+
if (ns.isStructSchema()) {
|
92
|
+
for (const [memberName, memberSchema] of ns.structIterator()) {
|
93
|
+
const memberTraits = memberSchema.getMergedTraits();
|
94
|
+
const xmlObjectKey = !memberTraits.httpPayload
|
95
|
+
? memberSchema.getMemberTraits().xmlName ?? memberName
|
96
|
+
: memberTraits.xmlName ?? memberSchema.getName();
|
97
|
+
if (value[xmlObjectKey] != null) {
|
98
|
+
buffer[memberName] = this.readSchema(memberSchema, value[xmlObjectKey]);
|
99
|
+
}
|
100
|
+
}
|
101
|
+
return buffer;
|
102
|
+
}
|
103
|
+
if (ns.isDocumentSchema()) {
|
104
|
+
return value;
|
105
|
+
}
|
106
|
+
throw new Error(`@aws-sdk/core/protocols - xml deserializer unhandled schema type for ${ns.getName(true)}`);
|
107
|
+
}
|
108
|
+
else {
|
109
|
+
if (ns.isListSchema()) {
|
110
|
+
return [];
|
111
|
+
}
|
112
|
+
else if (ns.isMapSchema() || ns.isStructSchema()) {
|
113
|
+
return {};
|
114
|
+
}
|
115
|
+
return this.stringDeserializer.read(ns, value);
|
116
|
+
}
|
117
|
+
}
|
118
|
+
parseXml(xml) {
|
119
|
+
if (xml.length) {
|
120
|
+
const parser = new XMLParser({
|
121
|
+
attributeNamePrefix: "",
|
122
|
+
htmlEntities: true,
|
123
|
+
ignoreAttributes: false,
|
124
|
+
ignoreDeclaration: true,
|
125
|
+
parseTagValue: false,
|
126
|
+
trimValues: false,
|
127
|
+
tagValueProcessor: (_, val) => (val.trim() === "" && val.includes("\n") ? "" : undefined),
|
128
|
+
});
|
129
|
+
parser.addEntity("#xD", "\r");
|
130
|
+
parser.addEntity("#10", "\n");
|
131
|
+
let parsedObj;
|
132
|
+
try {
|
133
|
+
parsedObj = parser.parse(xml, true);
|
134
|
+
}
|
135
|
+
catch (e) {
|
136
|
+
if (e && typeof e === "object") {
|
137
|
+
Object.defineProperty(e, "$responseBodyText", {
|
138
|
+
value: xml,
|
139
|
+
});
|
140
|
+
}
|
141
|
+
throw e;
|
142
|
+
}
|
143
|
+
const textNodeName = "#text";
|
144
|
+
const key = Object.keys(parsedObj)[0];
|
145
|
+
const parsedObjToReturn = parsedObj[key];
|
146
|
+
if (parsedObjToReturn[textNodeName]) {
|
147
|
+
parsedObjToReturn[key] = parsedObjToReturn[textNodeName];
|
148
|
+
delete parsedObjToReturn[textNodeName];
|
149
|
+
}
|
150
|
+
return getValueFromTextNode(parsedObjToReturn);
|
151
|
+
}
|
152
|
+
return {};
|
153
|
+
}
|
154
|
+
}
|