@smithy/core 3.36.1 → 3.36.2
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/CHANGELOG.md +7 -0
- package/dist-cjs/submodules/client/index.js +15 -2
- package/dist-cjs/submodules/event-streams/index.browser.js +10 -0
- package/dist-cjs/submodules/event-streams/index.js +10 -0
- package/dist-es/submodules/client/smithy-client/command.js +16 -2
- package/dist-es/submodules/event-streams/eventstream-codec/HeaderMarshaller.js +10 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -578,6 +578,7 @@ function schemaLogFilter(schema, data) {
|
|
|
578
578
|
return data;
|
|
579
579
|
}
|
|
580
580
|
|
|
581
|
+
const operationEventStreamMarker = Symbol.for("@smithy/op-event-stream");
|
|
581
582
|
class Command {
|
|
582
583
|
middlewareStack = constructStack();
|
|
583
584
|
schema;
|
|
@@ -611,9 +612,21 @@ class Command {
|
|
|
611
612
|
requestOptions = { ...requestOptions };
|
|
612
613
|
delete requestOptions.metricsRecorder;
|
|
613
614
|
}
|
|
614
|
-
|
|
615
|
+
let isEventStream;
|
|
616
|
+
const schema = this.schema;
|
|
617
|
+
const marker = schema?.[operationEventStreamMarker];
|
|
618
|
+
if (marker !== undefined) {
|
|
619
|
+
isEventStream = marker;
|
|
620
|
+
}
|
|
621
|
+
else if (schema) {
|
|
622
|
+
if (Array.isArray(schema) && schema[0] === 9) {
|
|
623
|
+
const [, , , , input$, output$] = schema;
|
|
624
|
+
isEventStream = schema[operationEventStreamMarker] = Boolean(NormalizedSchema.of(input$).getEventStreamMember() || NormalizedSchema.of(output$).getEventStreamMember());
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
if (isEventStream) {
|
|
615
628
|
requestOptions = {
|
|
616
|
-
isEventStream
|
|
629
|
+
isEventStream,
|
|
617
630
|
...requestOptions,
|
|
618
631
|
};
|
|
619
632
|
}
|
|
@@ -60,6 +60,9 @@ class HeaderMarshaller {
|
|
|
60
60
|
if (!hasOwn(headers, headerName))
|
|
61
61
|
continue;
|
|
62
62
|
const bytes = this.fromUtf8(headerName);
|
|
63
|
+
if (bytes.byteLength > 255) {
|
|
64
|
+
throw new Error(`@smithy/core/event-streams - header name exceeds 255 bytes: ${bytes.byteLength}`);
|
|
65
|
+
}
|
|
63
66
|
chunks.push(Uint8Array.from([bytes.byteLength]), bytes, this.formatHeaderValue(headers[headerName]));
|
|
64
67
|
}
|
|
65
68
|
const out = new Uint8Array(chunks.reduce((carry, bytes) => carry + bytes.byteLength, 0));
|
|
@@ -92,6 +95,9 @@ class HeaderMarshaller {
|
|
|
92
95
|
longBytes.set(header.value.bytes, 1);
|
|
93
96
|
return longBytes;
|
|
94
97
|
case "binary":
|
|
98
|
+
if (header.value.byteLength > MAX_HEADER_VALUE_BYTES) {
|
|
99
|
+
throw new Error(`@smithy/core/event-streams - header value (binary) exceeds ${MAX_HEADER_VALUE_BYTES} bytes: ${header.value.byteLength}`);
|
|
100
|
+
}
|
|
95
101
|
const binView = new DataView(new ArrayBuffer(3 + header.value.byteLength));
|
|
96
102
|
binView.setUint8(0, 6);
|
|
97
103
|
binView.setUint16(1, header.value.byteLength, false);
|
|
@@ -100,6 +106,9 @@ class HeaderMarshaller {
|
|
|
100
106
|
return binBytes;
|
|
101
107
|
case "string":
|
|
102
108
|
const utf8Bytes = this.fromUtf8(header.value);
|
|
109
|
+
if (utf8Bytes.byteLength > MAX_HEADER_VALUE_BYTES) {
|
|
110
|
+
throw new Error(`@smithy/core/event-streams - header value (string) exceeds ${MAX_HEADER_VALUE_BYTES} bytes: ${utf8Bytes.byteLength}`);
|
|
111
|
+
}
|
|
103
112
|
const strView = new DataView(new ArrayBuffer(3 + utf8Bytes.byteLength));
|
|
104
113
|
strView.setUint8(0, 7);
|
|
105
114
|
strView.setUint16(1, utf8Bytes.byteLength, false);
|
|
@@ -231,6 +240,7 @@ const STRING_TAG = "string";
|
|
|
231
240
|
const TIMESTAMP_TAG = "timestamp";
|
|
232
241
|
const UUID_TAG = "uuid";
|
|
233
242
|
const UUID_PATTERN = /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/;
|
|
243
|
+
const MAX_HEADER_VALUE_BYTES = 32767;
|
|
234
244
|
|
|
235
245
|
const PRELUDE_MEMBER_LENGTH = 4;
|
|
236
246
|
const PRELUDE_LENGTH = PRELUDE_MEMBER_LENGTH * 2;
|
|
@@ -61,6 +61,9 @@ class HeaderMarshaller {
|
|
|
61
61
|
if (!hasOwn(headers, headerName))
|
|
62
62
|
continue;
|
|
63
63
|
const bytes = this.fromUtf8(headerName);
|
|
64
|
+
if (bytes.byteLength > 255) {
|
|
65
|
+
throw new Error(`@smithy/core/event-streams - header name exceeds 255 bytes: ${bytes.byteLength}`);
|
|
66
|
+
}
|
|
64
67
|
chunks.push(Uint8Array.from([bytes.byteLength]), bytes, this.formatHeaderValue(headers[headerName]));
|
|
65
68
|
}
|
|
66
69
|
const out = new Uint8Array(chunks.reduce((carry, bytes) => carry + bytes.byteLength, 0));
|
|
@@ -93,6 +96,9 @@ class HeaderMarshaller {
|
|
|
93
96
|
longBytes.set(header.value.bytes, 1);
|
|
94
97
|
return longBytes;
|
|
95
98
|
case "binary":
|
|
99
|
+
if (header.value.byteLength > MAX_HEADER_VALUE_BYTES) {
|
|
100
|
+
throw new Error(`@smithy/core/event-streams - header value (binary) exceeds ${MAX_HEADER_VALUE_BYTES} bytes: ${header.value.byteLength}`);
|
|
101
|
+
}
|
|
96
102
|
const binView = new DataView(new ArrayBuffer(3 + header.value.byteLength));
|
|
97
103
|
binView.setUint8(0, 6);
|
|
98
104
|
binView.setUint16(1, header.value.byteLength, false);
|
|
@@ -101,6 +107,9 @@ class HeaderMarshaller {
|
|
|
101
107
|
return binBytes;
|
|
102
108
|
case "string":
|
|
103
109
|
const utf8Bytes = this.fromUtf8(header.value);
|
|
110
|
+
if (utf8Bytes.byteLength > MAX_HEADER_VALUE_BYTES) {
|
|
111
|
+
throw new Error(`@smithy/core/event-streams - header value (string) exceeds ${MAX_HEADER_VALUE_BYTES} bytes: ${utf8Bytes.byteLength}`);
|
|
112
|
+
}
|
|
104
113
|
const strView = new DataView(new ArrayBuffer(3 + utf8Bytes.byteLength));
|
|
105
114
|
strView.setUint8(0, 7);
|
|
106
115
|
strView.setUint16(1, utf8Bytes.byteLength, false);
|
|
@@ -232,6 +241,7 @@ const STRING_TAG = "string";
|
|
|
232
241
|
const TIMESTAMP_TAG = "timestamp";
|
|
233
242
|
const UUID_TAG = "uuid";
|
|
234
243
|
const UUID_PATTERN = /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/;
|
|
244
|
+
const MAX_HEADER_VALUE_BYTES = 32767;
|
|
235
245
|
|
|
236
246
|
const PRELUDE_MEMBER_LENGTH = 4;
|
|
237
247
|
const PRELUDE_LENGTH = PRELUDE_MEMBER_LENGTH * 2;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { SMITHY_CONTEXT_KEY, } from "@smithy/types";
|
|
2
2
|
import { constructStack } from "../middleware-stack/MiddlewareStack";
|
|
3
3
|
import { schemaLogFilter } from "./schemaLogFilter";
|
|
4
|
+
import { NormalizedSchema } from "@smithy/core/schema";
|
|
5
|
+
const operationEventStreamMarker = Symbol.for("@smithy/op-event-stream");
|
|
4
6
|
export class Command {
|
|
5
7
|
middlewareStack = constructStack();
|
|
6
8
|
schema;
|
|
@@ -34,9 +36,21 @@ export class Command {
|
|
|
34
36
|
requestOptions = { ...requestOptions };
|
|
35
37
|
delete requestOptions.metricsRecorder;
|
|
36
38
|
}
|
|
37
|
-
|
|
39
|
+
let isEventStream;
|
|
40
|
+
const schema = this.schema;
|
|
41
|
+
const marker = schema?.[operationEventStreamMarker];
|
|
42
|
+
if (marker !== undefined) {
|
|
43
|
+
isEventStream = marker;
|
|
44
|
+
}
|
|
45
|
+
else if (schema) {
|
|
46
|
+
if (Array.isArray(schema) && schema[0] === 9) {
|
|
47
|
+
const [, , , , input$, output$] = schema;
|
|
48
|
+
isEventStream = schema[operationEventStreamMarker] = Boolean(NormalizedSchema.of(input$).getEventStreamMember() || NormalizedSchema.of(output$).getEventStreamMember());
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (isEventStream) {
|
|
38
52
|
requestOptions = {
|
|
39
|
-
isEventStream
|
|
53
|
+
isEventStream,
|
|
40
54
|
...requestOptions,
|
|
41
55
|
};
|
|
42
56
|
}
|
|
@@ -14,6 +14,9 @@ export class HeaderMarshaller {
|
|
|
14
14
|
if (!hasOwn(headers, headerName))
|
|
15
15
|
continue;
|
|
16
16
|
const bytes = this.fromUtf8(headerName);
|
|
17
|
+
if (bytes.byteLength > 255) {
|
|
18
|
+
throw new Error(`@smithy/core/event-streams - header name exceeds 255 bytes: ${bytes.byteLength}`);
|
|
19
|
+
}
|
|
17
20
|
chunks.push(Uint8Array.from([bytes.byteLength]), bytes, this.formatHeaderValue(headers[headerName]));
|
|
18
21
|
}
|
|
19
22
|
const out = new Uint8Array(chunks.reduce((carry, bytes) => carry + bytes.byteLength, 0));
|
|
@@ -46,6 +49,9 @@ export class HeaderMarshaller {
|
|
|
46
49
|
longBytes.set(header.value.bytes, 1);
|
|
47
50
|
return longBytes;
|
|
48
51
|
case "binary":
|
|
52
|
+
if (header.value.byteLength > MAX_HEADER_VALUE_BYTES) {
|
|
53
|
+
throw new Error(`@smithy/core/event-streams - header value (binary) exceeds ${MAX_HEADER_VALUE_BYTES} bytes: ${header.value.byteLength}`);
|
|
54
|
+
}
|
|
49
55
|
const binView = new DataView(new ArrayBuffer(3 + header.value.byteLength));
|
|
50
56
|
binView.setUint8(0, 6);
|
|
51
57
|
binView.setUint16(1, header.value.byteLength, false);
|
|
@@ -54,6 +60,9 @@ export class HeaderMarshaller {
|
|
|
54
60
|
return binBytes;
|
|
55
61
|
case "string":
|
|
56
62
|
const utf8Bytes = this.fromUtf8(header.value);
|
|
63
|
+
if (utf8Bytes.byteLength > MAX_HEADER_VALUE_BYTES) {
|
|
64
|
+
throw new Error(`@smithy/core/event-streams - header value (string) exceeds ${MAX_HEADER_VALUE_BYTES} bytes: ${utf8Bytes.byteLength}`);
|
|
65
|
+
}
|
|
57
66
|
const strView = new DataView(new ArrayBuffer(3 + utf8Bytes.byteLength));
|
|
58
67
|
strView.setUint8(0, 7);
|
|
59
68
|
strView.setUint16(1, utf8Bytes.byteLength, false);
|
|
@@ -185,3 +194,4 @@ const STRING_TAG = "string";
|
|
|
185
194
|
const TIMESTAMP_TAG = "timestamp";
|
|
186
195
|
const UUID_TAG = "uuid";
|
|
187
196
|
const UUID_PATTERN = /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/;
|
|
197
|
+
const MAX_HEADER_VALUE_BYTES = 32767;
|