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