arvo-event-handler 2.0.3 → 2.0.4

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.
@@ -111,12 +111,12 @@ export default class ArvoEventHandler<TContract extends ArvoContract> extends Ab
111
111
  errorMessage: import("zod").ZodString;
112
112
  errorStack: import("zod").ZodNullable<import("zod").ZodString>;
113
113
  }, "strip", import("zod").ZodTypeAny, {
114
- errorMessage: string;
115
114
  errorName: string;
115
+ errorMessage: string;
116
116
  errorStack: string | null;
117
117
  }, {
118
- errorMessage: string;
119
118
  errorName: string;
119
+ errorMessage: string;
120
120
  errorStack: string | null;
121
121
  }>>;
122
122
  }
@@ -182,7 +182,7 @@ var ArvoEventHandler = /** @class */ (function (_super) {
182
182
  opentelemetryConfig: opentelemetry,
183
183
  });
184
184
  return [4 /*yield*/, api_1.context.with(api_1.trace.setSpan(api_1.context.active(), span), function () { return __awaiter(_this, void 0, void 0, function () {
185
- var otelSpanHeaders, parsedDataSchema, handlerContract, inputEventValidation, _handleOutput, outputs, eventFactory_1, error_1, eventFactory, result;
185
+ var otelSpanHeaders, parsedDataSchema, handlerContract, inputEventValidation, _handleOutput, outputs, eventFactory_1, result, error_1, eventFactory, result;
186
186
  var _a, _b, _c, _d, _e;
187
187
  return __generator(this, function (_f) {
188
188
  switch (_f.label) {
@@ -195,14 +195,22 @@ var ArvoEventHandler = /** @class */ (function (_super) {
195
195
  if (this.contract.type !== event.type) {
196
196
  throw new Error("Invalid event type='".concat(event.type, "' is provide to handler for type='").concat(this.contract.type, "'"));
197
197
  }
198
- parsedDataSchema = (0, arvo_core_1.parseEventDataSchema)(event);
198
+ (0, arvo_core_1.logToSpan)({
199
+ level: 'INFO',
200
+ message: "Event type validated againt the required event tyoe imposed by contract (uri=".concat(this.contract.uri, ")"),
201
+ });
202
+ parsedDataSchema = arvo_core_1.EventDataschemaUtil.parse(event);
199
203
  if (!(parsedDataSchema === null || parsedDataSchema === void 0 ? void 0 : parsedDataSchema.version)) {
200
204
  (0, arvo_core_1.logToSpan)({
201
205
  level: 'WARNING',
202
- message: "Unable to resolve the event version from dataschema \"".concat(event.dataschema, "\". Defaulting to the latest version."),
206
+ message: "Unable to resolve the event version from event dataschema \"".concat(event.dataschema, "\""),
203
207
  });
204
208
  }
205
209
  handlerContract = this.contract.version((_a = parsedDataSchema === null || parsedDataSchema === void 0 ? void 0 : parsedDataSchema.version) !== null && _a !== void 0 ? _a : 'latest');
210
+ (0, arvo_core_1.logToSpan)({
211
+ level: 'INFO',
212
+ message: "Using contract and handler version (=".concat(handlerContract.version, ") to handle the event"),
213
+ });
206
214
  Object.entries(event.otelAttributes).forEach(function (_a) {
207
215
  var key = _a[0], value = _a[1];
208
216
  return span.setAttribute("to_process.0.".concat(key), value);
@@ -211,6 +219,10 @@ var ArvoEventHandler = /** @class */ (function (_super) {
211
219
  if (inputEventValidation.error) {
212
220
  throw new Error("Invalid event payload: ".concat(inputEventValidation.error));
213
221
  }
222
+ (0, arvo_core_1.logToSpan)({
223
+ level: 'INFO',
224
+ message: "Event payload validated against contract (uri=".concat(handlerContract.uri, ", version=").concat(handlerContract.version, ")"),
225
+ });
214
226
  return [4 /*yield*/, this._handler[handlerContract.version]({
215
227
  event: event,
216
228
  source: this.source,
@@ -227,15 +239,20 @@ var ArvoEventHandler = /** @class */ (function (_super) {
227
239
  outputs = [_handleOutput];
228
240
  }
229
241
  eventFactory_1 = (0, arvo_core_1.createArvoEventFactory)(handlerContract);
230
- return [2 /*return*/, (0, utils_1.eventHandlerOutputEventCreator)(outputs, otelSpanHeaders, this.source, event, this.executionunits, function (param, extension) {
231
- var _a;
232
- return eventFactory_1.emits(param, extension, {
233
- tracer: (_a = opentelemetry === null || opentelemetry === void 0 ? void 0 : opentelemetry.tracer) !== null && _a !== void 0 ? _a : (0, OpenTelemetry_1.fetchOpenTelemetryTracer)(),
234
- });
235
- })];
242
+ result = (0, utils_1.eventHandlerOutputEventCreator)(outputs, otelSpanHeaders, this.source, event, this.executionunits, function (param, extension) {
243
+ var _a;
244
+ return eventFactory_1.emits(param, extension, {
245
+ tracer: (_a = opentelemetry === null || opentelemetry === void 0 ? void 0 : opentelemetry.tracer) !== null && _a !== void 0 ? _a : (0, OpenTelemetry_1.fetchOpenTelemetryTracer)(),
246
+ });
247
+ });
248
+ (0, arvo_core_1.logToSpan)({
249
+ level: 'INFO',
250
+ message: 'Event handled successfully',
251
+ });
252
+ return [2 /*return*/, result];
236
253
  case 3:
237
254
  error_1 = _f.sent();
238
- eventFactory = (0, arvo_core_1.createArvoEventFactory)(this.contract.version('any'));
255
+ eventFactory = (0, arvo_core_1.createArvoEventFactory)(this.contract.version('latest'));
239
256
  (0, arvo_core_1.exceptionToSpan)(error_1);
240
257
  span.setStatus({
241
258
  code: api_1.SpanStatusCode.ERROR,
@@ -5,7 +5,7 @@ import { z } from 'zod';
5
5
  * Represents the input for an ArvoEvent handler function.
6
6
  * @template TAccepts - The type of ArvoContractRecord that the handler accepts.
7
7
  */
8
- export type ArvoEventHandlerFunctionInput<TContract extends VersionedArvoContract<ArvoContract, ArvoSemanticVersion>> = {
8
+ export type ArvoEventHandlerFunctionInput<TContract extends VersionedArvoContract<any, any>> = {
9
9
  /** The ArvoEvent object. */
10
10
  event: ArvoEvent<z.infer<TContract['accepts']['schema']>, Record<string, any>, TContract['accepts']['type']>;
11
11
  /** The source field data of the handler */
@@ -15,7 +15,7 @@ export type ArvoEventHandlerFunctionInput<TContract extends VersionedArvoContrac
15
15
  * Represents the output of an ArvoEvent handler function.
16
16
  * @template TContract - The type of ArvoContract that the handler is associated with.
17
17
  */
18
- export type ArvoEventHandlerFunctionOutput<TContract extends VersionedArvoContract<ArvoContract, ArvoSemanticVersion>> = {
18
+ export type ArvoEventHandlerFunctionOutput<TContract extends VersionedArvoContract<any, any>> = {
19
19
  [K in keyof TContract['emits']]: Omit<CreateArvoEvent<z.infer<TContract['emits'][K]>, K & string>, 'subject' | 'source' | 'executionunits' | 'traceparent' | 'tracestate'> & {
20
20
  /**
21
21
  * An optional override for the execution units of this specific event.
@@ -113,12 +113,12 @@ export declare class ArvoEventRouter extends AbstractArvoEventHandler {
113
113
  errorMessage: import("zod").ZodString;
114
114
  errorStack: import("zod").ZodNullable<import("zod").ZodString>;
115
115
  }, "strip", import("zod").ZodTypeAny, {
116
- errorMessage: string;
117
116
  errorName: string;
117
+ errorMessage: string;
118
118
  errorStack: string | null;
119
119
  }, {
120
- errorMessage: string;
121
120
  errorName: string;
121
+ errorMessage: string;
122
122
  errorStack: string | null;
123
123
  }>;
124
124
  };
@@ -116,12 +116,12 @@ export default class MultiArvoEventHandler extends AbstractArvoEventHandler {
116
116
  errorMessage: import("zod").ZodString;
117
117
  errorStack: import("zod").ZodNullable<import("zod").ZodString>;
118
118
  }, "strip", import("zod").ZodTypeAny, {
119
- errorMessage: string;
120
119
  errorName: string;
120
+ errorMessage: string;
121
121
  errorStack: string | null;
122
122
  }, {
123
- errorMessage: string;
124
123
  errorName: string;
124
+ errorMessage: string;
125
125
  errorStack: string | null;
126
126
  }>;
127
127
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arvo-event-handler",
3
- "version": "2.0.3",
3
+ "version": "2.0.4",
4
4
  "description": "Type-safe event handler system with versioning, telemetry, and contract validation for distributed Arvo event-driven architectures, featuring routing and multi-handler support.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -50,7 +50,7 @@
50
50
  "dependencies": {
51
51
  "@opentelemetry/api": "^1.9.0",
52
52
  "@opentelemetry/core": "^1.27.0",
53
- "arvo-core": "^2.0.10",
53
+ "arvo-core": "^2.1.2",
54
54
  "uuid": "^10.0.0",
55
55
  "zod": "^3.23.8"
56
56
  }