arvo-core 1.0.30 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -52,3 +52,7 @@
52
52
 
53
53
  - Added SonarCloud integration for code scanning
54
54
 
55
+ ## [1.1.0] - 2024-09-20
56
+
57
+ - Added support for Arvo orchestration subject management
58
+
@@ -0,0 +1,36 @@
1
+ import { ArvoOchestratorVersion, ArvoOrchestrationSubjectContent } from "./type";
2
+ /**
3
+ * Handles the creation and parsing of Arvo orchestration subjects.
4
+ */
5
+ export default class ArvoOrchestrationSubject {
6
+ /**
7
+ * Creates a new Arvo orchestration subject.
8
+ *
9
+ * @param param - Parameters for creating the subject
10
+ * @param param.orchestrator - Name of the orchestrator
11
+ * @param param.version - Version of the orchestrator
12
+ * @param param.initiator - Initiator of the orchestration
13
+ * @returns A base64 encoded string representing the orchestration subject
14
+ */
15
+ static new(param: {
16
+ orchestator: string;
17
+ version: ArvoOchestratorVersion;
18
+ initiator: string;
19
+ }): string;
20
+ /**
21
+ * Creates an Arvo orchestration subject from the provided content.
22
+ *
23
+ * @param param - The orchestration subject content
24
+ * @returns A base64 encoded string representing the orchestration subject
25
+ * @throws Error if the provided content is invalid or if compression fails
26
+ */
27
+ static create(param: ArvoOrchestrationSubjectContent): string;
28
+ /**
29
+ * Parses a base64 encoded Arvo orchestration subject string.
30
+ *
31
+ * @param subject - The base64 encoded subject string to parse
32
+ * @returns The parsed ArvoOrchestrationSubjectContent
33
+ * @throws Error if parsing or validation fails
34
+ */
35
+ static parse(subject: string): ArvoOrchestrationSubjectContent;
36
+ }
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ var schema_1 = require("./schema");
27
+ var zlib = __importStar(require("zlib"));
28
+ var utils_1 = require("../utils");
29
+ var uuid_1 = require("uuid");
30
+ /**
31
+ * Handles the creation and parsing of Arvo orchestration subjects.
32
+ */
33
+ var ArvoOrchestrationSubject = /** @class */ (function () {
34
+ function ArvoOrchestrationSubject() {
35
+ }
36
+ /**
37
+ * Creates a new Arvo orchestration subject.
38
+ *
39
+ * @param param - Parameters for creating the subject
40
+ * @param param.orchestrator - Name of the orchestrator
41
+ * @param param.version - Version of the orchestrator
42
+ * @param param.initiator - Initiator of the orchestration
43
+ * @returns A base64 encoded string representing the orchestration subject
44
+ */
45
+ ArvoOrchestrationSubject.new = function (param) {
46
+ return ArvoOrchestrationSubject.create({
47
+ orchestrator: {
48
+ name: param.orchestator,
49
+ version: param.version,
50
+ },
51
+ execution: {
52
+ id: (0, uuid_1.v4)(),
53
+ initiator: param.initiator
54
+ }
55
+ });
56
+ };
57
+ /**
58
+ * Creates an Arvo orchestration subject from the provided content.
59
+ *
60
+ * @param param - The orchestration subject content
61
+ * @returns A base64 encoded string representing the orchestration subject
62
+ * @throws Error if the provided content is invalid or if compression fails
63
+ */
64
+ ArvoOrchestrationSubject.create = function (param) {
65
+ try {
66
+ var validationResult = schema_1.ArvoOrchestrationSubjectContentSchema.safeParse(param);
67
+ if (!validationResult.success) {
68
+ throw new Error("Invalid ArvoOrchestrationContextType: ".concat(validationResult.error));
69
+ }
70
+ var jsonString = JSON.stringify(param);
71
+ var compressed = zlib.deflateSync(jsonString);
72
+ return compressed.toString('base64');
73
+ }
74
+ catch (e) {
75
+ throw new Error((0, utils_1.cleanString)("\n Error creating orchestration subject string from the provided context. \n Error -> ".concat(e.message, " \n Context -> ").concat(JSON.stringify(param, null, 2), "\n ")));
76
+ }
77
+ };
78
+ /**
79
+ * Parses a base64 encoded Arvo orchestration subject string.
80
+ *
81
+ * @param subject - The base64 encoded subject string to parse
82
+ * @returns The parsed ArvoOrchestrationSubjectContent
83
+ * @throws Error if parsing or validation fails
84
+ */
85
+ ArvoOrchestrationSubject.parse = function (subject) {
86
+ try {
87
+ var compressed = Buffer.from(subject, 'base64');
88
+ var jsonString = zlib.inflateSync(compressed).toString();
89
+ var parsed = JSON.parse(jsonString);
90
+ var validationResult = schema_1.ArvoOrchestrationSubjectContentSchema.safeParse(parsed);
91
+ if (!validationResult.success) {
92
+ throw new Error("Invalid ArvoOrchestrationContextType: ".concat(validationResult.error));
93
+ }
94
+ return parsed;
95
+ }
96
+ catch (e) {
97
+ throw new Error((0, utils_1.cleanString)("\n Error parsing orchestration subject string to the context. \n Error -> ".concat(e.message, " \n subject -> ").concat(subject, "\n ")));
98
+ }
99
+ };
100
+ return ArvoOrchestrationSubject;
101
+ }());
102
+ exports.default = ArvoOrchestrationSubject;
@@ -0,0 +1,42 @@
1
+ import { z } from "zod";
2
+ export declare const ArvoOchestratorVersionSchema: z.ZodEffects<z.ZodString, string, string>;
3
+ export declare const ArvoOrchestrationSubjectContentSchema: z.ZodObject<{
4
+ orchestrator: z.ZodObject<{
5
+ name: z.ZodEffects<z.ZodString, string, string>;
6
+ version: z.ZodEffects<z.ZodString, string, string>;
7
+ }, "strip", z.ZodTypeAny, {
8
+ name: string;
9
+ version: string;
10
+ }, {
11
+ name: string;
12
+ version: string;
13
+ }>;
14
+ execution: z.ZodObject<{
15
+ id: z.ZodEffects<z.ZodString, string, string>;
16
+ initiator: z.ZodEffects<z.ZodString, string, string>;
17
+ }, "strip", z.ZodTypeAny, {
18
+ id: string;
19
+ initiator: string;
20
+ }, {
21
+ id: string;
22
+ initiator: string;
23
+ }>;
24
+ }, "strip", z.ZodTypeAny, {
25
+ orchestrator: {
26
+ name: string;
27
+ version: string;
28
+ };
29
+ execution: {
30
+ id: string;
31
+ initiator: string;
32
+ };
33
+ }, {
34
+ orchestrator: {
35
+ name: string;
36
+ version: string;
37
+ };
38
+ execution: {
39
+ id: string;
40
+ initiator: string;
41
+ };
42
+ }>;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ArvoOrchestrationSubjectContentSchema = exports.ArvoOchestratorVersionSchema = void 0;
4
+ var zod_1 = require("zod");
5
+ // Zod schema for ArvoOchestratorVersion
6
+ exports.ArvoOchestratorVersionSchema = zod_1.z
7
+ .string()
8
+ .regex(/^\d+\.\d+\.\d+$/, 'Invalid version format')
9
+ .refine(function (value) { return !value.includes(';'); }, 'Version must not contain semicolon')
10
+ .describe('Semantic version of the Arvo Orchestrator in the format X.Y.Z');
11
+ // Zod schema for ArvoOrchestrationSubjectContent
12
+ exports.ArvoOrchestrationSubjectContentSchema = zod_1.z.object({
13
+ orchestrator: zod_1.z.object({
14
+ name: zod_1.z
15
+ .string()
16
+ .regex(/^[a-z0-9]+(\.[a-z0-9]+)+\.[a-z0-9]+$/, 'Orchestrator name should be prefixed with a reverse-DNS name')
17
+ .refine(function (value) { return !value.includes(';'); }, 'Orchestrator name must not contain semicolon')
18
+ .describe('Name of the orchestrator'),
19
+ version: exports.ArvoOchestratorVersionSchema,
20
+ })
21
+ .describe('Information about the orchestrator'),
22
+ execution: zod_1.z.object({
23
+ id: zod_1.z
24
+ .string()
25
+ .min(1, 'ID must be a non-empty string')
26
+ .refine(function (value) { return !value.includes(';'); }, 'ID must not contain semicolon')
27
+ .describe('Unique identifier for the execution'),
28
+ initiator: zod_1.z
29
+ .string()
30
+ .regex(/^[a-z0-9]+(\.[a-z0-9]+)+\.[a-z0-9]+$/, 'Orchestration initiator should be prefixed with a reverse-DNS name')
31
+ .refine(function (value) { return !value.includes(';'); }, 'Initiator must not contain semicolon')
32
+ .describe('Entity or process that initiated the execution'),
33
+ }).describe('Details about the current execution'),
34
+ }).describe('Context information for Arvo orchestration');
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Represents the version of the Arvo Orchestrator.
3
+ *
4
+ * @remark
5
+ * The version follows the Semantic Versioning format: MAJOR.MINOR.PATCH
6
+ * **Note**: The string must not contain ';'
7
+ *
8
+ * @example
9
+ * "1.0.0", "2.3.1", "0.5.2"
10
+ */
11
+ export type ArvoOchestratorVersion = `${number}.${number}.${number}`;
12
+ /**
13
+ * Represents the content for Arvo orchestration subject.
14
+ * This type provides information about the orchestrator and the current execution.
15
+ */
16
+ export type ArvoOrchestrationSubjectContent = {
17
+ /**
18
+ * Information about the orchestrator.
19
+ */
20
+ orchestrator: {
21
+ /**
22
+ * The name of the orchestrator.
23
+ *
24
+ * @remark
25
+ * Should be prefixed with a reverse-DNS name.
26
+ * **Note**: The string must not contain ';'
27
+ *
28
+ * @example
29
+ * "com.example.myorchestrator"
30
+ */
31
+ name: string;
32
+ /**
33
+ * The version of the orchestrator.
34
+ */
35
+ version: ArvoOchestratorVersion;
36
+ };
37
+ /**
38
+ * Details about the current execution.
39
+ */
40
+ execution: {
41
+ /**
42
+ * A unique identifier for the execution.
43
+ *
44
+ * @remark
45
+ * Should be a non-empty string. The recomendation
46
+ * is to use uuid v4 to generate these ids.
47
+ * **Note**: The string must not contain ';'
48
+ *
49
+ * @example
50
+ * "abc123", "execution-2023-05-15-001"
51
+ */
52
+ id: string;
53
+ /**
54
+ * The entity or process that initiated the execution.
55
+ *
56
+ * @remark
57
+ * Should be prefixed with a reverse-DNS name.
58
+ * **Note**: The string must not contain ';'
59
+ *
60
+ * @example
61
+ * "com.example.initiator-service"
62
+ */
63
+ initiator: string;
64
+ };
65
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/dist/index.d.ts CHANGED
@@ -18,6 +18,9 @@ import OpenInference from './OpenTelemetry/OpenInference';
18
18
  import ArvoExecution from './OpenTelemetry/ArvoExecution';
19
19
  import { ArvoExecutionSpanKind } from './OpenTelemetry/ArvoExecution/types';
20
20
  import { OpenInferenceSpanKind } from './OpenTelemetry/OpenInference/types';
21
+ import ArvoOrchestrationSubject from './ArvoOrchestrationSubject';
22
+ import { ArvoOrchestrationSubjectContentSchema, ArvoOchestratorVersionSchema } from './ArvoOrchestrationSubject/schema';
23
+ import { ArvoOrchestrationSubjectContent, ArvoOchestratorVersion } from './ArvoOrchestrationSubject/type';
21
24
  /**
22
25
  * Collection of Zod schemas for validating various aspects of Arvo events.
23
26
  * @property {z.ZodObject} CloudEventContextSchema - Schema for core CloudEvent properties.
@@ -84,4 +87,4 @@ declare const ArvoEventSchemas: {
84
87
  tracestate: string | null;
85
88
  }>;
86
89
  };
87
- export { ArvoEvent, createArvoEvent, ArvoDataContentType, ArvoEventData, CloudEventExtension, ArvoEventSchemas, CloudEventContext, ArvoExtension, OpenTelemetryExtension, CreateArvoEvent, exceptionToSpan, logToSpan, OpenTelemetryHeaders, TelemetryLogLevel, OTelNull, validateURI, cleanString, ArvoContract, createArvoContract, ArvoContractValidators, ArvoContractRecord, InferArvoContract, IArvoContract, ResolveArvoContractRecord, ArvoContractLibrary, createArvoContractLibrary, ArvoEventFactory, createArvoEventFactory, ArvoErrorSchema, currentOpenTelemetryHeaders, OpenInference, OpenInferenceSpanKind, ArvoExecution, ArvoExecutionSpanKind, ArvoContractJSONSchema, };
90
+ export { ArvoEvent, createArvoEvent, ArvoDataContentType, ArvoEventData, CloudEventExtension, ArvoEventSchemas, CloudEventContext, ArvoExtension, OpenTelemetryExtension, CreateArvoEvent, exceptionToSpan, logToSpan, OpenTelemetryHeaders, TelemetryLogLevel, OTelNull, validateURI, cleanString, ArvoContract, createArvoContract, ArvoContractValidators, ArvoContractRecord, InferArvoContract, IArvoContract, ResolveArvoContractRecord, ArvoContractLibrary, createArvoContractLibrary, ArvoEventFactory, createArvoEventFactory, ArvoErrorSchema, currentOpenTelemetryHeaders, OpenInference, OpenInferenceSpanKind, ArvoExecution, ArvoExecutionSpanKind, ArvoContractJSONSchema, ArvoOrchestrationSubject, ArvoOrchestrationSubjectContentSchema, ArvoOchestratorVersionSchema, ArvoOrchestrationSubjectContent, ArvoOchestratorVersion, };
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.ArvoExecutionSpanKind = exports.ArvoExecution = exports.OpenInferenceSpanKind = exports.OpenInference = exports.currentOpenTelemetryHeaders = exports.ArvoErrorSchema = exports.createArvoEventFactory = exports.ArvoEventFactory = exports.createArvoContractLibrary = exports.ArvoContractLibrary = exports.ArvoContractValidators = exports.createArvoContract = exports.ArvoContract = exports.cleanString = exports.validateURI = exports.OTelNull = exports.logToSpan = exports.exceptionToSpan = exports.ArvoEventSchemas = exports.ArvoDataContentType = exports.createArvoEvent = exports.ArvoEvent = void 0;
6
+ exports.ArvoOchestratorVersionSchema = exports.ArvoOrchestrationSubjectContentSchema = exports.ArvoOrchestrationSubject = exports.ArvoExecutionSpanKind = exports.ArvoExecution = exports.OpenInferenceSpanKind = exports.OpenInference = exports.currentOpenTelemetryHeaders = exports.ArvoErrorSchema = exports.createArvoEventFactory = exports.ArvoEventFactory = exports.createArvoContractLibrary = exports.ArvoContractLibrary = exports.ArvoContractValidators = exports.createArvoContract = exports.ArvoContract = exports.cleanString = exports.validateURI = exports.OTelNull = exports.logToSpan = exports.exceptionToSpan = exports.ArvoEventSchemas = exports.ArvoDataContentType = exports.createArvoEvent = exports.ArvoEvent = void 0;
7
7
  var ArvoEvent_1 = __importDefault(require("./ArvoEvent"));
8
8
  exports.ArvoEvent = ArvoEvent_1.default;
9
9
  var schema_1 = require("./ArvoEvent/schema");
@@ -42,6 +42,11 @@ var types_1 = require("./OpenTelemetry/ArvoExecution/types");
42
42
  Object.defineProperty(exports, "ArvoExecutionSpanKind", { enumerable: true, get: function () { return types_1.ArvoExecutionSpanKind; } });
43
43
  var types_2 = require("./OpenTelemetry/OpenInference/types");
44
44
  Object.defineProperty(exports, "OpenInferenceSpanKind", { enumerable: true, get: function () { return types_2.OpenInferenceSpanKind; } });
45
+ var ArvoOrchestrationSubject_1 = __importDefault(require("./ArvoOrchestrationSubject"));
46
+ exports.ArvoOrchestrationSubject = ArvoOrchestrationSubject_1.default;
47
+ var schema_3 = require("./ArvoOrchestrationSubject/schema");
48
+ Object.defineProperty(exports, "ArvoOrchestrationSubjectContentSchema", { enumerable: true, get: function () { return schema_3.ArvoOrchestrationSubjectContentSchema; } });
49
+ Object.defineProperty(exports, "ArvoOchestratorVersionSchema", { enumerable: true, get: function () { return schema_3.ArvoOchestratorVersionSchema; } });
45
50
  /**
46
51
  * Collection of Zod schemas for validating various aspects of Arvo events.
47
52
  * @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": "1.0.30",
3
+ "version": "1.1.0",
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": {
@@ -41,13 +41,14 @@
41
41
  "ts-jest": "^29.2.5",
42
42
  "ts-node": "^10.9.2",
43
43
  "typedoc": "^0.26.6",
44
+ "typedoc-github-theme": "^0.1.2",
44
45
  "typedoc-plugin-zod": "^1.2.1",
45
- "typescript": "^5.5.4",
46
- "typedoc-github-theme": "^0.1.2"
46
+ "typescript": "^5.5.4"
47
47
  },
48
48
  "dependencies": {
49
49
  "@opentelemetry/api": "^1.9.0",
50
50
  "uuid": "^10.0.0",
51
+ "zlib": "^1.0.5",
51
52
  "zod": "^3.23.8",
52
53
  "zod-to-json-schema": "^3.23.2"
53
54
  }