@cdk8s/awscdk-resolver 0.0.348 → 0.0.350

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 (104) hide show
  1. package/.jsii +3 -3
  2. package/lib/resolve.js +1 -1
  3. package/node_modules/@aws-sdk/client-cloudformation/package.json +12 -12
  4. package/node_modules/@aws-sdk/client-sso/package.json +11 -11
  5. package/node_modules/@aws-sdk/core/dist-cjs/submodules/protocols/index.js +320 -216
  6. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/ProtocolLib.js +94 -0
  7. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/cbor/AwsSmithyRpcV2CborProtocol.js +39 -0
  8. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/common.js +2 -1
  9. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/index.js +1 -0
  10. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/AwsJson1_0Protocol.js +2 -1
  11. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/AwsJson1_1Protocol.js +2 -1
  12. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/AwsJsonRpcProtocol.js +17 -31
  13. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/AwsRestJsonProtocol.js +8 -56
  14. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/query/AwsQueryProtocol.js +5 -32
  15. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/xml/AwsRestXmlProtocol.js +9 -57
  16. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/ProtocolLib.d.ts +57 -0
  17. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/cbor/AwsSmithyRpcV2CborProtocol.d.ts +23 -0
  18. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/index.d.ts +1 -0
  19. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/json/AwsJson1_0Protocol.d.ts +2 -1
  20. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/json/AwsJson1_1Protocol.d.ts +2 -1
  21. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/json/AwsJsonRpcProtocol.d.ts +6 -3
  22. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/json/AwsRestJsonProtocol.d.ts +2 -1
  23. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/query/AwsQueryProtocol.d.ts +2 -2
  24. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/xml/AwsRestXmlProtocol.d.ts +1 -0
  25. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/ProtocolLib.d.ts +39 -0
  26. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/cbor/AwsSmithyRpcV2CborProtocol.d.ts +33 -0
  27. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/index.d.ts +1 -0
  28. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/json/AwsJson1_0Protocol.d.ts +2 -0
  29. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/json/AwsJson1_1Protocol.d.ts +2 -0
  30. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/json/AwsJsonRpcProtocol.d.ts +5 -1
  31. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/json/AwsRestJsonProtocol.d.ts +1 -0
  32. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/query/AwsQueryProtocol.d.ts +2 -1
  33. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/xml/AwsRestXmlProtocol.d.ts +1 -0
  34. package/node_modules/@aws-sdk/core/package.json +3 -3
  35. package/node_modules/@aws-sdk/credential-provider-env/package.json +2 -2
  36. package/node_modules/@aws-sdk/credential-provider-http/package.json +3 -3
  37. package/node_modules/@aws-sdk/credential-provider-ini/package.json +8 -8
  38. package/node_modules/@aws-sdk/credential-provider-node/package.json +7 -7
  39. package/node_modules/@aws-sdk/credential-provider-process/package.json +2 -2
  40. package/node_modules/@aws-sdk/credential-provider-sso/package.json +4 -4
  41. package/node_modules/@aws-sdk/credential-provider-web-identity/package.json +3 -3
  42. package/node_modules/@aws-sdk/middleware-user-agent/package.json +4 -4
  43. package/node_modules/@aws-sdk/nested-clients/package.json +11 -11
  44. package/node_modules/@aws-sdk/token-providers/package.json +3 -3
  45. package/node_modules/@aws-sdk/util-endpoints/dist-cjs/index.js +4 -1
  46. package/node_modules/@aws-sdk/util-endpoints/dist-cjs/lib/aws/partitions.json +4 -1
  47. package/node_modules/@aws-sdk/util-endpoints/dist-es/lib/aws/partitions.json +4 -1
  48. package/node_modules/@aws-sdk/util-endpoints/package.json +1 -1
  49. package/node_modules/@aws-sdk/util-user-agent-node/package.json +2 -2
  50. package/node_modules/@smithy/core/dist-cjs/submodules/cbor/index.js +44 -15
  51. package/node_modules/@smithy/core/dist-cjs/submodules/event-streams/index.js +261 -0
  52. package/node_modules/@smithy/core/dist-cjs/submodules/protocols/index.js +129 -39
  53. package/node_modules/@smithy/core/dist-cjs/submodules/schema/index.js +25 -0
  54. package/node_modules/@smithy/core/dist-es/submodules/cbor/SmithyRpcV2CborProtocol.js +36 -15
  55. package/node_modules/@smithy/core/dist-es/submodules/event-streams/EventStreamSerde.js +200 -0
  56. package/node_modules/@smithy/core/dist-es/submodules/event-streams/index.js +1 -0
  57. package/node_modules/@smithy/core/dist-es/submodules/protocols/HttpBindingProtocol.js +11 -26
  58. package/node_modules/@smithy/core/dist-es/submodules/protocols/HttpProtocol.js +36 -0
  59. package/node_modules/@smithy/core/dist-es/submodules/protocols/RpcProtocol.js +36 -10
  60. package/node_modules/@smithy/core/dist-es/submodules/protocols/index.js +1 -0
  61. package/node_modules/@smithy/core/dist-es/submodules/schema/schemas/NormalizedSchema.js +17 -0
  62. package/node_modules/@smithy/core/dist-types/submodules/cbor/CborCodec.d.ts +6 -2
  63. package/node_modules/@smithy/core/dist-types/submodules/cbor/SmithyRpcV2CborProtocol.d.ts +1 -0
  64. package/node_modules/@smithy/core/dist-types/submodules/cbor/parseCborBody.d.ts +1 -1
  65. package/node_modules/@smithy/core/dist-types/submodules/event-streams/EventStreamSerde.d.ts +60 -0
  66. package/node_modules/@smithy/core/dist-types/submodules/event-streams/index.d.ts +1 -0
  67. package/node_modules/@smithy/core/dist-types/submodules/protocols/HttpBindingProtocol.d.ts +1 -1
  68. package/node_modules/@smithy/core/dist-types/submodules/protocols/HttpProtocol.d.ts +39 -1
  69. package/node_modules/@smithy/core/dist-types/submodules/protocols/RpcProtocol.d.ts +1 -1
  70. package/node_modules/@smithy/core/dist-types/submodules/protocols/index.d.ts +1 -0
  71. package/node_modules/@smithy/core/dist-types/submodules/protocols/serde/FromStringShapeDeserializer.d.ts +1 -1
  72. package/node_modules/@smithy/core/dist-types/submodules/protocols/serde/HttpInterceptingShapeDeserializer.d.ts +1 -1
  73. package/node_modules/@smithy/core/dist-types/submodules/protocols/serde/HttpInterceptingShapeSerializer.d.ts +1 -1
  74. package/node_modules/@smithy/core/dist-types/submodules/protocols/serde/ToStringShapeSerializer.d.ts +1 -1
  75. package/node_modules/@smithy/core/dist-types/submodules/protocols/serde/determineTimestampFormat.d.ts +1 -1
  76. package/node_modules/@smithy/core/dist-types/submodules/schema/middleware/getSchemaSerdePlugin.d.ts +1 -1
  77. package/node_modules/@smithy/core/dist-types/submodules/schema/middleware/schemaDeserializationMiddleware.d.ts +1 -1
  78. package/node_modules/@smithy/core/dist-types/submodules/schema/schemas/NormalizedSchema.d.ts +10 -0
  79. package/node_modules/@smithy/core/dist-types/submodules/schema/schemas/SimpleSchema.d.ts +1 -1
  80. package/node_modules/@smithy/core/dist-types/submodules/schema/schemas/sentinels.d.ts +1 -1
  81. package/node_modules/@smithy/core/dist-types/submodules/serde/copyDocumentWithTransform.d.ts +1 -1
  82. package/node_modules/@smithy/core/dist-types/ts3.4/submodules/cbor/CborCodec.d.ts +5 -1
  83. package/node_modules/@smithy/core/dist-types/ts3.4/submodules/cbor/SmithyRpcV2CborProtocol.d.ts +1 -0
  84. package/node_modules/@smithy/core/dist-types/ts3.4/submodules/event-streams/EventStreamSerde.d.ts +60 -0
  85. package/node_modules/@smithy/core/dist-types/ts3.4/submodules/event-streams/index.d.ts +1 -0
  86. package/node_modules/@smithy/core/dist-types/ts3.4/submodules/protocols/HttpProtocol.d.ts +39 -1
  87. package/node_modules/@smithy/core/dist-types/ts3.4/submodules/protocols/index.d.ts +1 -0
  88. package/node_modules/@smithy/core/dist-types/ts3.4/submodules/protocols/serde/determineTimestampFormat.d.ts +1 -1
  89. package/node_modules/@smithy/core/dist-types/ts3.4/submodules/schema/schemas/NormalizedSchema.d.ts +10 -0
  90. package/node_modules/@smithy/core/event-streams.d.ts +7 -0
  91. package/node_modules/@smithy/core/event-streams.js +6 -0
  92. package/node_modules/@smithy/core/package.json +11 -1
  93. package/node_modules/@smithy/middleware-endpoint/package.json +2 -2
  94. package/node_modules/@smithy/middleware-retry/package.json +4 -4
  95. package/node_modules/@smithy/smithy-client/dist-cjs/index.js +43 -6
  96. package/node_modules/@smithy/smithy-client/dist-cjs/schemaLogFilter.js +1 -0
  97. package/node_modules/@smithy/smithy-client/dist-es/command.js +7 -4
  98. package/node_modules/@smithy/smithy-client/dist-es/schemaLogFilter.js +34 -0
  99. package/node_modules/@smithy/smithy-client/dist-types/schemaLogFilter.d.ts +9 -0
  100. package/node_modules/@smithy/smithy-client/dist-types/ts3.4/schemaLogFilter.d.ts +9 -0
  101. package/node_modules/@smithy/smithy-client/package.json +3 -3
  102. package/node_modules/@smithy/util-defaults-mode-browser/package.json +2 -2
  103. package/node_modules/@smithy/util-defaults-mode-node/package.json +2 -2
  104. package/package.json +4 -4
@@ -0,0 +1,94 @@
1
+ import { TypeRegistry } from "@smithy/core/schema";
2
+ import { calculateBodyLength } from "@smithy/util-body-length-browser";
3
+ export class ProtocolLib {
4
+ calculateContentLength(body, serdeContext) {
5
+ const bodyLengthCalculator = serdeContext?.bodyLengthChecker ?? calculateBodyLength;
6
+ return String(bodyLengthCalculator(body));
7
+ }
8
+ resolveRestContentType(defaultContentType, inputSchema) {
9
+ const members = inputSchema.getMemberSchemas();
10
+ const httpPayloadMember = Object.values(members).find((m) => {
11
+ return !!m.getMergedTraits().httpPayload;
12
+ });
13
+ if (httpPayloadMember) {
14
+ const mediaType = httpPayloadMember.getMergedTraits().mediaType;
15
+ if (mediaType) {
16
+ return mediaType;
17
+ }
18
+ else if (httpPayloadMember.isStringSchema()) {
19
+ return "text/plain";
20
+ }
21
+ else if (httpPayloadMember.isBlobSchema()) {
22
+ return "application/octet-stream";
23
+ }
24
+ else {
25
+ return defaultContentType;
26
+ }
27
+ }
28
+ else if (!inputSchema.isUnitSchema()) {
29
+ const hasBody = Object.values(members).find((m) => {
30
+ const { httpQuery, httpQueryParams, httpHeader, httpLabel, httpPrefixHeaders } = m.getMergedTraits();
31
+ return !httpQuery && !httpQueryParams && !httpHeader && !httpLabel && httpPrefixHeaders === void 0;
32
+ });
33
+ if (hasBody) {
34
+ return defaultContentType;
35
+ }
36
+ }
37
+ }
38
+ async getErrorSchemaOrThrowBaseException(errorIdentifier, defaultNamespace, response, dataObject, metadata, getErrorSchema) {
39
+ let namespace = defaultNamespace;
40
+ let errorName = errorIdentifier;
41
+ if (errorIdentifier.includes("#")) {
42
+ [namespace, errorName] = errorIdentifier.split("#");
43
+ }
44
+ const errorMetadata = {
45
+ $metadata: metadata,
46
+ $response: response,
47
+ $fault: response.statusCode < 500 ? "client" : "server",
48
+ };
49
+ const registry = TypeRegistry.for(namespace);
50
+ try {
51
+ const errorSchema = getErrorSchema?.(registry, errorName) ?? registry.getSchema(errorIdentifier);
52
+ return { errorSchema, errorMetadata };
53
+ }
54
+ catch (e) {
55
+ if (dataObject.Message) {
56
+ dataObject.message = dataObject.Message;
57
+ }
58
+ const baseExceptionSchema = TypeRegistry.for("smithy.ts.sdk.synthetic." + namespace).getBaseException();
59
+ if (baseExceptionSchema) {
60
+ const ErrorCtor = baseExceptionSchema.ctor;
61
+ throw Object.assign(new ErrorCtor({ name: errorName }), errorMetadata, dataObject);
62
+ }
63
+ throw Object.assign(new Error(errorName), errorMetadata, dataObject);
64
+ }
65
+ }
66
+ setQueryCompatError(output, response) {
67
+ const queryErrorHeader = response.headers?.["x-amzn-query-error"];
68
+ if (output !== undefined && queryErrorHeader != null) {
69
+ const [Code, Type] = queryErrorHeader.split(";");
70
+ const entries = Object.entries(output);
71
+ const Error = {
72
+ Code,
73
+ Type,
74
+ };
75
+ Object.assign(output, Error);
76
+ for (const [k, v] of entries) {
77
+ Error[k] = v;
78
+ }
79
+ delete Error.__type;
80
+ output.Error = Error;
81
+ }
82
+ }
83
+ queryCompatOutput(queryCompatErrorData, errorData) {
84
+ if (queryCompatErrorData.Error) {
85
+ errorData.Error = queryCompatErrorData.Error;
86
+ }
87
+ if (queryCompatErrorData.Type) {
88
+ errorData.Type = queryCompatErrorData.Type;
89
+ }
90
+ if (queryCompatErrorData.Code) {
91
+ errorData.Code = queryCompatErrorData.Code;
92
+ }
93
+ }
94
+ }
@@ -0,0 +1,39 @@
1
+ import { loadSmithyRpcV2CborErrorCode, SmithyRpcV2CborProtocol } from "@smithy/core/cbor";
2
+ import { NormalizedSchema } from "@smithy/core/schema";
3
+ import { ProtocolLib } from "../ProtocolLib";
4
+ export class AwsSmithyRpcV2CborProtocol extends SmithyRpcV2CborProtocol {
5
+ awsQueryCompatible;
6
+ mixin = new ProtocolLib();
7
+ constructor({ defaultNamespace, awsQueryCompatible, }) {
8
+ super({ defaultNamespace });
9
+ this.awsQueryCompatible = !!awsQueryCompatible;
10
+ }
11
+ async serializeRequest(operationSchema, input, context) {
12
+ const request = await super.serializeRequest(operationSchema, input, context);
13
+ if (this.awsQueryCompatible) {
14
+ request.headers["x-amzn-query-mode"] = "true";
15
+ }
16
+ return request;
17
+ }
18
+ async handleError(operationSchema, context, response, dataObject, metadata) {
19
+ if (this.awsQueryCompatible) {
20
+ this.mixin.setQueryCompatError(dataObject, response);
21
+ }
22
+ const errorName = loadSmithyRpcV2CborErrorCode(response, dataObject) ?? "Unknown";
23
+ const { errorSchema, errorMetadata } = await this.mixin.getErrorSchemaOrThrowBaseException(errorName, this.options.defaultNamespace, response, dataObject, metadata);
24
+ const ns = NormalizedSchema.of(errorSchema);
25
+ const message = dataObject.message ?? dataObject.Message ?? "Unknown";
26
+ const exception = new errorSchema.ctor(message);
27
+ const output = {};
28
+ for (const [name, member] of ns.structIterator()) {
29
+ output[name] = this.deserializer.readValue(member, dataObject[name]);
30
+ }
31
+ if (this.awsQueryCompatible) {
32
+ this.mixin.queryCompatOutput(dataObject, output);
33
+ }
34
+ throw Object.assign(exception, errorMetadata, {
35
+ $fault: ns.getMergedTraits().error,
36
+ message,
37
+ }, output);
38
+ }
39
+ }
@@ -1,2 +1,3 @@
1
1
  import { collectBody } from "@smithy/smithy-client";
2
- export const collectBodyString = (streamBody, context) => collectBody(streamBody, context).then((body) => context.utf8Encoder(body));
2
+ import { toUtf8 } from "@smithy/util-utf8";
3
+ export const collectBodyString = (streamBody, context) => collectBody(streamBody, context).then((body) => (context?.utf8Encoder ?? toUtf8)(body));
@@ -1,3 +1,4 @@
1
+ export * from "./cbor/AwsSmithyRpcV2CborProtocol";
1
2
  export * from "./coercing-serializers";
2
3
  export * from "./json/AwsJson1_0Protocol";
3
4
  export * from "./json/AwsJson1_1Protocol";
@@ -1,9 +1,10 @@
1
1
  import { AwsJsonRpcProtocol } from "./AwsJsonRpcProtocol";
2
2
  export class AwsJson1_0Protocol extends AwsJsonRpcProtocol {
3
- constructor({ defaultNamespace, serviceTarget }) {
3
+ constructor({ defaultNamespace, serviceTarget, awsQueryCompatible, }) {
4
4
  super({
5
5
  defaultNamespace,
6
6
  serviceTarget,
7
+ awsQueryCompatible,
7
8
  });
8
9
  }
9
10
  getShapeId() {
@@ -1,9 +1,10 @@
1
1
  import { AwsJsonRpcProtocol } from "./AwsJsonRpcProtocol";
2
2
  export class AwsJson1_1Protocol extends AwsJsonRpcProtocol {
3
- constructor({ defaultNamespace, serviceTarget }) {
3
+ constructor({ defaultNamespace, serviceTarget, awsQueryCompatible, }) {
4
4
  super({
5
5
  defaultNamespace,
6
6
  serviceTarget,
7
+ awsQueryCompatible,
7
8
  });
8
9
  }
9
10
  getShapeId() {
@@ -1,6 +1,6 @@
1
1
  import { RpcProtocol } from "@smithy/core/protocols";
2
- import { deref, NormalizedSchema, SCHEMA, TypeRegistry } from "@smithy/core/schema";
3
- import { calculateBodyLength } from "@smithy/util-body-length-browser";
2
+ import { deref, NormalizedSchema, SCHEMA } from "@smithy/core/schema";
3
+ import { ProtocolLib } from "../ProtocolLib";
4
4
  import { JsonCodec } from "./JsonCodec";
5
5
  import { loadRestJsonErrorCode } from "./parseJsonBody";
6
6
  export class AwsJsonRpcProtocol extends RpcProtocol {
@@ -8,7 +8,9 @@ export class AwsJsonRpcProtocol extends RpcProtocol {
8
8
  deserializer;
9
9
  serviceTarget;
10
10
  codec;
11
- constructor({ defaultNamespace, serviceTarget }) {
11
+ mixin = new ProtocolLib();
12
+ awsQueryCompatible;
13
+ constructor({ defaultNamespace, serviceTarget, awsQueryCompatible, }) {
12
14
  super({
13
15
  defaultNamespace,
14
16
  });
@@ -22,6 +24,7 @@ export class AwsJsonRpcProtocol extends RpcProtocol {
22
24
  });
23
25
  this.serializer = this.codec.createSerializer();
24
26
  this.deserializer = this.codec.createDeserializer();
27
+ this.awsQueryCompatible = !!awsQueryCompatible;
25
28
  }
26
29
  async serializeRequest(operationSchema, input, context) {
27
30
  const request = await super.serializeRequest(operationSchema, input, context);
@@ -32,11 +35,14 @@ export class AwsJsonRpcProtocol extends RpcProtocol {
32
35
  "content-type": `application/x-amz-json-${this.getJsonRpcVersion()}`,
33
36
  "x-amz-target": `${this.serviceTarget}.${NormalizedSchema.of(operationSchema).getName()}`,
34
37
  });
38
+ if (this.awsQueryCompatible) {
39
+ request.headers["x-amzn-query-mode"] = "true";
40
+ }
35
41
  if (deref(operationSchema.input) === "unit" || !request.body) {
36
42
  request.body = "{}";
37
43
  }
38
44
  try {
39
- request.headers["content-length"] = String(calculateBodyLength(request.body));
45
+ request.headers["content-length"] = this.mixin.calculateContentLength(request.body, this.serdeContext);
40
46
  }
41
47
  catch (e) { }
42
48
  return request;
@@ -45,42 +51,22 @@ export class AwsJsonRpcProtocol extends RpcProtocol {
45
51
  return this.codec;
46
52
  }
47
53
  async handleError(operationSchema, context, response, dataObject, metadata) {
48
- const errorIdentifier = loadRestJsonErrorCode(response, dataObject) ?? "Unknown";
49
- let namespace = this.options.defaultNamespace;
50
- let errorName = errorIdentifier;
51
- if (errorIdentifier.includes("#")) {
52
- [namespace, errorName] = errorIdentifier.split("#");
53
- }
54
- const errorMetadata = {
55
- $metadata: metadata,
56
- $response: response,
57
- $fault: response.statusCode <= 500 ? "client" : "server",
58
- };
59
- const registry = TypeRegistry.for(namespace);
60
- let errorSchema;
61
- try {
62
- errorSchema = registry.getSchema(errorIdentifier);
63
- }
64
- catch (e) {
65
- if (dataObject.Message) {
66
- dataObject.message = dataObject.Message;
67
- }
68
- const baseExceptionSchema = TypeRegistry.for("smithy.ts.sdk.synthetic." + namespace).getBaseException();
69
- if (baseExceptionSchema) {
70
- const ErrorCtor = baseExceptionSchema.ctor;
71
- throw Object.assign(new ErrorCtor({ name: errorName }), errorMetadata, dataObject);
72
- }
73
- throw Object.assign(new Error(errorName), errorMetadata, dataObject);
54
+ if (this.awsQueryCompatible) {
55
+ this.mixin.setQueryCompatError(dataObject, response);
74
56
  }
57
+ const errorIdentifier = loadRestJsonErrorCode(response, dataObject) ?? "Unknown";
58
+ const { errorSchema, errorMetadata } = await this.mixin.getErrorSchemaOrThrowBaseException(errorIdentifier, this.options.defaultNamespace, response, dataObject, metadata);
75
59
  const ns = NormalizedSchema.of(errorSchema);
76
60
  const message = dataObject.message ?? dataObject.Message ?? "Unknown";
77
61
  const exception = new errorSchema.ctor(message);
78
- await this.deserializeHttpMessage(errorSchema, context, response, dataObject);
79
62
  const output = {};
80
63
  for (const [name, member] of ns.structIterator()) {
81
64
  const target = member.getMergedTraits().jsonName ?? name;
82
65
  output[name] = this.codec.createDeserializer().readObject(member, dataObject[target]);
83
66
  }
67
+ if (this.awsQueryCompatible) {
68
+ this.mixin.queryCompatOutput(dataObject, output);
69
+ }
84
70
  throw Object.assign(exception, errorMetadata, {
85
71
  $fault: ns.getMergedTraits().error,
86
72
  message,
@@ -1,12 +1,13 @@
1
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";
2
+ import { NormalizedSchema, SCHEMA } from "@smithy/core/schema";
3
+ import { ProtocolLib } from "../ProtocolLib";
4
4
  import { JsonCodec } from "./JsonCodec";
5
5
  import { loadRestJsonErrorCode } from "./parseJsonBody";
6
6
  export class AwsRestJsonProtocol extends HttpBindingProtocol {
7
7
  serializer;
8
8
  deserializer;
9
9
  codec;
10
+ mixin = new ProtocolLib();
10
11
  constructor({ defaultNamespace }) {
11
12
  super({
12
13
  defaultNamespace,
@@ -36,34 +37,10 @@ export class AwsRestJsonProtocol extends HttpBindingProtocol {
36
37
  async serializeRequest(operationSchema, input, context) {
37
38
  const request = await super.serializeRequest(operationSchema, input, context);
38
39
  const inputSchema = NormalizedSchema.of(operationSchema.input);
39
- const members = inputSchema.getMemberSchemas();
40
40
  if (!request.headers["content-type"]) {
41
- const httpPayloadMember = Object.values(members).find((m) => {
42
- return !!m.getMergedTraits().httpPayload;
43
- });
44
- if (httpPayloadMember) {
45
- const mediaType = httpPayloadMember.getMergedTraits().mediaType;
46
- if (mediaType) {
47
- request.headers["content-type"] = mediaType;
48
- }
49
- else if (httpPayloadMember.isStringSchema()) {
50
- request.headers["content-type"] = "text/plain";
51
- }
52
- else if (httpPayloadMember.isBlobSchema()) {
53
- request.headers["content-type"] = "application/octet-stream";
54
- }
55
- else {
56
- request.headers["content-type"] = this.getDefaultContentType();
57
- }
58
- }
59
- else if (!inputSchema.isUnitSchema()) {
60
- const hasBody = Object.values(members).find((m) => {
61
- const { httpQuery, httpQueryParams, httpHeader, httpLabel, httpPrefixHeaders } = m.getMergedTraits();
62
- return !httpQuery && !httpQueryParams && !httpHeader && !httpLabel && httpPrefixHeaders === void 0;
63
- });
64
- if (hasBody) {
65
- request.headers["content-type"] = this.getDefaultContentType();
66
- }
41
+ const contentType = this.mixin.resolveRestContentType(this.getDefaultContentType(), inputSchema);
42
+ if (contentType) {
43
+ request.headers["content-type"] = contentType;
67
44
  }
68
45
  }
69
46
  if (request.headers["content-type"] && !request.body) {
@@ -71,7 +48,7 @@ export class AwsRestJsonProtocol extends HttpBindingProtocol {
71
48
  }
72
49
  if (request.body) {
73
50
  try {
74
- request.headers["content-length"] = String(calculateBodyLength(request.body));
51
+ request.headers["content-length"] = this.mixin.calculateContentLength(request.body, this.serdeContext);
75
52
  }
76
53
  catch (e) { }
77
54
  }
@@ -79,32 +56,7 @@ export class AwsRestJsonProtocol extends HttpBindingProtocol {
79
56
  }
80
57
  async handleError(operationSchema, context, response, dataObject, metadata) {
81
58
  const errorIdentifier = loadRestJsonErrorCode(response, dataObject) ?? "Unknown";
82
- let namespace = this.options.defaultNamespace;
83
- let errorName = errorIdentifier;
84
- if (errorIdentifier.includes("#")) {
85
- [namespace, errorName] = errorIdentifier.split("#");
86
- }
87
- const errorMetadata = {
88
- $metadata: metadata,
89
- $response: response,
90
- $fault: response.statusCode <= 500 ? "client" : "server",
91
- };
92
- const registry = TypeRegistry.for(namespace);
93
- let errorSchema;
94
- try {
95
- errorSchema = registry.getSchema(errorIdentifier);
96
- }
97
- catch (e) {
98
- if (dataObject.Message) {
99
- dataObject.message = dataObject.Message;
100
- }
101
- const baseExceptionSchema = TypeRegistry.for("smithy.ts.sdk.synthetic." + namespace).getBaseException();
102
- if (baseExceptionSchema) {
103
- const ErrorCtor = baseExceptionSchema.ctor;
104
- throw Object.assign(new ErrorCtor({ name: errorName }), errorMetadata, dataObject);
105
- }
106
- throw Object.assign(new Error(errorName), errorMetadata, dataObject);
107
- }
59
+ const { errorSchema, errorMetadata } = await this.mixin.getErrorSchemaOrThrowBaseException(errorIdentifier, this.options.defaultNamespace, response, dataObject, metadata);
108
60
  const ns = NormalizedSchema.of(errorSchema);
109
61
  const message = dataObject.message ?? dataObject.Message ?? "Unknown";
110
62
  const exception = new errorSchema.ctor(message);
@@ -1,12 +1,13 @@
1
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";
2
+ import { deref, NormalizedSchema, SCHEMA } from "@smithy/core/schema";
3
+ import { ProtocolLib } from "../ProtocolLib";
4
4
  import { XmlShapeDeserializer } from "../xml/XmlShapeDeserializer";
5
5
  import { QueryShapeSerializer } from "./QueryShapeSerializer";
6
6
  export class AwsQueryProtocol extends RpcProtocol {
7
7
  options;
8
8
  serializer;
9
9
  deserializer;
10
+ mixin = new ProtocolLib();
10
11
  constructor(options) {
11
12
  super({
12
13
  defaultNamespace: options.defaultNamespace,
@@ -51,7 +52,7 @@ export class AwsQueryProtocol extends RpcProtocol {
51
52
  request.body = request.body.slice(-1);
52
53
  }
53
54
  try {
54
- request.headers["content-length"] = String(calculateBodyLength(request.body));
55
+ request.headers["content-length"] = this.mixin.calculateContentLength(request.body, this.serdeContext);
55
56
  }
56
57
  catch (e) { }
57
58
  return request;
@@ -88,36 +89,8 @@ export class AwsQueryProtocol extends RpcProtocol {
88
89
  }
89
90
  async handleError(operationSchema, context, response, dataObject, metadata) {
90
91
  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
92
  const errorData = this.loadQueryError(dataObject);
97
- const errorMetadata = {
98
- $metadata: metadata,
99
- $response: response,
100
- $fault: response.statusCode <= 500 ? "client" : "server",
101
- };
102
- const registry = TypeRegistry.for(namespace);
103
- let errorSchema;
104
- try {
105
- errorSchema = registry.find((schema) => NormalizedSchema.of(schema).getMergedTraits().awsQueryError?.[0] === errorName);
106
- if (!errorSchema) {
107
- errorSchema = registry.getSchema(errorIdentifier);
108
- }
109
- }
110
- catch (e) {
111
- if (errorData.Message) {
112
- errorData.message = errorData.Message;
113
- }
114
- const baseExceptionSchema = TypeRegistry.for("smithy.ts.sdk.synthetic." + namespace).getBaseException();
115
- if (baseExceptionSchema) {
116
- const ErrorCtor = baseExceptionSchema.ctor;
117
- throw Object.assign(new ErrorCtor({ name: errorName }), errorMetadata, dataObject);
118
- }
119
- throw Object.assign(new Error(errorName), errorMetadata, errorData);
120
- }
93
+ const { errorSchema, errorMetadata } = await this.mixin.getErrorSchemaOrThrowBaseException(errorIdentifier, this.options.defaultNamespace, response, errorData, metadata, (registry, errorName) => registry.find((schema) => NormalizedSchema.of(schema).getMergedTraits().awsQueryError?.[0] === errorName));
121
94
  const ns = NormalizedSchema.of(errorSchema);
122
95
  const message = this.loadQueryErrorMessage(dataObject);
123
96
  const exception = new errorSchema.ctor(message);
@@ -1,12 +1,13 @@
1
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";
2
+ import { NormalizedSchema, SCHEMA } from "@smithy/core/schema";
3
+ import { ProtocolLib } from "../ProtocolLib";
4
4
  import { loadRestXmlErrorCode } from "./parseXmlBody";
5
5
  import { XmlCodec } from "./XmlCodec";
6
6
  export class AwsRestXmlProtocol extends HttpBindingProtocol {
7
7
  codec;
8
8
  serializer;
9
9
  deserializer;
10
+ mixin = new ProtocolLib();
10
11
  constructor(options) {
11
12
  super(options);
12
13
  const settings = {
@@ -30,35 +31,11 @@ export class AwsRestXmlProtocol extends HttpBindingProtocol {
30
31
  }
31
32
  async serializeRequest(operationSchema, input, context) {
32
33
  const request = await super.serializeRequest(operationSchema, input, context);
33
- const ns = NormalizedSchema.of(operationSchema.input);
34
- const members = ns.getMemberSchemas();
34
+ const inputSchema = NormalizedSchema.of(operationSchema.input);
35
35
  if (!request.headers["content-type"]) {
36
- const httpPayloadMember = Object.values(members).find((m) => {
37
- return !!m.getMergedTraits().httpPayload;
38
- });
39
- if (httpPayloadMember) {
40
- const mediaType = httpPayloadMember.getMergedTraits().mediaType;
41
- if (mediaType) {
42
- request.headers["content-type"] = mediaType;
43
- }
44
- else if (httpPayloadMember.isStringSchema()) {
45
- request.headers["content-type"] = "text/plain";
46
- }
47
- else if (httpPayloadMember.isBlobSchema()) {
48
- request.headers["content-type"] = "application/octet-stream";
49
- }
50
- else {
51
- request.headers["content-type"] = this.getDefaultContentType();
52
- }
53
- }
54
- else if (!ns.isUnitSchema()) {
55
- const hasBody = Object.values(members).find((m) => {
56
- const { httpQuery, httpQueryParams, httpHeader, httpLabel, httpPrefixHeaders } = m.getMergedTraits();
57
- return !httpQuery && !httpQueryParams && !httpHeader && !httpLabel && httpPrefixHeaders === void 0;
58
- });
59
- if (hasBody) {
60
- request.headers["content-type"] = this.getDefaultContentType();
61
- }
36
+ const contentType = this.mixin.resolveRestContentType(this.getDefaultContentType(), inputSchema);
37
+ if (contentType) {
38
+ request.headers["content-type"] = contentType;
62
39
  }
63
40
  }
64
41
  if (request.headers["content-type"] === this.getDefaultContentType()) {
@@ -68,7 +45,7 @@ export class AwsRestXmlProtocol extends HttpBindingProtocol {
68
45
  }
69
46
  if (request.body) {
70
47
  try {
71
- request.headers["content-length"] = String(calculateBodyLength(request.body));
48
+ request.headers["content-length"] = this.mixin.calculateContentLength(request.body, this.serdeContext);
72
49
  }
73
50
  catch (e) { }
74
51
  }
@@ -79,32 +56,7 @@ export class AwsRestXmlProtocol extends HttpBindingProtocol {
79
56
  }
80
57
  async handleError(operationSchema, context, response, dataObject, metadata) {
81
58
  const errorIdentifier = loadRestXmlErrorCode(response, dataObject) ?? "Unknown";
82
- let namespace = this.options.defaultNamespace;
83
- let errorName = errorIdentifier;
84
- if (errorIdentifier.includes("#")) {
85
- [namespace, errorName] = errorIdentifier.split("#");
86
- }
87
- const errorMetadata = {
88
- $metadata: metadata,
89
- $response: response,
90
- $fault: response.statusCode <= 500 ? "client" : "server",
91
- };
92
- const registry = TypeRegistry.for(namespace);
93
- let errorSchema;
94
- try {
95
- errorSchema = registry.getSchema(errorIdentifier);
96
- }
97
- catch (e) {
98
- if (dataObject.Message) {
99
- dataObject.message = dataObject.Message;
100
- }
101
- const baseExceptionSchema = TypeRegistry.for("smithy.ts.sdk.synthetic." + namespace).getBaseException();
102
- if (baseExceptionSchema) {
103
- const ErrorCtor = baseExceptionSchema.ctor;
104
- throw Object.assign(new ErrorCtor({ name: errorName }), errorMetadata, dataObject);
105
- }
106
- throw Object.assign(new Error(errorName), errorMetadata, dataObject);
107
- }
59
+ const { errorSchema, errorMetadata } = await this.mixin.getErrorSchemaOrThrowBaseException(errorIdentifier, this.options.defaultNamespace, response, dataObject, metadata);
108
60
  const ns = NormalizedSchema.of(errorSchema);
109
61
  const message = dataObject.Error?.message ?? dataObject.Error?.Message ?? dataObject.message ?? dataObject.Message ?? "Unknown";
110
62
  const exception = new errorSchema.ctor(message);
@@ -0,0 +1,57 @@
1
+ import { ErrorSchema, NormalizedSchema, TypeRegistry } from "@smithy/core/schema";
2
+ import type { HttpResponse as IHttpResponse, MetadataBearer, ResponseMetadata, SerdeFunctions } from "@smithy/types";
3
+ /**
4
+ * @internal
5
+ */
6
+ type ErrorMetadataBearer = MetadataBearer & {
7
+ $response: IHttpResponse;
8
+ $fault: "client" | "server";
9
+ };
10
+ /**
11
+ * Shared code for Protocols.
12
+ *
13
+ * @internal
14
+ */
15
+ export declare class ProtocolLib {
16
+ /**
17
+ * @param body - to be inspected.
18
+ * @param serdeContext - this is a subset type but in practice is the client.config having a property called bodyLengthChecker.
19
+ *
20
+ * @returns content-length value for the body if possible.
21
+ * @throws Error and should be caught and handled if not possible to determine length.
22
+ */
23
+ calculateContentLength(body: any, serdeContext?: SerdeFunctions): string;
24
+ /**
25
+ * This is only for REST protocols.
26
+ *
27
+ * @param defaultContentType - of the protocol.
28
+ * @param inputSchema - schema for which to determine content type.
29
+ *
30
+ * @returns content-type header value or undefined when not applicable.
31
+ */
32
+ resolveRestContentType(defaultContentType: string, inputSchema: NormalizedSchema): string | undefined;
33
+ /**
34
+ * Shared code for finding error schema or throwing an unmodeled base error.
35
+ * @returns error schema and error metadata.
36
+ *
37
+ * @throws ServiceBaseException or generic Error if no error schema could be found.
38
+ */
39
+ getErrorSchemaOrThrowBaseException(errorIdentifier: string, defaultNamespace: string, response: IHttpResponse, dataObject: any, metadata: ResponseMetadata, getErrorSchema?: (registry: TypeRegistry, errorName: string) => ErrorSchema): Promise<{
40
+ errorSchema: ErrorSchema;
41
+ errorMetadata: ErrorMetadataBearer;
42
+ }>;
43
+ /**
44
+ * Reads the x-amzn-query-error header for awsQuery compatibility.
45
+ *
46
+ * @param output - values that will be assigned to an error object.
47
+ * @param response - from which to read awsQueryError headers.
48
+ */
49
+ setQueryCompatError(output: Record<string, any>, response: IHttpResponse): void;
50
+ /**
51
+ * Assigns Error, Type, Code from the awsQuery error object to the output error object.
52
+ * @param queryCompatErrorData - query compat error object.
53
+ * @param errorData - canonical error object returned to the caller.
54
+ */
55
+ queryCompatOutput(queryCompatErrorData: any, errorData: any): void;
56
+ }
57
+ export {};
@@ -0,0 +1,23 @@
1
+ import { SmithyRpcV2CborProtocol } from "@smithy/core/cbor";
2
+ import type { EndpointBearer, HandlerExecutionContext, HttpRequest, HttpResponse, OperationSchema, ResponseMetadata, SerdeFunctions } from "@smithy/types";
3
+ /**
4
+ * Extends the Smithy implementation to add AwsQueryCompatibility support.
5
+ *
6
+ * @alpha
7
+ */
8
+ export declare class AwsSmithyRpcV2CborProtocol extends SmithyRpcV2CborProtocol {
9
+ private readonly awsQueryCompatible;
10
+ private readonly mixin;
11
+ constructor({ defaultNamespace, awsQueryCompatible, }: {
12
+ defaultNamespace: string;
13
+ awsQueryCompatible?: boolean;
14
+ });
15
+ /**
16
+ * @override
17
+ */
18
+ serializeRequest<Input extends object>(operationSchema: OperationSchema, input: Input, context: HandlerExecutionContext & SerdeFunctions & EndpointBearer): Promise<HttpRequest>;
19
+ /**
20
+ * @override
21
+ */
22
+ protected handleError(operationSchema: OperationSchema, context: HandlerExecutionContext & SerdeFunctions, response: HttpResponse, dataObject: any, metadata: ResponseMetadata): Promise<never>;
23
+ }
@@ -1,3 +1,4 @@
1
+ export * from "./cbor/AwsSmithyRpcV2CborProtocol";
1
2
  export * from "./coercing-serializers";
2
3
  export * from "./json/AwsJson1_0Protocol";
3
4
  export * from "./json/AwsJson1_1Protocol";
@@ -4,9 +4,10 @@ import { AwsJsonRpcProtocol } from "./AwsJsonRpcProtocol";
4
4
  * @see https://smithy.io/2.0/aws/protocols/aws-json-1_1-protocol.html#differences-between-awsjson1-0-and-awsjson1-1
5
5
  */
6
6
  export declare class AwsJson1_0Protocol extends AwsJsonRpcProtocol {
7
- constructor({ defaultNamespace, serviceTarget }: {
7
+ constructor({ defaultNamespace, serviceTarget, awsQueryCompatible, }: {
8
8
  defaultNamespace: string;
9
9
  serviceTarget: string;
10
+ awsQueryCompatible?: boolean;
10
11
  });
11
12
  getShapeId(): string;
12
13
  protected getJsonRpcVersion(): "1.0";
@@ -4,9 +4,10 @@ import { AwsJsonRpcProtocol } from "./AwsJsonRpcProtocol";
4
4
  * @see https://smithy.io/2.0/aws/protocols/aws-json-1_1-protocol.html#differences-between-awsjson1-0-and-awsjson1-1
5
5
  */
6
6
  export declare class AwsJson1_1Protocol extends AwsJsonRpcProtocol {
7
- constructor({ defaultNamespace, serviceTarget }: {
7
+ constructor({ defaultNamespace, serviceTarget, awsQueryCompatible, }: {
8
8
  defaultNamespace: string;
9
9
  serviceTarget: string;
10
+ awsQueryCompatible?: boolean;
10
11
  });
11
12
  getShapeId(): string;
12
13
  protected getJsonRpcVersion(): "1.1";