assignment-user-matcher 1.1.6 → 1.2.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 (44) hide show
  1. package/README.md +18 -2
  2. package/dist/index.d.ts +4 -0
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +26 -1
  5. package/dist/managers/ReliabilityManager.d.ts +42 -0
  6. package/dist/managers/ReliabilityManager.d.ts.map +1 -0
  7. package/dist/managers/ReliabilityManager.js +115 -0
  8. package/dist/managers/TelemetryManager.d.ts +13 -0
  9. package/dist/managers/TelemetryManager.d.ts.map +1 -0
  10. package/dist/managers/TelemetryManager.js +52 -0
  11. package/dist/managers/WorkflowManager.d.ts +69 -0
  12. package/dist/managers/WorkflowManager.d.ts.map +1 -0
  13. package/dist/managers/WorkflowManager.js +735 -0
  14. package/dist/matcher.class.d.ts +143 -77
  15. package/dist/matcher.class.d.ts.map +1 -1
  16. package/dist/matcher.class.js +460 -447
  17. package/dist/queries/index.d.ts +5 -0
  18. package/dist/queries/index.d.ts.map +1 -0
  19. package/dist/queries/index.js +20 -0
  20. package/dist/queries/pagination.d.ts +51 -0
  21. package/dist/queries/pagination.d.ts.map +1 -0
  22. package/dist/queries/pagination.js +200 -0
  23. package/dist/scoring/index.d.ts +5 -0
  24. package/dist/scoring/index.d.ts.map +1 -0
  25. package/dist/scoring/index.js +20 -0
  26. package/dist/scoring/match-score.d.ts +29 -0
  27. package/dist/scoring/match-score.d.ts.map +1 -0
  28. package/dist/scoring/match-score.js +131 -0
  29. package/dist/types/matcher.d.ts +279 -0
  30. package/dist/types/matcher.d.ts.map +1 -0
  31. package/dist/types/matcher.js +2 -0
  32. package/dist/utils/cidr.d.ts +40 -0
  33. package/dist/utils/cidr.d.ts.map +1 -0
  34. package/dist/utils/cidr.js +150 -0
  35. package/dist/utils/index.d.ts +6 -0
  36. package/dist/utils/index.d.ts.map +1 -0
  37. package/dist/utils/index.js +21 -0
  38. package/dist/utils/keys.d.ts +45 -0
  39. package/dist/utils/keys.d.ts.map +1 -0
  40. package/dist/utils/keys.js +57 -0
  41. package/dist/workflow-builder.d.ts +195 -0
  42. package/dist/workflow-builder.d.ts.map +1 -0
  43. package/dist/workflow-builder.js +366 -0
  44. package/package.json +1 -1
@@ -0,0 +1,195 @@
1
+ /**
2
+ * Workflow Builder DSL
3
+ *
4
+ * Provides a fluent API for constructing workflow definitions programmatically.
5
+ * This makes workflow creation more intuitive and type-safe.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * const workflow = WorkflowBuilder.create('approval-flow', 'Document Approval')
10
+ * .step('submit')
11
+ * .name('Submit Document')
12
+ * .assignment({ tags: ['document'], title: 'Submit your document' })
13
+ * .targetUser('initiator')
14
+ * .route('result.approved === true', 'review')
15
+ * .route('result.approved === false', 'rejected')
16
+ * .defaultNext('review')
17
+ * .done()
18
+ * .step('review')
19
+ * .name('Manager Review')
20
+ * .assignment({ tags: ['review'], title: 'Review submission' })
21
+ * .targetUser({ tag: 'managers' })
22
+ * .timeout(86400000) // 24 hours
23
+ * .route('result.decision === "approve"', 'complete')
24
+ * .route('result.decision === "reject"', 'rejected')
25
+ * .done()
26
+ * .step('complete')
27
+ * .name('Completion')
28
+ * .assignment({ tags: ['notification'], title: 'Process complete' })
29
+ * .targetUser('initiator')
30
+ * .done()
31
+ * .step('rejected')
32
+ * .name('Rejection Notice')
33
+ * .assignment({ tags: ['notification'], title: 'Submission rejected' })
34
+ * .targetUser('initiator')
35
+ * .done()
36
+ * .initialStep('submit')
37
+ * .build();
38
+ * ```
39
+ */
40
+ import type { WorkflowDefinition, WorkflowStep, Assignment, WorkflowTaskType } from './types/matcher';
41
+ /**
42
+ * Builder for individual workflow steps.
43
+ */
44
+ export declare class WorkflowStepBuilder {
45
+ private step;
46
+ private parentBuilder;
47
+ constructor(id: string, parentBuilder: WorkflowBuilder);
48
+ /**
49
+ * Set execution mode for this step.
50
+ */
51
+ taskType(type: WorkflowTaskType): this;
52
+ /**
53
+ * Set the step name.
54
+ */
55
+ name(name: string): this;
56
+ /**
57
+ * Set the assignment template for this step.
58
+ */
59
+ assignment(template: Partial<Assignment>): this;
60
+ /**
61
+ * Configure this step as a machine/code task.
62
+ */
63
+ machineTask(handler: string, input?: Record<string, any>): this;
64
+ /**
65
+ * Set the target user for this step.
66
+ * @param target - 'initiator' | 'previous' | userId | { tag: string }
67
+ */
68
+ targetUser(target: 'initiator' | 'previous' | string | {
69
+ tag: string;
70
+ }): this;
71
+ /**
72
+ * Add a routing rule for conditional branching.
73
+ * @param condition - Expression to evaluate (e.g., 'result.approved === true')
74
+ * @param targetStepId - Step to go to if condition is true
75
+ */
76
+ route(condition: string, targetStepId: string): this;
77
+ /**
78
+ * Set the default next step if no routing conditions match.
79
+ * @param stepId - Next step ID, or null to end workflow
80
+ */
81
+ defaultNext(stepId: string | null): this;
82
+ /**
83
+ * Configure parallel execution with other steps.
84
+ * @param stepIds - Array of step IDs to execute in parallel with this step
85
+ */
86
+ parallel(stepIds: string[]): this;
87
+ /**
88
+ * Set whether to wait for all parallel branches before continuing.
89
+ */
90
+ waitForAll(wait?: boolean): this;
91
+ /**
92
+ * Set the failure policy for parallel execution.
93
+ */
94
+ failurePolicy(policy: 'abort' | 'continue' | 'retry'): this;
95
+ /**
96
+ * Set the maximum retry count for this step.
97
+ */
98
+ maxRetries(count: number): this;
99
+ /**
100
+ * Set a timeout for this step in milliseconds.
101
+ */
102
+ timeout(ms: number): this;
103
+ /**
104
+ * Finish configuring this step and return to the parent builder.
105
+ */
106
+ done(): WorkflowBuilder;
107
+ /**
108
+ * Get the built step (for internal use).
109
+ */
110
+ _getStep(): WorkflowStep;
111
+ }
112
+ /**
113
+ * Builder for workflow definitions.
114
+ */
115
+ export declare class WorkflowBuilder {
116
+ private definition;
117
+ private steps;
118
+ private constructor();
119
+ /**
120
+ * Create a new workflow builder.
121
+ * @param id - Unique identifier for the workflow
122
+ * @param name - Human-readable name
123
+ */
124
+ static create(id: string, name: string): WorkflowBuilder;
125
+ /**
126
+ * Set the workflow version.
127
+ */
128
+ version(version: number): this;
129
+ /**
130
+ * Set workflow metadata.
131
+ */
132
+ metadata(metadata: Record<string, any>): this;
133
+ /**
134
+ * Set the default timeout for all steps (in milliseconds).
135
+ */
136
+ defaultTimeout(ms: number): this;
137
+ /**
138
+ * Start building a new step.
139
+ * @param id - Unique identifier for the step within this workflow
140
+ */
141
+ step(id: string): WorkflowStepBuilder;
142
+ /**
143
+ * Add a pre-built step to the workflow.
144
+ */
145
+ addStep(step: WorkflowStep): this;
146
+ /**
147
+ * Internal method to add a step from the step builder.
148
+ */
149
+ _addStep(step: WorkflowStep): void;
150
+ /**
151
+ * Set the initial (entry point) step ID.
152
+ */
153
+ initialStep(stepId: string): this;
154
+ /**
155
+ * Build and return the workflow definition.
156
+ * @throws Error if the workflow is invalid
157
+ */
158
+ build(): WorkflowDefinition;
159
+ }
160
+ /**
161
+ * Convenience function to create a new workflow builder.
162
+ */
163
+ export declare function workflow(id: string, name: string): WorkflowBuilder;
164
+ /**
165
+ * Create a simple linear workflow with automatic step chaining.
166
+ * @param id - Workflow ID
167
+ * @param name - Workflow name
168
+ * @param steps - Array of step configurations
169
+ */
170
+ export declare function linearWorkflow(id: string, name: string, steps: Array<{
171
+ id: string;
172
+ name: string;
173
+ assignment: Partial<Assignment>;
174
+ targetUser?: 'initiator' | 'previous' | string | {
175
+ tag: string;
176
+ };
177
+ taskType?: WorkflowTaskType;
178
+ machineTask?: {
179
+ handler: string;
180
+ input?: Record<string, any>;
181
+ };
182
+ timeoutMs?: number;
183
+ }>): WorkflowDefinition;
184
+ /**
185
+ * Create an approval workflow with submit -> review -> complete/rejected pattern.
186
+ */
187
+ export declare function approvalWorkflow(id: string, name: string, options: {
188
+ submitAssignment: Partial<Assignment>;
189
+ reviewAssignment: Partial<Assignment>;
190
+ completeAssignment?: Partial<Assignment>;
191
+ rejectedAssignment?: Partial<Assignment>;
192
+ reviewerTag?: string;
193
+ reviewTimeoutMs?: number;
194
+ }): WorkflowDefinition;
195
+ //# sourceMappingURL=workflow-builder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflow-builder.d.ts","sourceRoot":"","sources":["../src/workflow-builder.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,366 @@
1
+ "use strict";
2
+ /**
3
+ * Workflow Builder DSL
4
+ *
5
+ * Provides a fluent API for constructing workflow definitions programmatically.
6
+ * This makes workflow creation more intuitive and type-safe.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * const workflow = WorkflowBuilder.create('approval-flow', 'Document Approval')
11
+ * .step('submit')
12
+ * .name('Submit Document')
13
+ * .assignment({ tags: ['document'], title: 'Submit your document' })
14
+ * .targetUser('initiator')
15
+ * .route('result.approved === true', 'review')
16
+ * .route('result.approved === false', 'rejected')
17
+ * .defaultNext('review')
18
+ * .done()
19
+ * .step('review')
20
+ * .name('Manager Review')
21
+ * .assignment({ tags: ['review'], title: 'Review submission' })
22
+ * .targetUser({ tag: 'managers' })
23
+ * .timeout(86400000) // 24 hours
24
+ * .route('result.decision === "approve"', 'complete')
25
+ * .route('result.decision === "reject"', 'rejected')
26
+ * .done()
27
+ * .step('complete')
28
+ * .name('Completion')
29
+ * .assignment({ tags: ['notification'], title: 'Process complete' })
30
+ * .targetUser('initiator')
31
+ * .done()
32
+ * .step('rejected')
33
+ * .name('Rejection Notice')
34
+ * .assignment({ tags: ['notification'], title: 'Submission rejected' })
35
+ * .targetUser('initiator')
36
+ * .done()
37
+ * .initialStep('submit')
38
+ * .build();
39
+ * ```
40
+ */
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.approvalWorkflow = exports.linearWorkflow = exports.workflow = exports.WorkflowBuilder = exports.WorkflowStepBuilder = void 0;
43
+ /**
44
+ * Builder for individual workflow steps.
45
+ */
46
+ class WorkflowStepBuilder {
47
+ constructor(id, parentBuilder) {
48
+ this.parentBuilder = parentBuilder;
49
+ this.step = {
50
+ id,
51
+ name: id,
52
+ taskType: 'assignment',
53
+ assignmentTemplate: {},
54
+ targetUser: 'initiator',
55
+ };
56
+ }
57
+ /**
58
+ * Set execution mode for this step.
59
+ */
60
+ taskType(type) {
61
+ this.step.taskType = type;
62
+ return this;
63
+ }
64
+ /**
65
+ * Set the step name.
66
+ */
67
+ name(name) {
68
+ this.step.name = name;
69
+ return this;
70
+ }
71
+ /**
72
+ * Set the assignment template for this step.
73
+ */
74
+ assignment(template) {
75
+ this.step.assignmentTemplate = template;
76
+ return this;
77
+ }
78
+ /**
79
+ * Configure this step as a machine/code task.
80
+ */
81
+ machineTask(handler, input) {
82
+ this.step.taskType = 'machine';
83
+ this.step.machineTask = { handler, input };
84
+ return this;
85
+ }
86
+ /**
87
+ * Set the target user for this step.
88
+ * @param target - 'initiator' | 'previous' | userId | { tag: string }
89
+ */
90
+ targetUser(target) {
91
+ this.step.targetUser = target;
92
+ return this;
93
+ }
94
+ /**
95
+ * Add a routing rule for conditional branching.
96
+ * @param condition - Expression to evaluate (e.g., 'result.approved === true')
97
+ * @param targetStepId - Step to go to if condition is true
98
+ */
99
+ route(condition, targetStepId) {
100
+ if (!this.step.routing) {
101
+ this.step.routing = [];
102
+ }
103
+ this.step.routing.push({ condition, targetStepId });
104
+ return this;
105
+ }
106
+ /**
107
+ * Set the default next step if no routing conditions match.
108
+ * @param stepId - Next step ID, or null to end workflow
109
+ */
110
+ defaultNext(stepId) {
111
+ this.step.defaultNextStepId = stepId;
112
+ return this;
113
+ }
114
+ /**
115
+ * Configure parallel execution with other steps.
116
+ * @param stepIds - Array of step IDs to execute in parallel with this step
117
+ */
118
+ parallel(stepIds) {
119
+ this.step.parallelStepIds = stepIds;
120
+ return this;
121
+ }
122
+ /**
123
+ * Set whether to wait for all parallel branches before continuing.
124
+ */
125
+ waitForAll(wait = true) {
126
+ this.step.waitForAll = wait;
127
+ return this;
128
+ }
129
+ /**
130
+ * Set the failure policy for parallel execution.
131
+ */
132
+ failurePolicy(policy) {
133
+ this.step.failurePolicy = policy;
134
+ return this;
135
+ }
136
+ /**
137
+ * Set the maximum retry count for this step.
138
+ */
139
+ maxRetries(count) {
140
+ this.step.maxRetries = count;
141
+ return this;
142
+ }
143
+ /**
144
+ * Set a timeout for this step in milliseconds.
145
+ */
146
+ timeout(ms) {
147
+ this.step.timeoutMs = ms;
148
+ return this;
149
+ }
150
+ /**
151
+ * Finish configuring this step and return to the parent builder.
152
+ */
153
+ done() {
154
+ if ((this.step.taskType ?? 'assignment') === 'machine' && !this.step.machineTask?.handler) {
155
+ throw new Error(`Machine step "${this.step.id}" requires machineTask(handler)`);
156
+ }
157
+ this.parentBuilder._addStep(this.step);
158
+ return this.parentBuilder;
159
+ }
160
+ /**
161
+ * Get the built step (for internal use).
162
+ */
163
+ _getStep() {
164
+ return this.step;
165
+ }
166
+ }
167
+ exports.WorkflowStepBuilder = WorkflowStepBuilder;
168
+ /**
169
+ * Builder for workflow definitions.
170
+ */
171
+ class WorkflowBuilder {
172
+ constructor(id, name) {
173
+ this.steps = [];
174
+ this.definition = {
175
+ id,
176
+ name,
177
+ version: 1,
178
+ steps: [],
179
+ };
180
+ }
181
+ /**
182
+ * Create a new workflow builder.
183
+ * @param id - Unique identifier for the workflow
184
+ * @param name - Human-readable name
185
+ */
186
+ static create(id, name) {
187
+ return new WorkflowBuilder(id, name);
188
+ }
189
+ /**
190
+ * Set the workflow version.
191
+ */
192
+ version(version) {
193
+ this.definition.version = version;
194
+ return this;
195
+ }
196
+ /**
197
+ * Set workflow metadata.
198
+ */
199
+ metadata(metadata) {
200
+ this.definition.metadata = metadata;
201
+ return this;
202
+ }
203
+ /**
204
+ * Set the default timeout for all steps (in milliseconds).
205
+ */
206
+ defaultTimeout(ms) {
207
+ this.definition.defaultTimeoutMs = ms;
208
+ return this;
209
+ }
210
+ /**
211
+ * Start building a new step.
212
+ * @param id - Unique identifier for the step within this workflow
213
+ */
214
+ step(id) {
215
+ return new WorkflowStepBuilder(id, this);
216
+ }
217
+ /**
218
+ * Add a pre-built step to the workflow.
219
+ */
220
+ addStep(step) {
221
+ this.steps.push(step);
222
+ return this;
223
+ }
224
+ /**
225
+ * Internal method to add a step from the step builder.
226
+ */
227
+ _addStep(step) {
228
+ this.steps.push(step);
229
+ }
230
+ /**
231
+ * Set the initial (entry point) step ID.
232
+ */
233
+ initialStep(stepId) {
234
+ this.definition.initialStepId = stepId;
235
+ return this;
236
+ }
237
+ /**
238
+ * Build and return the workflow definition.
239
+ * @throws Error if the workflow is invalid
240
+ */
241
+ build() {
242
+ // Validate
243
+ if (!this.definition.id) {
244
+ throw new Error('Workflow ID is required');
245
+ }
246
+ if (!this.definition.name) {
247
+ throw new Error('Workflow name is required');
248
+ }
249
+ if (this.steps.length === 0) {
250
+ throw new Error('Workflow must have at least one step');
251
+ }
252
+ if (!this.definition.initialStepId) {
253
+ // Default to first step if not specified
254
+ this.definition.initialStepId = this.steps[0].id;
255
+ }
256
+ // Validate initial step exists
257
+ const initialStep = this.steps.find(s => s.id === this.definition.initialStepId);
258
+ if (!initialStep) {
259
+ throw new Error(`Initial step "${this.definition.initialStepId}" not found`);
260
+ }
261
+ // Validate all referenced step IDs exist
262
+ for (const step of this.steps) {
263
+ const taskType = step.taskType ?? 'assignment';
264
+ if (taskType === 'machine' && !step.machineTask?.handler) {
265
+ throw new Error(`Step "${step.id}" has taskType "machine" but no machineTask.handler`);
266
+ }
267
+ if (step.routing) {
268
+ for (const route of step.routing) {
269
+ if (!this.steps.find(s => s.id === route.targetStepId)) {
270
+ throw new Error(`Step "${step.id}" references non-existent step "${route.targetStepId}" in routing`);
271
+ }
272
+ }
273
+ }
274
+ if (step.defaultNextStepId && !this.steps.find(s => s.id === step.defaultNextStepId)) {
275
+ throw new Error(`Step "${step.id}" references non-existent step "${step.defaultNextStepId}" as default next`);
276
+ }
277
+ if (step.parallelStepIds) {
278
+ for (const parallelId of step.parallelStepIds) {
279
+ if (!this.steps.find(s => s.id === parallelId)) {
280
+ throw new Error(`Step "${step.id}" references non-existent parallel step "${parallelId}"`);
281
+ }
282
+ }
283
+ }
284
+ }
285
+ return {
286
+ id: this.definition.id,
287
+ name: this.definition.name,
288
+ version: this.definition.version ?? 1,
289
+ initialStepId: this.definition.initialStepId,
290
+ steps: this.steps,
291
+ defaultTimeoutMs: this.definition.defaultTimeoutMs,
292
+ metadata: this.definition.metadata,
293
+ };
294
+ }
295
+ }
296
+ exports.WorkflowBuilder = WorkflowBuilder;
297
+ /**
298
+ * Convenience function to create a new workflow builder.
299
+ */
300
+ function workflow(id, name) {
301
+ return WorkflowBuilder.create(id, name);
302
+ }
303
+ exports.workflow = workflow;
304
+ /**
305
+ * Create a simple linear workflow with automatic step chaining.
306
+ * @param id - Workflow ID
307
+ * @param name - Workflow name
308
+ * @param steps - Array of step configurations
309
+ */
310
+ function linearWorkflow(id, name, steps) {
311
+ if (steps.length === 0) {
312
+ throw new Error('Linear workflow must have at least one step');
313
+ }
314
+ const workflowSteps = steps.map((step, index) => ({
315
+ id: step.id,
316
+ name: step.name,
317
+ taskType: step.taskType ?? 'assignment',
318
+ assignmentTemplate: step.assignment,
319
+ targetUser: step.targetUser ?? 'initiator',
320
+ machineTask: step.machineTask,
321
+ defaultNextStepId: index < steps.length - 1 ? steps[index + 1].id : null,
322
+ timeoutMs: step.timeoutMs,
323
+ }));
324
+ return {
325
+ id,
326
+ name,
327
+ version: 1,
328
+ initialStepId: steps[0].id,
329
+ steps: workflowSteps,
330
+ };
331
+ }
332
+ exports.linearWorkflow = linearWorkflow;
333
+ /**
334
+ * Create an approval workflow with submit -> review -> complete/rejected pattern.
335
+ */
336
+ function approvalWorkflow(id, name, options) {
337
+ return WorkflowBuilder.create(id, name)
338
+ .step('submit')
339
+ .name('Submit')
340
+ .assignment(options.submitAssignment)
341
+ .targetUser('initiator')
342
+ .defaultNext('review')
343
+ .done()
344
+ .step('review')
345
+ .name('Review')
346
+ .assignment(options.reviewAssignment)
347
+ .targetUser(options.reviewerTag ? { tag: options.reviewerTag } : 'initiator')
348
+ .timeout(options.reviewTimeoutMs ?? 86400000)
349
+ .route('result.decision === "approve"', 'complete')
350
+ .route('result.decision === "reject"', 'rejected')
351
+ .defaultNext('complete')
352
+ .done()
353
+ .step('complete')
354
+ .name('Completed')
355
+ .assignment(options.completeAssignment ?? { tags: ['notification'], title: 'Approved' })
356
+ .targetUser('initiator')
357
+ .done()
358
+ .step('rejected')
359
+ .name('Rejected')
360
+ .assignment(options.rejectedAssignment ?? { tags: ['notification'], title: 'Rejected' })
361
+ .targetUser('initiator')
362
+ .done()
363
+ .initialStep('submit')
364
+ .build();
365
+ }
366
+ exports.approvalWorkflow = approvalWorkflow;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "assignment-user-matcher",
3
- "version": "1.1.6",
3
+ "version": "1.2.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/ViljarVoidula/assignment-user-matcher"