assignment-user-matcher 1.0.11 → 1.1.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/README.md +10 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/matcher.class.d.ts +73 -0
- package/dist/matcher.class.d.ts.map +1 -0
- package/{src/matcher.class.ts → dist/matcher.class.js} +247 -200
- package/package.json +15 -2
- package/.github/workflows/npm-publish.yml +0 -82
- package/.mocharc.json +0 -11
- package/.prettierignore +0 -1
- package/.vscode/launch.json +0 -32
- package/docs/README.md +0 -406
- package/docs/classes/default.md +0 -423
- package/docs/interfaces/User.md +0 -45
- package/docs/modules.md +0 -91
- package/tests/matcher.test.ts +0 -441
- package/tsconfig.json +0 -22
package/README.md
CHANGED
|
@@ -400,6 +400,16 @@ Contributions are welcome! If you have ideas for improvements, new features, or
|
|
|
400
400
|
|
|
401
401
|
Please open an issue first to discuss significant changes.
|
|
402
402
|
|
|
403
|
+
## Packaging & Publishing
|
|
404
|
+
|
|
405
|
+
The npm package only ships the compiled artifacts in `dist/`. Before publishing:
|
|
406
|
+
|
|
407
|
+
1. Install dependencies: `pnpm install`
|
|
408
|
+
2. Build the library: `pnpm run build`
|
|
409
|
+
3. (Optional) Inspect the publish payload: `pnpm pack --dry-run`
|
|
410
|
+
|
|
411
|
+
Consumers can `import AssignmentMatcher from 'assignment-user-matcher'` or `const { AssignmentMatcher } = require('assignment-user-matcher')` without running TypeScript themselves.
|
|
412
|
+
|
|
403
413
|
## License
|
|
404
414
|
|
|
405
415
|
This library is licensed under the MIT License. (Assuming MIT - please update if incorrect)
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,iBAAiB,MAAM,iBAAiB,CAAC;AAEhD,YAAY,EAAE,UAAU,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAExE,OAAO,EAAE,iBAAiB,EAAE,CAAC;AAC7B,eAAe,iBAAiB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.AssignmentMatcher = void 0;
|
|
7
|
+
const matcher_class_1 = __importDefault(require("./matcher.class"));
|
|
8
|
+
exports.AssignmentMatcher = matcher_class_1.default;
|
|
9
|
+
exports.default = matcher_class_1.default;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { createClient } from 'redis';
|
|
2
|
+
export type RedisClientType = ReturnType<typeof createClient>;
|
|
3
|
+
export interface User {
|
|
4
|
+
id: string;
|
|
5
|
+
tags: string[];
|
|
6
|
+
routingWeights?: Record<string, number>;
|
|
7
|
+
[key: string]: any;
|
|
8
|
+
}
|
|
9
|
+
export type Assignment = {
|
|
10
|
+
id: string;
|
|
11
|
+
tags: string[];
|
|
12
|
+
priority?: number;
|
|
13
|
+
[key: string]: any;
|
|
14
|
+
};
|
|
15
|
+
export type Stats = {
|
|
16
|
+
users?: number;
|
|
17
|
+
usersWithoutAssignment?: string[];
|
|
18
|
+
remainingAssignments?: number;
|
|
19
|
+
};
|
|
20
|
+
export type options = {
|
|
21
|
+
relevantBatchSize?: number;
|
|
22
|
+
redisPrefix?: string;
|
|
23
|
+
maxUserBacklogSize?: number;
|
|
24
|
+
enableDefaultMatching?: boolean;
|
|
25
|
+
matchExpirationMs?: number;
|
|
26
|
+
prioritizationFunction?: (...args: (Assignment | undefined)[]) => Promise<number>;
|
|
27
|
+
matchingFunction?: (user: User, assignmentTags: string, assignmentPriority: number | string, assignmentId?: string) => Promise<[number, number]>;
|
|
28
|
+
};
|
|
29
|
+
export default class AssignmentMatcher {
|
|
30
|
+
redisClient: RedisClientType;
|
|
31
|
+
relevantBatchSize: number;
|
|
32
|
+
redisPrefix: string;
|
|
33
|
+
assignmentsKey: string;
|
|
34
|
+
assignmentsRefKey: string;
|
|
35
|
+
usersKey: string;
|
|
36
|
+
maxUserBacklogSize: number;
|
|
37
|
+
enableDefaultMatching: boolean;
|
|
38
|
+
matchExpirationMs: number;
|
|
39
|
+
pendingAssignmentsKey: string;
|
|
40
|
+
pendingAssignmentsExpiryKey: string;
|
|
41
|
+
assignmentOwnerKey: string;
|
|
42
|
+
allTagsKey: string;
|
|
43
|
+
constructor(redisClient: RedisClientType, options?: options);
|
|
44
|
+
private initRedis;
|
|
45
|
+
addUser(user: User): Promise<User>;
|
|
46
|
+
addAssignment(assignment: Assignment): Promise<Assignment>;
|
|
47
|
+
removeAssignment(id: string): Promise<string>;
|
|
48
|
+
removeUser(userId: string): Promise<string>;
|
|
49
|
+
getAllAssignments(): Promise<Assignment[]>;
|
|
50
|
+
private matchScore;
|
|
51
|
+
private calculatePriority;
|
|
52
|
+
get stats(): Promise<Stats>;
|
|
53
|
+
get usersWithoutAssignment(): Promise<string[]>;
|
|
54
|
+
setAssignmentPriority(id: string, priority: number): Promise<{
|
|
55
|
+
id: string;
|
|
56
|
+
priority: number;
|
|
57
|
+
}>;
|
|
58
|
+
setAssignmentPriorityByTags(tags: string[], priority: number): Promise<{
|
|
59
|
+
id: string;
|
|
60
|
+
priority: number;
|
|
61
|
+
}[]>;
|
|
62
|
+
private getUserRelatedAssignments;
|
|
63
|
+
matchUsersAssignments(userId?: string): Promise<void>;
|
|
64
|
+
getCurrentAssignmentsForUser(userId: string): Promise<string[]>;
|
|
65
|
+
acceptAssignment(userId: string, assignmentId: string): Promise<boolean>;
|
|
66
|
+
rejectAssignment(userId: string, assignmentId: string): Promise<boolean>;
|
|
67
|
+
processExpiredMatches(): Promise<number>;
|
|
68
|
+
private autoReleaseInterval;
|
|
69
|
+
startAutoReleaseInterval(intervalMs?: number): void;
|
|
70
|
+
stopAutoReleaseInterval(): void;
|
|
71
|
+
private expandTagWildcards;
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=matcher.class.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matcher.class.d.ts","sourceRoot":"","sources":["../src/matcher.class.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AACrC,MAAM,MAAM,eAAe,GAAG,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC;AAE9D,MAAM,WAAW,IAAI;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,EAAE,CAAC;IAGf,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACtB;AAED,MAAM,MAAM,UAAU,GAAG;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,KAAK,GAAG;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,sBAAsB,CAAC,EAAE,MAAM,EAAE,CAAC;IAClC,oBAAoB,CAAC,EAAE,MAAM,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG;IAClB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,sBAAsB,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,UAAU,GAAG,SAAS,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