assignment-user-matcher 1.1.2 → 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.
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +26 -1
- package/dist/managers/ReliabilityManager.d.ts +42 -0
- package/dist/managers/ReliabilityManager.d.ts.map +1 -0
- package/dist/managers/ReliabilityManager.js +115 -0
- package/dist/managers/TelemetryManager.d.ts +13 -0
- package/dist/managers/TelemetryManager.d.ts.map +1 -0
- package/dist/managers/TelemetryManager.js +52 -0
- package/dist/managers/WorkflowManager.d.ts +62 -0
- package/dist/managers/WorkflowManager.d.ts.map +1 -0
- package/dist/managers/WorkflowManager.js +654 -0
- package/dist/matcher.class.d.ts +161 -51
- package/dist/matcher.class.d.ts.map +1 -1
- package/dist/matcher.class.js +472 -254
- package/dist/queries/index.d.ts +5 -0
- package/dist/queries/index.d.ts.map +1 -0
- package/dist/queries/index.js +20 -0
- package/dist/queries/pagination.d.ts +51 -0
- package/dist/queries/pagination.d.ts.map +1 -0
- package/dist/queries/pagination.js +200 -0
- package/dist/scoring/index.d.ts +5 -0
- package/dist/scoring/index.d.ts.map +1 -0
- package/dist/scoring/index.js +20 -0
- package/dist/scoring/match-score.d.ts +19 -0
- package/dist/scoring/match-score.d.ts.map +1 -0
- package/dist/scoring/match-score.js +84 -0
- package/dist/types/matcher.d.ts +261 -0
- package/dist/types/matcher.d.ts.map +1 -0
- package/dist/types/matcher.js +2 -0
- package/dist/utils/cidr.d.ts +40 -0
- package/dist/utils/cidr.d.ts.map +1 -0
- package/dist/utils/cidr.js +150 -0
- package/dist/utils/index.d.ts +6 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +21 -0
- package/dist/utils/keys.d.ts +45 -0
- package/dist/utils/keys.d.ts.map +1 -0
- package/dist/utils/keys.js +57 -0
- package/dist/workflow-builder.d.ts +182 -0
- package/dist/workflow-builder.d.ts.map +1 -0
- package/dist/workflow-builder.js +341 -0
- package/package.json +6 -2
|
@@ -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 @@
|
|
|
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,19 @@
|
|
|
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
|
+
* Calculate match score between a user and assignment tags
|
|
11
|
+
* Returns [score, combinedPriority]
|
|
12
|
+
*/
|
|
13
|
+
export declare function calculateMatchScore(user: User, assignmentTags: string, assignmentPriority: string | number, enableDefaultMatching: boolean): [number, number];
|
|
14
|
+
/**
|
|
15
|
+
* Calculate default priority based on creation time
|
|
16
|
+
* Note: Returns 0 if createdAt is undefined to match original behavior
|
|
17
|
+
*/
|
|
18
|
+
export declare function calculateDefaultPriority(createdAt?: number): number;
|
|
19
|
+
//# 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,mBAAmB,CAC/B,IAAI,EAAE,IAAI,EACV,cAAc,EAAE,MAAM,EACtB,kBAAkB,EAAE,MAAM,GAAG,MAAM,EACnC,qBAAqB,EAAE,OAAO,GAC/B,CAAC,MAAM,EAAE,MAAM,CAAC,CAyDlB;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAGnE"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.calculateDefaultPriority = exports.calculateMatchScore = 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
|
+
* Calculate match score between a user and assignment tags
|
|
19
|
+
* Returns [score, combinedPriority]
|
|
20
|
+
*/
|
|
21
|
+
function calculateMatchScore(user, assignmentTags, assignmentPriority, enableDefaultMatching) {
|
|
22
|
+
const aTags = assignmentTags ? assignmentTags.split(',') : [];
|
|
23
|
+
// If weighted skills are present, use them for scoring
|
|
24
|
+
if (user.routingWeights && Object.keys(user.routingWeights).length > 0) {
|
|
25
|
+
// Check for exclusions (weight 0)
|
|
26
|
+
for (const [pattern, weight] of Object.entries(user.routingWeights)) {
|
|
27
|
+
if (weight === 0) {
|
|
28
|
+
for (const t of aTags) {
|
|
29
|
+
if (matchesPattern(pattern, t)) {
|
|
30
|
+
return [0, Number(assignmentPriority) || 0];
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
let weightSum = 0;
|
|
36
|
+
for (const t of aTags) {
|
|
37
|
+
let matchedByRouting = false;
|
|
38
|
+
for (const [pattern, weight] of Object.entries(user.routingWeights)) {
|
|
39
|
+
if (typeof weight === 'number' && weight > 0) {
|
|
40
|
+
if (matchesPattern(pattern, t)) {
|
|
41
|
+
weightSum += weight;
|
|
42
|
+
matchedByRouting = true;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
// If enableDefaultMatching is true, and the tag is 'default',
|
|
47
|
+
// and it wasn't matched by any routing weight, give it default weight 1
|
|
48
|
+
if (enableDefaultMatching && t === 'default' && !matchedByRouting) {
|
|
49
|
+
weightSum += 1;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const base = Number(assignmentPriority) || 0;
|
|
53
|
+
return [weightSum, base + weightSum];
|
|
54
|
+
}
|
|
55
|
+
// Fallback to default tag-intersection scoring
|
|
56
|
+
const userTagSet = new Set(user.tags);
|
|
57
|
+
const assignmentTagSet = new Set(aTags);
|
|
58
|
+
let intersectionSize = 0;
|
|
59
|
+
for (const userTag of userTagSet) {
|
|
60
|
+
let matched = false;
|
|
61
|
+
for (const assignmentTag of assignmentTagSet) {
|
|
62
|
+
if (matchesPattern(userTag, assignmentTag)) {
|
|
63
|
+
matched = true;
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (matched)
|
|
68
|
+
intersectionSize++;
|
|
69
|
+
}
|
|
70
|
+
const score = userTagSet.size > 0 ? intersectionSize / userTagSet.size : 0;
|
|
71
|
+
const base = Number(assignmentPriority) || 0;
|
|
72
|
+
return [score || 0, base + (score || 0)];
|
|
73
|
+
}
|
|
74
|
+
exports.calculateMatchScore = calculateMatchScore;
|
|
75
|
+
/**
|
|
76
|
+
* Calculate default priority based on creation time
|
|
77
|
+
* Note: Returns 0 if createdAt is undefined to match original behavior
|
|
78
|
+
*/
|
|
79
|
+
function calculateDefaultPriority(createdAt) {
|
|
80
|
+
if (createdAt === undefined)
|
|
81
|
+
return 0;
|
|
82
|
+
return new Date().getTime() - createdAt;
|
|
83
|
+
}
|
|
84
|
+
exports.calculateDefaultPriority = calculateDefaultPriority;
|