assignment-user-matcher 1.3.0 → 1.7.0

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.
@@ -18,16 +18,36 @@ function validateStepBasics(step) {
18
18
  ensureNonEmpty(step.machineTask?.handler, `Step "${step.id}" has taskType "machine" but no machineTask.handler`);
19
19
  return;
20
20
  }
21
+ if (taskType === 'external') {
22
+ ensureNonEmpty(step.external?.name, `Step "${step.id}" has taskType "external" but no external.name`);
23
+ return;
24
+ }
21
25
  if (!step.assignmentTemplate) {
22
26
  throw new Error(`Assignment step "${step.id}" is missing assignmentTemplate`);
23
27
  }
24
28
  }
29
+ /**
30
+ * External steps must be able to time out — an uncalled-back external step
31
+ * would otherwise hang a run forever. Checked at the definition level (not in
32
+ * validateStepBasics) because a step's effective timeout also depends on the
33
+ * workflow's defaultTimeoutMs.
34
+ */
35
+ function validateExternalStepTimeout(definition) {
36
+ for (const step of definition.steps) {
37
+ if ((step.taskType ?? 'assignment') !== 'external')
38
+ continue;
39
+ if (!step.timeoutMs && !definition.defaultTimeoutMs) {
40
+ throw new Error(`External step "${step.id}" requires a timeoutMs (or the workflow's defaultTimeoutMs)`);
41
+ }
42
+ }
43
+ }
25
44
  function validateWorkflowDefinition(definition) {
26
45
  ensureNonEmpty(definition.id, 'Workflow ID is required');
27
46
  ensureNonEmpty(definition.name, 'Workflow name is required');
28
47
  if (!definition.steps.length) {
29
48
  throw new Error('Workflow must have at least one step');
30
49
  }
50
+ validateExternalStepTimeout(definition);
31
51
  const stepIds = new Set();
32
52
  for (const step of definition.steps) {
33
53
  validateStepBasics(step);
@@ -59,9 +79,38 @@ function validateWorkflowDefinition(definition) {
59
79
  }
60
80
  }
61
81
  }
82
+ validateEscalationTargets(definition, stepIds);
62
83
  return definition;
63
84
  }
64
85
  exports.validateWorkflowDefinition = validateWorkflowDefinition;
86
+ /**
87
+ * `onTimeoutStepId` turns a timeout into a forward hop instead of a failure.
88
+ * Everything that would make that hop meaningless or non-terminating is
89
+ * rejected at registration rather than discovered at 3am.
90
+ */
91
+ function validateEscalationTargets(definition, stepIds) {
92
+ const parallelMembers = new Set();
93
+ for (const step of definition.steps) {
94
+ for (const id of step.parallelStepIds ?? [])
95
+ parallelMembers.add(id);
96
+ }
97
+ for (const step of definition.steps) {
98
+ if (!step.onTimeoutStepId)
99
+ continue;
100
+ if (!stepIds.has(step.onTimeoutStepId)) {
101
+ throw new Error(`Step "${step.id}" escalates to non-existent step "${step.onTimeoutStepId}" on timeout`);
102
+ }
103
+ if (step.onTimeoutStepId === step.id) {
104
+ throw new Error(`Step "${step.id}" escalates to itself on timeout, which never terminates`);
105
+ }
106
+ if (!step.timeoutMs && !definition.defaultTimeoutMs) {
107
+ throw new Error(`Step "${step.id}" escalates on timeout but has no timeoutMs (or workflow defaultTimeoutMs)`);
108
+ }
109
+ if (parallelMembers.has(step.id)) {
110
+ throw new Error(`Step "${step.id}" is part of a parallel group; escalate-on-timeout is not supported there`);
111
+ }
112
+ }
113
+ }
65
114
  function normalizeWorkflowDefinition(definition) {
66
115
  const steps = [...definition.steps];
67
116
  if (!steps.length) {
@@ -77,6 +126,9 @@ function normalizeWorkflowDefinition(definition) {
77
126
  if (definition.defaultTimeoutMs !== undefined) {
78
127
  normalized.defaultTimeoutMs = definition.defaultTimeoutMs;
79
128
  }
129
+ if (definition.maxEscalationDepth !== undefined) {
130
+ normalized.maxEscalationDepth = definition.maxEscalationDepth;
131
+ }
80
132
  if (definition.metadata !== undefined) {
81
133
  normalized.metadata = definition.metadata;
82
134
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "assignment-user-matcher",
3
- "version": "1.3.0",
3
+ "version": "1.7.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/ViljarVoidula/assignment-user-matcher"
@@ -1,5 +0,0 @@
1
- /**
2
- * Query module exports
3
- */
4
- export * from './pagination';
5
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/queries/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,cAAc,cAAc,CAAC"}
@@ -1,20 +0,0 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- /**
18
- * Query module exports
19
- */
20
- __exportStar(require("./pagination"), exports);
@@ -1,5 +0,0 @@
1
- /**
2
- * Scoring module exports
3
- */
4
- export * from './match-score';
5
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/scoring/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,cAAc,eAAe,CAAC"}
@@ -1,20 +0,0 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- /**
18
- * Scoring module exports
19
- */
20
- __exportStar(require("./match-score"), exports);
@@ -1,6 +0,0 @@
1
- /**
2
- * Utility exports
3
- */
4
- export * from './cidr';
5
- export * from './keys';
6
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC"}
@@ -1,21 +0,0 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- /**
18
- * Utility exports
19
- */
20
- __exportStar(require("./cidr"), exports);
21
- __exportStar(require("./keys"), exports);