@rachelallyson/planning-center-people-ts 2.3.1 โ 2.4.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/CHANGELOG.md +66 -0
- package/dist/helpers.d.ts +25 -0
- package/dist/helpers.js +69 -0
- package/dist/matching/matcher.d.ts +4 -0
- package/dist/matching/matcher.js +25 -1
- package/dist/matching/scoring.d.ts +5 -1
- package/dist/matching/scoring.js +83 -15
- package/dist/modules/people.d.ts +4 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,72 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [2.4.0] - 2025-01-10
|
|
9
|
+
|
|
10
|
+
### ๐ฏ **NEW FEATURES - Age Preference Matching & Exact Name Matching**
|
|
11
|
+
|
|
12
|
+
This release introduces intelligent age-based person matching and precise name matching capabilities to enhance person discovery and reduce false positives.
|
|
13
|
+
|
|
14
|
+
### Added
|
|
15
|
+
|
|
16
|
+
#### **๐ฅ Age Preference Matching**
|
|
17
|
+
|
|
18
|
+
- **๐ Age-Based Filtering**: New `agePreference` option to prefer adults or children
|
|
19
|
+
- **๐
Age Range Matching**: Support for `minAge` and `maxAge` parameters for precise age targeting
|
|
20
|
+
- **๐๏ธ Birth Year Matching**: `birthYear` parameter for matching people born in specific years
|
|
21
|
+
- **๐งฎ Smart Age Calculation**: Enhanced age calculation with timezone-safe date handling
|
|
22
|
+
- **๐ Age-Based Scoring**: Age matching contributes 15% to overall match score for better accuracy
|
|
23
|
+
|
|
24
|
+
#### **๐ฏ Exact Name Matching**
|
|
25
|
+
|
|
26
|
+
- **โ
Precise Name Matching**: Only matches exact names, eliminating false positives from similar names
|
|
27
|
+
- **๐ค Case-Insensitive**: Maintains case-insensitive matching while ensuring exact character matching
|
|
28
|
+
- **โก Performance Optimized**: Simple string comparison for faster matching than fuzzy algorithms
|
|
29
|
+
- **๐ก๏ธ Reduced False Positives**: Prevents matching "Jon" when searching for "John"
|
|
30
|
+
|
|
31
|
+
#### **๐ง Enhanced Matching System**
|
|
32
|
+
|
|
33
|
+
- **๐ Improved Scoring Algorithm**: Updated scoring weights for better match prioritization
|
|
34
|
+
- **๐ฏ Candidate Filtering**: Age-based pre-filtering before scoring for more relevant results
|
|
35
|
+
- **๐ Enhanced Match Reasons**: More descriptive match explanations including age-based reasons
|
|
36
|
+
- **๐งช Comprehensive Testing**: 30+ new test cases covering age preferences and exact name matching
|
|
37
|
+
|
|
38
|
+
### Usage Examples
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
// Age preference matching
|
|
42
|
+
const adultPerson = await client.people.findOrCreate({
|
|
43
|
+
firstName: 'Jane',
|
|
44
|
+
lastName: 'Smith',
|
|
45
|
+
agePreference: 'adults', // Prefer 18+ years old
|
|
46
|
+
matchStrategy: 'fuzzy'
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// Age range matching
|
|
50
|
+
const youngAdult = await client.people.findOrCreate({
|
|
51
|
+
firstName: 'Alice',
|
|
52
|
+
lastName: 'Brown',
|
|
53
|
+
minAge: 20,
|
|
54
|
+
maxAge: 30,
|
|
55
|
+
matchStrategy: 'fuzzy'
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// Birth year matching
|
|
59
|
+
const millennial = await client.people.findOrCreate({
|
|
60
|
+
firstName: 'David',
|
|
61
|
+
lastName: 'Wilson',
|
|
62
|
+
birthYear: 1990,
|
|
63
|
+
matchStrategy: 'fuzzy'
|
|
64
|
+
});
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Technical Details
|
|
68
|
+
|
|
69
|
+
- **New Helper Functions**: `calculateAgeSafe()`, `isAdult()`, `isChild()`, `matchesAgeCriteria()`
|
|
70
|
+
- **Enhanced PersonMatchOptions**: Added `agePreference`, `minAge`, `maxAge`, `birthYear` properties
|
|
71
|
+
- **Updated Scoring System**: Age matching now contributes 15% to overall match score
|
|
72
|
+
- **Backward Compatibility**: All existing functionality remains unchanged
|
|
73
|
+
|
|
8
74
|
## [2.3.1] - 2025-01-10
|
|
9
75
|
|
|
10
76
|
### ๐ **BUG FIXES & STABILITY IMPROVEMENTS**
|
package/dist/helpers.d.ts
CHANGED
|
@@ -15,6 +15,31 @@ export declare function buildQueryParams(params?: {
|
|
|
15
15
|
* Calculate age from birthdate string
|
|
16
16
|
*/
|
|
17
17
|
export declare function calculateAge(birthdate: string): number;
|
|
18
|
+
/**
|
|
19
|
+
* Calculate age from birthdate string, handling invalid dates
|
|
20
|
+
*/
|
|
21
|
+
export declare function calculateAgeSafe(birthdate: string | undefined): number | null;
|
|
22
|
+
/**
|
|
23
|
+
* Check if a person is an adult (18+ years old)
|
|
24
|
+
*/
|
|
25
|
+
export declare function isAdult(birthdate: string | undefined): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Check if a person is a child (under 18 years old)
|
|
28
|
+
*/
|
|
29
|
+
export declare function isChild(birthdate: string | undefined): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Check if a person's age matches the given criteria
|
|
32
|
+
*/
|
|
33
|
+
export declare function matchesAgeCriteria(birthdate: string | undefined, criteria: {
|
|
34
|
+
agePreference?: 'adults' | 'children' | 'any';
|
|
35
|
+
minAge?: number;
|
|
36
|
+
maxAge?: number;
|
|
37
|
+
birthYear?: number;
|
|
38
|
+
}): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Calculate birth year from age
|
|
41
|
+
*/
|
|
42
|
+
export declare function calculateBirthYearFromAge(age: number): number;
|
|
18
43
|
/**
|
|
19
44
|
* Validate email format
|
|
20
45
|
*/
|
package/dist/helpers.js
CHANGED
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.buildQueryParams = buildQueryParams;
|
|
4
4
|
exports.calculateAge = calculateAge;
|
|
5
|
+
exports.calculateAgeSafe = calculateAgeSafe;
|
|
6
|
+
exports.isAdult = isAdult;
|
|
7
|
+
exports.isChild = isChild;
|
|
8
|
+
exports.matchesAgeCriteria = matchesAgeCriteria;
|
|
9
|
+
exports.calculateBirthYearFromAge = calculateBirthYearFromAge;
|
|
5
10
|
exports.isValidEmail = isValidEmail;
|
|
6
11
|
exports.isValidPhone = isValidPhone;
|
|
7
12
|
exports.formatPersonName = formatPersonName;
|
|
@@ -61,6 +66,70 @@ function calculateAge(birthdate) {
|
|
|
61
66
|
}
|
|
62
67
|
return age;
|
|
63
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Calculate age from birthdate string, handling invalid dates
|
|
71
|
+
*/
|
|
72
|
+
function calculateAgeSafe(birthdate) {
|
|
73
|
+
if (!birthdate)
|
|
74
|
+
return null;
|
|
75
|
+
try {
|
|
76
|
+
const birth = new Date(birthdate);
|
|
77
|
+
if (isNaN(birth.getTime()))
|
|
78
|
+
return null;
|
|
79
|
+
return calculateAge(birthdate);
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Check if a person is an adult (18+ years old)
|
|
87
|
+
*/
|
|
88
|
+
function isAdult(birthdate) {
|
|
89
|
+
const age = calculateAgeSafe(birthdate);
|
|
90
|
+
return age !== null && age >= 18;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Check if a person is a child (under 18 years old)
|
|
94
|
+
*/
|
|
95
|
+
function isChild(birthdate) {
|
|
96
|
+
const age = calculateAgeSafe(birthdate);
|
|
97
|
+
return age !== null && age < 18;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Check if a person's age matches the given criteria
|
|
101
|
+
*/
|
|
102
|
+
function matchesAgeCriteria(birthdate, criteria) {
|
|
103
|
+
const age = calculateAgeSafe(birthdate);
|
|
104
|
+
// If no birthdate, only match if preference is 'any'
|
|
105
|
+
if (age === null) {
|
|
106
|
+
return criteria.agePreference === 'any' || criteria.agePreference === undefined;
|
|
107
|
+
}
|
|
108
|
+
// Check age preference
|
|
109
|
+
if (criteria.agePreference === 'adults' && age < 18)
|
|
110
|
+
return false;
|
|
111
|
+
if (criteria.agePreference === 'children' && age >= 18)
|
|
112
|
+
return false;
|
|
113
|
+
// Check age range
|
|
114
|
+
if (criteria.minAge !== undefined && age < criteria.minAge)
|
|
115
|
+
return false;
|
|
116
|
+
if (criteria.maxAge !== undefined && age > criteria.maxAge)
|
|
117
|
+
return false;
|
|
118
|
+
// Check birth year
|
|
119
|
+
if (criteria.birthYear !== undefined) {
|
|
120
|
+
const birthYear = new Date(birthdate).getFullYear();
|
|
121
|
+
if (birthYear !== criteria.birthYear)
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Calculate birth year from age
|
|
128
|
+
*/
|
|
129
|
+
function calculateBirthYearFromAge(age) {
|
|
130
|
+
const currentYear = new Date().getFullYear();
|
|
131
|
+
return currentYear - age;
|
|
132
|
+
}
|
|
64
133
|
/**
|
|
65
134
|
* Validate email format
|
|
66
135
|
*/
|
package/dist/matching/matcher.js
CHANGED
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.PersonMatcher = void 0;
|
|
7
7
|
const strategies_1 = require("./strategies");
|
|
8
8
|
const scoring_1 = require("./scoring");
|
|
9
|
+
const helpers_1 = require("../helpers");
|
|
9
10
|
class PersonMatcher {
|
|
10
11
|
constructor(peopleModule) {
|
|
11
12
|
this.peopleModule = peopleModule;
|
|
@@ -102,7 +103,30 @@ class PersonMatcher {
|
|
|
102
103
|
}
|
|
103
104
|
// Remove duplicates based on person ID
|
|
104
105
|
const uniqueCandidates = candidates.filter((person, index, self) => index === self.findIndex(p => p.id === person.id));
|
|
105
|
-
|
|
106
|
+
// Filter by age preferences if specified
|
|
107
|
+
const ageFilteredCandidates = this.filterByAgePreferences(uniqueCandidates, options);
|
|
108
|
+
return ageFilteredCandidates;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Filter candidates by age preferences
|
|
112
|
+
*/
|
|
113
|
+
filterByAgePreferences(candidates, options) {
|
|
114
|
+
// If no age criteria specified, return all candidates
|
|
115
|
+
if (!options.agePreference &&
|
|
116
|
+
options.minAge === undefined &&
|
|
117
|
+
options.maxAge === undefined &&
|
|
118
|
+
options.birthYear === undefined) {
|
|
119
|
+
return candidates;
|
|
120
|
+
}
|
|
121
|
+
return candidates.filter(person => {
|
|
122
|
+
const birthdate = person.attributes?.birthdate;
|
|
123
|
+
return (0, helpers_1.matchesAgeCriteria)(birthdate, {
|
|
124
|
+
agePreference: options.agePreference,
|
|
125
|
+
minAge: options.minAge,
|
|
126
|
+
maxAge: options.maxAge,
|
|
127
|
+
birthYear: options.birthYear
|
|
128
|
+
});
|
|
129
|
+
});
|
|
106
130
|
}
|
|
107
131
|
/**
|
|
108
132
|
* Create a new person
|
|
@@ -21,9 +21,13 @@ export declare class MatchScorer {
|
|
|
21
21
|
*/
|
|
22
22
|
private scorePhoneMatch;
|
|
23
23
|
/**
|
|
24
|
-
* Score name matching
|
|
24
|
+
* Score name matching - only exact matches
|
|
25
25
|
*/
|
|
26
26
|
private scoreNameMatch;
|
|
27
|
+
/**
|
|
28
|
+
* Score age matching
|
|
29
|
+
*/
|
|
30
|
+
private scoreAgeMatch;
|
|
27
31
|
/**
|
|
28
32
|
* Score additional criteria
|
|
29
33
|
*/
|
package/dist/matching/scoring.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.MatchScorer = void 0;
|
|
7
|
+
const helpers_1 = require("../helpers");
|
|
7
8
|
class MatchScorer {
|
|
8
9
|
/**
|
|
9
10
|
* Score a person match based on various criteria
|
|
@@ -14,14 +15,14 @@ class MatchScorer {
|
|
|
14
15
|
// Email matching (highest weight)
|
|
15
16
|
if (options.email) {
|
|
16
17
|
const emailScore = this.scoreEmailMatch(person, options.email);
|
|
17
|
-
totalScore += emailScore * 0.
|
|
18
|
-
maxScore += 0.
|
|
18
|
+
totalScore += emailScore * 0.35;
|
|
19
|
+
maxScore += 0.35;
|
|
19
20
|
}
|
|
20
21
|
// Phone matching (high weight)
|
|
21
22
|
if (options.phone) {
|
|
22
23
|
const phoneScore = this.scorePhoneMatch(person, options.phone);
|
|
23
|
-
totalScore += phoneScore * 0.
|
|
24
|
-
maxScore += 0.
|
|
24
|
+
totalScore += phoneScore * 0.25;
|
|
25
|
+
maxScore += 0.25;
|
|
25
26
|
}
|
|
26
27
|
// Name matching (medium weight)
|
|
27
28
|
if (options.firstName || options.lastName) {
|
|
@@ -29,10 +30,14 @@ class MatchScorer {
|
|
|
29
30
|
totalScore += nameScore * 0.2;
|
|
30
31
|
maxScore += 0.2;
|
|
31
32
|
}
|
|
33
|
+
// Age matching (medium weight)
|
|
34
|
+
const ageScore = this.scoreAgeMatch(person, options);
|
|
35
|
+
totalScore += ageScore * 0.15;
|
|
36
|
+
maxScore += 0.15;
|
|
32
37
|
// Additional criteria (lower weight)
|
|
33
38
|
const additionalScore = this.scoreAdditionalCriteria(person, options);
|
|
34
|
-
totalScore += additionalScore * 0.
|
|
35
|
-
maxScore += 0.
|
|
39
|
+
totalScore += additionalScore * 0.05;
|
|
40
|
+
maxScore += 0.05;
|
|
36
41
|
return maxScore > 0 ? totalScore / maxScore : 0;
|
|
37
42
|
}
|
|
38
43
|
/**
|
|
@@ -51,8 +56,24 @@ class MatchScorer {
|
|
|
51
56
|
if (nameScore > 0.8) {
|
|
52
57
|
reasons.push('exact name match');
|
|
53
58
|
}
|
|
54
|
-
else if (nameScore > 0
|
|
55
|
-
reasons.push('
|
|
59
|
+
else if (nameScore > 0) {
|
|
60
|
+
reasons.push('partial name match');
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
// Add age-based match reasons
|
|
64
|
+
const ageScore = this.scoreAgeMatch(person, options);
|
|
65
|
+
if (ageScore > 0.8) {
|
|
66
|
+
const age = (0, helpers_1.calculateAgeSafe)(person.attributes?.birthdate);
|
|
67
|
+
if (age !== null) {
|
|
68
|
+
if (options.agePreference === 'adults') {
|
|
69
|
+
reasons.push('adult age match');
|
|
70
|
+
}
|
|
71
|
+
else if (options.agePreference === 'children') {
|
|
72
|
+
reasons.push('child age match');
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
reasons.push(`age ${age} match`);
|
|
76
|
+
}
|
|
56
77
|
}
|
|
57
78
|
}
|
|
58
79
|
if (reasons.length === 0) {
|
|
@@ -79,25 +100,72 @@ class MatchScorer {
|
|
|
79
100
|
return 0;
|
|
80
101
|
}
|
|
81
102
|
/**
|
|
82
|
-
* Score name matching
|
|
103
|
+
* Score name matching - only exact matches
|
|
83
104
|
*/
|
|
84
105
|
scoreNameMatch(person, options) {
|
|
85
106
|
const attrs = person.attributes;
|
|
86
107
|
if (!attrs)
|
|
87
108
|
return 0;
|
|
88
109
|
let score = 0;
|
|
89
|
-
// First name matching
|
|
110
|
+
// First name matching - exact match only
|
|
90
111
|
if (options.firstName && attrs.first_name) {
|
|
91
|
-
const
|
|
92
|
-
score +=
|
|
112
|
+
const firstNameMatch = options.firstName.toLowerCase() === attrs.first_name.toLowerCase();
|
|
113
|
+
score += firstNameMatch ? 0.5 : 0;
|
|
93
114
|
}
|
|
94
|
-
// Last name matching
|
|
115
|
+
// Last name matching - exact match only
|
|
95
116
|
if (options.lastName && attrs.last_name) {
|
|
96
|
-
const
|
|
97
|
-
score +=
|
|
117
|
+
const lastNameMatch = options.lastName.toLowerCase() === attrs.last_name.toLowerCase();
|
|
118
|
+
score += lastNameMatch ? 0.5 : 0;
|
|
98
119
|
}
|
|
99
120
|
return score;
|
|
100
121
|
}
|
|
122
|
+
/**
|
|
123
|
+
* Score age matching
|
|
124
|
+
*/
|
|
125
|
+
scoreAgeMatch(person, options) {
|
|
126
|
+
const birthdate = person.attributes?.birthdate;
|
|
127
|
+
// If no age criteria specified, return neutral score
|
|
128
|
+
if (!options.agePreference &&
|
|
129
|
+
options.minAge === undefined &&
|
|
130
|
+
options.maxAge === undefined &&
|
|
131
|
+
options.birthYear === undefined) {
|
|
132
|
+
return 0.5; // Neutral score
|
|
133
|
+
}
|
|
134
|
+
// If no birthdate available, return low score
|
|
135
|
+
if (!birthdate) {
|
|
136
|
+
return 0.1;
|
|
137
|
+
}
|
|
138
|
+
// Check if person matches age criteria
|
|
139
|
+
const matches = (0, helpers_1.matchesAgeCriteria)(birthdate, {
|
|
140
|
+
agePreference: options.agePreference,
|
|
141
|
+
minAge: options.minAge,
|
|
142
|
+
maxAge: options.maxAge,
|
|
143
|
+
birthYear: options.birthYear
|
|
144
|
+
});
|
|
145
|
+
if (!matches) {
|
|
146
|
+
return 0; // No match
|
|
147
|
+
}
|
|
148
|
+
// Calculate bonus score based on how well the age matches
|
|
149
|
+
const age = (0, helpers_1.calculateAgeSafe)(birthdate);
|
|
150
|
+
if (age === null)
|
|
151
|
+
return 0.5;
|
|
152
|
+
let bonusScore = 0;
|
|
153
|
+
// Bonus for exact age range match
|
|
154
|
+
if (options.minAge !== undefined && options.maxAge !== undefined) {
|
|
155
|
+
if (age >= options.minAge && age <= options.maxAge) {
|
|
156
|
+
bonusScore += 0.3;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
// Bonus for exact birth year match
|
|
160
|
+
if (options.birthYear !== undefined) {
|
|
161
|
+
const birthYear = new Date(birthdate).getFullYear();
|
|
162
|
+
if (birthYear === options.birthYear) {
|
|
163
|
+
bonusScore += 0.4;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
// Base score for matching criteria
|
|
167
|
+
return Math.min(0.6 + bonusScore, 1.0);
|
|
168
|
+
}
|
|
101
169
|
/**
|
|
102
170
|
* Score additional criteria
|
|
103
171
|
*/
|
package/dist/modules/people.d.ts
CHANGED
|
@@ -50,6 +50,10 @@ export interface PersonMatchOptions {
|
|
|
50
50
|
matchStrategy?: 'exact' | 'fuzzy' | 'aggressive';
|
|
51
51
|
campus?: string;
|
|
52
52
|
createIfNotFound?: boolean;
|
|
53
|
+
agePreference?: 'adults' | 'children' | 'any';
|
|
54
|
+
minAge?: number;
|
|
55
|
+
maxAge?: number;
|
|
56
|
+
birthYear?: number;
|
|
53
57
|
}
|
|
54
58
|
export declare class PeopleModule extends BaseModule {
|
|
55
59
|
private personMatcher;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rachelallyson/planning-center-people-ts",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
4
4
|
"description": "A strictly typed TypeScript client for Planning Center Online People API with smart matching, batch operations, and enhanced developer experience",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|