@cdk8s/awscdk-resolver 0.0.304 → 0.0.306

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.
Files changed (115) hide show
  1. package/.jsii +3 -3
  2. package/lib/resolve.js +1 -1
  3. package/node_modules/@aws-sdk/client-cloudformation/package.json +5 -5
  4. package/node_modules/@aws-sdk/client-sso/package.json +4 -4
  5. package/node_modules/@aws-sdk/core/dist-cjs/submodules/protocols/index.js +1466 -14
  6. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/ConfigurableSerdeContext.js +6 -0
  7. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/index.js +13 -0
  8. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/AwsJson1_0Protocol.js +14 -0
  9. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/AwsJson1_1Protocol.js +14 -0
  10. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/AwsJsonRpcProtocol.js +89 -0
  11. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/AwsRestJsonProtocol.js +123 -0
  12. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/JsonCodec.js +20 -0
  13. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/JsonShapeDeserializer.js +105 -0
  14. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/JsonShapeSerializer.js +106 -0
  15. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/jsonReplacer.js +46 -0
  16. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/jsonReviver.js +18 -0
  17. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/query/AwsEc2QueryProtocol.js +3 -0
  18. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/query/AwsQueryProtocol.js +134 -0
  19. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/query/QueryShapeSerializer.js +143 -0
  20. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/xml/AwsRestXmlProtocol.js +131 -0
  21. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/xml/XmlCodec.js +20 -0
  22. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/xml/XmlShapeDeserializer.js +154 -0
  23. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/xml/XmlShapeSerializer.js +279 -0
  24. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/xml/simpleFormatXml.js +27 -0
  25. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/ConfigurableSerdeContext.d.ts +8 -0
  26. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/common.d.ts +2 -2
  27. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/index.d.ts +13 -0
  28. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/json/AwsJson1_0Protocol.d.ts +12 -0
  29. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/json/AwsJson1_1Protocol.d.ts +12 -0
  30. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/json/AwsJsonRpcProtocol.d.ts +18 -0
  31. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/json/AwsRestJsonProtocol.d.ts +19 -0
  32. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/json/JsonCodec.d.ts +19 -0
  33. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/json/JsonShapeDeserializer.d.ts +13 -0
  34. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/json/JsonShapeSerializer.d.ts +15 -0
  35. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/json/jsonReplacer.d.ts +21 -0
  36. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/json/jsonReviver.d.ts +15 -0
  37. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/json/parseJsonBody.d.ts +3 -3
  38. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/query/AwsEc2QueryProtocol.d.ts +6 -0
  39. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/query/AwsQueryProtocol.d.ts +29 -0
  40. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/query/QueryShapeSerializer.d.ts +14 -0
  41. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/xml/AwsRestXmlProtocol.d.ts +21 -0
  42. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/xml/XmlCodec.d.ts +14 -0
  43. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/xml/XmlShapeDeserializer.d.ts +20 -0
  44. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/xml/XmlShapeSerializer.d.ts +21 -0
  45. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/xml/simpleFormatXml.d.ts +6 -0
  46. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/ConfigurableSerdeContext.d.ts +5 -0
  47. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/common.d.ts +2 -2
  48. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/index.d.ts +13 -0
  49. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/json/AwsJson1_0Protocol.d.ts +6 -0
  50. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/json/AwsJson1_1Protocol.d.ts +6 -0
  51. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/json/AwsJsonRpcProtocol.d.ts +33 -0
  52. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/json/AwsRestJsonProtocol.d.ts +34 -0
  53. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/json/JsonCodec.d.ts +16 -0
  54. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/json/JsonShapeDeserializer.d.ts +13 -0
  55. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/json/JsonShapeSerializer.d.ts +15 -0
  56. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/json/jsonReplacer.d.ts +7 -0
  57. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/json/jsonReviver.d.ts +7 -0
  58. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/json/parseJsonBody.d.ts +3 -3
  59. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/query/AwsEc2QueryProtocol.d.ts +2 -0
  60. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/query/AwsQueryProtocol.d.ts +52 -0
  61. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/query/QueryShapeSerializer.d.ts +14 -0
  62. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/xml/AwsRestXmlProtocol.d.ts +39 -0
  63. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/xml/XmlCodec.d.ts +17 -0
  64. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/xml/XmlShapeDeserializer.d.ts +15 -0
  65. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/xml/XmlShapeSerializer.d.ts +21 -0
  66. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/xml/simpleFormatXml.d.ts +1 -0
  67. package/node_modules/@aws-sdk/core/package.json +5 -1
  68. package/node_modules/@aws-sdk/credential-provider-env/package.json +2 -2
  69. package/node_modules/@aws-sdk/credential-provider-http/package.json +2 -2
  70. package/node_modules/@aws-sdk/credential-provider-ini/package.json +8 -8
  71. package/node_modules/@aws-sdk/credential-provider-node/package.json +7 -7
  72. package/node_modules/@aws-sdk/credential-provider-process/package.json +2 -2
  73. package/node_modules/@aws-sdk/credential-provider-sso/package.json +4 -4
  74. package/node_modules/@aws-sdk/credential-provider-web-identity/package.json +3 -3
  75. package/node_modules/@aws-sdk/middleware-user-agent/package.json +2 -2
  76. package/node_modules/@aws-sdk/nested-clients/package.json +4 -4
  77. package/node_modules/@aws-sdk/token-providers/package.json +3 -3
  78. package/node_modules/@aws-sdk/util-user-agent-node/package.json +2 -2
  79. package/node_modules/@aws-sdk/xml-builder/LICENSE +201 -0
  80. package/node_modules/@aws-sdk/xml-builder/README.md +10 -0
  81. package/node_modules/@aws-sdk/xml-builder/dist-cjs/index.js +173 -0
  82. package/node_modules/@aws-sdk/xml-builder/dist-es/XmlNode.js +88 -0
  83. package/node_modules/@aws-sdk/xml-builder/dist-es/XmlText.js +10 -0
  84. package/node_modules/@aws-sdk/xml-builder/dist-es/escape-attribute.js +3 -0
  85. package/node_modules/@aws-sdk/xml-builder/dist-es/escape-element.js +12 -0
  86. package/node_modules/@aws-sdk/xml-builder/dist-es/index.js +2 -0
  87. package/node_modules/@aws-sdk/xml-builder/dist-es/stringable.js +1 -0
  88. package/node_modules/@aws-sdk/xml-builder/dist-types/XmlNode.d.ts +49 -0
  89. package/node_modules/@aws-sdk/xml-builder/dist-types/XmlText.d.ts +11 -0
  90. package/node_modules/@aws-sdk/xml-builder/dist-types/escape-attribute.d.ts +6 -0
  91. package/node_modules/@aws-sdk/xml-builder/dist-types/escape-element.d.ts +6 -0
  92. package/node_modules/@aws-sdk/xml-builder/dist-types/index.d.ts +8 -0
  93. package/node_modules/@aws-sdk/xml-builder/dist-types/stringable.d.ts +6 -0
  94. package/node_modules/@aws-sdk/xml-builder/dist-types/ts3.4/XmlNode.d.ts +29 -0
  95. package/node_modules/@aws-sdk/xml-builder/dist-types/ts3.4/XmlText.d.ts +6 -0
  96. package/node_modules/@aws-sdk/xml-builder/dist-types/ts3.4/escape-attribute.d.ts +1 -0
  97. package/node_modules/@aws-sdk/xml-builder/dist-types/ts3.4/escape-element.d.ts +1 -0
  98. package/node_modules/@aws-sdk/xml-builder/dist-types/ts3.4/index.d.ts +2 -0
  99. package/node_modules/@aws-sdk/xml-builder/dist-types/ts3.4/stringable.d.ts +3 -0
  100. package/node_modules/@aws-sdk/xml-builder/package.json +54 -0
  101. package/node_modules/@smithy/core/dist-cjs/submodules/protocols/index.js +9 -8
  102. package/node_modules/@smithy/core/dist-cjs/submodules/schema/index.js +4 -1
  103. package/node_modules/@smithy/core/dist-es/submodules/protocols/HttpBindingProtocol.js +1 -6
  104. package/node_modules/@smithy/core/dist-es/submodules/protocols/HttpProtocol.js +9 -2
  105. package/node_modules/@smithy/core/dist-es/submodules/schema/TypeRegistry.js +1 -1
  106. package/node_modules/@smithy/core/dist-es/submodules/schema/schemas/NormalizedSchema.js +3 -0
  107. package/node_modules/@smithy/core/dist-types/submodules/protocols/HttpProtocol.d.ts +4 -0
  108. package/node_modules/@smithy/core/dist-types/ts3.4/submodules/protocols/HttpProtocol.d.ts +4 -0
  109. package/node_modules/@smithy/core/package.json +1 -1
  110. package/node_modules/@smithy/middleware-endpoint/package.json +2 -2
  111. package/node_modules/@smithy/middleware-retry/package.json +2 -2
  112. package/node_modules/@smithy/smithy-client/package.json +3 -3
  113. package/node_modules/@smithy/util-defaults-mode-browser/package.json +2 -2
  114. package/node_modules/@smithy/util-defaults-mode-node/package.json +2 -2
  115. package/package.json +4 -4
@@ -0,0 +1,134 @@
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
+ };
24
+ this.serializer = new QueryShapeSerializer(settings);
25
+ this.deserializer = new XmlShapeDeserializer(settings);
26
+ }
27
+ getShapeId() {
28
+ return "aws.protocols#awsQuery";
29
+ }
30
+ setSerdeContext(serdeContext) {
31
+ this.serializer.setSerdeContext(serdeContext);
32
+ this.deserializer.setSerdeContext(serdeContext);
33
+ }
34
+ getPayloadCodec() {
35
+ throw new Error("AWSQuery protocol has no payload codec.");
36
+ }
37
+ async serializeRequest(operationSchema, input, context) {
38
+ const request = await super.serializeRequest(operationSchema, input, context);
39
+ if (!request.path.endsWith("/")) {
40
+ request.path += "/";
41
+ }
42
+ Object.assign(request.headers, {
43
+ "content-type": `application/x-www-form-urlencoded`,
44
+ });
45
+ if (deref(operationSchema.input) === "unit" || !request.body) {
46
+ request.body = "";
47
+ }
48
+ request.body = `Action=${operationSchema.name.split("#")[1]}&Version=${this.options.version}` + request.body;
49
+ if (request.body.endsWith("&")) {
50
+ request.body = request.body.slice(-1);
51
+ }
52
+ try {
53
+ request.headers["content-length"] = String(calculateBodyLength(request.body));
54
+ }
55
+ catch (e) { }
56
+ return request;
57
+ }
58
+ async deserializeResponse(operationSchema, context, response) {
59
+ const deserializer = this.deserializer;
60
+ const ns = NormalizedSchema.of(operationSchema.output);
61
+ const dataObject = {};
62
+ if (response.statusCode >= 300) {
63
+ const bytes = await collectBody(response.body, context);
64
+ if (bytes.byteLength > 0) {
65
+ Object.assign(dataObject, await deserializer.read(SCHEMA.DOCUMENT, bytes));
66
+ }
67
+ await this.handleError(operationSchema, context, response, dataObject, this.deserializeMetadata(response));
68
+ }
69
+ for (const header in response.headers) {
70
+ const value = response.headers[header];
71
+ delete response.headers[header];
72
+ response.headers[header.toLowerCase()] = value;
73
+ }
74
+ const awsQueryResultKey = ns.isStructSchema() ? operationSchema.name.split("#")[1] + "Result" : undefined;
75
+ const bytes = await collectBody(response.body, context);
76
+ if (bytes.byteLength > 0) {
77
+ Object.assign(dataObject, await deserializer.read(ns, bytes, awsQueryResultKey));
78
+ }
79
+ const output = {
80
+ $metadata: this.deserializeMetadata(response),
81
+ ...dataObject,
82
+ };
83
+ return output;
84
+ }
85
+ async handleError(operationSchema, context, response, dataObject, metadata) {
86
+ const errorIdentifier = this.loadQueryErrorCode(response, dataObject) ?? "Unknown";
87
+ let namespace = this.options.defaultNamespace;
88
+ let errorName = errorIdentifier;
89
+ if (errorIdentifier.includes("#")) {
90
+ [namespace, errorName] = errorIdentifier.split("#");
91
+ }
92
+ const registry = TypeRegistry.for(namespace);
93
+ let errorSchema;
94
+ try {
95
+ errorSchema = registry.find((schema) => NormalizedSchema.of(schema).getMergedTraits().awsQueryError?.[0] === errorName);
96
+ if (!errorSchema) {
97
+ errorSchema = registry.getSchema(errorIdentifier);
98
+ }
99
+ }
100
+ catch (e) {
101
+ const baseExceptionSchema = TypeRegistry.for("awssdkjs.synthetic." + namespace).getBaseException();
102
+ if (baseExceptionSchema) {
103
+ const ErrorCtor = baseExceptionSchema.ctor;
104
+ throw Object.assign(new ErrorCtor(errorName), dataObject);
105
+ }
106
+ throw new Error(errorName);
107
+ }
108
+ const ns = NormalizedSchema.of(errorSchema);
109
+ const message = dataObject.Error?.message ?? dataObject.Error?.Message ?? dataObject.message ?? dataObject.Message ?? "Unknown";
110
+ const exception = new errorSchema.ctor(message);
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.deserializer.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
+ loadQueryErrorCode(output, data) {
127
+ if (data.Error?.Code !== undefined) {
128
+ return data.Error.Code;
129
+ }
130
+ if (output.statusCode == 404) {
131
+ return "NotFound";
132
+ }
133
+ }
134
+ }
@@ -0,0 +1,143 @@
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
+ this.writeKey(prefix);
70
+ this.writeValue("");
71
+ }
72
+ else {
73
+ const member = ns.getValueSchema();
74
+ const flat = ns.getMergedTraits().xmlFlattened;
75
+ let i = 1;
76
+ for (const item of value) {
77
+ if (item == null) {
78
+ continue;
79
+ }
80
+ const suffix = member.getMergedTraits().xmlName ?? "member";
81
+ const key = flat ? `${prefix}${i}` : `${prefix}${suffix}.${i}`;
82
+ this.write(member, item, key);
83
+ ++i;
84
+ }
85
+ }
86
+ }
87
+ }
88
+ else if (ns.isMapSchema()) {
89
+ if (value && typeof value === "object") {
90
+ const keySchema = ns.getKeySchema();
91
+ const memberSchema = ns.getValueSchema();
92
+ const flat = ns.getMergedTraits().xmlFlattened;
93
+ let i = 1;
94
+ for (const [k, v] of Object.entries(value)) {
95
+ if (v == null) {
96
+ continue;
97
+ }
98
+ const keySuffix = keySchema.getMergedTraits().xmlName ?? "key";
99
+ const key = flat ? `${prefix}${i}.${keySuffix}` : `${prefix}entry.${i}.${keySuffix}`;
100
+ const valueSuffix = memberSchema.getMergedTraits().xmlName ?? "value";
101
+ const valueKey = flat ? `${prefix}${i}.${valueSuffix}` : `${prefix}entry.${i}.${valueSuffix}`;
102
+ this.write(keySchema, k, key);
103
+ this.write(memberSchema, v, valueKey);
104
+ ++i;
105
+ }
106
+ }
107
+ }
108
+ else if (ns.isStructSchema()) {
109
+ if (value && typeof value === "object") {
110
+ for (const [memberName, member] of ns.structIterator()) {
111
+ if (value[memberName] == null) {
112
+ continue;
113
+ }
114
+ const suffix = member.getMergedTraits().xmlName ?? memberName;
115
+ const key = `${prefix}${suffix}`;
116
+ this.write(member, value[memberName], key);
117
+ }
118
+ }
119
+ }
120
+ else if (ns.isUnitSchema()) {
121
+ }
122
+ else {
123
+ throw new Error(`@aws-sdk/core/protocols - QuerySerializer unrecognized schema type ${ns.getName(true)}`);
124
+ }
125
+ }
126
+ flush() {
127
+ if (this.buffer === undefined) {
128
+ throw new Error("@aws-sdk/core/protocols - QuerySerializer cannot flush with nothing written to buffer.");
129
+ }
130
+ const str = this.buffer;
131
+ delete this.buffer;
132
+ return str;
133
+ }
134
+ writeKey(key) {
135
+ if (key.endsWith(".")) {
136
+ key = key.slice(0, key.length - 1);
137
+ }
138
+ this.buffer += `&${extendedEncodeURIComponent(key)}=`;
139
+ }
140
+ writeValue(value) {
141
+ this.buffer += extendedEncodeURIComponent(value);
142
+ }
143
+ }
@@ -0,0 +1,131 @@
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("awssdkjs.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
+ const headerBindings = new Set(Object.values(NormalizedSchema.of(errorSchema).getMemberSchemas())
111
+ .map((schema) => {
112
+ return schema.getMergedTraits().httpHeader;
113
+ })
114
+ .filter(Boolean));
115
+ await this.deserializeHttpMessage(errorSchema, context, response, headerBindings, dataObject);
116
+ const output = {};
117
+ for (const [name, member] of ns.structIterator()) {
118
+ const target = member.getMergedTraits().xmlName ?? name;
119
+ const value = dataObject.Error?.[target] ?? dataObject[target];
120
+ output[name] = this.codec.createDeserializer().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
+ }
@@ -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
+ }