@rachelallyson/planning-center-people-ts 1.0.0 → 1.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.
package/dist/people.js DELETED
@@ -1,598 +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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.getPeople = getPeople;
37
- exports.getPerson = getPerson;
38
- exports.createPerson = createPerson;
39
- exports.updatePerson = updatePerson;
40
- exports.deletePerson = deletePerson;
41
- exports.getPersonEmails = getPersonEmails;
42
- exports.createPersonEmail = createPersonEmail;
43
- exports.getPersonPhoneNumbers = getPersonPhoneNumbers;
44
- exports.createPersonPhoneNumber = createPersonPhoneNumber;
45
- exports.getPersonAddresses = getPersonAddresses;
46
- exports.createPersonFieldData = createPersonFieldData;
47
- exports.deletePersonFieldData = deletePersonFieldData;
48
- exports.createPersonAddress = createPersonAddress;
49
- exports.updatePersonAddress = updatePersonAddress;
50
- exports.getPersonFieldData = getPersonFieldData;
51
- exports.createPersonFileFieldData = createPersonFileFieldData;
52
- exports.getHouseholds = getHouseholds;
53
- exports.getHousehold = getHousehold;
54
- exports.getFieldDefinitions = getFieldDefinitions;
55
- exports.getPersonSocialProfiles = getPersonSocialProfiles;
56
- exports.createPersonSocialProfile = createPersonSocialProfile;
57
- exports.getFieldOptions = getFieldOptions;
58
- exports.createFieldOption = createFieldOption;
59
- exports.getWorkflowCardNotes = getWorkflowCardNotes;
60
- exports.createWorkflowCardNote = createWorkflowCardNote;
61
- exports.getWorkflowCards = getWorkflowCards;
62
- exports.createWorkflowCard = createWorkflowCard;
63
- exports.getLists = getLists;
64
- exports.getListById = getListById;
65
- exports.getListCategories = getListCategories;
66
- exports.getNotes = getNotes;
67
- exports.getNote = getNote;
68
- exports.getNoteCategories = getNoteCategories;
69
- exports.getWorkflows = getWorkflows;
70
- exports.getWorkflow = getWorkflow;
71
- exports.getOrganization = getOrganization;
72
- const core_1 = require("./core");
73
- const error_handling_1 = require("./error-handling");
74
- // ===== Helper Functions =====
75
- /**
76
- * Transform complex params object into flat query params for API calls
77
- */
78
- function buildQueryParams(params) {
79
- const queryParams = {};
80
- if (params?.where) {
81
- Object.entries(params.where).forEach(([key, value]) => {
82
- queryParams[`where[${key}]`] = value;
83
- });
84
- }
85
- if (params?.include) {
86
- queryParams.include = params.include.join(',');
87
- }
88
- if (params?.per_page) {
89
- queryParams.per_page = params.per_page;
90
- }
91
- if (params?.page) {
92
- queryParams.page = params.page;
93
- }
94
- return queryParams;
95
- }
96
- // ===== People API Functions =====
97
- /**
98
- * Get all people with optional filtering and pagination
99
- */
100
- async function getPeople(client, params, context) {
101
- const queryParams = {};
102
- if (params?.where) {
103
- Object.entries(params.where).forEach(([key, value]) => {
104
- queryParams[`where[${key}]`] = value;
105
- });
106
- }
107
- if (params?.include) {
108
- queryParams.include = params.include.join(',');
109
- }
110
- if (params?.per_page) {
111
- queryParams.per_page = params.per_page;
112
- }
113
- if (params?.page) {
114
- queryParams.page = params.page;
115
- }
116
- const result = await (0, core_1.getList)(client, '/people', queryParams, {
117
- ...context,
118
- endpoint: '/people',
119
- method: 'GET',
120
- });
121
- return result;
122
- }
123
- /**
124
- * Get a single person by ID
125
- */
126
- async function getPerson(client, id, include, context) {
127
- const params = {};
128
- if (include) {
129
- params.include = include.join(',');
130
- }
131
- return (await (0, core_1.getSingle)(client, `/people/${id}`, params, {
132
- ...context,
133
- endpoint: `/people/${id}`,
134
- method: 'GET',
135
- personId: id,
136
- }));
137
- }
138
- /**
139
- * Create a new person
140
- */
141
- async function createPerson(client, data, context) {
142
- return (0, core_1.post)(client, '/people', data, undefined, {
143
- ...context,
144
- endpoint: '/people',
145
- method: 'POST',
146
- });
147
- }
148
- /**
149
- * Update a person
150
- */
151
- async function updatePerson(client, id, data, context) {
152
- return (0, core_1.patch)(client, `/people/${id}`, data, undefined, {
153
- ...context,
154
- endpoint: `/people/${id}`,
155
- method: 'PATCH',
156
- personId: id,
157
- });
158
- }
159
- /**
160
- * Delete a person
161
- */
162
- async function deletePerson(client, id, context) {
163
- return (0, core_1.del)(client, `/people/${id}`, undefined, {
164
- ...context,
165
- endpoint: `/people/${id}`,
166
- method: 'DELETE',
167
- personId: id,
168
- });
169
- }
170
- /**
171
- * Get all emails for a person
172
- */
173
- async function getPersonEmails(client, personId, context) {
174
- return (0, core_1.getList)(client, `/people/${personId}/emails`, undefined, {
175
- ...context,
176
- endpoint: `/people/${personId}/emails`,
177
- method: 'GET',
178
- personId,
179
- });
180
- }
181
- /**
182
- * Create an email for a person
183
- */
184
- async function createPersonEmail(client, personId, data, context) {
185
- return (0, core_1.post)(client, `/people/${personId}/emails`, data, undefined, {
186
- ...context,
187
- endpoint: `/people/${personId}/emails`,
188
- method: 'POST',
189
- personId,
190
- });
191
- }
192
- /**
193
- * Get all phone numbers for a person
194
- */
195
- async function getPersonPhoneNumbers(client, personId, context) {
196
- return (0, core_1.getList)(client, `/people/${personId}/phone_numbers`, undefined, {
197
- ...context,
198
- endpoint: `/people/${personId}/phone_numbers`,
199
- method: 'GET',
200
- personId,
201
- });
202
- }
203
- /**
204
- * Create a phone number for a person
205
- */
206
- async function createPersonPhoneNumber(client, personId, data, context) {
207
- return (0, core_1.post)(client, `/people/${personId}/phone_numbers`, data, undefined, {
208
- ...context,
209
- endpoint: `/people/${personId}/phone_numbers`,
210
- method: 'POST',
211
- personId,
212
- });
213
- }
214
- /**
215
- * Get all addresses for a person
216
- */
217
- async function getPersonAddresses(client, personId, context) {
218
- return (0, core_1.getList)(client, `/people/${personId}/addresses`, undefined, {
219
- ...context,
220
- endpoint: `/people/${personId}/addresses`,
221
- method: 'GET',
222
- personId,
223
- });
224
- }
225
- /**
226
- * Create field data for a person
227
- */
228
- async function createPersonFieldData(client, personId, fieldDefinitionId, value, context) {
229
- return (0, core_1.post)(client, `/people/${personId}/field_data`, {
230
- field_definition_id: fieldDefinitionId,
231
- value,
232
- }, undefined, {
233
- ...context,
234
- endpoint: `/people/${personId}/field_data`,
235
- method: 'POST',
236
- personId,
237
- });
238
- }
239
- /**
240
- * Delete field data for a person
241
- */
242
- async function deletePersonFieldData(client, personId, fieldDataId, context) {
243
- return (0, core_1.del)(client, `/people/${personId}/field_data/${fieldDataId}`, undefined, {
244
- ...context,
245
- endpoint: `/people/${personId}/field_data/${fieldDataId}`,
246
- method: 'DELETE',
247
- personId,
248
- });
249
- }
250
- /**
251
- * Create an address for a person
252
- */
253
- async function createPersonAddress(client, personId, data, context) {
254
- return (0, core_1.post)(client, `/people/${personId}/addresses`, data, undefined, {
255
- ...context,
256
- endpoint: `/people/${personId}/addresses`,
257
- method: 'POST',
258
- personId,
259
- });
260
- }
261
- /**
262
- * Update an address for a person
263
- */
264
- async function updatePersonAddress(client, personId, addressId, data, context) {
265
- return (0, core_1.patch)(client, `/people/${personId}/addresses/${addressId}`, data, undefined, {
266
- ...context,
267
- endpoint: `/people/${personId}/addresses/${addressId}`,
268
- method: 'PATCH',
269
- personId,
270
- });
271
- }
272
- /**
273
- * Get field data for a person (custom fields)
274
- */
275
- async function getPersonFieldData(client, personId, context) {
276
- return (0, core_1.getList)(client, `/people/${personId}/field_data`, undefined, {
277
- ...context,
278
- endpoint: `/people/${personId}/field_data`,
279
- method: 'GET',
280
- personId,
281
- });
282
- }
283
- /**
284
- * Upload a file to PCO and create field data
285
- */
286
- async function createPersonFileFieldData(client, personId, fieldDefinitionId, fileUrl, context) {
287
- return (0, error_handling_1.withErrorBoundary)(async () => {
288
- const axios = await Promise.resolve().then(() => __importStar(require('axios')));
289
- // Extract filename from URL
290
- const urlParts = fileUrl.split('/');
291
- const filename = urlParts[urlParts.length - 1] ?? 'file';
292
- // Extract file extension
293
- const extension = filename.includes('.')
294
- ? (filename.split('.').pop() ?? '')
295
- : '';
296
- // Get MIME type from file extension
297
- const getMimeType = (ext) => {
298
- const mimeTypes = {
299
- csv: 'text/csv',
300
- doc: 'application/msword',
301
- docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
302
- gif: 'image/gif',
303
- jpeg: 'image/jpeg',
304
- jpg: 'image/jpeg',
305
- pdf: 'application/pdf',
306
- png: 'image/png',
307
- txt: 'text/plain',
308
- xls: 'application/vnd.ms-excel',
309
- xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
310
- };
311
- return mimeTypes[ext.toLowerCase()] || 'application/octet-stream';
312
- };
313
- // Download the file from the provided URL
314
- const fileResponse = await axios.default.get(fileUrl, {
315
- responseType: 'arraybuffer',
316
- timeout: 30000, // 30 second timeout
317
- });
318
- // Step 1: Upload to PCO's upload service first
319
- const FormDataModule = await Promise.resolve().then(() => __importStar(require('form-data')));
320
- const FormDataConstructor = FormDataModule.default;
321
- const uploadFormData = new FormDataConstructor();
322
- uploadFormData.append('file', fileResponse.data, {
323
- contentType: getMimeType(extension),
324
- filename,
325
- });
326
- // Create a separate axios instance for the upload service with the same auth
327
- const uploadAxios = axios.default.create({
328
- headers: {
329
- Authorization: client.config.accessToken
330
- ? `Bearer ${client.config.accessToken}`
331
- : `Basic ${Buffer.from(`${client.config.appId}:${client.config.appSecret}`).toString('base64')}`,
332
- },
333
- });
334
- const uploadResponse = await uploadAxios.post('https://upload.planningcenteronline.com/v2/files', uploadFormData, {
335
- headers: uploadFormData.getHeaders(),
336
- timeout: 60000,
337
- });
338
- // Step 2: Get the file UUID from the response
339
- const fileUUID = uploadResponse.data?.data?.[0]?.id;
340
- if (!fileUUID) {
341
- throw new Error('Failed to get file UUID from upload response');
342
- }
343
- // Step 3: Use the UUID to assign the file to the field
344
- return createPersonFieldData(client, personId, fieldDefinitionId, fileUUID, {
345
- ...context,
346
- endpoint: `/people/${personId}/field_data`,
347
- metadata: {
348
- ...context?.metadata,
349
- operation: 'create_file_field_data',
350
- originalFileUrl: fileUrl,
351
- uploadedFileUUID: fileUUID,
352
- },
353
- method: 'POST',
354
- });
355
- }, {
356
- ...context,
357
- category: error_handling_1.ErrorCategory.EXTERNAL_API,
358
- severity: error_handling_1.ErrorSeverity.HIGH,
359
- });
360
- }
361
- /**
362
- * Get all households
363
- */
364
- async function getHouseholds(client, params, context) {
365
- const queryParams = {};
366
- if (params?.include) {
367
- queryParams.include = params.include.join(',');
368
- }
369
- if (params?.per_page) {
370
- queryParams.per_page = params.per_page;
371
- }
372
- if (params?.page) {
373
- queryParams.page = params.page;
374
- }
375
- return (0, core_1.getList)(client, '/households', queryParams, {
376
- ...context,
377
- endpoint: '/households',
378
- method: 'GET',
379
- });
380
- }
381
- /**
382
- * Get a single household by ID
383
- */
384
- async function getHousehold(client, id, include, context) {
385
- const params = {};
386
- if (include) {
387
- params.include = include.join(',');
388
- }
389
- return (0, core_1.getSingle)(client, `/households/${id}`, params, {
390
- ...context,
391
- endpoint: `/households/${id}`,
392
- householdId: id,
393
- method: 'GET',
394
- });
395
- }
396
- /**
397
- * Get field definitions
398
- */
399
- async function getFieldDefinitions(client, params, context) {
400
- const queryParams = {};
401
- if (params?.include) {
402
- queryParams.include = params.include.join(',');
403
- }
404
- if (params?.per_page) {
405
- queryParams.per_page = params.per_page;
406
- }
407
- if (params?.page) {
408
- queryParams.page = params.page;
409
- }
410
- return (0, core_1.getList)(client, '/field_definitions', queryParams, {
411
- ...context,
412
- endpoint: '/field_definitions',
413
- method: 'GET',
414
- });
415
- }
416
- /**
417
- * Get social profiles for a person
418
- */
419
- async function getPersonSocialProfiles(client, personId, context) {
420
- return (0, core_1.getList)(client, `/people/${personId}/social_profiles`, undefined, {
421
- ...context,
422
- endpoint: `/people/${personId}/social_profiles`,
423
- method: 'GET',
424
- personId,
425
- });
426
- }
427
- /**
428
- * Create a social profile for a person
429
- */
430
- async function createPersonSocialProfile(client, personId, data, context) {
431
- return (0, core_1.post)(client, `/people/${personId}/social_profiles`, data, undefined, {
432
- ...context,
433
- endpoint: `/people/${personId}/social_profiles`,
434
- method: 'POST',
435
- personId,
436
- });
437
- }
438
- /**
439
- * Get field options for a field definition
440
- */
441
- async function getFieldOptions(client, fieldDefinitionId, context) {
442
- return (0, core_1.getList)(client, `/field_definitions/${fieldDefinitionId}/field_options`, undefined, {
443
- ...context,
444
- endpoint: `/field_definitions/${fieldDefinitionId}/field_options`,
445
- fieldDefinitionId,
446
- method: 'GET',
447
- });
448
- }
449
- /**
450
- * Create a field option for a field definition
451
- */
452
- async function createFieldOption(client, fieldDefinitionId, data, context) {
453
- return (0, core_1.post)(client, `/field_definitions/${fieldDefinitionId}/field_options`, data, undefined, {
454
- ...context,
455
- endpoint: `/field_definitions/${fieldDefinitionId}/field_options`,
456
- fieldDefinitionId,
457
- method: 'POST',
458
- });
459
- }
460
- /**
461
- * List notes for a workflow card
462
- */
463
- async function getWorkflowCardNotes(client, personId, workflowCardId, context) {
464
- return (0, core_1.getList)(client, `/people/${personId}/workflow_cards/${workflowCardId}/notes`, undefined, {
465
- ...context,
466
- endpoint: `/people/${personId}/workflow_cards/${workflowCardId}/notes`,
467
- method: 'GET',
468
- personId,
469
- });
470
- }
471
- /**
472
- * Create a note for a workflow card
473
- */
474
- async function createWorkflowCardNote(client, personId, workflowCardId, data, context) {
475
- return (0, core_1.post)(client, `/people/${personId}/workflow_cards/${workflowCardId}/notes`, data, undefined, {
476
- ...context,
477
- endpoint: `/people/${personId}/workflow_cards/${workflowCardId}/notes`,
478
- method: 'POST',
479
- personId,
480
- });
481
- }
482
- /**
483
- * List workflow cards for a person
484
- */
485
- async function getWorkflowCards(client, personId, context) {
486
- return (0, core_1.getList)(client, `/people/${personId}/workflow_cards`, undefined, {
487
- ...context,
488
- endpoint: `/people/${personId}/workflow_cards`,
489
- method: 'GET',
490
- personId,
491
- });
492
- }
493
- /**
494
- * Create a workflow card in a workflow for a person
495
- */
496
- async function createWorkflowCard(client, workflowId, personId, context) {
497
- return (0, core_1.post)(client, `/workflows/${workflowId}/cards`, { person_id: personId }, undefined, {
498
- ...context,
499
- endpoint: `/workflows/${workflowId}/cards`,
500
- metadata: { ...(context?.metadata ?? {}), workflowId },
501
- method: 'POST',
502
- personId,
503
- });
504
- }
505
- // ===== List API Functions =====
506
- /**
507
- * Get all lists
508
- */
509
- async function getLists(client, params, context) {
510
- return (0, core_1.getList)(client, '/lists', buildQueryParams(params), {
511
- ...context,
512
- endpoint: '/lists',
513
- method: 'GET',
514
- });
515
- }
516
- /**
517
- * Get a single list
518
- */
519
- async function getListById(client, listId, params, context) {
520
- return (0, core_1.getSingle)(client, `/lists/${listId}`, buildQueryParams(params), {
521
- ...context,
522
- endpoint: `/lists/${listId}`,
523
- method: 'GET',
524
- });
525
- }
526
- /**
527
- * Get all list categories
528
- */
529
- async function getListCategories(client, params, context) {
530
- return (0, core_1.getList)(client, '/list_categories', buildQueryParams(params), {
531
- ...context,
532
- endpoint: '/list_categories',
533
- method: 'GET',
534
- });
535
- }
536
- // ===== Note API Functions =====
537
- /**
538
- * Get all notes
539
- */
540
- async function getNotes(client, params, context) {
541
- return (0, core_1.getList)(client, '/notes', buildQueryParams(params), {
542
- ...context,
543
- endpoint: '/notes',
544
- method: 'GET',
545
- });
546
- }
547
- /**
548
- * Get a single note
549
- */
550
- async function getNote(client, noteId, params, context) {
551
- return (0, core_1.getSingle)(client, `/notes/${noteId}`, buildQueryParams(params), {
552
- ...context,
553
- endpoint: `/notes/${noteId}`,
554
- method: 'GET',
555
- });
556
- }
557
- /**
558
- * Get all note categories
559
- */
560
- async function getNoteCategories(client, params, context) {
561
- return (0, core_1.getList)(client, '/note_categories', buildQueryParams(params), {
562
- ...context,
563
- endpoint: '/note_categories',
564
- method: 'GET',
565
- });
566
- }
567
- // ===== Workflow API Functions =====
568
- /**
569
- * Get all workflows
570
- */
571
- async function getWorkflows(client, params, context) {
572
- return (0, core_1.getList)(client, '/workflows', buildQueryParams(params), {
573
- ...context,
574
- endpoint: '/workflows',
575
- method: 'GET',
576
- });
577
- }
578
- /**
579
- * Get a single workflow
580
- */
581
- async function getWorkflow(client, workflowId, params, context) {
582
- return (0, core_1.getSingle)(client, `/workflows/${workflowId}`, buildQueryParams(params), {
583
- ...context,
584
- endpoint: `/workflows/${workflowId}`,
585
- method: 'GET',
586
- });
587
- }
588
- // ===== Organization API Functions =====
589
- /**
590
- * Get organization information
591
- */
592
- async function getOrganization(client, params, context) {
593
- return (0, core_1.getSingle)(client, '/', buildQueryParams(params), {
594
- ...context,
595
- endpoint: '/',
596
- method: 'GET',
597
- });
598
- }