arvo-core 3.0.5 → 3.0.7

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.
@@ -4,16 +4,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.createArvoEvent = void 0;
7
- var uuid_1 = require("uuid");
8
7
  var _1 = __importDefault(require("."));
9
8
  var OpenTelemetry_1 = require("../OpenTelemetry");
10
9
  var utils_1 = require("../utils");
11
10
  var schema_1 = require("./schema");
11
+ var id_1 = require("./id");
12
12
  /**
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, _l;
16
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
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)({
@@ -22,22 +22,22 @@ var generator = function (event, extensions, otelHeaders) {
22
22
  });
23
23
  }
24
24
  return new _1.default({
25
- id: (_a = event.id) !== null && _a !== void 0 ? _a : (0, uuid_1.v4)(),
25
+ id: (0, id_1.createArvoEventId)(event.id),
26
26
  type: event.type,
27
- accesscontrol: (_b = event.accesscontrol) !== null && _b !== void 0 ? _b : null,
28
- executionunits: (_c = event.executionunits) !== null && _c !== void 0 ? _c : null,
29
- traceparent: (_e = (_d = event.traceparent) !== null && _d !== void 0 ? _d : otelHeaders.traceparent) !== null && _e !== void 0 ? _e : null,
30
- tracestate: (_g = (_f = event.tracestate) !== null && _f !== void 0 ? _f : otelHeaders.tracestate) !== null && _g !== void 0 ? _g : null,
31
- datacontenttype: (_h = event.datacontenttype) !== null && _h !== void 0 ? _h : schema_1.ArvoDataContentType,
32
- specversion: (_j = event.specversion) !== null && _j !== void 0 ? _j : '1.0',
33
- time: (_k = event.time) !== null && _k !== void 0 ? _k : (0, utils_1.createTimestamp)(),
27
+ accesscontrol: (_a = event.accesscontrol) !== null && _a !== void 0 ? _a : null,
28
+ executionunits: (_b = event.executionunits) !== null && _b !== void 0 ? _b : null,
29
+ traceparent: (_d = (_c = event.traceparent) !== null && _c !== void 0 ? _c : otelHeaders.traceparent) !== null && _d !== void 0 ? _d : null,
30
+ tracestate: (_f = (_e = event.tracestate) !== null && _e !== void 0 ? _e : otelHeaders.tracestate) !== null && _f !== void 0 ? _f : null,
31
+ datacontenttype: (_g = event.datacontenttype) !== null && _g !== void 0 ? _g : schema_1.ArvoDataContentType,
32
+ specversion: (_h = event.specversion) !== null && _h !== void 0 ? _h : '1.0',
33
+ time: (_j = event.time) !== null && _j !== void 0 ? _j : (0, utils_1.createTimestamp)(),
34
34
  source: encodeURI(event.source),
35
35
  subject: encodeURI(event.subject),
36
36
  to: event.to ? encodeURI(event.to) : encodeURI(event.type),
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
+ domain: (_k = event.domain) !== null && _k !== void 0 ? _k : null,
41
41
  }, event.data, extensions);
42
42
  };
43
43
  /**
@@ -0,0 +1,18 @@
1
+ import { CreateArvoEvent } from './types';
2
+ import { z } from 'zod';
3
+ export declare const ArvoEventIdObjectSchema: z.ZodObject<{
4
+ uuid: z.ZodString;
5
+ value: z.ZodString;
6
+ }, "strip", z.ZodTypeAny, {
7
+ value: string;
8
+ uuid: string;
9
+ }, {
10
+ value: string;
11
+ uuid: string;
12
+ }>;
13
+ export type ArvoEventIdObject = z.infer<typeof ArvoEventIdObjectSchema>;
14
+ export declare const createArvoEventId: (id?: CreateArvoEvent<Record<string, unknown>, string>["id"]) => string;
15
+ export declare const parseArvoEventId: (id: string) => readonly [{
16
+ value: string;
17
+ uuid: string;
18
+ }, null] | readonly [string, Error];
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.parseArvoEventId = exports.createArvoEventId = exports.ArvoEventIdObjectSchema = void 0;
7
+ var pako_1 = __importDefault(require("pako"));
8
+ var uuid_1 = require("uuid");
9
+ var zod_1 = require("zod");
10
+ exports.ArvoEventIdObjectSchema = zod_1.z.object({
11
+ uuid: zod_1.z.string(),
12
+ value: zod_1.z.string(),
13
+ });
14
+ var createArvoEventId = function (id) {
15
+ if ((id === null || id === void 0 ? void 0 : id.deduplication) === 'ARVO_MANAGED' && id.value.trim()) {
16
+ var data = exports.ArvoEventIdObjectSchema.parse({ uuid: (0, uuid_1.v4)(), value: id.value.trim() });
17
+ var jsonString = JSON.stringify(data);
18
+ var compressed = pako_1.default.deflate(new TextEncoder().encode(jsonString));
19
+ return Buffer.from(compressed).toString('base64');
20
+ }
21
+ if ((id === null || id === void 0 ? void 0 : id.deduplication) === 'DEVELOPER_MANAGED' && id.value.trim()) {
22
+ return id.value.trim();
23
+ }
24
+ return (0, uuid_1.v4)();
25
+ };
26
+ exports.createArvoEventId = createArvoEventId;
27
+ var parseArvoEventId = function (id) {
28
+ try {
29
+ var compressed = Buffer.from(id, 'base64');
30
+ var decompressed = pako_1.default.inflate(compressed);
31
+ var jsonString = new TextDecoder().decode(decompressed);
32
+ var parsed = JSON.parse(jsonString);
33
+ return [exports.ArvoEventIdObjectSchema.parse(parsed), null];
34
+ }
35
+ catch (e) {
36
+ return [id, e];
37
+ }
38
+ };
39
+ exports.parseArvoEventId = parseArvoEventId;
@@ -26,8 +26,28 @@ export type OpenTelemetryExtension = z.infer<typeof OpenTelemetryExtensionSchema
26
26
  * @template TType - The type name of the event
27
27
  */
28
28
  export type CreateArvoEvent<TData extends ArvoEventData, TType extends string> = {
29
- /** Unique identifier of the event. Must be a non-empty string. If not provided, a UUID will be generated. */
30
- id?: string;
29
+ /**
30
+ * The event id serves as the primary deduplication key within the Arvo system,
31
+ * ensuring idempotent event processing. If not provided, a UUID v4 will be automatically generated.
32
+ */
33
+ id?: {
34
+ /**
35
+ * Deduplication identifier management strategy.
36
+ *
37
+ * - `DEVELOPER_MANAGED`: You, the developer, guarantee uniqueness of the identifier value.
38
+ * The provided value is used directly as the deduplication key without modification.
39
+ *
40
+ * - `ARVO_MANAGED`: Arvo manages identifier uniqueness by generating a composite key.
41
+ * The final identifier follows the format `base64({uuid: uuid4(), value: value})`,
42
+ * where a UUID v4 prefix ensures global uniqueness while preserving the developer's
43
+ * value for reference.
44
+ */
45
+ deduplication: 'DEVELOPER_MANAGED' | 'ARVO_MANAGED';
46
+ /**
47
+ * The id value
48
+ */
49
+ value: string;
50
+ };
31
51
  /** Timestamp of when the occurrence happened. Must be in ISO 8601 format with timezone offset. */
32
52
  time?: string;
33
53
  /** Identifies the context in which an event happened. Must be a valid URI representing the event producer. */
package/dist/index.d.ts CHANGED
@@ -29,6 +29,7 @@ import { OpenInferenceSpanKind } from './OpenTelemetry/OpenInference/types';
29
29
  import { ViolationError, ViolationErrorParam } from './errors';
30
30
  import { ArvoErrorSchema, ArvoSemanticVersionSchema, isValidArvoSemanticVersion } from './schema';
31
31
  import { ArvoErrorType, ArvoSemanticVersion, InferArvoEvent, InferVersionedArvoContract } from './types';
32
+ import { ArvoEventIdObjectSchema, createArvoEventId, parseArvoEventId, ArvoEventIdObject } from './ArvoEvent/id';
32
33
  /**
33
34
  * Collection of Zod schemas for validating various aspects of Arvo events.
34
35
  * @property {z.ZodObject} CloudEventContextSchema - Schema for core CloudEvent properties.
@@ -109,4 +110,4 @@ declare const ArvoEventSchema: {
109
110
  parentSubject$$: string | null;
110
111
  }>;
111
112
  };
112
- export { ArvoEvent, createArvoEvent, ArvoDataContentType, ArvoEventData, CloudEventExtension, ArvoEventSchema, CloudEventContext, ArvoExtension, OpenTelemetryExtension, CreateArvoEvent, exceptionToSpan, logToSpan, OpenTelemetryHeaders, TelemetryLogLevel, OTelNull, validateURI, cleanString, ArvoContract, createArvoContract, ArvoContractValidators, ArvoContractRecord, IArvoContract, ResolveArvoContractRecord, ArvoEventFactory, createArvoEventFactory, currentOpenTelemetryHeaders, OpenInference, OpenInferenceSpanKind, ArvoExecution, ArvoExecutionSpanKind, ArvoContractJSONSchema, ArvoOrchestrationSubject, ArvoOrchestrationSubjectContent, ArvoSemanticVersion, InferArvoEvent, createArvoOrchestratorContract, ICreateArvoOrchestratorContract, ArvoOrchestratorEventTypeGen, EventDataschemaUtil, ArvoOrchestrationSubjectContentSchema, ArvoSemanticVersionSchema, ArvoErrorSchema, ArvoErrorType, compareSemanticVersions, parseSemanticVersion, createSimpleArvoContract, ArvoOrchestratorContract, VersionedArvoContract, InferVersionedArvoContract, isWildCardArvoSematicVersion, WildCardArvoSemanticVersion, isValidArvoSemanticVersion, SimpleArvoContract, ArvoOrchestratorEventFactory, createArvoOrchestratorEventFactory, ArvoOpenTelemetry, ViolationError, ViolationErrorParam, createArvoError, };
113
+ export { ArvoEvent, createArvoEvent, ArvoDataContentType, ArvoEventData, CloudEventExtension, ArvoEventSchema, CloudEventContext, ArvoExtension, OpenTelemetryExtension, CreateArvoEvent, exceptionToSpan, logToSpan, OpenTelemetryHeaders, TelemetryLogLevel, OTelNull, validateURI, cleanString, ArvoContract, createArvoContract, ArvoContractValidators, ArvoContractRecord, IArvoContract, ResolveArvoContractRecord, ArvoEventFactory, createArvoEventFactory, currentOpenTelemetryHeaders, OpenInference, OpenInferenceSpanKind, ArvoExecution, ArvoExecutionSpanKind, ArvoContractJSONSchema, ArvoOrchestrationSubject, ArvoOrchestrationSubjectContent, ArvoSemanticVersion, InferArvoEvent, createArvoOrchestratorContract, ICreateArvoOrchestratorContract, ArvoOrchestratorEventTypeGen, EventDataschemaUtil, ArvoOrchestrationSubjectContentSchema, ArvoSemanticVersionSchema, ArvoErrorSchema, ArvoErrorType, compareSemanticVersions, parseSemanticVersion, createSimpleArvoContract, ArvoOrchestratorContract, VersionedArvoContract, InferVersionedArvoContract, isWildCardArvoSematicVersion, WildCardArvoSemanticVersion, isValidArvoSemanticVersion, SimpleArvoContract, ArvoOrchestratorEventFactory, createArvoOrchestratorEventFactory, ArvoOpenTelemetry, ViolationError, ViolationErrorParam, createArvoError, createArvoEventId, parseArvoEventId, ArvoEventIdObjectSchema, ArvoEventIdObject, };
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.createArvoError = exports.ViolationError = exports.ArvoOpenTelemetry = exports.createArvoOrchestratorEventFactory = exports.ArvoOrchestratorEventFactory = exports.isValidArvoSemanticVersion = exports.WildCardArvoSemanticVersion = exports.isWildCardArvoSematicVersion = exports.VersionedArvoContract = exports.createSimpleArvoContract = exports.parseSemanticVersion = exports.compareSemanticVersions = exports.ArvoErrorSchema = exports.ArvoSemanticVersionSchema = exports.ArvoOrchestrationSubjectContentSchema = exports.EventDataschemaUtil = exports.ArvoOrchestratorEventTypeGen = exports.createArvoOrchestratorContract = exports.ArvoOrchestrationSubject = exports.ArvoExecutionSpanKind = exports.ArvoExecution = exports.OpenInferenceSpanKind = exports.OpenInference = exports.currentOpenTelemetryHeaders = exports.createArvoEventFactory = exports.ArvoEventFactory = exports.ArvoContractValidators = exports.createArvoContract = exports.ArvoContract = exports.cleanString = exports.validateURI = exports.OTelNull = exports.logToSpan = exports.exceptionToSpan = exports.ArvoEventSchema = exports.ArvoDataContentType = exports.createArvoEvent = exports.ArvoEvent = void 0;
6
+ exports.ArvoEventIdObjectSchema = exports.parseArvoEventId = exports.createArvoEventId = exports.createArvoError = exports.ViolationError = exports.ArvoOpenTelemetry = exports.createArvoOrchestratorEventFactory = exports.ArvoOrchestratorEventFactory = exports.isValidArvoSemanticVersion = exports.WildCardArvoSemanticVersion = exports.isWildCardArvoSematicVersion = exports.VersionedArvoContract = exports.createSimpleArvoContract = exports.parseSemanticVersion = exports.compareSemanticVersions = exports.ArvoErrorSchema = exports.ArvoSemanticVersionSchema = exports.ArvoOrchestrationSubjectContentSchema = exports.EventDataschemaUtil = exports.ArvoOrchestratorEventTypeGen = exports.createArvoOrchestratorContract = exports.ArvoOrchestrationSubject = exports.ArvoExecutionSpanKind = exports.ArvoExecution = exports.OpenInferenceSpanKind = exports.OpenInference = exports.currentOpenTelemetryHeaders = exports.createArvoEventFactory = exports.ArvoEventFactory = exports.ArvoContractValidators = exports.createArvoContract = exports.ArvoContract = exports.cleanString = exports.validateURI = exports.OTelNull = exports.logToSpan = exports.exceptionToSpan = exports.ArvoEventSchema = exports.ArvoDataContentType = exports.createArvoEvent = exports.ArvoEvent = void 0;
7
7
  var ArvoContract_1 = __importDefault(require("./ArvoContract"));
8
8
  exports.ArvoContract = ArvoContract_1.default;
9
9
  var helpers_1 = require("./ArvoContract/helpers");
@@ -66,6 +66,10 @@ var schema_4 = require("./schema");
66
66
  Object.defineProperty(exports, "ArvoErrorSchema", { enumerable: true, get: function () { return schema_4.ArvoErrorSchema; } });
67
67
  Object.defineProperty(exports, "ArvoSemanticVersionSchema", { enumerable: true, get: function () { return schema_4.ArvoSemanticVersionSchema; } });
68
68
  Object.defineProperty(exports, "isValidArvoSemanticVersion", { enumerable: true, get: function () { return schema_4.isValidArvoSemanticVersion; } });
69
+ var id_1 = require("./ArvoEvent/id");
70
+ Object.defineProperty(exports, "ArvoEventIdObjectSchema", { enumerable: true, get: function () { return id_1.ArvoEventIdObjectSchema; } });
71
+ Object.defineProperty(exports, "createArvoEventId", { enumerable: true, get: function () { return id_1.createArvoEventId; } });
72
+ Object.defineProperty(exports, "parseArvoEventId", { enumerable: true, get: function () { return id_1.parseArvoEventId; } });
69
73
  /**
70
74
  * Collection of Zod schemas for validating various aspects of Arvo events.
71
75
  * @property {z.ZodObject} CloudEventContextSchema - Schema for core CloudEvent properties.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arvo-core",
3
- "version": "3.0.5",
3
+ "version": "3.0.7",
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": {
@@ -44,8 +44,8 @@
44
44
  "@opentelemetry/core": "^1.30.1",
45
45
  "pako": "^2.1.0",
46
46
  "uuid": "^11.1.0",
47
- "zod": "^3.25.67",
48
- "zod-to-json-schema": "^3.24.5"
47
+ "zod": "^3.25.74",
48
+ "zod-to-json-schema": "^3.24.6"
49
49
  },
50
50
  "engines": {
51
51
  "node": ">=18.0.0"