@rachelallyson/planning-center-people-ts 2.10.0 โ†’ 2.11.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 CHANGED
@@ -5,6 +5,39 @@ 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.11.0] - 2025-01-15
9
+
10
+ ### โœจ **New Features**
11
+
12
+ - **๐Ÿ”„ Automatic Retry Logic for Contact Verification**: Added built-in retry logic to prevent duplicate person creation
13
+ - Automatically retries when searching for existing persons with email/phone
14
+ - Handles PCO contact verification delays (30-90+ seconds)
15
+ - Uses exponential backoff (10s โ†’ 15s โ†’ 22.5s โ†’ 33.75s โ†’ 50.6s)
16
+ - Configurable retry behavior via `retryConfig` option
17
+ - Default: 5 retries, 120 seconds max wait time
18
+ - Logs retry attempts with `[PERSON_MATCH]` prefix for debugging
19
+ - Prevents duplicate person creation when PCO takes time to verify/index contacts
20
+
21
+ ### ๐Ÿ”ง **Improvements**
22
+
23
+ - **Duplicate Prevention**: `findOrCreate` now automatically handles PCO contact verification delays
24
+ - Retry logic activates automatically when `createIfNotFound: false` and email/phone are provided
25
+ - No manual retry code needed - library handles it automatically
26
+ - Prevents race conditions where duplicate persons are created
27
+
28
+ ### ๐Ÿ“š **Documentation**
29
+
30
+ - Added `RETRY_LOGIC_FIX.md` - Detailed explanation of the retry logic fix
31
+ - Added `USING_RETRY_LOGIC.md` - Guide for using retry logic in your app
32
+ - Added `MIGRATION_GUIDE_FOR_YOUR_APP.md` - Migration guide to simplify existing code
33
+ - Added `TEST_FAILURE_ANALYSIS.md` - Troubleshooting guide for test failures
34
+
35
+ ### ๐Ÿงช **Testing**
36
+
37
+ - Added comprehensive integration tests for retry logic
38
+ - Tests verify retry logic prevents duplicate person creation
39
+ - Tests demonstrate bug scenario and fix
40
+
8
41
  ## [2.10.0] - 2025-01-15
9
42
 
10
43
  ### โœจ **New Features**
@@ -22,11 +22,20 @@ export declare class PersonMatcher {
22
22
  * - Verifies email/phone matches by checking actual contact information
23
23
  * - Only uses name matching when appropriate (multiple people share contact info, or no contact info provided)
24
24
  * - Can automatically add missing contact information when a match is found (if addMissingContactInfo is true)
25
+ * - Retries with exponential backoff when contacts may not be verified yet (PCO takes 30-90+ seconds)
25
26
  *
26
27
  * @param options - Matching options
27
28
  * @param options.addMissingContactInfo - If true, automatically adds missing email/phone to matched person's profile
29
+ * @param options.retryConfig - Configuration for retry logic to handle PCO contact verification delays
28
30
  */
29
31
  findOrCreate(options: PersonMatchOptions): Promise<PersonResource>;
32
+ /**
33
+ * Find or create with retry logic to handle PCO contact verification delays
34
+ *
35
+ * PCO takes 30-90+ seconds to verify/index contacts after a person is created.
36
+ * This method retries with exponential backoff to give PCO time to process contacts.
37
+ */
38
+ private findOrCreateWithRetry;
30
39
  /**
31
40
  * Find the best match for a person
32
41
  */
@@ -20,12 +20,26 @@ class PersonMatcher {
20
20
  * - Verifies email/phone matches by checking actual contact information
21
21
  * - Only uses name matching when appropriate (multiple people share contact info, or no contact info provided)
22
22
  * - Can automatically add missing contact information when a match is found (if addMissingContactInfo is true)
23
+ * - Retries with exponential backoff when contacts may not be verified yet (PCO takes 30-90+ seconds)
23
24
  *
24
25
  * @param options - Matching options
25
26
  * @param options.addMissingContactInfo - If true, automatically adds missing email/phone to matched person's profile
27
+ * @param options.retryConfig - Configuration for retry logic to handle PCO contact verification delays
26
28
  */
27
29
  async findOrCreate(options) {
28
- const { createIfNotFound = true, matchStrategy = 'fuzzy', addMissingContactInfo = false, ...searchOptions } = options;
30
+ const { createIfNotFound = true, matchStrategy = 'fuzzy', addMissingContactInfo = false, retryConfig, ...searchOptions } = options;
31
+ // Determine if retry logic should be enabled
32
+ // Retry is useful when:
33
+ // 1. We have email/phone (these need verification)
34
+ // 2. createIfNotFound is false (we're trying to find existing, not create new)
35
+ // 3. retryConfig.enabled is not explicitly false
36
+ const hasContactInfo = !!(options.email || options.phone);
37
+ const shouldRetry = hasContactInfo &&
38
+ !createIfNotFound &&
39
+ (retryConfig?.enabled !== false);
40
+ if (shouldRetry) {
41
+ return this.findOrCreateWithRetry(options);
42
+ }
29
43
  // Try to find existing person
30
44
  const match = await this.findMatch({ ...searchOptions, matchStrategy });
31
45
  if (match) {
@@ -42,6 +56,79 @@ class PersonMatcher {
42
56
  }
43
57
  throw new Error(`No matching person found and creation is disabled`);
44
58
  }
59
+ /**
60
+ * Find or create with retry logic to handle PCO contact verification delays
61
+ *
62
+ * PCO takes 30-90+ seconds to verify/index contacts after a person is created.
63
+ * This method retries with exponential backoff to give PCO time to process contacts.
64
+ */
65
+ async findOrCreateWithRetry(options) {
66
+ const { createIfNotFound = false, matchStrategy = 'fuzzy', addMissingContactInfo = false, retryConfig, ...searchOptions } = options;
67
+ // Default retry configuration
68
+ const maxRetries = retryConfig?.maxRetries ?? 5;
69
+ const maxWaitTime = retryConfig?.maxWaitTime ?? 120000; // 120 seconds
70
+ const initialDelay = retryConfig?.initialDelay ?? 10000; // 10 seconds
71
+ const backoffMultiplier = retryConfig?.backoffMultiplier ?? 1.5;
72
+ let totalWaitTime = 0;
73
+ let lastError = null;
74
+ for (let attempt = 1; attempt <= maxRetries; attempt++) {
75
+ try {
76
+ // Try to find existing person
77
+ const match = await this.findMatch({ ...searchOptions, matchStrategy });
78
+ if (match) {
79
+ const person = match.person;
80
+ // Add missing contact information if requested
81
+ if (addMissingContactInfo) {
82
+ await this.addMissingContactInfo(person, options);
83
+ }
84
+ // Log success if we had to retry
85
+ if (attempt > 1) {
86
+ console.log(`[PERSON_MATCH] Found person after ${attempt} attempts (waited ${totalWaitTime}ms)`, {
87
+ personId: person.id,
88
+ attempt,
89
+ totalWaitTime
90
+ });
91
+ }
92
+ return person;
93
+ }
94
+ // No match found - this might be because contacts aren't verified yet
95
+ lastError = new Error(`No matching person found and creation is disabled`);
96
+ }
97
+ catch (error) {
98
+ lastError = error instanceof Error ? error : new Error(String(error));
99
+ }
100
+ // Don't retry on the last attempt
101
+ if (attempt === maxRetries) {
102
+ break;
103
+ }
104
+ // Calculate delay with exponential backoff
105
+ const delay = Math.min(initialDelay * Math.pow(backoffMultiplier, attempt - 1), maxWaitTime - totalWaitTime // Don't exceed maxWaitTime
106
+ );
107
+ // Check if we've exceeded max wait time
108
+ if (totalWaitTime + delay > maxWaitTime) {
109
+ console.warn(`[PERSON_MATCH] Max wait time (${maxWaitTime}ms) exceeded, stopping retries`, {
110
+ attempt,
111
+ totalWaitTime,
112
+ remainingDelay: maxWaitTime - totalWaitTime
113
+ });
114
+ break;
115
+ }
116
+ totalWaitTime += delay;
117
+ // Log retry attempt
118
+ console.log(`[PERSON_MATCH] Attempt ${attempt} failed, retrying in ${delay}ms`, {
119
+ attempt,
120
+ delay,
121
+ totalWaitTime,
122
+ errorMessage: lastError?.message,
123
+ maxRetries,
124
+ maxWaitTime
125
+ });
126
+ // Wait before retrying
127
+ await new Promise(resolve => setTimeout(resolve, delay));
128
+ }
129
+ // All retries exhausted - throw error
130
+ throw lastError || new Error(`No matching person found after ${maxRetries} attempts (waited ${totalWaitTime}ms) and creation is disabled`);
131
+ }
45
132
  /**
46
133
  * Find the best match for a person
47
134
  */
@@ -76,6 +76,23 @@ export interface PersonMatchOptions {
76
76
  maxAge?: number;
77
77
  /** Birth year filter (exact match) */
78
78
  birthYear?: number;
79
+ /**
80
+ * Retry configuration for handling PCO contact verification delays.
81
+ * When a person is created, PCO needs time (30-90+ seconds) to verify/index contacts
82
+ * before they become searchable. This retry logic helps prevent duplicate person creation.
83
+ */
84
+ retryConfig?: {
85
+ /** Maximum number of retry attempts (default: 5) */
86
+ maxRetries?: number;
87
+ /** Maximum total wait time in milliseconds (default: 120000 = 120 seconds) */
88
+ maxWaitTime?: number;
89
+ /** Initial delay in milliseconds before first retry (default: 10000 = 10 seconds) */
90
+ initialDelay?: number;
91
+ /** Multiplier for exponential backoff (default: 1.5) */
92
+ backoffMultiplier?: number;
93
+ /** Whether to enable retry logic (default: true when email/phone provided and createIfNotFound: false) */
94
+ enabled?: boolean;
95
+ };
79
96
  }
80
97
  export declare class PeopleModule extends BaseModule {
81
98
  private personMatcher;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rachelallyson/planning-center-people-ts",
3
- "version": "2.10.0",
3
+ "version": "2.11.0",
4
4
  "description": "A strictly typed TypeScript client for Planning Center Online People API with comprehensive functionality and enhanced developer experience",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",