@yopdev/dev-server 1.4.0-alpha.1 → 1.4.1-alpha.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.
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { SQSEvent } from 'aws-lambda';
|
|
2
|
+
import { MessageAttributeValue } from '@aws-sdk/client-sqs';
|
|
2
3
|
import { Service } from './services';
|
|
3
4
|
export declare const newEventsProxy: (name: string, config: {
|
|
4
5
|
handlers: EventHandler[];
|
|
5
6
|
topic?: string;
|
|
6
7
|
}) => Service<any>;
|
|
7
8
|
export type EventHandler = {
|
|
9
|
+
name: string;
|
|
8
10
|
handler: (event: SQSEvent) => Promise<unknown>;
|
|
9
|
-
matcher: (subject: string) => boolean;
|
|
11
|
+
matcher: (subject: string, attributes: Record<string, MessageAttributeValue>) => boolean;
|
|
10
12
|
};
|
package/dist/src/event-proxy.js
CHANGED
|
@@ -89,29 +89,29 @@ var EventsProxy = /** @class */ (function () {
|
|
|
89
89
|
}); };
|
|
90
90
|
this.extractErrorMessage = function (e) { return typeof e === 'string' ? e : e.message !== undefined && typeof e.message === 'string' ? e.message : ''; };
|
|
91
91
|
this.onEachMessage = function (message) {
|
|
92
|
-
var body = (0, assert_1.assertNotUndefined)(message.Body, 'body is not present');
|
|
93
|
-
var subject = JSON.parse(body).Subject;
|
|
94
92
|
if (_this.stopped) {
|
|
95
|
-
_this.LOGGER.warn('stopped events proxy received message
|
|
93
|
+
_this.LOGGER.warn('stopped events proxy received message %o', message);
|
|
96
94
|
return;
|
|
97
95
|
}
|
|
98
|
-
var
|
|
96
|
+
var body = (0, assert_1.assertNotUndefined)(message.Body, 'body is not present');
|
|
97
|
+
var subject = JSON.parse(body).Subject;
|
|
98
|
+
var handlers = _this.handlers.filter(function (handler) { var _a; return handler.matcher(subject, (_a = message.MessageAttributes) !== null && _a !== void 0 ? _a : {}); });
|
|
99
99
|
if (handlers.length === 0) {
|
|
100
|
-
_this.LOGGER.warn('no handlers found for
|
|
100
|
+
_this.LOGGER.warn('no handlers found for message %o', message);
|
|
101
101
|
}
|
|
102
|
+
var record = (0, mappers_1.mapToLambdaSqsRecord)(message);
|
|
102
103
|
handlers.forEach(function (handler) {
|
|
103
|
-
|
|
104
|
-
handler
|
|
104
|
+
return handler
|
|
105
105
|
.handler({ Records: [record] })
|
|
106
106
|
.then(function () {
|
|
107
107
|
var _a;
|
|
108
108
|
var json = JSON.parse(record.body);
|
|
109
109
|
var subject = json.Subject || ((_a = json.Message) === null || _a === void 0 ? void 0 : _a.eventname) || 'unknown';
|
|
110
|
-
_this.LOGGER.debug('
|
|
110
|
+
_this.LOGGER.debug('handler %s accepted message', handler.name);
|
|
111
111
|
})
|
|
112
112
|
.catch(function (e) {
|
|
113
113
|
var error = _this.extractErrorMessage(e);
|
|
114
|
-
_this.LOGGER.error(e, '
|
|
114
|
+
_this.LOGGER.error(e, 'handler %s failed with %s', handler.name, error);
|
|
115
115
|
});
|
|
116
116
|
});
|
|
117
117
|
};
|