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,5 @@
1
+ /**
2
+ * Query module exports
3
+ */
4
+ export * from './pagination';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/queries/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,cAAc,cAAc,CAAC"}
@@ -0,0 +1,20 @@
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);
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Pagination and querying utilities for assignments
3
+ */
4
+ import type { RedisClientType, Assignment } from '../matcher.class';
5
+ export type AssignmentStatus = 'queued' | 'pending' | 'accepted';
6
+ export interface PaginationOptions {
7
+ cursor?: string | null;
8
+ limit?: number;
9
+ status?: AssignmentStatus | 'all';
10
+ includeTotal?: boolean;
11
+ }
12
+ export interface PaginationResult {
13
+ assignments: Assignment[];
14
+ nextCursor: string | null;
15
+ hasMore: boolean;
16
+ total?: number;
17
+ }
18
+ export interface AssignmentCounts {
19
+ queued: number;
20
+ pending: number;
21
+ accepted: number;
22
+ total: number;
23
+ }
24
+ export interface AssignmentKeys {
25
+ queued: string;
26
+ pending: string;
27
+ accepted: string;
28
+ }
29
+ /**
30
+ * Get all assignments from all stores (queued, pending, accepted)
31
+ */
32
+ export declare function getAllAssignmentsFromStores(redisClient: RedisClientType, keys: AssignmentKeys): Promise<Assignment[]>;
33
+ /**
34
+ * Get assignment counts by status
35
+ */
36
+ export declare function getAssignmentCountsFromStores(redisClient: RedisClientType, keys: AssignmentKeys): Promise<AssignmentCounts>;
37
+ /**
38
+ * Get a single assignment by ID from any status
39
+ */
40
+ export declare function getAssignmentById(redisClient: RedisClientType, keys: AssignmentKeys, id: string): Promise<(Assignment & {
41
+ _status?: string;
42
+ }) | null>;
43
+ /**
44
+ * Get multiple assignments by IDs efficiently
45
+ */
46
+ export declare function getAssignmentsByIdsBatch(redisClient: RedisClientType, keys: AssignmentKeys, ids: string[]): Promise<Assignment[]>;
47
+ /**
48
+ * Get assignments with cursor-based pagination across statuses
49
+ */
50
+ export declare function getAssignmentsPaginatedFromStores(redisClient: RedisClientType, keys: AssignmentKeys, options?: PaginationOptions): Promise<PaginationResult>;
51
+ //# sourceMappingURL=pagination.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pagination.d.ts","sourceRoot":"","sources":["../../src/queries/pagination.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEpE,MAAM,MAAM,gBAAgB,GAAG,QAAQ,GAAG,SAAS,GAAG,UAAU,CAAC;AAEjE,MAAM,WAAW,iBAAiB;IAC9B,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,gBAAgB,GAAG,KAAK,CAAC;IAClC,YAAY,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,gBAAgB;IAC7B,WAAW,EAAE,UAAU,EAAE,CAAC;IAC1B,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,gBAAgB;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,cAAc;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,wBAAsB,2BAA2B,CAC7C,WAAW,EAAE,eAAe,EAC5B,IAAI,EAAE,cAAc,GACrB,OAAO,CAAC,UAAU,EAAE,CAAC,CASvB;AAED;;GAEG;AACH,wBAAsB,6BAA6B,CAC/C,WAAW,EAAE,eAAe,EAC5B,IAAI,EAAE,cAAc,GACrB,OAAO,CAAC,gBAAgB,CAAC,CAa3B;AAED;;GAEG;AACH,wBAAsB,iBAAiB,CACnC,WAAW,EAAE,eAAe,EAC5B,IAAI,EAAE,cAAc,EACpB,EAAE,EAAE,MAAM,GACX,OAAO,CAAC,CAAC,UAAU,GAAG;IAAE,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,GAAG,IAAI,CAAC,CAwBrD;AAED;;GAEG;AACH,wBAAsB,wBAAwB,CAC1C,WAAW,EAAE,eAAe,EAC5B,IAAI,EAAE,cAAc,EACpB,GAAG,EAAE,MAAM,EAAE,GACd,OAAO,CAAC,UAAU,EAAE,CAAC,CA+BvB;AAED;;GAEG;AACH,wBAAsB,iCAAiC,CACnD,WAAW,EAAE,eAAe,EAC5B,IAAI,EAAE,cAAc,EACpB,OAAO,CAAC,EAAE,iBAAiB,GAC5B,OAAO,CAAC,gBAAgB,CAAC,CAyH3B"}
@@ -0,0 +1,200 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAssignmentsPaginatedFromStores = exports.getAssignmentsByIdsBatch = exports.getAssignmentById = exports.getAssignmentCountsFromStores = exports.getAllAssignmentsFromStores = void 0;
4
+ /**
5
+ * Get all assignments from all stores (queued, pending, accepted)
6
+ */
7
+ async function getAllAssignmentsFromStores(redisClient, keys) {
8
+ const [queuedAssignments, pendingAssignments, acceptedAssignments] = await Promise.all([
9
+ redisClient.hGetAll(keys.queued),
10
+ redisClient.hGetAll(keys.pending),
11
+ redisClient.hGetAll(keys.accepted),
12
+ ]);
13
+ const allAssignments = { ...queuedAssignments, ...pendingAssignments, ...acceptedAssignments };
14
+ return Object.values(allAssignments).map((assignment) => JSON.parse(assignment));
15
+ }
16
+ exports.getAllAssignmentsFromStores = getAllAssignmentsFromStores;
17
+ /**
18
+ * Get assignment counts by status
19
+ */
20
+ async function getAssignmentCountsFromStores(redisClient, keys) {
21
+ const [queued, pending, accepted] = await Promise.all([
22
+ redisClient.hLen(keys.queued),
23
+ redisClient.hLen(keys.pending),
24
+ redisClient.hLen(keys.accepted),
25
+ ]);
26
+ return {
27
+ queued,
28
+ pending,
29
+ accepted,
30
+ total: queued + pending + accepted,
31
+ };
32
+ }
33
+ exports.getAssignmentCountsFromStores = getAssignmentCountsFromStores;
34
+ /**
35
+ * Get a single assignment by ID from any status
36
+ */
37
+ async function getAssignmentById(redisClient, keys, id) {
38
+ const [queued, pending, accepted] = await Promise.all([
39
+ redisClient.hGet(keys.queued, id),
40
+ redisClient.hGet(keys.pending, id),
41
+ redisClient.hGet(keys.accepted, id),
42
+ ]);
43
+ if (queued) {
44
+ const assignment = JSON.parse(queued);
45
+ assignment._status = 'queued';
46
+ return assignment;
47
+ }
48
+ if (pending) {
49
+ const assignment = JSON.parse(pending);
50
+ assignment._status = 'pending';
51
+ return assignment;
52
+ }
53
+ if (accepted) {
54
+ const assignment = JSON.parse(accepted);
55
+ assignment._status = 'accepted';
56
+ return assignment;
57
+ }
58
+ return null;
59
+ }
60
+ exports.getAssignmentById = getAssignmentById;
61
+ /**
62
+ * Get multiple assignments by IDs efficiently
63
+ */
64
+ async function getAssignmentsByIdsBatch(redisClient, keys, ids) {
65
+ if (ids.length === 0)
66
+ return [];
67
+ const multi = redisClient.multi();
68
+ for (const id of ids) {
69
+ multi.hGet(keys.queued, id);
70
+ multi.hGet(keys.pending, id);
71
+ multi.hGet(keys.accepted, id);
72
+ }
73
+ const results = await multi.exec();
74
+ const assignments = [];
75
+ for (let i = 0; i < ids.length; i++) {
76
+ const queued = results[i * 3];
77
+ const pending = results[i * 3 + 1];
78
+ const accepted = results[i * 3 + 2];
79
+ const json = queued || pending || accepted;
80
+ if (json) {
81
+ try {
82
+ const assignment = JSON.parse(json);
83
+ assignment._status = queued ? 'queued' : pending ? 'pending' : 'accepted';
84
+ assignments.push(assignment);
85
+ }
86
+ catch {
87
+ // Skip invalid JSON
88
+ }
89
+ }
90
+ }
91
+ return assignments;
92
+ }
93
+ exports.getAssignmentsByIdsBatch = getAssignmentsByIdsBatch;
94
+ /**
95
+ * Get assignments with cursor-based pagination across statuses
96
+ */
97
+ async function getAssignmentsPaginatedFromStores(redisClient, keys, options) {
98
+ const limit = options?.limit ?? 100;
99
+ const status = options?.status ?? 'all';
100
+ const includeTotal = options?.includeTotal ?? false;
101
+ const getKeyForStatus = (s) => {
102
+ switch (s) {
103
+ case 'queued': return keys.queued;
104
+ case 'pending': return keys.pending;
105
+ case 'accepted': return keys.accepted;
106
+ }
107
+ };
108
+ const statusOrder = status === 'all' ? ['queued', 'pending', 'accepted'] : [status];
109
+ // Parse cursor: "statusIndex:offset"
110
+ let statusIndex = 0;
111
+ let offset = 0;
112
+ if (options?.cursor) {
113
+ const parts = options.cursor.split(':');
114
+ statusIndex = parseInt(parts[0], 10) || 0;
115
+ offset = parseInt(parts[1], 10) || 0;
116
+ }
117
+ const assignments = [];
118
+ let nextCursor = null;
119
+ let hasMore = false;
120
+ while (assignments.length < limit && statusIndex < statusOrder.length) {
121
+ const scanStatus = statusOrder[statusIndex];
122
+ const key = getKeyForStatus(scanStatus);
123
+ const totalInStatus = await redisClient.hLen(key);
124
+ const remainingInStatus = totalInStatus - offset;
125
+ if (remainingInStatus <= 0) {
126
+ statusIndex++;
127
+ offset = 0;
128
+ continue;
129
+ }
130
+ const needed = limit - assignments.length;
131
+ let scanned = 0;
132
+ let cursor = '0';
133
+ const seenIds = new Set();
134
+ do {
135
+ const { cursor: newCursor, entries } = await redisClient.hScan(key, cursor, {
136
+ COUNT: Math.max(needed + offset - scanned, 100),
137
+ });
138
+ for (const entry of entries) {
139
+ if (seenIds.has(entry.field))
140
+ continue;
141
+ seenIds.add(entry.field);
142
+ if (scanned < offset) {
143
+ scanned++;
144
+ continue;
145
+ }
146
+ if (assignments.length >= limit) {
147
+ nextCursor = `${statusIndex}:${offset + (assignments.length - (assignments.filter(a => a._status === scanStatus).length - 1))}`;
148
+ hasMore = true;
149
+ break;
150
+ }
151
+ try {
152
+ const assignment = JSON.parse(entry.value);
153
+ assignment._status = scanStatus;
154
+ assignments.push(assignment);
155
+ }
156
+ catch {
157
+ // Skip invalid JSON
158
+ }
159
+ scanned++;
160
+ }
161
+ cursor = newCursor;
162
+ } while (cursor !== '0' && assignments.length < limit);
163
+ if (assignments.length >= limit) {
164
+ const countFromCurrentStatus = assignments.filter(a => a._status === scanStatus).length;
165
+ nextCursor = `${statusIndex}:${offset + countFromCurrentStatus}`;
166
+ hasMore = true;
167
+ break;
168
+ }
169
+ statusIndex++;
170
+ offset = 0;
171
+ }
172
+ // Check for more data in remaining statuses
173
+ if (!hasMore && statusIndex < statusOrder.length) {
174
+ for (let i = statusIndex; i < statusOrder.length; i++) {
175
+ const count = await redisClient.hLen(getKeyForStatus(statusOrder[i]));
176
+ const processedInThisStatus = i === statusIndex ? offset : 0;
177
+ if (count > processedInThisStatus) {
178
+ nextCursor = `${i}:${processedInThisStatus}`;
179
+ hasMore = true;
180
+ break;
181
+ }
182
+ }
183
+ }
184
+ const result = {
185
+ assignments,
186
+ nextCursor: hasMore ? nextCursor : null,
187
+ hasMore,
188
+ };
189
+ if (includeTotal) {
190
+ if (status === 'all') {
191
+ const counts = await getAssignmentCountsFromStores(redisClient, keys);
192
+ result.total = counts.total;
193
+ }
194
+ else {
195
+ result.total = await redisClient.hLen(getKeyForStatus(status));
196
+ }
197
+ }
198
+ return result;
199
+ }
200
+ exports.getAssignmentsPaginatedFromStores = getAssignmentsPaginatedFromStores;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Scoring module exports
3
+ */
4
+ export * from './match-score';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/scoring/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,cAAc,eAAe,CAAC"}
@@ -0,0 +1,20 @@
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);
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Scoring and matching utilities
3
+ */
4
+ import type { User } from '../matcher.class';
5
+ /**
6
+ * Check if a pattern matches a tag (supports wildcard patterns ending with *)
7
+ */
8
+ export declare function matchesPattern(pattern: string, tag: string): boolean;
9
+ /**
10
+ * Get the effective weight for a skill tag from user's routingWeights
11
+ * Supports wildcard patterns (e.g., 'eng*' matches 'english')
12
+ */
13
+ export declare function getEffectiveWeight(routingWeights: Record<string, number>, tag: string): number;
14
+ /**
15
+ * Check if user meets all skill thresholds
16
+ * Returns true if all thresholds are met, false otherwise
17
+ */
18
+ export declare function meetsSkillThresholds(routingWeights: Record<string, number> | undefined, skillThresholds: Record<string, number> | undefined): boolean;
19
+ /**
20
+ * Calculate match score between a user and assignment tags
21
+ * Returns [score, combinedPriority]
22
+ */
23
+ export declare function calculateMatchScore(user: User, assignmentTags: string, assignmentPriority: string | number, enableDefaultMatching: boolean, skillThresholds?: Record<string, number>): [number, number];
24
+ /**
25
+ * Calculate default priority based on creation time
26
+ * Note: Returns 0 if createdAt is undefined to match original behavior
27
+ */
28
+ export declare function calculateDefaultPriority(createdAt?: number): number;
29
+ //# sourceMappingURL=match-score.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"match-score.d.ts","sourceRoot":"","sources":["../../src/scoring/match-score.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAE7C;;GAEG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAOpE;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAC9B,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACtC,GAAG,EAAE,MAAM,GACZ,MAAM,CAYR;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAChC,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,EAClD,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,GACpD,OAAO,CAeT;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAC/B,IAAI,EAAE,IAAI,EACV,cAAc,EAAE,MAAM,EACtB,kBAAkB,EAAE,MAAM,GAAG,MAAM,EACnC,qBAAqB,EAAE,OAAO,EAC9B,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACzC,CAAC,MAAM,EAAE,MAAM,CAAC,CAoElB;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAGnE"}
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.calculateDefaultPriority = exports.calculateMatchScore = exports.meetsSkillThresholds = exports.getEffectiveWeight = exports.matchesPattern = void 0;
4
+ /**
5
+ * Check if a pattern matches a tag (supports wildcard patterns ending with *)
6
+ */
7
+ function matchesPattern(pattern, tag) {
8
+ if (pattern === tag)
9
+ return true;
10
+ if (pattern.endsWith('*')) {
11
+ const prefix = pattern.slice(0, -1);
12
+ return tag.startsWith(prefix);
13
+ }
14
+ return false;
15
+ }
16
+ exports.matchesPattern = matchesPattern;
17
+ /**
18
+ * Get the effective weight for a skill tag from user's routingWeights
19
+ * Supports wildcard patterns (e.g., 'eng*' matches 'english')
20
+ */
21
+ function getEffectiveWeight(routingWeights, tag) {
22
+ // First check for exact match
23
+ if (tag in routingWeights) {
24
+ return routingWeights[tag];
25
+ }
26
+ // Check wildcard patterns
27
+ for (const [pattern, weight] of Object.entries(routingWeights)) {
28
+ if (matchesPattern(pattern, tag)) {
29
+ return weight;
30
+ }
31
+ }
32
+ return 0;
33
+ }
34
+ exports.getEffectiveWeight = getEffectiveWeight;
35
+ /**
36
+ * Check if user meets all skill thresholds
37
+ * Returns true if all thresholds are met, false otherwise
38
+ */
39
+ function meetsSkillThresholds(routingWeights, skillThresholds) {
40
+ if (!skillThresholds || Object.keys(skillThresholds).length === 0) {
41
+ return true; // No thresholds to check
42
+ }
43
+ if (!routingWeights || Object.keys(routingWeights).length === 0) {
44
+ return false; // User has no weights but thresholds exist
45
+ }
46
+ for (const [skill, minWeight] of Object.entries(skillThresholds)) {
47
+ const userWeight = getEffectiveWeight(routingWeights, skill);
48
+ if (userWeight < minWeight) {
49
+ return false;
50
+ }
51
+ }
52
+ return true;
53
+ }
54
+ exports.meetsSkillThresholds = meetsSkillThresholds;
55
+ /**
56
+ * Calculate match score between a user and assignment tags
57
+ * Returns [score, combinedPriority]
58
+ */
59
+ function calculateMatchScore(user, assignmentTags, assignmentPriority, enableDefaultMatching, skillThresholds) {
60
+ const aTags = assignmentTags ? assignmentTags.split(',') : [];
61
+ // If weighted skills are present, use them for scoring
62
+ if (user.routingWeights && Object.keys(user.routingWeights).length > 0) {
63
+ // Check skill thresholds first - reject if not met
64
+ if (!meetsSkillThresholds(user.routingWeights, skillThresholds)) {
65
+ return [0, Number(assignmentPriority) || 0];
66
+ }
67
+ // Check for exclusions (weight 0)
68
+ for (const [pattern, weight] of Object.entries(user.routingWeights)) {
69
+ if (weight === 0) {
70
+ for (const t of aTags) {
71
+ if (matchesPattern(pattern, t)) {
72
+ return [0, Number(assignmentPriority) || 0];
73
+ }
74
+ }
75
+ }
76
+ }
77
+ let weightSum = 0;
78
+ for (const t of aTags) {
79
+ let matchedByRouting = false;
80
+ for (const [pattern, weight] of Object.entries(user.routingWeights)) {
81
+ if (typeof weight === 'number' && weight > 0) {
82
+ if (matchesPattern(pattern, t)) {
83
+ weightSum += weight;
84
+ matchedByRouting = true;
85
+ }
86
+ }
87
+ }
88
+ // If enableDefaultMatching is true, and the tag is 'default',
89
+ // and it wasn't matched by any routing weight, give it default weight 1
90
+ if (enableDefaultMatching && t === 'default' && !matchedByRouting) {
91
+ weightSum += 1;
92
+ }
93
+ }
94
+ const base = Number(assignmentPriority) || 0;
95
+ return [weightSum, base + weightSum];
96
+ }
97
+ // For tag-based matching (no routingWeights), check thresholds
98
+ // If thresholds exist but user has no routingWeights, reject
99
+ if (skillThresholds && Object.keys(skillThresholds).length > 0) {
100
+ return [0, Number(assignmentPriority) || 0];
101
+ }
102
+ // Fallback to default tag-intersection scoring
103
+ const userTagSet = new Set(user.tags);
104
+ const assignmentTagSet = new Set(aTags);
105
+ let intersectionSize = 0;
106
+ for (const userTag of userTagSet) {
107
+ let matched = false;
108
+ for (const assignmentTag of assignmentTagSet) {
109
+ if (matchesPattern(userTag, assignmentTag)) {
110
+ matched = true;
111
+ break;
112
+ }
113
+ }
114
+ if (matched)
115
+ intersectionSize++;
116
+ }
117
+ const score = userTagSet.size > 0 ? intersectionSize / userTagSet.size : 0;
118
+ const base = Number(assignmentPriority) || 0;
119
+ return [score || 0, base + (score || 0)];
120
+ }
121
+ exports.calculateMatchScore = calculateMatchScore;
122
+ /**
123
+ * Calculate default priority based on creation time
124
+ * Note: Returns 0 if createdAt is undefined to match original behavior
125
+ */
126
+ function calculateDefaultPriority(createdAt) {
127
+ if (createdAt === undefined)
128
+ return 0;
129
+ return new Date().getTime() - createdAt;
130
+ }
131
+ exports.calculateDefaultPriority = calculateDefaultPriority;