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