@aws-sdk/eventstream-handler-node 3.893.0 → 3.910.0
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/dist-cjs/index.js +97 -139
- package/package.json +5 -5
package/dist-cjs/index.js
CHANGED
|
@@ -1,150 +1,108 @@
|
|
|
1
|
-
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
'use strict';
|
|
20
2
|
|
|
21
|
-
|
|
22
|
-
var
|
|
23
|
-
__export(index_exports, {
|
|
24
|
-
eventStreamPayloadHandlerProvider: () => eventStreamPayloadHandlerProvider
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(index_exports);
|
|
3
|
+
var eventstreamCodec = require('@smithy/eventstream-codec');
|
|
4
|
+
var stream = require('stream');
|
|
27
5
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
6
|
+
class EventSigningStream extends stream.Transform {
|
|
7
|
+
priorSignature;
|
|
8
|
+
messageSigner;
|
|
9
|
+
eventStreamCodec;
|
|
10
|
+
systemClockOffsetProvider;
|
|
11
|
+
constructor(options) {
|
|
12
|
+
super({
|
|
13
|
+
autoDestroy: true,
|
|
14
|
+
readableObjectMode: true,
|
|
15
|
+
writableObjectMode: true,
|
|
16
|
+
...options,
|
|
17
|
+
});
|
|
18
|
+
this.priorSignature = options.priorSignature;
|
|
19
|
+
this.eventStreamCodec = options.eventStreamCodec;
|
|
20
|
+
this.messageSigner = options.messageSigner;
|
|
21
|
+
this.systemClockOffsetProvider = options.systemClockOffsetProvider;
|
|
22
|
+
}
|
|
23
|
+
async _transform(chunk, encoding, callback) {
|
|
24
|
+
try {
|
|
25
|
+
const now = new Date(Date.now() + (await this.systemClockOffsetProvider()));
|
|
26
|
+
const dateHeader = {
|
|
27
|
+
":date": { type: "timestamp", value: now },
|
|
28
|
+
};
|
|
29
|
+
const signedMessage = await this.messageSigner.sign({
|
|
30
|
+
message: {
|
|
31
|
+
body: chunk,
|
|
32
|
+
headers: dateHeader,
|
|
33
|
+
},
|
|
34
|
+
priorSignature: this.priorSignature,
|
|
35
|
+
}, {
|
|
36
|
+
signingDate: now,
|
|
37
|
+
});
|
|
38
|
+
this.priorSignature = signedMessage.signature;
|
|
39
|
+
const serializedSigned = this.eventStreamCodec.encode({
|
|
40
|
+
headers: {
|
|
41
|
+
...dateHeader,
|
|
42
|
+
":chunk-signature": {
|
|
43
|
+
type: "binary",
|
|
44
|
+
value: getSignatureBinary(signedMessage.signature),
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
body: chunk,
|
|
48
|
+
});
|
|
49
|
+
this.push(serializedSigned);
|
|
50
|
+
return callback();
|
|
51
|
+
}
|
|
52
|
+
catch (err) {
|
|
53
|
+
callback(err);
|
|
70
54
|
}
|
|
71
|
-
);
|
|
72
|
-
this.priorSignature = signedMessage.signature;
|
|
73
|
-
const serializedSigned = this.eventStreamCodec.encode({
|
|
74
|
-
headers: {
|
|
75
|
-
...dateHeader,
|
|
76
|
-
":chunk-signature": {
|
|
77
|
-
type: "binary",
|
|
78
|
-
value: getSignatureBinary(signedMessage.signature)
|
|
79
|
-
}
|
|
80
|
-
},
|
|
81
|
-
body: chunk
|
|
82
|
-
});
|
|
83
|
-
this.push(serializedSigned);
|
|
84
|
-
return callback();
|
|
85
|
-
} catch (err) {
|
|
86
|
-
callback(err);
|
|
87
55
|
}
|
|
88
|
-
|
|
89
|
-
};
|
|
56
|
+
}
|
|
90
57
|
function getSignatureBinary(signature) {
|
|
91
|
-
|
|
92
|
-
|
|
58
|
+
const buf = Buffer.from(signature, "hex");
|
|
59
|
+
return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength / Uint8Array.BYTES_PER_ELEMENT);
|
|
93
60
|
}
|
|
94
|
-
__name(getSignatureBinary, "getSignatureBinary");
|
|
95
61
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
constructor(options) {
|
|
105
|
-
this.messageSigner = options.messageSigner;
|
|
106
|
-
this.eventStreamCodec = new import_eventstream_codec.EventStreamCodec(options.utf8Encoder, options.utf8Decoder);
|
|
107
|
-
this.systemClockOffsetProvider = async () => options.systemClockOffset ?? 0;
|
|
108
|
-
}
|
|
109
|
-
async handle(next, args, context = {}) {
|
|
110
|
-
const request = args.request;
|
|
111
|
-
const { body: payload, query } = request;
|
|
112
|
-
if (!(payload instanceof import_stream.Readable)) {
|
|
113
|
-
throw new Error("Eventstream payload must be a Readable stream.");
|
|
62
|
+
class EventStreamPayloadHandler {
|
|
63
|
+
messageSigner;
|
|
64
|
+
eventStreamCodec;
|
|
65
|
+
systemClockOffsetProvider;
|
|
66
|
+
constructor(options) {
|
|
67
|
+
this.messageSigner = options.messageSigner;
|
|
68
|
+
this.eventStreamCodec = new eventstreamCodec.EventStreamCodec(options.utf8Encoder, options.utf8Decoder);
|
|
69
|
+
this.systemClockOffsetProvider = async () => options.systemClockOffset ?? 0;
|
|
114
70
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
71
|
+
async handle(next, args, context = {}) {
|
|
72
|
+
const request = args.request;
|
|
73
|
+
const { body: payload, query } = request;
|
|
74
|
+
if (!(payload instanceof stream.Readable)) {
|
|
75
|
+
throw new Error("Eventstream payload must be a Readable stream.");
|
|
76
|
+
}
|
|
77
|
+
const payloadStream = payload;
|
|
78
|
+
request.body = new stream.PassThrough({
|
|
79
|
+
objectMode: true,
|
|
80
|
+
});
|
|
81
|
+
const match = request.headers?.authorization?.match(/Signature=([\w]+)$/);
|
|
82
|
+
const priorSignature = match?.[1] ?? query?.["X-Amz-Signature"] ?? "";
|
|
83
|
+
const signingStream = new EventSigningStream({
|
|
84
|
+
priorSignature,
|
|
85
|
+
eventStreamCodec: this.eventStreamCodec,
|
|
86
|
+
messageSigner: await this.messageSigner(),
|
|
87
|
+
systemClockOffsetProvider: this.systemClockOffsetProvider,
|
|
88
|
+
});
|
|
89
|
+
stream.pipeline(payloadStream, signingStream, request.body, (err) => {
|
|
90
|
+
if (err) {
|
|
91
|
+
throw err;
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
let result;
|
|
95
|
+
try {
|
|
96
|
+
result = await next(args);
|
|
97
|
+
}
|
|
98
|
+
catch (e) {
|
|
99
|
+
request.body.end();
|
|
100
|
+
throw e;
|
|
101
|
+
}
|
|
102
|
+
return result;
|
|
138
103
|
}
|
|
139
|
-
|
|
140
|
-
}
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
// src/provider.ts
|
|
144
|
-
var eventStreamPayloadHandlerProvider = /* @__PURE__ */ __name((options) => new EventStreamPayloadHandler(options), "eventStreamPayloadHandlerProvider");
|
|
145
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
104
|
+
}
|
|
146
105
|
|
|
147
|
-
|
|
148
|
-
eventStreamPayloadHandlerProvider
|
|
149
|
-
});
|
|
106
|
+
const eventStreamPayloadHandlerProvider = (options) => new EventStreamPayloadHandler(options);
|
|
150
107
|
|
|
108
|
+
exports.eventStreamPayloadHandlerProvider = eventStreamPayloadHandlerProvider;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-sdk/eventstream-handler-node",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.910.0",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'",
|
|
6
6
|
"build:cjs": "node ../../scripts/compilation/inline eventstream-handler-node",
|
|
@@ -22,13 +22,13 @@
|
|
|
22
22
|
},
|
|
23
23
|
"license": "Apache-2.0",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@aws-sdk/types": "3.
|
|
26
|
-
"@smithy/eventstream-codec": "^4.
|
|
27
|
-
"@smithy/types": "^4.
|
|
25
|
+
"@aws-sdk/types": "3.910.0",
|
|
26
|
+
"@smithy/eventstream-codec": "^4.2.2",
|
|
27
|
+
"@smithy/types": "^4.7.1",
|
|
28
28
|
"tslib": "^2.6.2"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@smithy/util-utf8": "^4.
|
|
31
|
+
"@smithy/util-utf8": "^4.2.0",
|
|
32
32
|
"@tsconfig/recommended": "1.0.1",
|
|
33
33
|
"@types/node": "^18.19.69",
|
|
34
34
|
"concurrently": "7.0.0",
|