@rachelallyson/planning-center-people-ts 2.14.1 → 3.0.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 (77) hide show
  1. package/CHANGELOG.md +76 -7
  2. package/README.md +42 -4
  3. package/dist/auth.d.ts +1 -1
  4. package/dist/auth.js +14 -6
  5. package/dist/client.d.ts +33 -8
  6. package/dist/client.js +47 -22
  7. package/dist/core.d.ts +4 -2
  8. package/dist/core.js +3 -2
  9. package/dist/error-handling.d.ts +4 -4
  10. package/dist/error-handling.js +13 -2
  11. package/dist/error-scenarios.d.ts +11 -7
  12. package/dist/error-scenarios.js +26 -10
  13. package/dist/helpers.d.ts +124 -48
  14. package/dist/helpers.js +236 -93
  15. package/dist/index.d.ts +9 -7
  16. package/dist/index.js +31 -72
  17. package/dist/matching/matcher.d.ts +8 -4
  18. package/dist/matching/matcher.js +51 -58
  19. package/dist/matching/scoring.d.ts +9 -6
  20. package/dist/matching/scoring.js +18 -14
  21. package/dist/modules/campus.d.ts +31 -36
  22. package/dist/modules/campus.js +36 -49
  23. package/dist/modules/contacts.d.ts +33 -29
  24. package/dist/modules/contacts.js +36 -12
  25. package/dist/modules/fields.d.ts +39 -55
  26. package/dist/modules/fields.js +65 -105
  27. package/dist/modules/forms.d.ts +35 -24
  28. package/dist/modules/forms.js +41 -23
  29. package/dist/modules/households.d.ts +17 -19
  30. package/dist/modules/households.js +25 -34
  31. package/dist/modules/lists.d.ts +30 -28
  32. package/dist/modules/lists.js +55 -42
  33. package/dist/modules/notes.d.ts +32 -30
  34. package/dist/modules/notes.js +40 -52
  35. package/dist/modules/people.d.ts +83 -71
  36. package/dist/modules/people.js +323 -172
  37. package/dist/modules/reports.d.ts +18 -32
  38. package/dist/modules/reports.js +28 -40
  39. package/dist/modules/service-time.d.ts +19 -24
  40. package/dist/modules/service-time.js +28 -28
  41. package/dist/modules/workflows.d.ts +42 -47
  42. package/dist/modules/workflows.js +50 -53
  43. package/dist/performance.d.ts +14 -10
  44. package/dist/performance.js +61 -25
  45. package/dist/testing/recorder.js +11 -2
  46. package/dist/testing/simple-builders.d.ts +6 -4
  47. package/dist/testing/simple-builders.js +36 -49
  48. package/dist/testing/types.d.ts +4 -0
  49. package/dist/types/api-options.d.ts +380 -0
  50. package/dist/types/api-options.js +6 -0
  51. package/dist/types/client.d.ts +4 -2
  52. package/dist/types/client.js +1 -1
  53. package/dist/types/index.d.ts +1 -1
  54. package/dist/types/people.d.ts +47 -9
  55. package/package.json +7 -7
  56. package/dist/core/http.d.ts +0 -56
  57. package/dist/core/http.js +0 -360
  58. package/dist/core/pagination.d.ts +0 -34
  59. package/dist/core/pagination.js +0 -178
  60. package/dist/people/contacts.d.ts +0 -43
  61. package/dist/people/contacts.js +0 -122
  62. package/dist/people/core.d.ts +0 -28
  63. package/dist/people/core.js +0 -69
  64. package/dist/people/fields.d.ts +0 -68
  65. package/dist/people/fields.js +0 -305
  66. package/dist/people/households.d.ts +0 -15
  67. package/dist/people/households.js +0 -31
  68. package/dist/people/index.d.ts +0 -8
  69. package/dist/people/index.js +0 -25
  70. package/dist/people/lists.d.ts +0 -34
  71. package/dist/people/lists.js +0 -48
  72. package/dist/people/notes.d.ts +0 -30
  73. package/dist/people/notes.js +0 -37
  74. package/dist/people/organization.d.ts +0 -12
  75. package/dist/people/organization.js +0 -15
  76. package/dist/people/workflows.d.ts +0 -37
  77. package/dist/people/workflows.js +0 -75
@@ -1,122 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getPersonEmails = getPersonEmails;
4
- exports.createPersonEmail = createPersonEmail;
5
- exports.getPersonPhoneNumbers = getPersonPhoneNumbers;
6
- exports.createPersonPhoneNumber = createPersonPhoneNumber;
7
- exports.getPersonAddresses = getPersonAddresses;
8
- exports.createPersonAddress = createPersonAddress;
9
- exports.updatePersonAddress = updatePersonAddress;
10
- exports.getPersonSocialProfiles = getPersonSocialProfiles;
11
- exports.createPersonSocialProfile = createPersonSocialProfile;
12
- exports.deleteSocialProfile = deleteSocialProfile;
13
- const core_1 = require("../core");
14
- /**
15
- * Get all emails for a person
16
- */
17
- async function getPersonEmails(client, personId, context) {
18
- return (0, core_1.getList)(client, `/people/${personId}/emails`, undefined, {
19
- ...context,
20
- endpoint: `/people/${personId}/emails`,
21
- method: 'GET',
22
- personId,
23
- });
24
- }
25
- /**
26
- * Create an email for a person
27
- */
28
- async function createPersonEmail(client, personId, data, context) {
29
- return (0, core_1.post)(client, `/people/${personId}/emails`, data, undefined, {
30
- ...context,
31
- endpoint: `/people/${personId}/emails`,
32
- method: 'POST',
33
- personId,
34
- });
35
- }
36
- /**
37
- * Get all phone numbers for a person
38
- */
39
- async function getPersonPhoneNumbers(client, personId, context) {
40
- return (0, core_1.getList)(client, `/people/${personId}/phone_numbers`, undefined, {
41
- ...context,
42
- endpoint: `/people/${personId}/phone_numbers`,
43
- method: 'GET',
44
- personId,
45
- });
46
- }
47
- /**
48
- * Create a phone number for a person
49
- */
50
- async function createPersonPhoneNumber(client, personId, data, context) {
51
- return (0, core_1.post)(client, `/people/${personId}/phone_numbers`, data, undefined, {
52
- ...context,
53
- endpoint: `/people/${personId}/phone_numbers`,
54
- method: 'POST',
55
- personId,
56
- });
57
- }
58
- /**
59
- * Get all addresses for a person
60
- */
61
- async function getPersonAddresses(client, personId, context) {
62
- return (0, core_1.getList)(client, `/people/${personId}/addresses`, undefined, {
63
- ...context,
64
- endpoint: `/people/${personId}/addresses`,
65
- method: 'GET',
66
- personId,
67
- });
68
- }
69
- /**
70
- * Create an address for a person
71
- */
72
- async function createPersonAddress(client, personId, data, context) {
73
- return (0, core_1.post)(client, `/people/${personId}/addresses`, data, undefined, {
74
- ...context,
75
- endpoint: `/people/${personId}/addresses`,
76
- method: 'POST',
77
- personId,
78
- });
79
- }
80
- /**
81
- * Update an address for a person
82
- */
83
- async function updatePersonAddress(client, personId, addressId, data, context) {
84
- return (0, core_1.patch)(client, `/people/${personId}/addresses/${addressId}`, data, undefined, {
85
- ...context,
86
- endpoint: `/people/${personId}/addresses/${addressId}`,
87
- method: 'PATCH',
88
- personId,
89
- });
90
- }
91
- /**
92
- * Get social profiles for a person
93
- */
94
- async function getPersonSocialProfiles(client, personId, context) {
95
- return (0, core_1.getList)(client, `/people/${personId}/social_profiles`, undefined, {
96
- ...context,
97
- endpoint: `/people/${personId}/social_profiles`,
98
- method: 'GET',
99
- personId,
100
- });
101
- }
102
- /**
103
- * Create a social profile for a person
104
- */
105
- async function createPersonSocialProfile(client, personId, data, context) {
106
- return (0, core_1.post)(client, `/people/${personId}/social_profiles`, data, undefined, {
107
- ...context,
108
- endpoint: `/people/${personId}/social_profiles`,
109
- method: 'POST',
110
- personId,
111
- });
112
- }
113
- /**
114
- * Delete a social profile
115
- */
116
- async function deleteSocialProfile(client, socialProfileId, context) {
117
- return (0, core_1.del)(client, `/social_profiles/${socialProfileId}`, {
118
- ...context,
119
- endpoint: `/social_profiles/${socialProfileId}`,
120
- method: 'DELETE',
121
- });
122
- }
@@ -1,28 +0,0 @@
1
- import { PcoClientState } from '../core';
2
- import type { ErrorContext } from '@rachelallyson/planning-center-base-ts';
3
- import { PeopleList, PersonAttributes, PersonSingle } from '../types';
4
- /**
5
- * Get all people with optional filtering and pagination
6
- */
7
- export declare function getPeople(client: PcoClientState, params?: {
8
- where?: Record<string, any>;
9
- include?: string[];
10
- per_page?: number;
11
- page?: number;
12
- }, context?: Partial<ErrorContext>): Promise<PeopleList>;
13
- /**
14
- * Get a single person by ID
15
- */
16
- export declare function getPerson(client: PcoClientState, id: string, include?: string[], context?: Partial<ErrorContext>): Promise<PersonSingle>;
17
- /**
18
- * Create a new person
19
- */
20
- export declare function createPerson(client: PcoClientState, data: Partial<PersonAttributes>, context?: Partial<ErrorContext>): Promise<PersonSingle>;
21
- /**
22
- * Update a person
23
- */
24
- export declare function updatePerson(client: PcoClientState, id: string, data: Partial<PersonAttributes>, context?: Partial<ErrorContext>): Promise<PersonSingle>;
25
- /**
26
- * Delete a person
27
- */
28
- export declare function deletePerson(client: PcoClientState, id: string, context?: Partial<ErrorContext>): Promise<void>;
@@ -1,69 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getPeople = getPeople;
4
- exports.getPerson = getPerson;
5
- exports.createPerson = createPerson;
6
- exports.updatePerson = updatePerson;
7
- exports.deletePerson = deletePerson;
8
- const core_1 = require("../core");
9
- const helpers_1 = require("../helpers");
10
- /**
11
- * Get all people with optional filtering and pagination
12
- */
13
- async function getPeople(client, params, context) {
14
- const result = await (0, core_1.getList)(client, '/people', (0, helpers_1.buildQueryParams)(params), {
15
- ...context,
16
- endpoint: '/people',
17
- method: 'GET',
18
- });
19
- return result;
20
- }
21
- /**
22
- * Get a single person by ID
23
- */
24
- async function getPerson(client, id, include, context) {
25
- const params = {};
26
- if (include) {
27
- params.include = include.join(',');
28
- }
29
- return (await (0, core_1.getSingle)(client, `/people/${id}`, params, {
30
- ...context,
31
- endpoint: `/people/${id}`,
32
- method: 'GET',
33
- personId: id,
34
- }));
35
- }
36
- /**
37
- * Create a new person
38
- */
39
- async function createPerson(client, data, context) {
40
- return (0, core_1.post)(client, '/people', data, undefined, {
41
- ...context,
42
- endpoint: '/people',
43
- method: 'POST',
44
- });
45
- }
46
- /**
47
- * Update a person
48
- */
49
- async function updatePerson(client, id, data, context) {
50
- return (0, core_1.patch)(client, `/people/${id}`, data, undefined, {
51
- ...context,
52
- endpoint: `/people/${id}`,
53
- method: 'PATCH',
54
- personId: id,
55
- });
56
- }
57
- /**
58
- * Delete a person
59
- */
60
- async function deletePerson(client, id, context) {
61
- return (0, core_1.del)(client, `/people/${id}`, undefined, {
62
- ...context,
63
- endpoint: `/people/${id}`,
64
- method: 'DELETE',
65
- personId: id,
66
- metadata: { operation: 'delete_person' },
67
- timestamp: new Date().toISOString(),
68
- });
69
- }
@@ -1,68 +0,0 @@
1
- import { PcoClientState } from '../core';
2
- import type { ErrorContext } from '@rachelallyson/planning-center-base-ts';
3
- import { FieldDataList, FieldDataSingle, FieldDataType, FieldDefinitionsList, FieldDefinitionSingle, FieldOptionAttributes, FieldOptionSingle, FieldOptionsList, TabSingle, TabsList } from '../types';
4
- /**
5
- * Delete field data for a person
6
- */
7
- export declare function deletePersonFieldData(client: PcoClientState, personId: string, fieldDataId: string, context?: Partial<ErrorContext>): Promise<void>;
8
- /**
9
- * Get field data for a person (custom fields)
10
- */
11
- export declare function getPersonFieldData(client: PcoClientState, personId: string, context?: Partial<ErrorContext>): Promise<FieldDataList>;
12
- /**
13
- * Get field definitions
14
- */
15
- export declare function getFieldDefinitions(client: PcoClientState, params?: {
16
- include?: string[];
17
- per_page?: number;
18
- page?: number;
19
- filter?: string;
20
- order?: string;
21
- }, context?: Partial<ErrorContext>): Promise<FieldDefinitionsList>;
22
- /**
23
- * Get a single field definition by ID
24
- */
25
- export declare function getFieldDefinition(client: PcoClientState, fieldId: string, params?: {
26
- include?: string[];
27
- }, context?: Partial<ErrorContext>): Promise<FieldDefinitionSingle>;
28
- /**
29
- * Get field options for a field definition
30
- */
31
- export declare function getFieldOptions(client: PcoClientState, fieldDefinitionId: string, context?: Partial<ErrorContext>): Promise<FieldOptionsList>;
32
- /**
33
- * Create a field option for a field definition
34
- */
35
- export declare function createFieldOption(client: PcoClientState, fieldDefinitionId: string, data: Partial<FieldOptionAttributes>, context?: Partial<ErrorContext>): Promise<FieldOptionSingle>;
36
- /**
37
- * Get tabs
38
- */
39
- export declare function getTabs(client: PcoClientState, params?: {
40
- include?: string[];
41
- per_page?: number;
42
- page?: number;
43
- }, context?: Partial<ErrorContext>): Promise<TabsList>;
44
- /**
45
- * Get a single tab by ID
46
- */
47
- export declare function getTab(client: PcoClientState, tabId: string, params?: {
48
- include?: string[];
49
- }, context?: Partial<ErrorContext>): Promise<TabSingle>;
50
- /**
51
- * Create a field definition
52
- */
53
- export declare function createFieldDefinition(client: PcoClientState, tabId: string, data: {
54
- name: string;
55
- data_type: FieldDataType;
56
- sequence?: number;
57
- slug?: string;
58
- config?: string | Record<string, any>;
59
- }, context?: Partial<ErrorContext>): Promise<FieldDefinitionSingle>;
60
- /**
61
- * Delete a field definition
62
- */
63
- export declare function deleteFieldDefinition(client: PcoClientState, fieldDefinitionId: string, context?: Partial<ErrorContext>): Promise<void>;
64
- /**
65
- * Create field data for a person with automatic file upload handling
66
- * Determines field type and uses appropriate creation method
67
- */
68
- export declare function createPersonFieldData(client: PcoClientState, personId: string, fieldId: string, value: string, context?: Partial<ErrorContext>): Promise<FieldDataSingle>;
@@ -1,305 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.deletePersonFieldData = deletePersonFieldData;
4
- exports.getPersonFieldData = getPersonFieldData;
5
- exports.getFieldDefinitions = getFieldDefinitions;
6
- exports.getFieldDefinition = getFieldDefinition;
7
- exports.getFieldOptions = getFieldOptions;
8
- exports.createFieldOption = createFieldOption;
9
- exports.getTabs = getTabs;
10
- exports.getTab = getTab;
11
- exports.createFieldDefinition = createFieldDefinition;
12
- exports.deleteFieldDefinition = deleteFieldDefinition;
13
- exports.createPersonFieldData = createPersonFieldData;
14
- const core_1 = require("../core");
15
- const planning_center_base_ts_1 = require("@rachelallyson/planning-center-base-ts");
16
- const helpers_1 = require("../helpers");
17
- /**
18
- * Create field data for a person (internal)
19
- */
20
- async function createPersonFieldDataInternal(client, personId, fieldDefinitionId, value, context) {
21
- return (0, core_1.post)(client, `/people/${personId}/field_data`, {
22
- field_definition_id: fieldDefinitionId,
23
- value,
24
- }, undefined, {
25
- ...context,
26
- endpoint: `/people/${personId}/field_data`,
27
- method: 'POST',
28
- personId,
29
- });
30
- }
31
- /**
32
- * Delete field data for a person
33
- */
34
- async function deletePersonFieldData(client, personId, fieldDataId, context) {
35
- return (0, core_1.del)(client, `/people/${personId}/field_data/${fieldDataId}`, undefined, {
36
- ...context,
37
- endpoint: `/people/${personId}/field_data/${fieldDataId}`,
38
- method: 'DELETE',
39
- personId,
40
- });
41
- }
42
- /**
43
- * Get field data for a person (custom fields)
44
- */
45
- async function getPersonFieldData(client, personId, context) {
46
- return (0, core_1.getList)(client, `/people/${personId}/field_data`, undefined, {
47
- ...context,
48
- endpoint: `/people/${personId}/field_data`,
49
- method: 'GET',
50
- personId,
51
- });
52
- }
53
- /**
54
- * Upload a file to PCO and create field data (internal)
55
- */
56
- async function createPersonFileFieldDataInternal(client, personId, fieldDefinitionId, fileUrl, context) {
57
- return (0, planning_center_base_ts_1.withErrorBoundary)(async () => {
58
- // No external dependencies needed - using native fetch API
59
- // Extract filename from URL
60
- const urlParts = fileUrl.split('/');
61
- const filename = urlParts[urlParts.length - 1] ?? 'file';
62
- // Extract file extension
63
- const extension = filename.includes('.')
64
- ? (filename.split('.').pop() ?? '')
65
- : '';
66
- // Get MIME type from file extension
67
- const getMimeType = (ext) => {
68
- const mimeTypes = {
69
- csv: 'text/csv',
70
- doc: 'application/msword',
71
- docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
72
- gif: 'image/gif',
73
- jpeg: 'image/jpeg',
74
- jpg: 'image/jpeg',
75
- pdf: 'application/pdf',
76
- png: 'image/png',
77
- txt: 'text/plain',
78
- xls: 'application/vnd.ms-excel',
79
- xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
80
- };
81
- return mimeTypes[ext.toLowerCase()] || 'application/octet-stream';
82
- };
83
- // Download the file from the provided URL using native fetch
84
- const fileResponse = await fetch(fileUrl, {
85
- method: 'GET',
86
- headers: {
87
- 'Accept': '*/*',
88
- },
89
- });
90
- if (!fileResponse.ok) {
91
- throw new Error(`Failed to download file: ${fileResponse.status} ${fileResponse.statusText}`);
92
- }
93
- const fileBuffer = await fileResponse.arrayBuffer();
94
- // Step 1: Upload to PCO's upload service first
95
- let FormDataConstructor;
96
- try {
97
- // eslint-disable-next-line @typescript-eslint/no-var-requires
98
- const FormDataModule = require('form-data');
99
- // Handle different export patterns
100
- FormDataConstructor = FormDataModule.default || FormDataModule;
101
- }
102
- catch (error) {
103
- throw new Error('form-data package is required for file uploads. Please install it: npm install form-data');
104
- }
105
- const uploadFormData = new FormDataConstructor();
106
- uploadFormData.append('file', Buffer.from(fileBuffer), {
107
- contentType: getMimeType(extension),
108
- filename,
109
- });
110
- // Upload to PCO's upload service using native fetch
111
- const uploadResponse = await fetch('https://upload.planningcenteronline.com/v2/files', {
112
- method: 'POST',
113
- headers: {
114
- ...uploadFormData.getHeaders(),
115
- Authorization: client.config.accessToken
116
- ? `Bearer ${client.config.accessToken}`
117
- : `Basic ${Buffer.from(`${client.config.appId}:${client.config.appSecret}`).toString('base64')}`,
118
- },
119
- body: uploadFormData,
120
- });
121
- if (!uploadResponse.ok) {
122
- throw new Error(`Failed to upload file: ${uploadResponse.status} ${uploadResponse.statusText}`);
123
- }
124
- const uploadData = await uploadResponse.json();
125
- // Step 2: Get the file UUID from the response
126
- const fileUUID = uploadData?.data?.[0]?.id;
127
- if (!fileUUID) {
128
- throw new Error('Failed to get file UUID from upload response');
129
- }
130
- // Step 3: Use the UUID to assign the file to the field
131
- return createPersonFieldDataInternal(client, personId, fieldDefinitionId, fileUUID, {
132
- ...context,
133
- endpoint: `/people/${personId}/field_data`,
134
- metadata: {
135
- ...context?.metadata,
136
- operation: 'create_file_field_data',
137
- originalFileUrl: fileUrl,
138
- uploadedFileUUID: fileUUID,
139
- },
140
- method: 'POST',
141
- });
142
- }, {
143
- ...context,
144
- category: planning_center_base_ts_1.ErrorCategory.EXTERNAL_API,
145
- severity: planning_center_base_ts_1.ErrorSeverity.HIGH,
146
- });
147
- }
148
- /**
149
- * Get field definitions
150
- */
151
- async function getFieldDefinitions(client, params, context) {
152
- return (0, core_1.getList)(client, '/field_definitions', (0, helpers_1.buildQueryParams)(params), {
153
- ...context,
154
- endpoint: '/field_definitions',
155
- method: 'GET',
156
- });
157
- }
158
- /**
159
- * Get a single field definition by ID
160
- */
161
- async function getFieldDefinition(client, fieldId, params, context) {
162
- return (0, core_1.getSingle)(client, `/field_definitions/${fieldId}`, (0, helpers_1.buildQueryParams)(params), {
163
- ...context,
164
- endpoint: `/field_definitions/${fieldId}`,
165
- method: 'GET',
166
- });
167
- }
168
- /**
169
- * Get field options for a field definition
170
- */
171
- async function getFieldOptions(client, fieldDefinitionId, context) {
172
- return (0, core_1.getList)(client, `/field_definitions/${fieldDefinitionId}/field_options`, undefined, {
173
- ...context,
174
- endpoint: `/field_definitions/${fieldDefinitionId}/field_options`,
175
- fieldDefinitionId,
176
- method: 'GET',
177
- });
178
- }
179
- /**
180
- * Create a field option for a field definition
181
- */
182
- async function createFieldOption(client, fieldDefinitionId, data, context) {
183
- return (0, core_1.post)(client, `/field_definitions/${fieldDefinitionId}/field_options`, data, undefined, {
184
- ...context,
185
- endpoint: `/field_definitions/${fieldDefinitionId}/field_options`,
186
- fieldDefinitionId,
187
- method: 'POST',
188
- });
189
- }
190
- /**
191
- * Get tabs
192
- */
193
- async function getTabs(client, params, context) {
194
- return (0, core_1.getList)(client, '/tabs', (0, helpers_1.buildQueryParams)(params), {
195
- ...context,
196
- endpoint: '/tabs',
197
- method: 'GET',
198
- });
199
- }
200
- /**
201
- * Get a single tab by ID
202
- */
203
- async function getTab(client, tabId, params, context) {
204
- return (0, core_1.getSingle)(client, `/tabs/${tabId}`, (0, helpers_1.buildQueryParams)(params), {
205
- ...context,
206
- endpoint: `/tabs/${tabId}`,
207
- method: 'GET',
208
- });
209
- }
210
- /**
211
- * Create a field definition
212
- */
213
- async function createFieldDefinition(client, tabId, data, context) {
214
- return (0, core_1.post)(client, `/tabs/${tabId}/field_definitions`, data, undefined, {
215
- ...context,
216
- endpoint: `/tabs/${tabId}/field_definitions`,
217
- method: 'POST',
218
- });
219
- }
220
- /**
221
- * Delete a field definition
222
- */
223
- async function deleteFieldDefinition(client, fieldDefinitionId, context) {
224
- return (0, core_1.del)(client, `/field_definitions/${fieldDefinitionId}`, undefined, {
225
- ...context,
226
- endpoint: `/field_definitions/${fieldDefinitionId}`,
227
- method: 'DELETE',
228
- fieldDefinitionId,
229
- });
230
- }
231
- /**
232
- * Helper function to check if a field definition has a data_type attribute
233
- */
234
- function hasDataType(fieldDef) {
235
- return fieldDef && typeof fieldDef.data_type === 'string';
236
- }
237
- /**
238
- * Create field data for a person with automatic file upload handling
239
- * Determines field type and uses appropriate creation method
240
- */
241
- async function createPersonFieldData(client, personId, fieldId, value, context) {
242
- // Get field definition to determine type
243
- // Get field definition by ID - try direct fetch first, then search in ordered list
244
- let fieldDef;
245
- // First try direct fetch
246
- const singleFieldDef = await getFieldDefinition(client, fieldId, { include: [] }, {
247
- ...context,
248
- metadata: {
249
- ...context?.metadata,
250
- operation: 'get_field_definition_direct',
251
- },
252
- });
253
- fieldDef = singleFieldDef.data || undefined;
254
- // If direct fetch fails, search through the list ordered by creation date (newest first)
255
- if (!fieldDef) {
256
- const fieldDefinition = await getFieldDefinitions(client, {
257
- include: [],
258
- // Include deleted fields in case the field was soft-deleted
259
- filter: 'include_deleted',
260
- per_page: 200, // Get more fields to ensure we find the one we need
261
- order: '-created_at', // Order by creation date, newest first
262
- }, {
263
- ...context,
264
- metadata: {
265
- ...context?.metadata,
266
- operation: 'get_field_definition_list',
267
- },
268
- });
269
- // Find the specific field definition
270
- fieldDef = fieldDefinition.data?.find(f => f.id === fieldId);
271
- if (!fieldDef) {
272
- // Debug: log available field IDs to help troubleshoot
273
- const availableIds = fieldDefinition.data?.map(f => f.id) || [];
274
- console.log(`Field definition not found for field ID: ${fieldId}`);
275
- console.log(`Available field definition IDs: ${availableIds.slice(0, 10).join(', ')}${availableIds.length > 10 ? '...' : ''}`);
276
- console.log(`Total field definitions found: ${fieldDefinition.data?.length || 0}`);
277
- throw new Error(`Field definition not found for field ID: ${fieldId}`);
278
- }
279
- }
280
- // Check if this is a file field
281
- if (hasDataType(fieldDef.attributes) && fieldDef.attributes.data_type === 'file') {
282
- // This is a file field - always use file upload
283
- const fileUrl = (0, helpers_1.isFileUpload)(value) ? (0, helpers_1.extractFileUrl)(value) : value;
284
- return createPersonFileFieldDataInternal(client, personId, fieldId, fileUrl, {
285
- ...context,
286
- endpoint: `/people/${personId}/field_data`,
287
- metadata: {
288
- ...context?.metadata,
289
- operation: 'create_file_field_data',
290
- },
291
- method: 'POST',
292
- });
293
- }
294
- // This is a text field - clean the value if it's a file URL
295
- const cleanValue = (0, helpers_1.isFileUpload)(value) ? (0, helpers_1.extractFileUrl)(value) : value;
296
- return createPersonFieldDataInternal(client, personId, fieldId, cleanValue, {
297
- ...context,
298
- endpoint: `/people/${personId}/field_data`,
299
- metadata: {
300
- ...context?.metadata,
301
- operation: 'create_text_field_data',
302
- },
303
- method: 'POST',
304
- });
305
- }
@@ -1,15 +0,0 @@
1
- import { PcoClientState } from '../core';
2
- import type { ErrorContext } from '@rachelallyson/planning-center-base-ts';
3
- import { HouseholdSingle, HouseholdsList } from '../types';
4
- /**
5
- * Get all households
6
- */
7
- export declare function getHouseholds(client: PcoClientState, params?: {
8
- include?: string[];
9
- per_page?: number;
10
- page?: number;
11
- }, context?: Partial<ErrorContext>): Promise<HouseholdsList>;
12
- /**
13
- * Get a single household by ID
14
- */
15
- export declare function getHousehold(client: PcoClientState, id: string, include?: string[], context?: Partial<ErrorContext>): Promise<HouseholdSingle>;
@@ -1,31 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getHouseholds = getHouseholds;
4
- exports.getHousehold = getHousehold;
5
- const core_1 = require("../core");
6
- const helpers_1 = require("../helpers");
7
- /**
8
- * Get all households
9
- */
10
- async function getHouseholds(client, params, context) {
11
- return (0, core_1.getList)(client, '/households', (0, helpers_1.buildQueryParams)(params), {
12
- ...context,
13
- endpoint: '/households',
14
- method: 'GET',
15
- });
16
- }
17
- /**
18
- * Get a single household by ID
19
- */
20
- async function getHousehold(client, id, include, context) {
21
- const params = {};
22
- if (include) {
23
- params.include = include.join(',');
24
- }
25
- return (0, core_1.getSingle)(client, `/households/${id}`, params, {
26
- ...context,
27
- endpoint: `/households/${id}`,
28
- householdId: id,
29
- method: 'GET',
30
- });
31
- }
@@ -1,8 +0,0 @@
1
- export * from './core';
2
- export * from './contacts';
3
- export * from './fields';
4
- export * from './households';
5
- export * from './lists';
6
- export * from './notes';
7
- export * from './workflows';
8
- export * from './organization';
@@ -1,25 +0,0 @@
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
- // Re-export all people-related functions from their respective modules
18
- __exportStar(require("./core"), exports);
19
- __exportStar(require("./contacts"), exports);
20
- __exportStar(require("./fields"), exports);
21
- __exportStar(require("./households"), exports);
22
- __exportStar(require("./lists"), exports);
23
- __exportStar(require("./notes"), exports);
24
- __exportStar(require("./workflows"), exports);
25
- __exportStar(require("./organization"), exports);