arvo-core 2.3.3 → 3.0.1

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.
Files changed (31) hide show
  1. package/dist/ArvoContract/SimpleArvoContract/index.d.ts +1 -0
  2. package/dist/ArvoContract/SimpleArvoContract/index.js +1 -0
  3. package/dist/ArvoContract/VersionedArvoContract/index.d.ts +1 -0
  4. package/dist/ArvoContract/VersionedArvoContract/index.js +8 -0
  5. package/dist/ArvoContract/VersionedArvoContract/types.d.ts +1 -0
  6. package/dist/ArvoContract/helpers.d.ts +1 -0
  7. package/dist/ArvoContract/helpers.js +8 -7
  8. package/dist/ArvoContract/index.d.ts +3 -0
  9. package/dist/ArvoContract/index.js +15 -2
  10. package/dist/ArvoContract/types.d.ts +3 -0
  11. package/dist/ArvoContract/validators.d.ts +1 -0
  12. package/dist/ArvoContract/validators.js +6 -0
  13. package/dist/ArvoEvent/helpers.js +2 -1
  14. package/dist/ArvoEvent/index.d.ts +166 -36
  15. package/dist/ArvoEvent/index.js +142 -39
  16. package/dist/ArvoEvent/schema.d.ts +3 -0
  17. package/dist/ArvoEvent/schema.js +6 -0
  18. package/dist/ArvoEvent/types.d.ts +2 -0
  19. package/dist/ArvoEventFactory/Orchestrator.d.ts +4 -2
  20. package/dist/ArvoEventFactory/Orchestrator.js +6 -4
  21. package/dist/ArvoEventFactory/index.d.ts +6 -3
  22. package/dist/ArvoEventFactory/index.js +6 -6
  23. package/dist/ArvoOrchestrationSubject/index.d.ts +2 -0
  24. package/dist/ArvoOrchestrationSubject/index.js +6 -4
  25. package/dist/ArvoOrchestrationSubject/schema.d.ts +5 -0
  26. package/dist/ArvoOrchestrationSubject/schema.js +6 -0
  27. package/dist/ArvoOrchestrationSubject/type.d.ts +2 -0
  28. package/dist/ArvoOrchestratorContract/index.js +3 -2
  29. package/dist/ArvoOrchestratorContract/types.d.ts +1 -0
  30. package/dist/index.d.ts +3 -0
  31. package/package.json +1 -1
@@ -50,6 +50,7 @@ export declare const createSimpleArvoContract: <TUri extends string, TType exten
50
50
  uri: TUri;
51
51
  type: TType;
52
52
  versions: TVersions;
53
+ domain?: string;
53
54
  metadata?: TMetaData;
54
55
  description?: string;
55
56
  }) => SimpleArvoContract<TUri, TType, TVersions, TMetaData>;
@@ -61,6 +61,7 @@ var createSimpleArvoContract = function (param) {
61
61
  var emitType = "evt.".concat(param.type, ".success");
62
62
  return (0, helpers_1.createArvoContract)({
63
63
  uri: param.uri,
64
+ domain: param.domain,
64
65
  type: "com.".concat(param.type),
65
66
  description: param.description,
66
67
  metadata: mergedMetadata,
@@ -26,6 +26,7 @@ export declare class VersionedArvoContract<TContract extends ArvoContract, TVers
26
26
  get emits(): TContract["versions"][TVersion]["emits"];
27
27
  get emitList(): { [K in keyof TContract["versions"][TVersion]["emits"] & string]: ArvoContractRecord<K, TContract["versions"][TVersion]["emits"][K]>; }[keyof TContract["versions"][TVersion]["emits"] & string][];
28
28
  get dataschema(): `${TContract["uri"]}/${TVersion}`;
29
+ get domain(): string | null;
29
30
  constructor(param: IVersionedArvoContract<TContract, TVersion>);
30
31
  /**
31
32
  * Converts the contract to JSON Schema format
@@ -98,6 +98,13 @@ var VersionedArvoContract = /** @class */ (function () {
98
98
  enumerable: false,
99
99
  configurable: true
100
100
  });
101
+ Object.defineProperty(VersionedArvoContract.prototype, "domain", {
102
+ get: function () {
103
+ return this._contract.domain;
104
+ },
105
+ enumerable: false,
106
+ configurable: true
107
+ });
101
108
  /**
102
109
  * Converts the contract to JSON Schema format
103
110
  * @returns Contract specification in JSON Schema format for documentation/serialization
@@ -107,6 +114,7 @@ var VersionedArvoContract = /** @class */ (function () {
107
114
  return {
108
115
  uri: this.uri,
109
116
  description: this.description,
117
+ domain: this.domain,
110
118
  version: this.version,
111
119
  metadata: this.metadata,
112
120
  accepts: {
@@ -30,6 +30,7 @@ export type ArvoContractRecordJsonSchema = {
30
30
  export type VersionedArvoContractJSONSchema = {
31
31
  uri: string;
32
32
  description: string | null;
33
+ domain: string | null;
33
34
  version: ArvoSemanticVersion;
34
35
  accepts: ArvoContractRecordJsonSchema;
35
36
  systemError: ArvoContractRecordJsonSchema;
@@ -39,6 +39,7 @@ export declare const createArvoContract: <TUri extends string, TType extends str
39
39
  uri: TUri;
40
40
  type: TType;
41
41
  versions: TVersions;
42
+ domain?: string;
42
43
  metadata?: TMetaData;
43
44
  description?: string;
44
45
  }) => ArvoContract<TUri, TType, TVersions, TMetaData>;
@@ -39,7 +39,7 @@ var utils_1 = require("../utils");
39
39
  * ```
40
40
  */
41
41
  var createArvoContract = function (contract) {
42
- var _a, _b;
42
+ var _a, _b, _c;
43
43
  var createErrorMessage = function (source, type, version) {
44
44
  var versionString = version ? ", version=".concat(version) : '';
45
45
  return (0, utils_1.cleanString)("\n In contract (uri=".concat(contract.uri).concat(versionString, "), the '").concat(source, "' event (type=").concat(type, ") must not start\n with '").concat(typegen_1.ArvoOrchestratorEventTypeGen.prefix, "' because this is a reserved pattern\n for Arvo orchestrators.\n "));
@@ -47,10 +47,10 @@ var createArvoContract = function (contract) {
47
47
  if (typegen_1.ArvoOrchestratorEventTypeGen.isOrchestratorEventType(contract.type)) {
48
48
  throw new Error(createErrorMessage('accepts', contract.type, null));
49
49
  }
50
- for (var _i = 0, _c = Object.entries(contract.versions); _i < _c.length; _i++) {
51
- var _d = _c[_i], version = _d[0], versionContract = _d[1];
52
- for (var _e = 0, _f = Object.keys(versionContract['emits']); _e < _f.length; _e++) {
53
- var emitType = _f[_e];
50
+ for (var _i = 0, _d = Object.entries(contract.versions); _i < _d.length; _i++) {
51
+ var _e = _d[_i], version = _e[0], versionContract = _e[1];
52
+ for (var _f = 0, _g = Object.keys(versionContract['emits']); _f < _g.length; _f++) {
53
+ var emitType = _g[_f];
54
54
  if (typegen_1.ArvoOrchestratorEventTypeGen.isOrchestratorEventType(emitType)) {
55
55
  throw new Error(createErrorMessage('emits', emitType, version));
56
56
  }
@@ -59,8 +59,9 @@ var createArvoContract = function (contract) {
59
59
  return new _1.default({
60
60
  uri: contract.uri,
61
61
  type: contract.type,
62
- description: (_a = contract.description) !== null && _a !== void 0 ? _a : null,
63
- metadata: (_b = contract.metadata) !== null && _b !== void 0 ? _b : {},
62
+ domain: (_a = contract === null || contract === void 0 ? void 0 : contract.domain) !== null && _a !== void 0 ? _a : null,
63
+ description: (_b = contract.description) !== null && _b !== void 0 ? _b : null,
64
+ metadata: (_c = contract.metadata) !== null && _c !== void 0 ? _c : {},
64
65
  versions: contract.versions,
65
66
  });
66
67
  };
@@ -46,11 +46,13 @@ export default class ArvoContract<TUri extends string = string, TType extends st
46
46
  protected readonly _versions: TVersions;
47
47
  protected readonly _description: string | null;
48
48
  protected readonly _metadata: TMetaData;
49
+ protected readonly _domain: string | null;
49
50
  get uri(): TUri;
50
51
  get type(): TType;
51
52
  get versions(): TVersions;
52
53
  get description(): string | null;
53
54
  get metadata(): TMetaData;
55
+ get domain(): string | null;
54
56
  /**
55
57
  * Creates a new ArvoContract instance with validated parameters.
56
58
  *
@@ -62,6 +64,7 @@ export default class ArvoContract<TUri extends string = string, TType extends st
62
64
  * @throws {Error} When version is a reserved wildcard version
63
65
  * @throws {Error} When emit type format is invalid
64
66
  * @throws {Error} When no versions are provided
67
+ * @throws {Error} When domain does not have follow the condition Domain must contain only lowercase letters, numbers, and dots
65
68
  */
66
69
  constructor(params: IArvoContract<TUri, TType, TVersions, TMetaData>);
67
70
  /**
@@ -49,16 +49,19 @@ var ArvoContract = /** @class */ (function () {
49
49
  * @throws {Error} When version is a reserved wildcard version
50
50
  * @throws {Error} When emit type format is invalid
51
51
  * @throws {Error} When no versions are provided
52
+ * @throws {Error} When domain does not have follow the condition Domain must contain only lowercase letters, numbers, and dots
52
53
  */
53
54
  function ArvoContract(params) {
54
55
  var _a;
56
+ validators_1.ArvoContractValidators.contract.uri.parse(params.uri);
57
+ validators_1.ArvoContractValidators.record.type.parse(params.type);
58
+ validators_1.ArvoContractValidators.contract.domain.parse(params.domain);
55
59
  this._uri = params.uri;
56
60
  this._type = params.type;
57
61
  this._versions = params.versions;
58
62
  this._description = (_a = params.description) !== null && _a !== void 0 ? _a : null;
59
63
  this._metadata = params.metadata;
60
- validators_1.ArvoContractValidators.contract.uri.parse(params.uri);
61
- validators_1.ArvoContractValidators.record.type.parse(params.type);
64
+ this._domain = params.domain;
62
65
  for (var _i = 0, _b = Object.entries(params.versions); _i < _b.length; _i++) {
63
66
  var _c = _b[_i], version = _c[0], versionContract = _c[1];
64
67
  schema_1.ArvoSemanticVersionSchema.parse(version);
@@ -109,6 +112,13 @@ var ArvoContract = /** @class */ (function () {
109
112
  enumerable: false,
110
113
  configurable: true
111
114
  });
115
+ Object.defineProperty(ArvoContract.prototype, "domain", {
116
+ get: function () {
117
+ return this._domain;
118
+ },
119
+ enumerable: false,
120
+ configurable: true
121
+ });
112
122
  Object.defineProperty(ArvoContract.prototype, "systemError", {
113
123
  /**
114
124
  * Gets the system error event specification for this contract.
@@ -183,6 +193,7 @@ var ArvoContract = /** @class */ (function () {
183
193
  return {
184
194
  uri: this._uri,
185
195
  type: this._type,
196
+ domain: this._domain,
186
197
  description: this._description,
187
198
  versions: this._versions,
188
199
  metadata: this._metadata,
@@ -198,11 +209,13 @@ var ArvoContract = /** @class */ (function () {
198
209
  try {
199
210
  return {
200
211
  uri: this._uri,
212
+ domain: this._domain,
201
213
  description: this._description,
202
214
  metadata: this._metadata,
203
215
  versions: Object.keys(this._versions).map(function (version) {
204
216
  var jsonSchema = _this.version(version).toJsonSchema();
205
217
  return {
218
+ domain: jsonSchema.domain,
206
219
  version: jsonSchema.version,
207
220
  accepts: jsonSchema.accepts,
208
221
  systemError: jsonSchema.systemError,
@@ -44,6 +44,8 @@ export interface IArvoContract<TUri extends string = string, TType extends strin
44
44
  metadata: TMetaData;
45
45
  /** A record mapping semantic versions to their corresponding schemas */
46
46
  versions: TVersions;
47
+ /** The domain of the contract handler */
48
+ domain: string | null;
47
49
  }
48
50
  /**
49
51
  * Represents the JSON Schema representation of an ArvoContract, used for serialization
@@ -51,6 +53,7 @@ export interface IArvoContract<TUri extends string = string, TType extends strin
51
53
  */
52
54
  export type ArvoContractJSONSchema = {
53
55
  uri: string;
56
+ domain: string | null;
54
57
  description: string | null;
55
58
  metadata: Record<string, any> | null;
56
59
  versions: Omit<VersionedArvoContractJSONSchema, 'uri' | 'description'>[];
@@ -2,6 +2,7 @@ import { z } from 'zod';
2
2
  export declare const ArvoContractValidators: {
3
3
  contract: {
4
4
  uri: z.ZodEffects<z.ZodString, string, string>;
5
+ domain: z.ZodNullable<z.ZodString>;
5
6
  };
6
7
  record: {
7
8
  type: z.ZodString;
@@ -10,6 +10,12 @@ exports.ArvoContractValidators = {
10
10
  .min(1, 'URI must be a non-empty string')
11
11
  .refine(utils_1.validateURI, 'The URI must a valid URI string')
12
12
  .describe((0, utils_1.cleanString)("\n The addressable unique URI of the contract so that\n it can be located and address for reference during\n operations\n ")),
13
+ domain: zod_1.z
14
+ .string()
15
+ .min(1, 'The domain must be non-empty string')
16
+ .regex(/^[a-z0-9.]+$/, 'Domain must contain only lowercase letters, numbers, and dots')
17
+ .nullable()
18
+ .describe('The contract handler domian'),
13
19
  },
14
20
  record: {
15
21
  type: zod_1.z
@@ -13,7 +13,7 @@ var schema_1 = require("./schema");
13
13
  * Internal generator function for creating instances.
14
14
  */
15
15
  var generator = function (event, extensions, otelHeaders) {
16
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
16
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
17
17
  if (event.datacontenttype && event.datacontenttype !== schema_1.ArvoDataContentType) {
18
18
  var warning = (0, utils_1.cleanString)("\n Warning! The provided datacontenttype(=".concat(event.datacontenttype, ")\n is not ArvoEvent compatible (=").concat(schema_1.ArvoDataContentType, "). There may \n be some limited functionality.\n "));
19
19
  (0, OpenTelemetry_1.logToSpan)({
@@ -37,6 +37,7 @@ var generator = function (event, extensions, otelHeaders) {
37
37
  redirectto: event.redirectto ? encodeURI(event.redirectto) : null,
38
38
  dataschema: event.dataschema ? encodeURI(event.dataschema) : null,
39
39
  parentid: event.parentid ? encodeURI(event.parentid) : null,
40
+ domain: (_l = event.domain) !== null && _l !== void 0 ? _l : null,
40
41
  }, event.data, extensions);
41
42
  };
42
43
  /**
@@ -1,37 +1,105 @@
1
1
  import type { InferArvoEvent } from '../types';
2
2
  import type { ArvoEventData, ArvoExtension, CloudEventContext, CloudEventExtension, OpenTelemetryExtension } from './types';
3
3
  /**
4
- * Represents an ArvoEvent, which extends the CloudEvent specification.
4
+ * Represents an ArvoEvent, which extends the CloudEvent specification with
5
+ * Arvo-specific extensions for event routing, access control, execution metrics,
6
+ * and OpenTelemetry distributed tracing support.
5
7
  */
6
8
  export default class ArvoEvent<TData extends ArvoEventData = ArvoEventData, TExtension extends CloudEventExtension = CloudEventExtension, TType extends string = string> {
9
+ /** Unique identifier of the event */
7
10
  readonly id: string;
11
+ /**
12
+ * URI reference identifying the context in which the event happened.
13
+ * Must be a properly encoded URI representing the event producer.
14
+ */
8
15
  readonly source: string;
16
+ /**
17
+ * The version of the CloudEvents specification which the event uses.
18
+ * Must be '1.0' for this version of the specification.
19
+ */
9
20
  readonly specversion: string;
21
+ /**
22
+ * Describes the type of event related to the originating occurrence.
23
+ * Must follow reverse-DNS naming convention (e.g., 'com.example.service.eventtype').
24
+ */
10
25
  readonly type: TType;
26
+ /**
27
+ * Identifies the subject of the event in the context of the event producer.
28
+ * In Arvo, this must be the Process ID and must be a properly encoded URI.
29
+ */
11
30
  readonly subject: string;
31
+ /**
32
+ * Content type of the data value following RFC 2046 format.
33
+ * Must contain 'application/cloudevents+json' or 'application/json'.
34
+ * Defaults to 'application/cloudevents+json;charset=UTF-8;profile=arvo'.
35
+ */
12
36
  readonly datacontenttype: string;
37
+ /**
38
+ * URI identifying the schema that the data adheres to.
39
+ * Must be a properly encoded URI if present, null otherwise.
40
+ */
13
41
  readonly dataschema: string | null;
42
+ /** The event data payload as a JSON serializable object */
14
43
  readonly data: TData;
44
+ /**
45
+ * Timestamp of when the occurrence happened in RFC 3339 format.
46
+ * If the actual occurrence time cannot be determined, this may be set
47
+ * to another time (such as current time) by the producer.
48
+ */
15
49
  readonly time: string;
16
50
  private readonly _extensions;
17
51
  /**
18
- * Creates an instance of ArvoEvent.
19
- * @param context - The CloudEvent context along with Arvo and OpenTelemetry extensions.
20
- * @param data - The event data.
21
- * @param extensions - Optional additional extensions.
52
+ * Creates an instance of ArvoEvent with CloudEvent context, data, and optional extensions.
22
53
  *
23
- * @throws {Error} If the datacontenttype is {@link ArvoDataContentType} but the `to` field
24
- * is not defined
54
+ * @param context - The CloudEvent context combined with required Arvo and OpenTelemetry extensions
55
+ * @param data - The event data payload (must be JSON serializable)
56
+ * @param extensions - Optional additional custom extensions with lowercase alphanumeric keys
57
+ *
58
+ * @throws {Error} If datacontenttype is "application/cloudevents+json;charset=UTF-8;profile=arvo" but the 'to' field is not defined
59
+ * @throws {Error} If any validation fails according to the respective schemas
60
+ *
61
+ * @example
62
+ * ```typescript
63
+ * const event = new ArvoEvent(
64
+ * {
65
+ * id: 'event-123',
66
+ * source: 'https://example.com/service',
67
+ * type: 'com.example.user.created',
68
+ * subject: 'https://example.com/users/123',
69
+ * time: new Date().toISOString(),
70
+ * specversion: '1.0',
71
+ * datacontenttype: 'application/cloudevents+json;charset=UTF-8;profile=arvo',
72
+ * dataschema: null,
73
+ * to: 'com.example.user.processor',
74
+ * accesscontrol: 'role:admin;department:hr',
75
+ * redirectto: null,
76
+ * executionunits: 10,
77
+ * parentid: 'parent-event-456',
78
+ * domain: 'analytics',
79
+ * traceparent: '00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01',
80
+ * tracestate: 'vendor=trace-data'
81
+ * },
82
+ * { userId: '123', name: 'John Doe' }
83
+ * );
84
+ * ```
25
85
  */
26
86
  constructor(context: CloudEventContext & ArvoExtension & OpenTelemetryExtension, data: TData, extensions?: TExtension);
27
87
  /**
28
- * Gets the CloudEvent-specified default fields and extensions.
29
- * @returns An object containing the base CloudEvent default fields and extensions.
30
- * `default` fields are the standard CloudEvents attributes, which include:
31
- * `extension` fields are additional attributes that provide extra context or functionality:
32
- * - ArvoExtension: Arvo-specific extensions (to, accesscontrol, redirectto, executionunits)
33
- * - OpenTelemetryExtension: OpenTelemetry-specific extensions (traceparent, tracestate)
34
- * - TExtension: Any additional custom extensions
88
+ * Gets the CloudEvent-specified fields separated into default attributes and extensions.
89
+ *
90
+ * @returns An object containing:
91
+ * - `default`: Standard CloudEvent attributes (id, source, specversion, type, subject, datacontenttype, dataschema, data, time)
92
+ * - `extensions`: All extension attributes including:
93
+ * - Arvo extensions
94
+ * - OpenTelemetry extensions
95
+ * - Custom extensions
96
+ *
97
+ * @example
98
+ * ```typescript
99
+ * const { default: defaults, extensions } = event.cloudevent;
100
+ * console.log(defaults.id); // Event ID
101
+ * console.log(extensions.to); // Arvo 'to' field
102
+ * ```
35
103
  */
36
104
  get cloudevent(): {
37
105
  default: {
@@ -51,36 +119,56 @@ export default class ArvoEvent<TData extends ArvoEventData = ArvoEventData, TExt
51
119
  redirectto: string | null;
52
120
  executionunits: number | null;
53
121
  parentid: string | null;
122
+ domain: string | null;
54
123
  } & {
55
124
  traceparent: string | null;
56
125
  tracestate: string | null;
57
126
  };
58
127
  };
59
128
  /**
60
- * Converts the ArvoEvent to a JSON-serializable object.
61
- * It bundles the extensions and the cloudevent fields into
62
- * one object.
129
+ * Converts the ArvoEvent to a JSON-serializable object by combining
130
+ * all CloudEvent default fields with all extensions into a single flat object.
131
+ *
132
+ * @returns A flat object containing all CloudEvent fields and extensions,
133
+ * suitable for JSON serialization and network transmission
63
134
  *
64
135
  * @remarks
65
- * This method combines the default CloudEvent fields and all extensions
66
- * (including Arvo and OpenTelemetry extensions) into a single object.
67
- * If you need to access the CloudEvent fields and extensions separately,
68
- * use the `cloudevent` getter instead.
136
+ * This method creates a flattened representation where both standard CloudEvent
137
+ * fields and all extensions (Arvo, OpenTelemetry, and custom) are at the same level.
138
+ * For separated access to defaults and extensions, use the `cloudevent` getter instead.
139
+ *
140
+ * @example
141
+ * ```typescript
142
+ * const jsonObj = event.toJSON();
143
+ * // Contains: id, source, type, subject, data, time, to, traceparent, etc.
144
+ * ```
69
145
  */
70
146
  toJSON(): InferArvoEvent<typeof this>;
71
147
  /**
72
- * Converts the ArvoEvent to a JSON string.
73
- * @param [spacing=0] - The number of spaces to use for indentation in the resulting JSON string.
74
- * @returns A JSON string representation of the ArvoEvent.
148
+ * Converts the ArvoEvent to a JSON string representation.
149
+ *
150
+ * @param spacing - The number of spaces to use for indentation (default: 0 for compact output)
151
+ * @returns A JSON string representation of the complete ArvoEvent
152
+ *
153
+ * @example
154
+ * ```typescript
155
+ * const compactJson = event.toString(); // Compact JSON
156
+ * const prettyJson = event.toString(2); // Pretty-printed with 2-space indentation
157
+ * ```
75
158
  */
76
159
  toString(spacing?: number): string;
77
160
  /**
78
- * Gets OpenTelemetry attributes derived from the ArvoEvent.
79
- * @returns An object containing OpenTelemetry attributes.
80
- * The OpenTelemetry attributes for CloudEvents is as per
81
- * the spec provided [in the official documentation](https://opentelemetry.io/docs/specs/semconv/attributes-registry/cloudevents/).
82
- * Additionally, the Arvo extension attributed are also returned
83
- * as `cloudevents.arvo.event_*` fields.
161
+ * Gets OpenTelemetry attributes derived from the ArvoEvent for distributed tracing.
162
+ *
163
+ * @returns An object containing OpenTelemetry semantic convention attributes:
164
+ * - Standard CloudEvent attributes prefixed with 'cloudevents.event_*'
165
+ * - Arvo-specific attributes prefixed with 'cloudevents.arvo.*'
166
+ * - Uses 'N/A' for undefined/null values to maintain telemetry consistency
167
+ *
168
+ * @remarks
169
+ * The attributes follow the OpenTelemetry semantic conventions for CloudEvents
170
+ * as specified in the official documentation:
171
+ * https://opentelemetry.io/docs/specs/semconv/attributes-registry/cloudevents/
84
172
  */
85
173
  get otelAttributes(): {
86
174
  'cloudevents.event_id': string;
@@ -95,23 +183,65 @@ export default class ArvoEvent<TData extends ArvoEventData = ArvoEventData, TExt
95
183
  'cloudevents.arvo.event_to': string;
96
184
  'cloudevents.arvo.event_executionunits': string | number;
97
185
  'cloudevents.arvo.event_parentid': string;
186
+ 'cloudevents.arvo.event_domain': string;
98
187
  };
188
+ /**
189
+ * Gets the target consumer machine for event routing.
190
+ */
99
191
  get to(): string | null;
192
+ /**
193
+ * Gets the access control information for the event.
194
+ * Can contain:
195
+ * - A UserID (valid UUID)
196
+ * - An encrypted base64 string with access control data
197
+ * - Key-value pairs (semicolon-separated, colon-delimited)
198
+ * Example: "role:admin;department:finance;clearance:top-secret"
199
+ */
100
200
  get accesscontrol(): string | null;
201
+ /**
202
+ * Gets the alternative recipient or destination for dynamic routing.
203
+ * Enables complex workflows and conditional event routing.
204
+ */
101
205
  get redirectto(): string | null;
206
+ /**
207
+ * Gets the execution units representing the cost associated with
208
+ * generating this event. Used for tracking financial impact and
209
+ * resource utilization in cloud-based systems.
210
+ */
102
211
  get executionunits(): number | null;
212
+ /**
213
+ * Gets the OpenTelemetry traceparent header containing trace context
214
+ * information including trace ID, parent span ID, and trace flags
215
+ * for distributed tracing across services.
216
+ */
103
217
  get traceparent(): string | null;
218
+ /**
219
+ * Gets the OpenTelemetry tracestate header containing vendor-specific
220
+ * trace information as key-value pairs propagated alongside traceparent
221
+ * in distributed tracing scenarios.
222
+ */
104
223
  get tracestate(): string | null;
224
+ /**
225
+ * Gets the unique identifier of the event that directly triggered
226
+ * the creation of this event within the Arvo ecosystem.
227
+ * Establishes direct causal relationships for event lineage tracking.
228
+ * Null indicates an initiating event or generation outside direct causation.
229
+ */
105
230
  get parentid(): string | null;
106
231
  /**
107
- * Gets the custom extensions of the ArvoEvent.
232
+ * Gets the processing domain for event routing and workflow orchestration.
233
+ */
234
+ get domain(): string | null;
235
+ /**
236
+ * Gets only the custom extensions (TExtension) added to the ArvoEvent,
237
+ * excluding the standard Arvo and OpenTelemetry extensions.
238
+ *
239
+ * @returns The custom extensions object with Arvo and OpenTelemetry fields removed
108
240
  *
109
241
  * @remarks
110
- * This getter returns only the custom extensions (TExtension) added to the ArvoEvent,
111
- * excluding the standard Arvo and OpenTelemetry extensions.
112
- * For accessing all extensions including Arvo and OpenTelemetry,
113
- * use `<ArvoEvent>.cloudevent.extensions`.
114
- * For accessing the basic CloudEvent fields, use `<ArvoEvent>.cloudevent.default`.
242
+ * For accessing all extensions including Arvo and OpenTelemetry, use `cloudevent.extensions`.
243
+ * For accessing basic CloudEvent fields, use `cloudevent.default`.
244
+ * Custom extension keys must follow lowercase alphanumeric naming (a-z, 0-9 only).
115
245
  */
116
246
  get extensions(): TExtension;
117
247
  }
@@ -25,17 +25,45 @@ Object.defineProperty(exports, "__esModule", { value: true });
25
25
  var OpenTelemetry_1 = require("../OpenTelemetry");
26
26
  var schema_1 = require("./schema");
27
27
  /**
28
- * Represents an ArvoEvent, which extends the CloudEvent specification.
28
+ * Represents an ArvoEvent, which extends the CloudEvent specification with
29
+ * Arvo-specific extensions for event routing, access control, execution metrics,
30
+ * and OpenTelemetry distributed tracing support.
29
31
  */
30
32
  var ArvoEvent = /** @class */ (function () {
31
33
  /**
32
- * Creates an instance of ArvoEvent.
33
- * @param context - The CloudEvent context along with Arvo and OpenTelemetry extensions.
34
- * @param data - The event data.
35
- * @param extensions - Optional additional extensions.
34
+ * Creates an instance of ArvoEvent with CloudEvent context, data, and optional extensions.
36
35
  *
37
- * @throws {Error} If the datacontenttype is {@link ArvoDataContentType} but the `to` field
38
- * is not defined
36
+ * @param context - The CloudEvent context combined with required Arvo and OpenTelemetry extensions
37
+ * @param data - The event data payload (must be JSON serializable)
38
+ * @param extensions - Optional additional custom extensions with lowercase alphanumeric keys
39
+ *
40
+ * @throws {Error} If datacontenttype is "application/cloudevents+json;charset=UTF-8;profile=arvo" but the 'to' field is not defined
41
+ * @throws {Error} If any validation fails according to the respective schemas
42
+ *
43
+ * @example
44
+ * ```typescript
45
+ * const event = new ArvoEvent(
46
+ * {
47
+ * id: 'event-123',
48
+ * source: 'https://example.com/service',
49
+ * type: 'com.example.user.created',
50
+ * subject: 'https://example.com/users/123',
51
+ * time: new Date().toISOString(),
52
+ * specversion: '1.0',
53
+ * datacontenttype: 'application/cloudevents+json;charset=UTF-8;profile=arvo',
54
+ * dataschema: null,
55
+ * to: 'com.example.user.processor',
56
+ * accesscontrol: 'role:admin;department:hr',
57
+ * redirectto: null,
58
+ * executionunits: 10,
59
+ * parentid: 'parent-event-456',
60
+ * domain: 'analytics',
61
+ * traceparent: '00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01',
62
+ * tracestate: 'vendor=trace-data'
63
+ * },
64
+ * { userId: '123', name: 'John Doe' }
65
+ * );
66
+ * ```
39
67
  */
40
68
  function ArvoEvent(context, data, extensions) {
41
69
  var cloudEventContext = schema_1.CloudEventContextSchema.parse(context);
@@ -50,7 +78,7 @@ var ArvoEvent = /** @class */ (function () {
50
78
  this.data = schema_1.ArvoDataSchema.parse(data);
51
79
  var arvoExtension = schema_1.ArvoExtensionSchema.parse(context);
52
80
  var otelExtension = schema_1.OpenTelemetryExtensionSchema.parse(context);
53
- this._extensions = __assign(__assign({}, (extensions ? schema_1.CloudEventExtensionSchema.parse(extensions) : {})), { to: arvoExtension.to, accesscontrol: arvoExtension.accesscontrol, redirectto: arvoExtension.redirectto, executionunits: arvoExtension.executionunits, traceparent: otelExtension.traceparent, tracestate: otelExtension.tracestate, parentid: arvoExtension.parentid });
81
+ this._extensions = __assign(__assign({}, (extensions ? schema_1.CloudEventExtensionSchema.parse(extensions) : {})), { to: arvoExtension.to, accesscontrol: arvoExtension.accesscontrol, redirectto: arvoExtension.redirectto, executionunits: arvoExtension.executionunits, traceparent: otelExtension.traceparent, tracestate: otelExtension.tracestate, parentid: arvoExtension.parentid, domain: arvoExtension.domain });
54
82
  if (this.datacontenttype === schema_1.ArvoDataContentType) {
55
83
  if (!this._extensions.to) {
56
84
  throw new Error("The ArvoEvent must have a non-empty 'to' field");
@@ -61,13 +89,21 @@ var ArvoEvent = /** @class */ (function () {
61
89
  }
62
90
  Object.defineProperty(ArvoEvent.prototype, "cloudevent", {
63
91
  /**
64
- * Gets the CloudEvent-specified default fields and extensions.
65
- * @returns An object containing the base CloudEvent default fields and extensions.
66
- * `default` fields are the standard CloudEvents attributes, which include:
67
- * `extension` fields are additional attributes that provide extra context or functionality:
68
- * - ArvoExtension: Arvo-specific extensions (to, accesscontrol, redirectto, executionunits)
69
- * - OpenTelemetryExtension: OpenTelemetry-specific extensions (traceparent, tracestate)
70
- * - TExtension: Any additional custom extensions
92
+ * Gets the CloudEvent-specified fields separated into default attributes and extensions.
93
+ *
94
+ * @returns An object containing:
95
+ * - `default`: Standard CloudEvent attributes (id, source, specversion, type, subject, datacontenttype, dataschema, data, time)
96
+ * - `extensions`: All extension attributes including:
97
+ * - Arvo extensions
98
+ * - OpenTelemetry extensions
99
+ * - Custom extensions
100
+ *
101
+ * @example
102
+ * ```typescript
103
+ * const { default: defaults, extensions } = event.cloudevent;
104
+ * console.log(defaults.id); // Event ID
105
+ * console.log(extensions.to); // Arvo 'to' field
106
+ * ```
71
107
  */
72
108
  get: function () {
73
109
  return {
@@ -89,23 +125,37 @@ var ArvoEvent = /** @class */ (function () {
89
125
  configurable: true
90
126
  });
91
127
  /**
92
- * Converts the ArvoEvent to a JSON-serializable object.
93
- * It bundles the extensions and the cloudevent fields into
94
- * one object.
128
+ * Converts the ArvoEvent to a JSON-serializable object by combining
129
+ * all CloudEvent default fields with all extensions into a single flat object.
130
+ *
131
+ * @returns A flat object containing all CloudEvent fields and extensions,
132
+ * suitable for JSON serialization and network transmission
95
133
  *
96
134
  * @remarks
97
- * This method combines the default CloudEvent fields and all extensions
98
- * (including Arvo and OpenTelemetry extensions) into a single object.
99
- * If you need to access the CloudEvent fields and extensions separately,
100
- * use the `cloudevent` getter instead.
135
+ * This method creates a flattened representation where both standard CloudEvent
136
+ * fields and all extensions (Arvo, OpenTelemetry, and custom) are at the same level.
137
+ * For separated access to defaults and extensions, use the `cloudevent` getter instead.
138
+ *
139
+ * @example
140
+ * ```typescript
141
+ * const jsonObj = event.toJSON();
142
+ * // Contains: id, source, type, subject, data, time, to, traceparent, etc.
143
+ * ```
101
144
  */
102
145
  ArvoEvent.prototype.toJSON = function () {
103
146
  return __assign(__assign({}, this.cloudevent.default), this._extensions);
104
147
  };
105
148
  /**
106
- * Converts the ArvoEvent to a JSON string.
107
- * @param [spacing=0] - The number of spaces to use for indentation in the resulting JSON string.
108
- * @returns A JSON string representation of the ArvoEvent.
149
+ * Converts the ArvoEvent to a JSON string representation.
150
+ *
151
+ * @param spacing - The number of spaces to use for indentation (default: 0 for compact output)
152
+ * @returns A JSON string representation of the complete ArvoEvent
153
+ *
154
+ * @example
155
+ * ```typescript
156
+ * const compactJson = event.toString(); // Compact JSON
157
+ * const prettyJson = event.toString(2); // Pretty-printed with 2-space indentation
158
+ * ```
109
159
  */
110
160
  ArvoEvent.prototype.toString = function (spacing) {
111
161
  if (spacing === void 0) { spacing = 0; }
@@ -113,15 +163,20 @@ var ArvoEvent = /** @class */ (function () {
113
163
  };
114
164
  Object.defineProperty(ArvoEvent.prototype, "otelAttributes", {
115
165
  /**
116
- * Gets OpenTelemetry attributes derived from the ArvoEvent.
117
- * @returns An object containing OpenTelemetry attributes.
118
- * The OpenTelemetry attributes for CloudEvents is as per
119
- * the spec provided [in the official documentation](https://opentelemetry.io/docs/specs/semconv/attributes-registry/cloudevents/).
120
- * Additionally, the Arvo extension attributed are also returned
121
- * as `cloudevents.arvo.event_*` fields.
166
+ * Gets OpenTelemetry attributes derived from the ArvoEvent for distributed tracing.
167
+ *
168
+ * @returns An object containing OpenTelemetry semantic convention attributes:
169
+ * - Standard CloudEvent attributes prefixed with 'cloudevents.event_*'
170
+ * - Arvo-specific attributes prefixed with 'cloudevents.arvo.*'
171
+ * - Uses 'N/A' for undefined/null values to maintain telemetry consistency
172
+ *
173
+ * @remarks
174
+ * The attributes follow the OpenTelemetry semantic conventions for CloudEvents
175
+ * as specified in the official documentation:
176
+ * https://opentelemetry.io/docs/specs/semconv/attributes-registry/cloudevents/
122
177
  */
123
178
  get: function () {
124
- var _a, _b, _c, _d, _e;
179
+ var _a, _b, _c, _d, _e, _f;
125
180
  return {
126
181
  'cloudevents.event_id': this.id || OpenTelemetry_1.OTelNull,
127
182
  'cloudevents.event_source': this.source || OpenTelemetry_1.OTelNull,
@@ -135,12 +190,16 @@ var ArvoEvent = /** @class */ (function () {
135
190
  'cloudevents.arvo.event_to': (_c = this._extensions.to) !== null && _c !== void 0 ? _c : OpenTelemetry_1.OTelNull,
136
191
  'cloudevents.arvo.event_executionunits': (_d = this._extensions.executionunits) !== null && _d !== void 0 ? _d : OpenTelemetry_1.OTelNull,
137
192
  'cloudevents.arvo.event_parentid': (_e = this._extensions.parentid) !== null && _e !== void 0 ? _e : OpenTelemetry_1.OTelNull,
193
+ 'cloudevents.arvo.event_domain': (_f = this._extensions.domain) !== null && _f !== void 0 ? _f : OpenTelemetry_1.OTelNull,
138
194
  };
139
195
  },
140
196
  enumerable: false,
141
197
  configurable: true
142
198
  });
143
199
  Object.defineProperty(ArvoEvent.prototype, "to", {
200
+ /**
201
+ * Gets the target consumer machine for event routing.
202
+ */
144
203
  get: function () {
145
204
  return this._extensions.to;
146
205
  },
@@ -148,6 +207,14 @@ var ArvoEvent = /** @class */ (function () {
148
207
  configurable: true
149
208
  });
150
209
  Object.defineProperty(ArvoEvent.prototype, "accesscontrol", {
210
+ /**
211
+ * Gets the access control information for the event.
212
+ * Can contain:
213
+ * - A UserID (valid UUID)
214
+ * - An encrypted base64 string with access control data
215
+ * - Key-value pairs (semicolon-separated, colon-delimited)
216
+ * Example: "role:admin;department:finance;clearance:top-secret"
217
+ */
151
218
  get: function () {
152
219
  return this._extensions.accesscontrol;
153
220
  },
@@ -155,6 +222,10 @@ var ArvoEvent = /** @class */ (function () {
155
222
  configurable: true
156
223
  });
157
224
  Object.defineProperty(ArvoEvent.prototype, "redirectto", {
225
+ /**
226
+ * Gets the alternative recipient or destination for dynamic routing.
227
+ * Enables complex workflows and conditional event routing.
228
+ */
158
229
  get: function () {
159
230
  return this._extensions.redirectto;
160
231
  },
@@ -162,6 +233,11 @@ var ArvoEvent = /** @class */ (function () {
162
233
  configurable: true
163
234
  });
164
235
  Object.defineProperty(ArvoEvent.prototype, "executionunits", {
236
+ /**
237
+ * Gets the execution units representing the cost associated with
238
+ * generating this event. Used for tracking financial impact and
239
+ * resource utilization in cloud-based systems.
240
+ */
165
241
  get: function () {
166
242
  return this._extensions.executionunits;
167
243
  },
@@ -169,6 +245,11 @@ var ArvoEvent = /** @class */ (function () {
169
245
  configurable: true
170
246
  });
171
247
  Object.defineProperty(ArvoEvent.prototype, "traceparent", {
248
+ /**
249
+ * Gets the OpenTelemetry traceparent header containing trace context
250
+ * information including trace ID, parent span ID, and trace flags
251
+ * for distributed tracing across services.
252
+ */
172
253
  get: function () {
173
254
  return this._extensions.traceparent;
174
255
  },
@@ -176,6 +257,11 @@ var ArvoEvent = /** @class */ (function () {
176
257
  configurable: true
177
258
  });
178
259
  Object.defineProperty(ArvoEvent.prototype, "tracestate", {
260
+ /**
261
+ * Gets the OpenTelemetry tracestate header containing vendor-specific
262
+ * trace information as key-value pairs propagated alongside traceparent
263
+ * in distributed tracing scenarios.
264
+ */
179
265
  get: function () {
180
266
  return this._extensions.tracestate;
181
267
  },
@@ -183,26 +269,43 @@ var ArvoEvent = /** @class */ (function () {
183
269
  configurable: true
184
270
  });
185
271
  Object.defineProperty(ArvoEvent.prototype, "parentid", {
272
+ /**
273
+ * Gets the unique identifier of the event that directly triggered
274
+ * the creation of this event within the Arvo ecosystem.
275
+ * Establishes direct causal relationships for event lineage tracking.
276
+ * Null indicates an initiating event or generation outside direct causation.
277
+ */
186
278
  get: function () {
187
279
  return this._extensions.parentid;
188
280
  },
189
281
  enumerable: false,
190
282
  configurable: true
191
283
  });
284
+ Object.defineProperty(ArvoEvent.prototype, "domain", {
285
+ /**
286
+ * Gets the processing domain for event routing and workflow orchestration.
287
+ */
288
+ get: function () {
289
+ return this._extensions.domain;
290
+ },
291
+ enumerable: false,
292
+ configurable: true
293
+ });
192
294
  Object.defineProperty(ArvoEvent.prototype, "extensions", {
193
295
  /**
194
- * Gets the custom extensions of the ArvoEvent.
296
+ * Gets only the custom extensions (TExtension) added to the ArvoEvent,
297
+ * excluding the standard Arvo and OpenTelemetry extensions.
298
+ *
299
+ * @returns The custom extensions object with Arvo and OpenTelemetry fields removed
195
300
  *
196
301
  * @remarks
197
- * This getter returns only the custom extensions (TExtension) added to the ArvoEvent,
198
- * excluding the standard Arvo and OpenTelemetry extensions.
199
- * For accessing all extensions including Arvo and OpenTelemetry,
200
- * use `<ArvoEvent>.cloudevent.extensions`.
201
- * For accessing the basic CloudEvent fields, use `<ArvoEvent>.cloudevent.default`.
302
+ * For accessing all extensions including Arvo and OpenTelemetry, use `cloudevent.extensions`.
303
+ * For accessing basic CloudEvent fields, use `cloudevent.default`.
304
+ * Custom extension keys must follow lowercase alphanumeric naming (a-z, 0-9 only).
202
305
  */
203
306
  get: function () {
204
307
  var _a = this
205
- ._extensions, traceparent = _a.traceparent, tracestate = _a.tracestate, to = _a.to, redirectto = _a.redirectto, accesscontrol = _a.accesscontrol, executionunits = _a.executionunits, parentid = _a.parentid, rest = __rest(_a, ["traceparent", "tracestate", "to", "redirectto", "accesscontrol", "executionunits", "parentid"]);
308
+ ._extensions, traceparent = _a.traceparent, tracestate = _a.tracestate, to = _a.to, redirectto = _a.redirectto, accesscontrol = _a.accesscontrol, executionunits = _a.executionunits, parentid = _a.parentid, domain = _a.domain, rest = __rest(_a, ["traceparent", "tracestate", "to", "redirectto", "accesscontrol", "executionunits", "parentid", "domain"]);
206
309
  return rest;
207
310
  },
208
311
  enumerable: false,
@@ -59,18 +59,21 @@ export declare const ArvoExtensionSchema: z.ZodObject<{
59
59
  redirectto: z.ZodNullable<z.ZodEffects<z.ZodString, string, string>>;
60
60
  executionunits: z.ZodNullable<z.ZodNumber>;
61
61
  parentid: z.ZodNullable<z.ZodString>;
62
+ domain: z.ZodNullable<z.ZodString>;
62
63
  }, "strip", z.ZodTypeAny, {
63
64
  to: string | null;
64
65
  accesscontrol: string | null;
65
66
  redirectto: string | null;
66
67
  executionunits: number | null;
67
68
  parentid: string | null;
69
+ domain: string | null;
68
70
  }, {
69
71
  to: string | null;
70
72
  accesscontrol: string | null;
71
73
  redirectto: string | null;
72
74
  executionunits: number | null;
73
75
  parentid: string | null;
76
+ domain: string | null;
74
77
  }>;
75
78
  /**
76
79
  * Zod schema for validating OpenTelemetry extensions to the CloudEvent.
@@ -106,6 +106,12 @@ exports.ArvoExtensionSchema = zod_1.z
106
106
  .min(1, 'ID must be a non-empty string')
107
107
  .nullable()
108
108
  .describe((0, utils_1.cleanString)("\n The unique identifier of the event that directly triggered the creation \n of this event within the Arvo ecosystem. When set, it establishes a \n direct causal relationship for event lineage tracking and workflow \n orchestration. When null, it indicates this is an initiating event \n or was generated outside of direct event causation.\n ")),
109
+ domain: zod_1.z
110
+ .string()
111
+ .min(1, 'Domain must be non-empty string')
112
+ .regex(/^[a-z0-9.]+$/, 'Domain must contain only lowercase letters, numbers, and dots')
113
+ .nullable()
114
+ .describe((0, utils_1.cleanString)("\n Specifies the processing domain for event routing and workflow orchestration.\n Events can be assigned to specific domains (e.g., 'external', 'analytics', 'priority')\n to enable specialized processing flows such as human-in-the-loop operations,\n third-party integrations, or custom handling pipelines. Each event can only\n belong to one domain - if an event needs to be processed by multiple domains,\n separate identical events (with different IDs) must be created for each respective\n domain. Domain names must contain only lowercase letters, numbers, and dots.\n ")),
109
115
  })
110
116
  .describe('Schema for Arvo-specific extensions to the CloudEvent.');
111
117
  /**
@@ -61,4 +61,6 @@ export type CreateArvoEvent<TData extends ArvoEventData, TType extends string> =
61
61
  tracestate?: string;
62
62
  /** The unique identifier of the event that directly triggered the creation of this event within the Arvo ecosystem. */
63
63
  parentid?: string;
64
+ /** Specifies the processing domain for event routing and workflow orchestration. Must contain only lowercase letters, numbers, and dots. */
65
+ domain?: string;
64
66
  };
@@ -27,8 +27,9 @@ export declare class ArvoOrchestratorEventFactory<TContract extends VersionedArv
27
27
  *
28
28
  * @throws Error if event validation fails
29
29
  */
30
- init<TExtension extends Record<string, any>>(event: Omit<CreateArvoEvent<z.input<TContract['accepts']['schema']>, TContract['accepts']['type']>, 'type' | 'datacontenttype' | 'dataschema' | 'subject'> & {
30
+ init<TExtension extends Record<string, any>>(event: Omit<CreateArvoEvent<z.input<TContract['accepts']['schema']>, TContract['accepts']['type']>, 'type' | 'datacontenttype' | 'dataschema' | 'subject' | 'domain'> & {
31
31
  subject?: string;
32
+ domain?: string | null;
32
33
  }, extensions?: TExtension): import("..").ArvoEvent<z.TypeOf<TContract["accepts"]["schema"]>, TExtension, TContract["accepts"]["type"]>;
33
34
  /**
34
35
  * Creates a completion event for the orchestration flow.
@@ -40,7 +41,8 @@ export declare class ArvoOrchestratorEventFactory<TContract extends VersionedArv
40
41
  *
41
42
  * @throws Error if event validation fails or complete event type not configured
42
43
  */
43
- complete<TExtension extends Record<string, any>>(event: Omit<CreateArvoEvent<z.input<TContract['emits'][TContract['metadata']['completeEventType']]>, TContract['metadata']['completeEventType']>, 'datacontenttype' | 'dataschema' | 'type' | 'subject'> & {
44
+ complete<TExtension extends Record<string, any>>(event: Omit<CreateArvoEvent<z.input<TContract['emits'][TContract['metadata']['completeEventType']]>, TContract['metadata']['completeEventType']>, 'datacontenttype' | 'dataschema' | 'type' | 'subject' | 'domain'> & {
44
45
  subject?: string;
46
+ domain?: string | null;
45
47
  }, extensions?: TExtension): import("..").ArvoEvent<z.TypeOf<TContract["emits"][TContract["metadata"]["completeEventType"]]>, TExtension, TContract["metadata"]["completeEventType"]>;
46
48
  }
@@ -77,7 +77,7 @@ var ArvoOrchestratorEventFactory = /** @class */ (function (_super) {
77
77
  name: "".concat(this._name, ".init"),
78
78
  spanOptions: (0, utils_2.createSpanOptions)(this.contract),
79
79
  fn: function (span) {
80
- var _a, _b, _c, _d, _e, _f;
80
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
81
81
  var otelHeaders = (0, OpenTelemetry_1.currentOpenTelemetryHeaders)();
82
82
  var validationResult = _this.contract.accepts.schema.safeParse(event.data);
83
83
  if (!validationResult.success) {
@@ -97,13 +97,14 @@ var ArvoOrchestratorEventFactory = /** @class */ (function (_super) {
97
97
  orchestator: _this.contract.accepts.type,
98
98
  initiator: event.source,
99
99
  version: _this.contract.version,
100
+ domain: event.domain === null ? undefined : ((_d = (_c = event.domain) !== null && _c !== void 0 ? _c : _this.contract.domain) !== null && _d !== void 0 ? _d : undefined),
100
101
  meta: event.redirectto
101
102
  ? {
102
103
  redirectto: event.redirectto,
103
104
  }
104
105
  : undefined,
105
106
  }));
106
- var generatedEvent = (0, helpers_1.createArvoEvent)(__assign(__assign({}, event), { subject: eventSubject, traceparent: (_d = (_c = event.traceparent) !== null && _c !== void 0 ? _c : otelHeaders.traceparent) !== null && _d !== void 0 ? _d : undefined, tracestate: (_f = (_e = event.tracestate) !== null && _e !== void 0 ? _e : otelHeaders.tracestate) !== null && _f !== void 0 ? _f : undefined, type: _this.contract.accepts.type, datacontenttype: schema_1.ArvoDataContentType, dataschema: utils_1.EventDataschemaUtil.create(_this.contract), data: validationResult.data }), extensions, { disable: true });
107
+ var generatedEvent = (0, helpers_1.createArvoEvent)(__assign(__assign({}, event), { subject: eventSubject, traceparent: (_f = (_e = event.traceparent) !== null && _e !== void 0 ? _e : otelHeaders.traceparent) !== null && _f !== void 0 ? _f : undefined, tracestate: (_h = (_g = event.tracestate) !== null && _g !== void 0 ? _g : otelHeaders.tracestate) !== null && _h !== void 0 ? _h : undefined, type: _this.contract.accepts.type, datacontenttype: schema_1.ArvoDataContentType, dataschema: utils_1.EventDataschemaUtil.create(_this.contract), data: validationResult.data, domain: event.domain === null ? undefined : ((_k = (_j = event.domain) !== null && _j !== void 0 ? _j : _this.contract.domain) !== null && _k !== void 0 ? _k : undefined) }), extensions, { disable: true });
107
108
  span.setAttributes(generatedEvent.otelAttributes);
108
109
  return generatedEvent;
109
110
  },
@@ -125,7 +126,7 @@ var ArvoOrchestratorEventFactory = /** @class */ (function (_super) {
125
126
  name: "".concat(this._name, ".complete"),
126
127
  spanOptions: (0, utils_2.createSpanOptions)(this.contract),
127
128
  fn: function (span) {
128
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
129
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
129
130
  var otelHeaders = (0, OpenTelemetry_1.currentOpenTelemetryHeaders)();
130
131
  var validationResult = (_b = (_a = _this.contract.emits) === null || _a === void 0 ? void 0 : _a[_this.contract.metadata.completeEventType]) === null || _b === void 0 ? void 0 : _b.safeParse(event.data);
131
132
  if (!(validationResult === null || validationResult === void 0 ? void 0 : validationResult.success)) {
@@ -137,13 +138,14 @@ var ArvoOrchestratorEventFactory = /** @class */ (function (_super) {
137
138
  initiator: event.source,
138
139
  version: _this.contract.version,
139
140
  orchestator: eventType,
141
+ domain: event.domain === null ? undefined : ((_g = (_f = event.domain) !== null && _f !== void 0 ? _f : _this.contract.domain) !== null && _g !== void 0 ? _g : undefined),
140
142
  meta: event.redirectto
141
143
  ? {
142
144
  redirectto: event.redirectto,
143
145
  }
144
146
  : undefined,
145
147
  });
146
- var generatedEvent = (0, helpers_1.createArvoEvent)(__assign(__assign({}, event), { subject: eventSubject, type: eventType, traceparent: (_g = (_f = event.traceparent) !== null && _f !== void 0 ? _f : otelHeaders.traceparent) !== null && _g !== void 0 ? _g : undefined, tracestate: (_j = (_h = event.tracestate) !== null && _h !== void 0 ? _h : otelHeaders.tracestate) !== null && _j !== void 0 ? _j : undefined, datacontenttype: schema_1.ArvoDataContentType, dataschema: utils_1.EventDataschemaUtil.create(_this.contract), data: validationResult.data }), extensions, { disable: true });
148
+ var generatedEvent = (0, helpers_1.createArvoEvent)(__assign(__assign({}, event), { subject: eventSubject, type: eventType, traceparent: (_j = (_h = event.traceparent) !== null && _h !== void 0 ? _h : otelHeaders.traceparent) !== null && _j !== void 0 ? _j : undefined, tracestate: (_l = (_k = event.tracestate) !== null && _k !== void 0 ? _k : otelHeaders.tracestate) !== null && _l !== void 0 ? _l : undefined, datacontenttype: schema_1.ArvoDataContentType, dataschema: utils_1.EventDataschemaUtil.create(_this.contract), data: validationResult.data, domain: event.domain === null ? undefined : ((_o = (_m = event.domain) !== null && _m !== void 0 ? _m : _this.contract.domain) !== null && _o !== void 0 ? _o : undefined) }), extensions, { disable: true });
147
149
  span.setAttributes(generatedEvent.otelAttributes);
148
150
  return generatedEvent;
149
151
  },
@@ -44,8 +44,9 @@ export default class ArvoEventFactory<TContract extends VersionedArvoContract<an
44
44
  * });
45
45
  * ```
46
46
  */
47
- accepts<TExtension extends Record<string, any>>(event: Omit<CreateArvoEvent<z.input<TContract['accepts']['schema']>, TContract['accepts']['type']>, 'type' | 'datacontenttype' | 'dataschema' | 'subject'> & {
47
+ accepts<TExtension extends Record<string, any>>(event: Omit<CreateArvoEvent<z.input<TContract['accepts']['schema']>, TContract['accepts']['type']>, 'type' | 'datacontenttype' | 'dataschema' | 'subject' | 'domain'> & {
48
48
  subject?: string;
49
+ domain?: string | null;
49
50
  }, extensions?: TExtension): import("..").ArvoEvent<z.TypeOf<TContract["accepts"]["schema"]>, TExtension, TContract["accepts"]["type"]>;
50
51
  /**
51
52
  * Creates and validates an event matching one of the contract's emit specifications.
@@ -66,8 +67,9 @@ export default class ArvoEventFactory<TContract extends VersionedArvoContract<an
66
67
  * });
67
68
  * ```
68
69
  */
69
- emits<U extends string & keyof TContract['emits'], TExtension extends Record<string, any>>(event: Omit<CreateArvoEvent<z.input<TContract['emits'][U]>, U>, 'datacontenttype' | 'dataschema' | 'subject'> & {
70
+ emits<U extends string & keyof TContract['emits'], TExtension extends Record<string, any>>(event: Omit<CreateArvoEvent<z.input<TContract['emits'][U]>, U>, 'datacontenttype' | 'dataschema' | 'subject' | 'domain'> & {
70
71
  subject?: string;
72
+ domain?: string | null;
71
73
  }, extensions?: TExtension): import("..").ArvoEvent<z.TypeOf<TContract["emits"][U]>, TExtension, U>;
72
74
  /**
73
75
  * Creates a system error event for error reporting and handling.
@@ -88,9 +90,10 @@ export default class ArvoEventFactory<TContract extends VersionedArvoContract<an
88
90
  * });
89
91
  * ```
90
92
  */
91
- systemError<TExtension extends Record<string, any>>(event: Omit<CreateArvoEvent<any, any>, 'data' | 'type' | 'datacontenttype' | 'dataschema' | 'subject'> & {
93
+ systemError<TExtension extends Record<string, any>>(event: Omit<CreateArvoEvent<any, any>, 'data' | 'type' | 'datacontenttype' | 'dataschema' | 'subject' | 'domain'> & {
92
94
  error: Error;
93
95
  subject?: string;
96
+ domain?: string | null;
94
97
  }, extensions?: TExtension): import("..").ArvoEvent<{
95
98
  errorName: string;
96
99
  errorMessage: string;
@@ -81,7 +81,7 @@ var ArvoEventFactory = /** @class */ (function () {
81
81
  name: "".concat(this._name, ".accepts"),
82
82
  spanOptions: (0, utils_2.createSpanOptions)(this.contract),
83
83
  fn: function (span) {
84
- var _a, _b, _c, _d, _e;
84
+ var _a, _b, _c, _d, _e, _f, _g;
85
85
  var otelHeaders = (0, OpenTelemetry_1.currentOpenTelemetryHeaders)();
86
86
  var validationResult = _this.contract.accepts.schema.safeParse(event.data);
87
87
  if (!validationResult.success) {
@@ -98,7 +98,7 @@ var ArvoEventFactory = /** @class */ (function () {
98
98
  }
99
99
  : undefined,
100
100
  });
101
- var generatedEvent = (0, helpers_1.createArvoEvent)(__assign(__assign({}, event), { subject: eventSubject, traceparent: (_c = (_b = event.traceparent) !== null && _b !== void 0 ? _b : otelHeaders.traceparent) !== null && _c !== void 0 ? _c : undefined, tracestate: (_e = (_d = event.tracestate) !== null && _d !== void 0 ? _d : otelHeaders.tracestate) !== null && _e !== void 0 ? _e : undefined, type: eventType, datacontenttype: schema_1.ArvoDataContentType, dataschema: utils_1.EventDataschemaUtil.create(_this.contract), data: validationResult.data }), extensions, { disable: true });
101
+ var generatedEvent = (0, helpers_1.createArvoEvent)(__assign(__assign({}, event), { subject: eventSubject, traceparent: (_c = (_b = event.traceparent) !== null && _b !== void 0 ? _b : otelHeaders.traceparent) !== null && _c !== void 0 ? _c : undefined, tracestate: (_e = (_d = event.tracestate) !== null && _d !== void 0 ? _d : otelHeaders.tracestate) !== null && _e !== void 0 ? _e : undefined, type: eventType, datacontenttype: schema_1.ArvoDataContentType, dataschema: utils_1.EventDataschemaUtil.create(_this.contract), data: validationResult.data, domain: event.domain === null ? undefined : ((_g = (_f = event.domain) !== null && _f !== void 0 ? _f : _this.contract.domain) !== null && _g !== void 0 ? _g : undefined) }), extensions, { disable: true });
102
102
  span.setAttributes(generatedEvent.otelAttributes);
103
103
  return generatedEvent;
104
104
  },
@@ -129,7 +129,7 @@ var ArvoEventFactory = /** @class */ (function () {
129
129
  name: "".concat(this._name, ".emits<").concat(event.type, ">"),
130
130
  spanOptions: (0, utils_2.createSpanOptions)(this.contract),
131
131
  fn: function (span) {
132
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
132
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
133
133
  var otelHeaders = (0, OpenTelemetry_1.currentOpenTelemetryHeaders)();
134
134
  var validationResult = (_b = (_a = _this.contract.emits) === null || _a === void 0 ? void 0 : _a[event.type]) === null || _b === void 0 ? void 0 : _b.safeParse(event.data);
135
135
  if (!(validationResult === null || validationResult === void 0 ? void 0 : validationResult.success)) {
@@ -146,7 +146,7 @@ var ArvoEventFactory = /** @class */ (function () {
146
146
  }
147
147
  : undefined,
148
148
  });
149
- var generatedEvent = (0, helpers_1.createArvoEvent)(__assign(__assign({}, event), { subject: eventSubject, traceparent: (_g = (_f = event.traceparent) !== null && _f !== void 0 ? _f : otelHeaders.traceparent) !== null && _g !== void 0 ? _g : undefined, tracestate: (_j = (_h = event.tracestate) !== null && _h !== void 0 ? _h : otelHeaders.tracestate) !== null && _j !== void 0 ? _j : undefined, datacontenttype: schema_1.ArvoDataContentType, dataschema: utils_1.EventDataschemaUtil.create(_this.contract), data: validationResult.data }), extensions, { disable: true });
149
+ var generatedEvent = (0, helpers_1.createArvoEvent)(__assign(__assign({}, event), { subject: eventSubject, traceparent: (_g = (_f = event.traceparent) !== null && _f !== void 0 ? _f : otelHeaders.traceparent) !== null && _g !== void 0 ? _g : undefined, tracestate: (_j = (_h = event.tracestate) !== null && _h !== void 0 ? _h : otelHeaders.tracestate) !== null && _j !== void 0 ? _j : undefined, datacontenttype: schema_1.ArvoDataContentType, dataschema: utils_1.EventDataschemaUtil.create(_this.contract), data: validationResult.data, domain: event.domain === null ? undefined : ((_l = (_k = event.domain) !== null && _k !== void 0 ? _k : _this.contract.domain) !== null && _l !== void 0 ? _l : undefined) }), extensions, { disable: true });
150
150
  span.setAttributes(generatedEvent.otelAttributes);
151
151
  return generatedEvent;
152
152
  },
@@ -177,7 +177,7 @@ var ArvoEventFactory = /** @class */ (function () {
177
177
  name: "".concat(this._name, ".systemError"),
178
178
  spanOptions: (0, utils_2.createSpanOptions)(this.contract),
179
179
  fn: function (span) {
180
- var _a, _b, _c, _d, _e;
180
+ var _a, _b, _c, _d, _e, _f, _g;
181
181
  var otelHeaders = (0, OpenTelemetry_1.currentOpenTelemetryHeaders)();
182
182
  var error = event.error, _event = __rest(event, ["error"]);
183
183
  var eventType = _this.contract.systemError.type;
@@ -191,7 +191,7 @@ var ArvoEventFactory = /** @class */ (function () {
191
191
  }
192
192
  : undefined,
193
193
  });
194
- var generatedEvent = (0, helpers_1.createArvoEvent)(__assign(__assign({}, _event), { subject: eventSubject, traceparent: (_c = (_b = event.traceparent) !== null && _b !== void 0 ? _b : otelHeaders.traceparent) !== null && _c !== void 0 ? _c : undefined, tracestate: (_e = (_d = event.tracestate) !== null && _d !== void 0 ? _d : otelHeaders.tracestate) !== null && _e !== void 0 ? _e : undefined, type: eventType, data: (0, utils_1.createArvoError)(error), datacontenttype: schema_1.ArvoDataContentType, dataschema: utils_1.EventDataschemaUtil.createWithWildCardVersion(_this.contract) }), extensions, { disable: true });
194
+ var generatedEvent = (0, helpers_1.createArvoEvent)(__assign(__assign({}, _event), { subject: eventSubject, traceparent: (_c = (_b = event.traceparent) !== null && _b !== void 0 ? _b : otelHeaders.traceparent) !== null && _c !== void 0 ? _c : undefined, tracestate: (_e = (_d = event.tracestate) !== null && _d !== void 0 ? _d : otelHeaders.tracestate) !== null && _e !== void 0 ? _e : undefined, type: eventType, data: (0, utils_1.createArvoError)(error), datacontenttype: schema_1.ArvoDataContentType, dataschema: utils_1.EventDataschemaUtil.createWithWildCardVersion(_this.contract), domain: event.domain === null ? undefined : ((_g = (_f = event.domain) !== null && _f !== void 0 ? _f : _this.contract.domain) !== null && _g !== void 0 ? _g : undefined) }), extensions, { disable: true });
195
195
  span.setAttributes(generatedEvent.otelAttributes);
196
196
  return generatedEvent;
197
197
  },
@@ -40,6 +40,7 @@ export default class ArvoOrchestrationSubject {
40
40
  orchestator: string;
41
41
  version: ArvoSemanticVersion | null;
42
42
  initiator: string;
43
+ domain?: string;
43
44
  meta?: Record<string, string>;
44
45
  }): string;
45
46
  /**
@@ -79,6 +80,7 @@ export default class ArvoOrchestrationSubject {
79
80
  orchestator: string;
80
81
  version: ArvoSemanticVersion | null;
81
82
  subject: string;
83
+ domain?: string | null;
82
84
  meta?: Record<string, string>;
83
85
  }): string;
84
86
  /**
@@ -59,7 +59,7 @@ var ArvoOrchestrationSubject = /** @class */ (function () {
59
59
  * ```
60
60
  */
61
61
  ArvoOrchestrationSubject.new = function (param) {
62
- var _a, _b;
62
+ var _a, _b, _c;
63
63
  return ArvoOrchestrationSubject.create({
64
64
  orchestrator: {
65
65
  name: param.orchestator,
@@ -68,8 +68,9 @@ var ArvoOrchestrationSubject = /** @class */ (function () {
68
68
  execution: {
69
69
  id: (0, uuid_1.v4)(),
70
70
  initiator: param.initiator,
71
+ domain: (_b = param.domain) !== null && _b !== void 0 ? _b : null,
71
72
  },
72
- meta: (_b = param.meta) !== null && _b !== void 0 ? _b : {},
73
+ meta: (_c = param.meta) !== null && _c !== void 0 ? _c : {},
73
74
  });
74
75
  };
75
76
  /**
@@ -106,13 +107,14 @@ var ArvoOrchestrationSubject = /** @class */ (function () {
106
107
  * ```
107
108
  */
108
109
  ArvoOrchestrationSubject.from = function (param) {
109
- var _a, _b, _c;
110
+ var _a, _b, _c, _d, _e;
110
111
  var parsedSubject = ArvoOrchestrationSubject.parse(param.subject);
111
112
  return ArvoOrchestrationSubject.new({
112
113
  initiator: parsedSubject.orchestrator.name,
113
114
  version: (_a = param.version) !== null && _a !== void 0 ? _a : WildCardArvoSemanticVersion_1.WildCardArvoSemanticVersion,
114
115
  orchestator: param.orchestator,
115
- meta: __assign(__assign({}, ((_b = parsedSubject.meta) !== null && _b !== void 0 ? _b : {})), ((_c = param.meta) !== null && _c !== void 0 ? _c : {})),
116
+ domain: param.domain === null ? undefined : ((_c = (_b = param.domain) !== null && _b !== void 0 ? _b : parsedSubject.execution.domain) !== null && _c !== void 0 ? _c : undefined),
117
+ meta: __assign(__assign({}, ((_d = parsedSubject.meta) !== null && _d !== void 0 ? _d : {})), ((_e = param.meta) !== null && _e !== void 0 ? _e : {})),
116
118
  });
117
119
  };
118
120
  /**
@@ -13,11 +13,14 @@ export declare const ArvoOrchestrationSubjectContentSchema: z.ZodObject<{
13
13
  execution: z.ZodObject<{
14
14
  id: z.ZodEffects<z.ZodString, string, string>;
15
15
  initiator: z.ZodEffects<z.ZodString, string, string>;
16
+ domain: z.ZodNullable<z.ZodString>;
16
17
  }, "strip", z.ZodTypeAny, {
17
18
  id: string;
19
+ domain: string | null;
18
20
  initiator: string;
19
21
  }, {
20
22
  id: string;
23
+ domain: string | null;
21
24
  initiator: string;
22
25
  }>;
23
26
  meta: z.ZodRecord<z.ZodString, z.ZodString>;
@@ -28,6 +31,7 @@ export declare const ArvoOrchestrationSubjectContentSchema: z.ZodObject<{
28
31
  };
29
32
  execution: {
30
33
  id: string;
34
+ domain: string | null;
31
35
  initiator: string;
32
36
  };
33
37
  meta: Record<string, string>;
@@ -38,6 +42,7 @@ export declare const ArvoOrchestrationSubjectContentSchema: z.ZodObject<{
38
42
  };
39
43
  execution: {
40
44
  id: string;
45
+ domain: string | null;
41
46
  initiator: string;
42
47
  };
43
48
  meta: Record<string, string>;
@@ -29,6 +29,12 @@ exports.ArvoOrchestrationSubjectContentSchema = zod_1.z
29
29
  .regex(/^[a-z0-9]+(\.[a-z0-9]+)+\.[a-z0-9]+$/, 'Orchestration initiator should be prefixed with a reverse-DNS name')
30
30
  .refine(function (value) { return !value.includes(';'); }, 'Initiator must not contain semicolon')
31
31
  .describe('Entity or process that initiated the execution'),
32
+ domain: zod_1.z
33
+ .string()
34
+ .min(1, 'The domain must be non-empty string')
35
+ .regex(/^[a-z0-9.]+$/, 'Domain must contain only lowercase letters, numbers, and dots')
36
+ .nullable()
37
+ .describe('The domain of the orchestration init event'),
32
38
  })
33
39
  .describe('Details about the current execution'),
34
40
  meta: zod_1.z.record(zod_1.z.string(), zod_1.z.string()).describe((0, utils_1.cleanString)("\n Additional metadata for the orchestration process. Store essential key-value pairs \n that provide context or configuration details necessary for the orchestration. \n Use selectively to maintain clarity and avoid storing unnecessary information. \n ")),
@@ -48,6 +48,8 @@ export type ArvoOrchestrationSubjectContent = {
48
48
  * "com.example.initiator-service"
49
49
  */
50
50
  initiator: string;
51
+ /** The domain of the init event */
52
+ domain: string | null;
51
53
  };
52
54
  /**
53
55
  * Additional metadata for the orchestration process. Store essential key-value pairs
@@ -94,15 +94,16 @@ function isLowerAlphanumeric(input) {
94
94
  * ```
95
95
  */
96
96
  var createArvoOrchestratorContract = function (contract) {
97
- var _a, _b;
97
+ var _a, _b, _c;
98
98
  if (!isLowerAlphanumeric(contract.name)) {
99
99
  throw new Error("Invalid 'name' = '".concat(contract.name, "'. The 'name' must only contain alphanumeric characters. e.g. test.orchestrator"));
100
100
  }
101
101
  var mergedMetaData = __assign(__assign({}, ((_a = contract.metadata) !== null && _a !== void 0 ? _a : {})), { contractType: 'ArvoOrchestratorContract', rootType: contract.name, completeEventType: typegen_1.ArvoOrchestratorEventTypeGen.complete(contract.name), initEventType: typegen_1.ArvoOrchestratorEventTypeGen.init(contract.name) });
102
102
  return new ArvoContract_1.default({
103
103
  uri: contract.uri,
104
+ domain: (_b = contract.domain) !== null && _b !== void 0 ? _b : null,
104
105
  type: typegen_1.ArvoOrchestratorEventTypeGen.init(contract.name),
105
- description: (_b = contract.description) !== null && _b !== void 0 ? _b : null,
106
+ description: (_c = contract.description) !== null && _c !== void 0 ? _c : null,
106
107
  metadata: mergedMetaData,
107
108
  versions: Object.fromEntries(Object.entries(contract.versions).map(function (_a) {
108
109
  var _b;
@@ -68,4 +68,5 @@ export interface ICreateArvoOrchestratorContract<TUri extends string, TName exte
68
68
  versions: TVersions;
69
69
  metadata?: TMetaData;
70
70
  description?: string;
71
+ domain?: string;
71
72
  }
package/dist/index.d.ts CHANGED
@@ -75,18 +75,21 @@ declare const ArvoEventSchema: {
75
75
  redirectto: import("zod").ZodNullable<import("zod").ZodEffects<import("zod").ZodString, string, string>>;
76
76
  executionunits: import("zod").ZodNullable<import("zod").ZodNumber>;
77
77
  parentid: import("zod").ZodNullable<import("zod").ZodString>;
78
+ domain: import("zod").ZodNullable<import("zod").ZodString>;
78
79
  }, "strip", import("zod").ZodTypeAny, {
79
80
  to: string | null;
80
81
  accesscontrol: string | null;
81
82
  redirectto: string | null;
82
83
  executionunits: number | null;
83
84
  parentid: string | null;
85
+ domain: string | null;
84
86
  }, {
85
87
  to: string | null;
86
88
  accesscontrol: string | null;
87
89
  redirectto: string | null;
88
90
  executionunits: number | null;
89
91
  parentid: string | null;
92
+ domain: string | null;
90
93
  }>;
91
94
  OpenTelemetryExtensionSchema: import("zod").ZodObject<{
92
95
  traceparent: import("zod").ZodNullable<import("zod").ZodString>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arvo-core",
3
- "version": "2.3.3",
3
+ "version": "3.0.1",
4
4
  "description": "This core package contains all the core classes and components of the Arvo Event Driven System",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {