@rachelallyson/planning-center-people-ts 1.1.0 → 2.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.
Files changed (56) hide show
  1. package/CHANGELOG.md +181 -0
  2. package/README.md +16 -0
  3. package/dist/batch.d.ts +47 -0
  4. package/dist/batch.js +376 -0
  5. package/dist/client-manager.d.ts +66 -0
  6. package/dist/client-manager.js +156 -0
  7. package/dist/client.d.ts +71 -0
  8. package/dist/client.js +123 -0
  9. package/dist/core/http.d.ts +48 -0
  10. package/dist/core/http.js +265 -0
  11. package/dist/core/pagination.d.ts +34 -0
  12. package/dist/core/pagination.js +164 -0
  13. package/dist/index.d.ts +13 -3
  14. package/dist/index.js +23 -5
  15. package/dist/matching/matcher.d.ts +41 -0
  16. package/dist/matching/matcher.js +161 -0
  17. package/dist/matching/scoring.d.ts +35 -0
  18. package/dist/matching/scoring.js +141 -0
  19. package/dist/matching/strategies.d.ts +35 -0
  20. package/dist/matching/strategies.js +79 -0
  21. package/dist/modules/base.d.ts +46 -0
  22. package/dist/modules/base.js +82 -0
  23. package/dist/modules/contacts.d.ts +103 -0
  24. package/dist/modules/contacts.js +130 -0
  25. package/dist/modules/fields.d.ts +157 -0
  26. package/dist/modules/fields.js +294 -0
  27. package/dist/modules/households.d.ts +42 -0
  28. package/dist/modules/households.js +74 -0
  29. package/dist/modules/lists.d.ts +62 -0
  30. package/dist/modules/lists.js +92 -0
  31. package/dist/modules/notes.d.ts +74 -0
  32. package/dist/modules/notes.js +125 -0
  33. package/dist/modules/people.d.ts +196 -0
  34. package/dist/modules/people.js +221 -0
  35. package/dist/modules/workflows.d.ts +131 -0
  36. package/dist/modules/workflows.js +221 -0
  37. package/dist/monitoring.d.ts +53 -0
  38. package/dist/monitoring.js +142 -0
  39. package/dist/testing/index.d.ts +9 -0
  40. package/dist/testing/index.js +24 -0
  41. package/dist/testing/recorder.d.ts +58 -0
  42. package/dist/testing/recorder.js +195 -0
  43. package/dist/testing/simple-builders.d.ts +33 -0
  44. package/dist/testing/simple-builders.js +124 -0
  45. package/dist/testing/simple-factories.d.ts +91 -0
  46. package/dist/testing/simple-factories.js +288 -0
  47. package/dist/testing/types.d.ts +160 -0
  48. package/dist/testing/types.js +5 -0
  49. package/dist/types/batch.d.ts +50 -0
  50. package/dist/types/batch.js +5 -0
  51. package/dist/types/client.d.ts +89 -0
  52. package/dist/types/client.js +5 -0
  53. package/dist/types/events.d.ts +85 -0
  54. package/dist/types/events.js +5 -0
  55. package/dist/types/people.d.ts +20 -1
  56. package/package.json +9 -3
@@ -0,0 +1,66 @@
1
+ /**
2
+ * v2.0.0 Client Manager with Caching
3
+ */
4
+ import type { PcoClientConfig } from './types/client';
5
+ import { PcoClient } from './client';
6
+ export interface ClientConfigResolver {
7
+ (churchId: string): Promise<PcoClientConfig> | PcoClientConfig;
8
+ }
9
+ export declare class PcoClientManager {
10
+ private static instance;
11
+ private clientCache;
12
+ private configCache;
13
+ private constructor();
14
+ /**
15
+ * Get the singleton instance
16
+ */
17
+ static getInstance(): PcoClientManager;
18
+ /**
19
+ * Get a client instance with the given configuration
20
+ */
21
+ static getClient(config: PcoClientConfig): PcoClient;
22
+ /**
23
+ * Get a client instance for a specific church with config resolution
24
+ */
25
+ static getClientForChurch(churchId: string, configResolver: ClientConfigResolver): Promise<PcoClient>;
26
+ /**
27
+ * Clear the client cache
28
+ */
29
+ static clearCache(): void;
30
+ /**
31
+ * Get a client instance with caching
32
+ */
33
+ getClient(config: PcoClientConfig): PcoClient;
34
+ /**
35
+ * Get a client instance for a specific church
36
+ */
37
+ getClientForChurch(churchId: string, configResolver: ClientConfigResolver): Promise<PcoClient>;
38
+ /**
39
+ * Clear the client cache
40
+ */
41
+ clearCache(): void;
42
+ /**
43
+ * Remove a specific client from cache
44
+ */
45
+ removeClient(config: PcoClientConfig): void;
46
+ /**
47
+ * Remove a church client from cache
48
+ */
49
+ removeChurchClient(churchId: string): void;
50
+ /**
51
+ * Get cache statistics
52
+ */
53
+ getCacheStats(): {
54
+ clientCount: number;
55
+ configCount: number;
56
+ churchClients: number;
57
+ };
58
+ /**
59
+ * Generate a cache key for a configuration
60
+ */
61
+ private generateConfigKey;
62
+ /**
63
+ * Check if configuration has changed
64
+ */
65
+ private hasConfigChanged;
66
+ }
@@ -0,0 +1,156 @@
1
+ "use strict";
2
+ /**
3
+ * v2.0.0 Client Manager with Caching
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.PcoClientManager = void 0;
7
+ const client_1 = require("./client");
8
+ class PcoClientManager {
9
+ constructor() {
10
+ this.clientCache = new Map();
11
+ this.configCache = new Map();
12
+ }
13
+ /**
14
+ * Get the singleton instance
15
+ */
16
+ static getInstance() {
17
+ if (!PcoClientManager.instance) {
18
+ PcoClientManager.instance = new PcoClientManager();
19
+ }
20
+ return PcoClientManager.instance;
21
+ }
22
+ /**
23
+ * Get a client instance with the given configuration
24
+ */
25
+ static getClient(config) {
26
+ return PcoClientManager.getInstance().getClient(config);
27
+ }
28
+ /**
29
+ * Get a client instance for a specific church with config resolution
30
+ */
31
+ static async getClientForChurch(churchId, configResolver) {
32
+ return PcoClientManager.getInstance().getClientForChurch(churchId, configResolver);
33
+ }
34
+ /**
35
+ * Clear the client cache
36
+ */
37
+ static clearCache() {
38
+ PcoClientManager.getInstance().clearCache();
39
+ }
40
+ /**
41
+ * Get a client instance with caching
42
+ */
43
+ getClient(config) {
44
+ const configKey = this.generateConfigKey(config);
45
+ // Check if we have a cached client
46
+ let client = this.clientCache.get(configKey);
47
+ if (!client) {
48
+ // Create new client
49
+ client = new client_1.PcoClient(config);
50
+ this.clientCache.set(configKey, client);
51
+ this.configCache.set(configKey, { ...config });
52
+ }
53
+ else {
54
+ // Check if config has changed
55
+ const cachedConfig = this.configCache.get(configKey);
56
+ if (cachedConfig && this.hasConfigChanged(cachedConfig, config)) {
57
+ // Update client with new config
58
+ client.updateConfig(config);
59
+ this.configCache.set(configKey, { ...config });
60
+ }
61
+ }
62
+ return client;
63
+ }
64
+ /**
65
+ * Get a client instance for a specific church
66
+ */
67
+ async getClientForChurch(churchId, configResolver) {
68
+ const configKey = `church:${churchId}`;
69
+ // Check if we have a cached client
70
+ let client = this.clientCache.get(configKey);
71
+ if (!client) {
72
+ // Resolve configuration
73
+ const config = await configResolver(churchId);
74
+ // Create new client
75
+ client = new client_1.PcoClient(config);
76
+ this.clientCache.set(configKey, client);
77
+ this.configCache.set(configKey, { ...config });
78
+ }
79
+ return client;
80
+ }
81
+ /**
82
+ * Clear the client cache
83
+ */
84
+ clearCache() {
85
+ this.clientCache.clear();
86
+ this.configCache.clear();
87
+ }
88
+ /**
89
+ * Remove a specific client from cache
90
+ */
91
+ removeClient(config) {
92
+ const configKey = this.generateConfigKey(config);
93
+ this.clientCache.delete(configKey);
94
+ this.configCache.delete(configKey);
95
+ }
96
+ /**
97
+ * Remove a church client from cache
98
+ */
99
+ removeChurchClient(churchId) {
100
+ const configKey = `church:${churchId}`;
101
+ this.clientCache.delete(configKey);
102
+ this.configCache.delete(configKey);
103
+ }
104
+ /**
105
+ * Get cache statistics
106
+ */
107
+ getCacheStats() {
108
+ const churchClients = Array.from(this.clientCache.keys()).filter(key => key.startsWith('church:')).length;
109
+ return {
110
+ clientCount: this.clientCache.size,
111
+ configCount: this.configCache.size,
112
+ churchClients,
113
+ };
114
+ }
115
+ /**
116
+ * Generate a cache key for a configuration
117
+ */
118
+ generateConfigKey(config) {
119
+ // Create a hash of the configuration
120
+ const configStr = JSON.stringify({
121
+ authType: config.auth.type,
122
+ hasAccessToken: config.auth.type === 'oauth' ? !!config.auth.accessToken : false,
123
+ hasRefreshToken: config.auth.type === 'oauth' ? !!config.auth.refreshToken : false,
124
+ hasPersonalAccessToken: config.auth.type === 'personal_access_token' ? !!config.auth.personalAccessToken : false,
125
+ baseURL: config.baseURL,
126
+ timeout: config.timeout,
127
+ });
128
+ // Simple hash function
129
+ let hash = 0;
130
+ for (let i = 0; i < configStr.length; i++) {
131
+ const char = configStr.charCodeAt(i);
132
+ hash = ((hash << 5) - hash) + char;
133
+ hash = hash & hash; // Convert to 32-bit integer
134
+ }
135
+ return `config:${Math.abs(hash)}`;
136
+ }
137
+ /**
138
+ * Check if configuration has changed
139
+ */
140
+ hasConfigChanged(oldConfig, newConfig) {
141
+ // Compare key configuration properties
142
+ if (oldConfig.auth.type !== newConfig.auth.type) {
143
+ return true;
144
+ }
145
+ if (oldConfig.auth.type === 'oauth' && newConfig.auth.type === 'oauth') {
146
+ return (oldConfig.auth.accessToken !== newConfig.auth.accessToken ||
147
+ oldConfig.auth.refreshToken !== newConfig.auth.refreshToken);
148
+ }
149
+ if (oldConfig.auth.type === 'personal_access_token' && newConfig.auth.type === 'personal_access_token') {
150
+ return oldConfig.auth.personalAccessToken !== newConfig.auth.personalAccessToken;
151
+ }
152
+ return (oldConfig.baseURL !== newConfig.baseURL ||
153
+ oldConfig.timeout !== newConfig.timeout);
154
+ }
155
+ }
156
+ exports.PcoClientManager = PcoClientManager;
@@ -0,0 +1,71 @@
1
+ /**
2
+ * v2.0.0 Main PcoClient Class
3
+ */
4
+ import type { PcoClientConfig } from './types/client';
5
+ import type { EventEmitter } from './types/events';
6
+ import { PeopleModule } from './modules/people';
7
+ import { FieldsModule } from './modules/fields';
8
+ import { WorkflowsModule } from './modules/workflows';
9
+ import { ContactsModule } from './modules/contacts';
10
+ import { HouseholdsModule } from './modules/households';
11
+ import { NotesModule } from './modules/notes';
12
+ import { ListsModule } from './modules/lists';
13
+ import { BatchExecutor } from './batch';
14
+ export declare class PcoClient implements EventEmitter {
15
+ people: PeopleModule;
16
+ fields: FieldsModule;
17
+ workflows: WorkflowsModule;
18
+ contacts: ContactsModule;
19
+ households: HouseholdsModule;
20
+ notes: NotesModule;
21
+ lists: ListsModule;
22
+ batch: BatchExecutor;
23
+ private httpClient;
24
+ private paginationHelper;
25
+ private eventEmitter;
26
+ private config;
27
+ constructor(config: PcoClientConfig);
28
+ on<T extends import('./types/events').PcoEvent>(eventType: T['type'], handler: import('./types/events').EventHandler<T>): void;
29
+ off<T extends import('./types/events').PcoEvent>(eventType: T['type'], handler: import('./types/events').EventHandler<T>): void;
30
+ emit<T extends import('./types/events').PcoEvent>(event: T): void;
31
+ /**
32
+ * Get the current configuration
33
+ */
34
+ getConfig(): PcoClientConfig;
35
+ /**
36
+ * Update the configuration
37
+ */
38
+ updateConfig(updates: Partial<PcoClientConfig>): void;
39
+ /**
40
+ * Get performance metrics
41
+ */
42
+ getPerformanceMetrics(): Record<string, {
43
+ count: number;
44
+ averageTime: number;
45
+ minTime: number;
46
+ maxTime: number;
47
+ errorRate: number;
48
+ }>;
49
+ /**
50
+ * Get rate limit information
51
+ */
52
+ getRateLimitInfo(): Record<string, {
53
+ limit: number;
54
+ remaining: number;
55
+ resetTime: number;
56
+ }>;
57
+ /**
58
+ * Clear all event listeners
59
+ */
60
+ removeAllListeners(eventType?: import('./types/events').EventType): void;
61
+ /**
62
+ * Get the number of listeners for an event type
63
+ */
64
+ listenerCount(eventType: import('./types/events').EventType): number;
65
+ /**
66
+ * Get all registered event types
67
+ */
68
+ eventTypes(): import('./types/events').EventType[];
69
+ private setupEventHandlers;
70
+ private updateModules;
71
+ }
package/dist/client.js ADDED
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ /**
3
+ * v2.0.0 Main PcoClient Class
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.PcoClient = void 0;
7
+ const monitoring_1 = require("./monitoring");
8
+ const http_1 = require("./core/http");
9
+ const pagination_1 = require("./core/pagination");
10
+ const people_1 = require("./modules/people");
11
+ const fields_1 = require("./modules/fields");
12
+ const workflows_1 = require("./modules/workflows");
13
+ const contacts_1 = require("./modules/contacts");
14
+ const households_1 = require("./modules/households");
15
+ const notes_1 = require("./modules/notes");
16
+ const lists_1 = require("./modules/lists");
17
+ const batch_1 = require("./batch");
18
+ class PcoClient {
19
+ constructor(config) {
20
+ this.config = config;
21
+ this.eventEmitter = new monitoring_1.PcoEventEmitter();
22
+ this.httpClient = new http_1.PcoHttpClient(config, this.eventEmitter);
23
+ this.paginationHelper = new pagination_1.PaginationHelper(this.httpClient);
24
+ // Initialize modules
25
+ this.people = new people_1.PeopleModule(this.httpClient, this.paginationHelper, this.eventEmitter);
26
+ this.fields = new fields_1.FieldsModule(this.httpClient, this.paginationHelper, this.eventEmitter);
27
+ this.workflows = new workflows_1.WorkflowsModule(this.httpClient, this.paginationHelper, this.eventEmitter);
28
+ this.contacts = new contacts_1.ContactsModule(this.httpClient, this.paginationHelper, this.eventEmitter);
29
+ this.households = new households_1.HouseholdsModule(this.httpClient, this.paginationHelper, this.eventEmitter);
30
+ this.notes = new notes_1.NotesModule(this.httpClient, this.paginationHelper, this.eventEmitter);
31
+ this.lists = new lists_1.ListsModule(this.httpClient, this.paginationHelper, this.eventEmitter);
32
+ this.batch = new batch_1.BatchExecutor(this, this.eventEmitter);
33
+ // Set up event handlers from config
34
+ this.setupEventHandlers();
35
+ }
36
+ // EventEmitter implementation
37
+ on(eventType, handler) {
38
+ this.eventEmitter.on(eventType, handler);
39
+ }
40
+ off(eventType, handler) {
41
+ this.eventEmitter.off(eventType, handler);
42
+ }
43
+ emit(event) {
44
+ this.eventEmitter.emit(event);
45
+ }
46
+ /**
47
+ * Get the current configuration
48
+ */
49
+ getConfig() {
50
+ return { ...this.config };
51
+ }
52
+ /**
53
+ * Update the configuration
54
+ */
55
+ updateConfig(updates) {
56
+ this.config = { ...this.config, ...updates };
57
+ // Recreate HTTP client with new config
58
+ this.httpClient = new http_1.PcoHttpClient(this.config, this.eventEmitter);
59
+ this.paginationHelper = new pagination_1.PaginationHelper(this.httpClient);
60
+ // Update modules with new HTTP client
61
+ this.updateModules();
62
+ }
63
+ /**
64
+ * Get performance metrics
65
+ */
66
+ getPerformanceMetrics() {
67
+ return this.httpClient.getPerformanceMetrics();
68
+ }
69
+ /**
70
+ * Get rate limit information
71
+ */
72
+ getRateLimitInfo() {
73
+ return this.httpClient.getRateLimitInfo();
74
+ }
75
+ /**
76
+ * Clear all event listeners
77
+ */
78
+ removeAllListeners(eventType) {
79
+ this.eventEmitter.removeAllListeners(eventType);
80
+ }
81
+ /**
82
+ * Get the number of listeners for an event type
83
+ */
84
+ listenerCount(eventType) {
85
+ return this.eventEmitter.listenerCount(eventType);
86
+ }
87
+ /**
88
+ * Get all registered event types
89
+ */
90
+ eventTypes() {
91
+ return this.eventEmitter.eventTypes();
92
+ }
93
+ setupEventHandlers() {
94
+ // Set up config event handlers
95
+ if (this.config.events?.onError) {
96
+ this.on('error', this.config.events.onError);
97
+ }
98
+ if (this.config.events?.onAuthFailure) {
99
+ this.on('auth:failure', this.config.events.onAuthFailure);
100
+ }
101
+ if (this.config.events?.onRequestStart) {
102
+ this.on('request:start', this.config.events.onRequestStart);
103
+ }
104
+ if (this.config.events?.onRequestComplete) {
105
+ this.on('request:complete', this.config.events.onRequestComplete);
106
+ }
107
+ if (this.config.events?.onRateLimit) {
108
+ this.on('rate:limit', this.config.events.onRateLimit);
109
+ }
110
+ }
111
+ updateModules() {
112
+ // Recreate modules with new HTTP client
113
+ this.people = new people_1.PeopleModule(this.httpClient, this.paginationHelper, this.eventEmitter);
114
+ this.fields = new fields_1.FieldsModule(this.httpClient, this.paginationHelper, this.eventEmitter);
115
+ this.workflows = new workflows_1.WorkflowsModule(this.httpClient, this.paginationHelper, this.eventEmitter);
116
+ this.contacts = new contacts_1.ContactsModule(this.httpClient, this.paginationHelper, this.eventEmitter);
117
+ this.households = new households_1.HouseholdsModule(this.httpClient, this.paginationHelper, this.eventEmitter);
118
+ this.notes = new notes_1.NotesModule(this.httpClient, this.paginationHelper, this.eventEmitter);
119
+ this.lists = new lists_1.ListsModule(this.httpClient, this.paginationHelper, this.eventEmitter);
120
+ this.batch = new batch_1.BatchExecutor(this, this.eventEmitter);
121
+ }
122
+ }
123
+ exports.PcoClient = PcoClient;
@@ -0,0 +1,48 @@
1
+ /**
2
+ * v2.0.0 HTTP Client
3
+ */
4
+ import type { PcoClientConfig } from '../types/client';
5
+ import { PcoEventEmitter } from '../monitoring';
6
+ export interface HttpRequestOptions {
7
+ method: string;
8
+ endpoint: string;
9
+ data?: any;
10
+ params?: Record<string, any>;
11
+ headers?: Record<string, string>;
12
+ timeout?: number;
13
+ }
14
+ export interface HttpResponse<T = any> {
15
+ data: T;
16
+ status: number;
17
+ headers: Record<string, string>;
18
+ requestId: string;
19
+ duration: number;
20
+ }
21
+ export declare class PcoHttpClient {
22
+ private config;
23
+ private eventEmitter;
24
+ private requestIdGenerator;
25
+ private performanceMetrics;
26
+ private rateLimitTracker;
27
+ private rateLimiter;
28
+ constructor(config: PcoClientConfig, eventEmitter: PcoEventEmitter);
29
+ request<T = any>(options: HttpRequestOptions): Promise<HttpResponse<T>>;
30
+ private makeRequest;
31
+ private addAuthentication;
32
+ private getResourceTypeFromEndpoint;
33
+ private extractHeaders;
34
+ private attemptTokenRefresh;
35
+ private updateRateLimitTracking;
36
+ getPerformanceMetrics(): Record<string, {
37
+ count: number;
38
+ averageTime: number;
39
+ minTime: number;
40
+ maxTime: number;
41
+ errorRate: number;
42
+ }>;
43
+ getRateLimitInfo(): Record<string, {
44
+ limit: number;
45
+ remaining: number;
46
+ resetTime: number;
47
+ }>;
48
+ }