arvo-event-handler 2.3.3 → 3.0.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/dist/AbstractArvoEventHandler/index.d.ts +1 -1
- package/dist/ArvoEventHandler/helpers.d.ts +40 -6
- package/dist/ArvoEventHandler/helpers.js +40 -6
- package/dist/ArvoEventHandler/index.d.ts +78 -49
- package/dist/ArvoEventHandler/index.js +152 -83
- package/dist/ArvoEventHandler/types.d.ts +25 -2
- package/dist/ArvoMachine/createMachine.d.ts +208 -0
- package/dist/ArvoMachine/createMachine.js +283 -0
- package/dist/ArvoMachine/index.d.ts +93 -0
- package/dist/ArvoMachine/index.js +160 -0
- package/dist/ArvoMachine/types.d.ts +194 -0
- package/dist/ArvoMachine/utils.d.ts +40 -0
- package/dist/ArvoMachine/utils.js +70 -0
- package/dist/ArvoOrchestrator/error.d.ts +16 -0
- package/dist/ArvoOrchestrator/error.js +43 -0
- package/dist/ArvoOrchestrator/factory.d.ts +28 -0
- package/dist/ArvoOrchestrator/factory.js +56 -0
- package/dist/ArvoOrchestrator/index.d.ts +69 -0
- package/dist/ArvoOrchestrator/index.js +597 -0
- package/dist/ArvoOrchestrator/types.d.ts +98 -0
- package/dist/ArvoResumable/factory.d.ts +50 -0
- package/dist/ArvoResumable/factory.js +70 -0
- package/dist/ArvoResumable/index.d.ts +141 -0
- package/dist/ArvoResumable/index.js +694 -0
- package/dist/ArvoResumable/types.d.ts +147 -0
- package/dist/ArvoResumable/types.js +2 -0
- package/dist/MachineExecutionEngine/index.d.ts +29 -0
- package/dist/MachineExecutionEngine/index.js +132 -0
- package/dist/MachineExecutionEngine/interface.d.ts +14 -0
- package/dist/MachineExecutionEngine/interface.js +2 -0
- package/dist/MachineExecutionEngine/types.d.ts +14 -0
- package/dist/MachineExecutionEngine/types.js +2 -0
- package/dist/MachineMemory/Simple.d.ts +51 -0
- package/dist/MachineMemory/Simple.js +158 -0
- package/dist/MachineMemory/TelemetredSimple.d.ts +51 -0
- package/dist/MachineMemory/TelemetredSimple.js +230 -0
- package/dist/MachineMemory/interface.d.ts +57 -0
- package/dist/MachineMemory/interface.js +2 -0
- package/dist/MachineMemory/utils.d.ts +1 -0
- package/dist/MachineMemory/utils.js +18 -0
- package/dist/MachineRegistry/index.d.ts +37 -0
- package/dist/MachineRegistry/index.js +87 -0
- package/dist/MachineRegistry/interface.d.ts +21 -0
- package/dist/MachineRegistry/interface.js +2 -0
- package/dist/SyncEventResource/index.d.ts +110 -0
- package/dist/SyncEventResource/index.js +280 -0
- package/dist/SyncEventResource/types.d.ts +2 -0
- package/dist/SyncEventResource/types.js +2 -0
- package/dist/index.d.ts +26 -8
- package/dist/index.js +39 -16
- package/dist/utils/SimpleEventBroker/helper.d.ts +166 -0
- package/dist/utils/SimpleEventBroker/helper.js +276 -0
- package/dist/utils/SimpleEventBroker/index.d.ts +96 -0
- package/dist/utils/SimpleEventBroker/index.js +259 -0
- package/dist/utils/SimpleEventBroker/types.d.ts +6 -0
- package/dist/utils/SimpleEventBroker/types.js +2 -0
- package/dist/utils/SimpleEventBroker/utils.d.ts +1 -0
- package/dist/utils/SimpleEventBroker/utils.js +10 -0
- package/dist/{utils.d.ts → utils/index.d.ts} +3 -36
- package/dist/utils/index.js +91 -0
- package/dist/utils/object/index.d.ts +37 -0
- package/dist/utils/object/index.js +63 -0
- package/package.json +5 -3
- package/dist/ArvoEventRouter/helpers.d.ts +0 -19
- package/dist/ArvoEventRouter/helpers.js +0 -22
- package/dist/ArvoEventRouter/index.d.ts +0 -89
- package/dist/ArvoEventRouter/index.js +0 -268
- package/dist/ArvoEventRouter/types.d.ts +0 -36
- package/dist/ArvoEventRouter/utils.d.ts +0 -30
- package/dist/ArvoEventRouter/utils.js +0 -43
- package/dist/MultiArvoEventHandler/helpers.d.ts +0 -48
- package/dist/MultiArvoEventHandler/helpers.js +0 -56
- package/dist/MultiArvoEventHandler/index.d.ts +0 -68
- package/dist/MultiArvoEventHandler/index.js +0 -205
- package/dist/MultiArvoEventHandler/types.d.ts +0 -64
- package/dist/utils.js +0 -191
- /package/dist/{ArvoEventRouter → ArvoMachine}/types.js +0 -0
- /package/dist/{MultiArvoEventHandler → ArvoOrchestrator}/types.js +0 -0
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
var __assign = (this && this.__assign) || function () {
|
|
18
|
-
__assign = Object.assign || function(t) {
|
|
19
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
20
|
-
s = arguments[i];
|
|
21
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
22
|
-
t[p] = s[p];
|
|
23
|
-
}
|
|
24
|
-
return t;
|
|
25
|
-
};
|
|
26
|
-
return __assign.apply(this, arguments);
|
|
27
|
-
};
|
|
28
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
29
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
30
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
31
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
32
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
33
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
34
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
35
|
-
});
|
|
36
|
-
};
|
|
37
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
38
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
39
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
40
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
41
|
-
function step(op) {
|
|
42
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
43
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
44
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
45
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
46
|
-
switch (op[0]) {
|
|
47
|
-
case 0: case 1: t = op; break;
|
|
48
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
49
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
50
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
51
|
-
default:
|
|
52
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
53
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
54
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
55
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
56
|
-
if (t[2]) _.ops.pop();
|
|
57
|
-
_.trys.pop(); continue;
|
|
58
|
-
}
|
|
59
|
-
op = body.call(thisArg, _);
|
|
60
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
61
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
65
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
66
|
-
};
|
|
67
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
68
|
-
var api_1 = require("@opentelemetry/api");
|
|
69
|
-
var arvo_core_1 = require("arvo-core");
|
|
70
|
-
var AbstractArvoEventHandler_1 = __importDefault(require("../AbstractArvoEventHandler"));
|
|
71
|
-
var errors_1 = require("../errors");
|
|
72
|
-
var utils_1 = require("../utils");
|
|
73
|
-
/**
|
|
74
|
-
* MultiArvoEventHandler processes multiple event types without being bound to specific contracts.
|
|
75
|
-
* Manages event execution, telemetry tracking, and error handling for diverse event streams.
|
|
76
|
-
*
|
|
77
|
-
* @example
|
|
78
|
-
* const handler = createMultiArvoEventHandler({
|
|
79
|
-
* source: "order.handler",
|
|
80
|
-
* executionunits: 1,
|
|
81
|
-
* handler: async ({ event }) => {
|
|
82
|
-
* // Handle multiple event types
|
|
83
|
-
* }
|
|
84
|
-
* });
|
|
85
|
-
*/
|
|
86
|
-
var MultiArvoEventHandler = /** @class */ (function (_super) {
|
|
87
|
-
__extends(MultiArvoEventHandler, _super);
|
|
88
|
-
/**
|
|
89
|
-
* Creates handler instance with specified configuration.
|
|
90
|
-
* @param param Handler configuration including source and execution parameters
|
|
91
|
-
* @throws When source contains invalid characters
|
|
92
|
-
*/
|
|
93
|
-
function MultiArvoEventHandler(param) {
|
|
94
|
-
var _a;
|
|
95
|
-
var _b, _c;
|
|
96
|
-
var _this = _super.call(this) || this;
|
|
97
|
-
_this.executionunits = param.executionunits;
|
|
98
|
-
_this.handler = param.handler;
|
|
99
|
-
if (!(0, utils_1.isLowerAlphanumeric)(param.source)) {
|
|
100
|
-
throw new Error("Invalid source identifier '".concat(param.source, "': Must contain only alphanumeric characters (example: order.handler)"));
|
|
101
|
-
}
|
|
102
|
-
_this.source = param.source;
|
|
103
|
-
_this.spanOptions = __assign(__assign({ kind: api_1.SpanKind.CONSUMER }, param.spanOptions), { attributes: __assign(__assign((_a = {}, _a[arvo_core_1.ArvoExecution.ATTR_SPAN_KIND] = arvo_core_1.ArvoExecutionSpanKind.EVENT_HANDLER, _a[arvo_core_1.OpenInference.ATTR_SPAN_KIND] = arvo_core_1.OpenInferenceSpanKind.CHAIN, _a), ((_c = (_b = param.spanOptions) === null || _b === void 0 ? void 0 : _b.attributes) !== null && _c !== void 0 ? _c : {})), { 'arvo.handler.source': _this.source }) });
|
|
104
|
-
return _this;
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Processes an event through configured handler function. Creates telemetry span,
|
|
108
|
-
* validates event destination, executes handler, and manages errors.
|
|
109
|
-
*
|
|
110
|
-
* @param event Event to process
|
|
111
|
-
* @param opentelemetry Telemetry context configuration
|
|
112
|
-
* @returns Resulting events or error events
|
|
113
|
-
*
|
|
114
|
-
* @throws {ConfigViolation} When event destination does not match handler source
|
|
115
|
-
* @throws Other Violation error which are thrown by the event handler function
|
|
116
|
-
*/
|
|
117
|
-
MultiArvoEventHandler.prototype.execute = function (event_1) {
|
|
118
|
-
return __awaiter(this, arguments, void 0, function (event, opentelemetry) {
|
|
119
|
-
var otelConfig;
|
|
120
|
-
var _this = this;
|
|
121
|
-
if (opentelemetry === void 0) { opentelemetry = {
|
|
122
|
-
inheritFrom: 'EVENT',
|
|
123
|
-
}; }
|
|
124
|
-
return __generator(this, function (_a) {
|
|
125
|
-
switch (_a.label) {
|
|
126
|
-
case 0:
|
|
127
|
-
otelConfig = (0, utils_1.createEventHandlerTelemetryConfig)('MutliArvoEventHandler', this.spanOptions, opentelemetry, event);
|
|
128
|
-
return [4 /*yield*/, arvo_core_1.ArvoOpenTelemetry.getInstance().startActiveSpan(__assign(__assign({}, otelConfig), { fn: function (span) { return __awaiter(_this, void 0, void 0, function () {
|
|
129
|
-
var otelSpanHeaders, _i, _a, _b, key, value, _handlerOutput, outputs, resultingEvents, error_1, events;
|
|
130
|
-
return __generator(this, function (_c) {
|
|
131
|
-
switch (_c.label) {
|
|
132
|
-
case 0:
|
|
133
|
-
otelSpanHeaders = (0, arvo_core_1.currentOpenTelemetryHeaders)();
|
|
134
|
-
_c.label = 1;
|
|
135
|
-
case 1:
|
|
136
|
-
_c.trys.push([1, 3, 4, 5]);
|
|
137
|
-
span.setStatus({ code: api_1.SpanStatusCode.OK });
|
|
138
|
-
for (_i = 0, _a = Object.entries(event.otelAttributes); _i < _a.length; _i++) {
|
|
139
|
-
_b = _a[_i], key = _b[0], value = _b[1];
|
|
140
|
-
span.setAttribute("to_process.0.".concat(key), value);
|
|
141
|
-
}
|
|
142
|
-
(0, arvo_core_1.logToSpan)({
|
|
143
|
-
level: 'INFO',
|
|
144
|
-
message: "Initiating event resolution - Type: ".concat(event.type, ", Source: ").concat(event.source, ", Destination: ").concat(event.to),
|
|
145
|
-
});
|
|
146
|
-
if (event.to !== this.source) {
|
|
147
|
-
throw new errors_1.ConfigViolation("Event destination mismatch: Expected '".concat(this.source, "', received '").concat(event.to, "'"));
|
|
148
|
-
}
|
|
149
|
-
return [4 /*yield*/, this.handler({
|
|
150
|
-
event: event,
|
|
151
|
-
source: this.source,
|
|
152
|
-
span: span,
|
|
153
|
-
})];
|
|
154
|
-
case 2:
|
|
155
|
-
_handlerOutput = _c.sent();
|
|
156
|
-
if (!_handlerOutput)
|
|
157
|
-
return [2 /*return*/, {
|
|
158
|
-
events: [],
|
|
159
|
-
}];
|
|
160
|
-
outputs = [];
|
|
161
|
-
if (Array.isArray(_handlerOutput)) {
|
|
162
|
-
outputs = _handlerOutput;
|
|
163
|
-
}
|
|
164
|
-
else {
|
|
165
|
-
outputs = [_handlerOutput];
|
|
166
|
-
}
|
|
167
|
-
resultingEvents = (0, utils_1.eventHandlerOutputEventCreator)(outputs, otelSpanHeaders, this.source, event, this.executionunits, function (param, extensions) { return (0, arvo_core_1.createArvoEvent)(param, extensions); });
|
|
168
|
-
(0, arvo_core_1.logToSpan)({
|
|
169
|
-
level: 'INFO',
|
|
170
|
-
message: "Event processing completed successfully - Generated ".concat(resultingEvents.length, " new event(s)"),
|
|
171
|
-
});
|
|
172
|
-
return [2 /*return*/, { events: resultingEvents }];
|
|
173
|
-
case 3:
|
|
174
|
-
error_1 = _c.sent();
|
|
175
|
-
events = (0, utils_1.handleArvoEventHandlerCommonError)(error_1, otelSpanHeaders, "sys.".concat(this.source, ".error"), this.source, event, this.executionunits, function (param, extensions) { return (0, arvo_core_1.createArvoEvent)(param, extensions); });
|
|
176
|
-
return [2 /*return*/, { events: events }];
|
|
177
|
-
case 4:
|
|
178
|
-
span.end();
|
|
179
|
-
return [7 /*endfinally*/];
|
|
180
|
-
case 5: return [2 /*return*/];
|
|
181
|
-
}
|
|
182
|
-
});
|
|
183
|
-
}); } }))];
|
|
184
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
185
|
-
}
|
|
186
|
-
});
|
|
187
|
-
});
|
|
188
|
-
};
|
|
189
|
-
Object.defineProperty(MultiArvoEventHandler.prototype, "systemErrorSchema", {
|
|
190
|
-
/**
|
|
191
|
-
* System error schema configuration.
|
|
192
|
-
* Error events follow format: sys.<handler-source>.error
|
|
193
|
-
*/
|
|
194
|
-
get: function () {
|
|
195
|
-
return {
|
|
196
|
-
type: "sys.".concat(this.source, ".error"),
|
|
197
|
-
schema: arvo_core_1.ArvoErrorSchema,
|
|
198
|
-
};
|
|
199
|
-
},
|
|
200
|
-
enumerable: false,
|
|
201
|
-
configurable: true
|
|
202
|
-
});
|
|
203
|
-
return MultiArvoEventHandler;
|
|
204
|
-
}(AbstractArvoEventHandler_1.default));
|
|
205
|
-
exports.default = MultiArvoEventHandler;
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import type { Span, SpanOptions } from '@opentelemetry/api';
|
|
2
|
-
import type { ArvoEvent, CreateArvoEvent } from 'arvo-core';
|
|
3
|
-
/**
|
|
4
|
-
* Represents the input for a Multi ArvoEvent handler function.
|
|
5
|
-
*/
|
|
6
|
-
export type MultiArvoEventHandlerFunctionInput = {
|
|
7
|
-
/** The ArvoEvent object. */
|
|
8
|
-
event: ArvoEvent;
|
|
9
|
-
/** The source field data of the handler */
|
|
10
|
-
source: string;
|
|
11
|
-
/** The OpenTelemetry span */
|
|
12
|
-
span: Span;
|
|
13
|
-
};
|
|
14
|
-
/**
|
|
15
|
-
* Represents the output of a Multi ArvoEvent handler function.
|
|
16
|
-
* @template TContract - The type of ArvoContract that the handler is associated with.
|
|
17
|
-
*/
|
|
18
|
-
export type MultiArvoEventHandlerFunctionOutput = Omit<CreateArvoEvent<Record<string, any>, string>, 'subject' | 'source' | 'executionunits' | 'traceparent' | 'tracestate'> & {
|
|
19
|
-
/**
|
|
20
|
-
* An optional override for the execution units of this specific event.
|
|
21
|
-
*
|
|
22
|
-
* @remarks
|
|
23
|
-
* Execution units represent the computational cost or resources required to process this event.
|
|
24
|
-
* If not provided, the default value defined in the handler's constructor will be used.
|
|
25
|
-
*/
|
|
26
|
-
executionunits?: number;
|
|
27
|
-
/** Optional extensions for the event. */
|
|
28
|
-
__extensions?: Record<string, string | number | boolean>;
|
|
29
|
-
};
|
|
30
|
-
/**
|
|
31
|
-
* Defines the structure of a Multi ArvoEvent handler function.
|
|
32
|
-
* @template TContract - The type of ArvoContract that the handler is associated with.
|
|
33
|
-
*/
|
|
34
|
-
export type MultiArvoEventHandlerFunction = (param: MultiArvoEventHandlerFunctionInput) => Promise<Array<MultiArvoEventHandlerFunctionOutput> | MultiArvoEventHandlerFunctionOutput | void>;
|
|
35
|
-
/**
|
|
36
|
-
* Interface for an Multi ArvoEvent handler.
|
|
37
|
-
*/
|
|
38
|
-
export interface IMultiArvoEventHandler {
|
|
39
|
-
/**
|
|
40
|
-
* The source identifier for events produced by this handler
|
|
41
|
-
*
|
|
42
|
-
* @remarks
|
|
43
|
-
* The handler listens to the events with field `event.to` equal
|
|
44
|
-
* to the this `source` value. If the event does not confirm to
|
|
45
|
-
* this, a system error event is returned
|
|
46
|
-
*
|
|
47
|
-
* For all the events which are emitted by the handler, this is
|
|
48
|
-
* the source field value of them all.
|
|
49
|
-
*/
|
|
50
|
-
source: string;
|
|
51
|
-
/**
|
|
52
|
-
* The default execution cost of the function.
|
|
53
|
-
* This can represent a dollar value or some other number with a rate card.
|
|
54
|
-
*/
|
|
55
|
-
executionunits: number;
|
|
56
|
-
/**
|
|
57
|
-
* The functional handler of the event which takes the input, performs an action, and returns the result.
|
|
58
|
-
* @param params - The input parameters for the handler function.
|
|
59
|
-
* @returns A promise of object containing the created ArvoEvent and optional extensions.
|
|
60
|
-
*/
|
|
61
|
-
handler: MultiArvoEventHandlerFunction;
|
|
62
|
-
/** The OpenTelemetry span options */
|
|
63
|
-
spanOptions?: SpanOptions;
|
|
64
|
-
}
|
package/dist/utils.js
DELETED
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
14
|
-
var t = {};
|
|
15
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
16
|
-
t[p] = s[p];
|
|
17
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
18
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
19
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
20
|
-
t[p[i]] = s[p[i]];
|
|
21
|
-
}
|
|
22
|
-
return t;
|
|
23
|
-
};
|
|
24
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.createEventHandlerTelemetryConfig = exports.handleArvoEventHandlerCommonError = exports.eventHandlerOutputEventCreator = void 0;
|
|
26
|
-
exports.isNullOrUndefined = isNullOrUndefined;
|
|
27
|
-
exports.getValueOrDefault = getValueOrDefault;
|
|
28
|
-
exports.coalesce = coalesce;
|
|
29
|
-
exports.coalesceOrDefault = coalesceOrDefault;
|
|
30
|
-
exports.isLowerAlphanumeric = isLowerAlphanumeric;
|
|
31
|
-
var api_1 = require("@opentelemetry/api");
|
|
32
|
-
var arvo_core_1 = require("arvo-core");
|
|
33
|
-
/**
|
|
34
|
-
* Checks if the item is null or undefined.
|
|
35
|
-
*
|
|
36
|
-
* @param item - The value to check.
|
|
37
|
-
* @returns True if the item is null or undefined, false otherwise.
|
|
38
|
-
*/
|
|
39
|
-
function isNullOrUndefined(item) {
|
|
40
|
-
return item === null || item === undefined;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Returns the provided value if it's not null or undefined; otherwise, returns the default value.
|
|
44
|
-
*
|
|
45
|
-
* @template T - The type of the value and default value.
|
|
46
|
-
* @param value - The value to check.
|
|
47
|
-
* @param defaultValue - The default value to return if the provided value is null or undefined.
|
|
48
|
-
* @returns The provided value if it's not null or undefined; otherwise, the default value.
|
|
49
|
-
*/
|
|
50
|
-
function getValueOrDefault(value, defaultValue) {
|
|
51
|
-
return isNullOrUndefined(value) ? defaultValue : value;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Returns the first non-null and non-undefined value from the provided arguments.
|
|
55
|
-
* If all arguments are null or undefined, returns undefined.
|
|
56
|
-
*
|
|
57
|
-
* @template T - The type of the values.
|
|
58
|
-
* @param values - The values to coalesce.
|
|
59
|
-
* @returns The first non-null and non-undefined value, or undefined if all are null or undefined.
|
|
60
|
-
*/
|
|
61
|
-
function coalesce() {
|
|
62
|
-
var values = [];
|
|
63
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
64
|
-
values[_i] = arguments[_i];
|
|
65
|
-
}
|
|
66
|
-
for (var _a = 0, values_1 = values; _a < values_1.length; _a++) {
|
|
67
|
-
var value = values_1[_a];
|
|
68
|
-
if (!isNullOrUndefined(value)) {
|
|
69
|
-
return value;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return undefined;
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Returns the first non-null and non-undefined value from the provided array of values.
|
|
76
|
-
* If all values in the array are null or undefined, returns the specified default value.
|
|
77
|
-
*
|
|
78
|
-
* @template T - The type of the values and the default value.
|
|
79
|
-
* @param values - An array of values to coalesce.
|
|
80
|
-
* @param _default - The default value to return if all values in the array are null or undefined.
|
|
81
|
-
* @returns The first non-null and non-undefined value from the array, or the default value if all are null or undefined.
|
|
82
|
-
*
|
|
83
|
-
* @example
|
|
84
|
-
* const result = coalesceOrDefault([null, undefined, 'hello', 'world'], 'default');
|
|
85
|
-
* console.log(result); // Output: 'hello'
|
|
86
|
-
*
|
|
87
|
-
* @example
|
|
88
|
-
* const result = coalesceOrDefault([null, undefined], 'default');
|
|
89
|
-
* console.log(result); // Output: 'default'
|
|
90
|
-
*/
|
|
91
|
-
function coalesceOrDefault(values, _default) {
|
|
92
|
-
return getValueOrDefault(coalesce.apply(void 0, values), _default);
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Creates ArvoEvents from event handler output.
|
|
96
|
-
*
|
|
97
|
-
* @param events - An array of event handler function outputs.
|
|
98
|
-
* @param otelSpanHeaders - OpenTelemetry headers for tracing.
|
|
99
|
-
* @param source - The source of the event.
|
|
100
|
-
* @param defaultAccessControl - The default access control string for the events
|
|
101
|
-
* @param originalEvent - The original ArvoEvent that triggered the handler.
|
|
102
|
-
* @param handlerExectionUnits - The number of execution units for the handler.
|
|
103
|
-
* @param factory - A function to create ArvoEvents.
|
|
104
|
-
* @returns An array of ArvoEvents created from the handler output.
|
|
105
|
-
*/
|
|
106
|
-
var eventHandlerOutputEventCreator = function (events, otelSpanHeaders, source, originalEvent, handlerExectionUnits, factory) {
|
|
107
|
-
return events.map(function (item, index) {
|
|
108
|
-
var _a, _b;
|
|
109
|
-
var __extensions = item.__extensions, handlerResult = __rest(item, ["__extensions"]);
|
|
110
|
-
var result = factory(__assign(__assign({}, handlerResult), { traceparent: otelSpanHeaders.traceparent || undefined, tracestate: otelSpanHeaders.tracestate || undefined, source: source, subject: originalEvent.subject,
|
|
111
|
-
// prioritise returned 'to', 'redirectto' and then
|
|
112
|
-
// 'source'
|
|
113
|
-
to: coalesceOrDefault([handlerResult.to, originalEvent.redirectto], originalEvent.source), executionunits: coalesce(handlerResult.executionunits, handlerExectionUnits), accesscontrol: (_b = (_a = handlerResult.accesscontrol) !== null && _a !== void 0 ? _a : originalEvent.accesscontrol) !== null && _b !== void 0 ? _b : undefined, parentid: originalEvent.id }), __extensions);
|
|
114
|
-
var activeSpan = api_1.trace.getActiveSpan();
|
|
115
|
-
for (var _i = 0, _c = Object.entries(result.otelAttributes); _i < _c.length; _i++) {
|
|
116
|
-
var _d = _c[_i], key = _d[0], value = _d[1];
|
|
117
|
-
activeSpan === null || activeSpan === void 0 ? void 0 : activeSpan.setAttribute("to_emit.".concat(index, ".").concat(key), value);
|
|
118
|
-
}
|
|
119
|
-
return result;
|
|
120
|
-
});
|
|
121
|
-
};
|
|
122
|
-
exports.eventHandlerOutputEventCreator = eventHandlerOutputEventCreator;
|
|
123
|
-
var handleArvoEventHandlerCommonError = function (error, otelSpanHeaders, type, source, originalEvent, handlerExectionUnits, factory) {
|
|
124
|
-
var _a, _b, _c, _d, _e;
|
|
125
|
-
(0, arvo_core_1.exceptionToSpan)(error);
|
|
126
|
-
(_a = api_1.trace.getActiveSpan()) === null || _a === void 0 ? void 0 : _a.setStatus({
|
|
127
|
-
code: api_1.SpanStatusCode.ERROR,
|
|
128
|
-
message: error.message,
|
|
129
|
-
});
|
|
130
|
-
if (error.name.includes('ViolationError')) {
|
|
131
|
-
throw error;
|
|
132
|
-
}
|
|
133
|
-
var result = factory({
|
|
134
|
-
type: type,
|
|
135
|
-
source: source,
|
|
136
|
-
subject: originalEvent.subject,
|
|
137
|
-
to: originalEvent.source,
|
|
138
|
-
executionunits: handlerExectionUnits,
|
|
139
|
-
traceparent: (_b = otelSpanHeaders.traceparent) !== null && _b !== void 0 ? _b : undefined,
|
|
140
|
-
tracestate: (_c = otelSpanHeaders.tracestate) !== null && _c !== void 0 ? _c : undefined,
|
|
141
|
-
data: {
|
|
142
|
-
errorName: error.name,
|
|
143
|
-
errorMessage: error.message,
|
|
144
|
-
errorStack: (_d = error.stack) !== null && _d !== void 0 ? _d : null,
|
|
145
|
-
},
|
|
146
|
-
accesscontrol: (_e = originalEvent.accesscontrol) !== null && _e !== void 0 ? _e : undefined,
|
|
147
|
-
parentid: originalEvent.id,
|
|
148
|
-
});
|
|
149
|
-
var activeSpan = api_1.trace.getActiveSpan();
|
|
150
|
-
for (var _i = 0, _f = Object.entries(result.otelAttributes); _i < _f.length; _i++) {
|
|
151
|
-
var _g = _f[_i], key = _g[0], value = _g[1];
|
|
152
|
-
activeSpan === null || activeSpan === void 0 ? void 0 : activeSpan.setAttribute("to_emit.0.".concat(key), value);
|
|
153
|
-
}
|
|
154
|
-
return [result];
|
|
155
|
-
};
|
|
156
|
-
exports.handleArvoEventHandlerCommonError = handleArvoEventHandlerCommonError;
|
|
157
|
-
/**
|
|
158
|
-
* Validates if a string contains only uppercase or lowercase alphanumeric characters.
|
|
159
|
-
*
|
|
160
|
-
* This function checks if the input string consists solely of:
|
|
161
|
-
* - Lowercase letters (a-z)
|
|
162
|
-
* - Numbers (0-9)
|
|
163
|
-
* - Dot (.)
|
|
164
|
-
*
|
|
165
|
-
* It does not allow any special characters, spaces, or other non-alphanumeric characters.
|
|
166
|
-
*
|
|
167
|
-
* @param input - The string to be validated.
|
|
168
|
-
* @returns True if the string contains only alphanumeric characters, false otherwise.
|
|
169
|
-
*/
|
|
170
|
-
function isLowerAlphanumeric(input) {
|
|
171
|
-
var alphanumericRegex = /^[a-z0-9.]+$/;
|
|
172
|
-
return alphanumericRegex.test(input);
|
|
173
|
-
}
|
|
174
|
-
var createEventHandlerTelemetryConfig = function (name, options, contextConfig, event) { return ({
|
|
175
|
-
name: name,
|
|
176
|
-
disableSpanManagement: true,
|
|
177
|
-
spanOptions: options,
|
|
178
|
-
context: contextConfig.inheritFrom === 'EVENT'
|
|
179
|
-
? {
|
|
180
|
-
inheritFrom: 'TRACE_HEADERS',
|
|
181
|
-
traceHeaders: {
|
|
182
|
-
traceparent: event.traceparent,
|
|
183
|
-
tracestate: event.tracestate,
|
|
184
|
-
},
|
|
185
|
-
}
|
|
186
|
-
: {
|
|
187
|
-
inheritFrom: 'CONTEXT',
|
|
188
|
-
context: api_1.context.active(),
|
|
189
|
-
},
|
|
190
|
-
}); };
|
|
191
|
-
exports.createEventHandlerTelemetryConfig = createEventHandlerTelemetryConfig;
|
|
File without changes
|
|
File without changes
|