mp-js-api 0.0.4 → 0.0.5

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 (52) hide show
  1. package/dist/api.d.ts +74 -0
  2. package/dist/api.d.ts.map +1 -0
  3. package/dist/api.js +158 -0
  4. package/dist/index.d.ts +51 -48
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +72 -317
  7. package/dist/tables/addresses.d.ts +0 -2
  8. package/dist/tables/addresses.d.ts.map +1 -1
  9. package/dist/tables/addresses.js +0 -58
  10. package/dist/tables/contact-attributes.d.ts +0 -2
  11. package/dist/tables/contact-attributes.d.ts.map +1 -1
  12. package/dist/tables/contact-attributes.js +0 -22
  13. package/dist/tables/contacts.d.ts +0 -2
  14. package/dist/tables/contacts.d.ts.map +1 -1
  15. package/dist/tables/contacts.js +0 -112
  16. package/dist/tables/event-participants.d.ts +0 -2
  17. package/dist/tables/event-participants.d.ts.map +1 -1
  18. package/dist/tables/event-participants.js +0 -50
  19. package/dist/tables/events.d.ts +0 -2
  20. package/dist/tables/events.d.ts.map +1 -1
  21. package/dist/tables/events.js +0 -120
  22. package/dist/tables/from-response-answers.d.ts +6 -6
  23. package/dist/tables/from-response-answers.d.ts.map +1 -1
  24. package/dist/tables/group-participants.d.ts +0 -2
  25. package/dist/tables/group-participants.d.ts.map +1 -1
  26. package/dist/tables/group-participants.js +0 -64
  27. package/dist/tables/groups.d.ts +0 -2
  28. package/dist/tables/groups.d.ts.map +1 -1
  29. package/dist/tables/groups.js +0 -106
  30. package/dist/tables/households.d.ts +0 -2
  31. package/dist/tables/households.d.ts.map +1 -1
  32. package/dist/tables/households.js +0 -58
  33. package/dist/tables/participants.d.ts +0 -2
  34. package/dist/tables/participants.d.ts.map +1 -1
  35. package/dist/tables/participants.js +0 -66
  36. package/dist/utils/strings.d.ts +14 -5
  37. package/dist/utils/strings.d.ts.map +1 -1
  38. package/dist/utils/strings.js +28 -15
  39. package/package.json +1 -1
  40. package/src/api.ts +266 -0
  41. package/src/index.ts +197 -435
  42. package/src/tables/addresses.ts +1 -59
  43. package/src/tables/contact-attributes.ts +0 -23
  44. package/src/tables/contacts.ts +0 -118
  45. package/src/tables/event-participants.ts +1 -51
  46. package/src/tables/events.ts +0 -119
  47. package/src/tables/from-response-answers.ts +6 -8
  48. package/src/tables/group-participants.ts +55 -119
  49. package/src/tables/groups.ts +1 -107
  50. package/src/tables/households.ts +0 -58
  51. package/src/tables/participants.ts +1 -67
  52. package/src/utils/strings.ts +31 -17
@@ -98,110 +98,4 @@ export interface Group {
98
98
  createNextMeeting: boolean;
99
99
  nextScheduledMeeting: null | string;
100
100
  availableOnApp: null | string;
101
- }
102
-
103
- export function mapGroupRecord(record: GroupRecord): Group {
104
- return {
105
- groupID: record.Group_ID,
106
- groupName: record.Group_Name,
107
- groupTypeID: record.Group_Type_ID,
108
- ministryID: record.Ministry_ID,
109
- congregationID: record.Congregation_ID,
110
- primaryContact: record.Primary_Contact,
111
- description: record.Description,
112
- startDate: record.Start_Date,
113
- endDate: record.End_Date,
114
- targetSize: record.Target_Size,
115
- parentGroup: record.Parent_Group,
116
- priorityID: record.Priority_ID,
117
- smallGroupInformation: record.Small_Group_Information,
118
- offsiteMeetingAddress: record.Offsite_Meeting_Address,
119
- groupIsFull: record.Group_Is_Full,
120
- availableOnline: record.Available_Online,
121
- meetsOnline: record.Meets_Online,
122
- lifeStageID: record.Life_Stage_ID,
123
- groupFocusID: record.Group_Focus_ID,
124
- meetingTime: record.Meeting_Time,
125
- meetingDayID: record.Meeting_Day_ID,
126
- meetingFrequencyID: record.Meeting_Frequency_ID,
127
- meetingDurationID: record.Meeting_Duration_ID,
128
- requiredBook: record.Required_Book,
129
- descendedFrom: record.Descended_From,
130
- reasonEnded: record.Reason_Ended,
131
- lastAttendancePosted: record._Last_Attendance_Posted,
132
- lastGroupMemberChanged: record._Last_Group_Member_Changed,
133
- checkInInformation: record.Check_in_Information,
134
- secureCheckIn: record.Secure_Check_in,
135
- suppressNametag: record.Suppress_Nametag,
136
- suppressCareNote: record.Suppress_Care_Note,
137
- onClassroomManager: record.On_Classroom_Manager,
138
- promotionInformation: record.Promotion_Information,
139
- promoteToGroup: record.Promote_to_Group,
140
- ageInMonthsToPromote: record.Age_in_Months_to_Promote,
141
- promoteWeekly: record.Promote_Weekly,
142
- promotionDate: record.Promotion_Date,
143
- promoteParticipantsOnly: record.Promote_Participants_Only,
144
- notifications: record.Notifications,
145
- sendAttendanceNotification: record.Send_Attendance_Notification,
146
- sendServiceNotification: record.Send_Service_Notification,
147
- enableDiscussion: record.Enable_Discussion,
148
- smsNumber: record.SMS_Number,
149
- defaultMeetingRoom: record.Default_Meeting_Room,
150
- createNextMeeting: record.Create_Next_Meeting,
151
- nextScheduledMeeting: record.Next_Scheduled_Meeting,
152
- availableOnApp: record.Available_On_App,
153
- };
154
- }
155
-
156
- export function mapGroupToGroupRecord(group: Group): GroupRecord {
157
- return {
158
- Group_ID: group.groupID,
159
- Group_Name: group.groupName,
160
- Group_Type_ID: group.groupTypeID,
161
- Ministry_ID: group.ministryID,
162
- Congregation_ID: group.congregationID,
163
- Primary_Contact: group.primaryContact,
164
- Description: group.description,
165
- Start_Date: group.startDate,
166
- End_Date: group.endDate,
167
- Target_Size: group.targetSize,
168
- Parent_Group: group.parentGroup,
169
- Priority_ID: group.priorityID,
170
- Small_Group_Information: group.smallGroupInformation,
171
- Offsite_Meeting_Address: group.offsiteMeetingAddress,
172
- Group_Is_Full: group.groupIsFull,
173
- Available_Online: group.availableOnline,
174
- Meets_Online: group.meetsOnline,
175
- Life_Stage_ID: group.lifeStageID,
176
- Group_Focus_ID: group.groupFocusID,
177
- Meeting_Time: group.meetingTime,
178
- Meeting_Day_ID: group.meetingDayID,
179
- Meeting_Frequency_ID: group.meetingFrequencyID,
180
- Meeting_Duration_ID: group.meetingDurationID,
181
- Required_Book: group.requiredBook,
182
- Descended_From: group.descendedFrom,
183
- Reason_Ended: group.reasonEnded,
184
- _Last_Attendance_Posted: group.lastAttendancePosted,
185
- _Last_Group_Member_Changed: group.lastGroupMemberChanged,
186
- Check_in_Information: group.checkInInformation,
187
- Secure_Check_in: group.secureCheckIn,
188
- Suppress_Nametag: group.suppressNametag,
189
- Suppress_Care_Note: group.suppressCareNote,
190
- On_Classroom_Manager: group.onClassroomManager,
191
- Promotion_Information: group.promotionInformation,
192
- Promote_to_Group: group.promoteToGroup,
193
- Age_in_Months_to_Promote: group.ageInMonthsToPromote,
194
- Promote_Weekly: group.promoteWeekly,
195
- Promotion_Date: group.promotionDate,
196
- Promote_Participants_Only: group.promoteParticipantsOnly,
197
- Notifications: group.notifications,
198
- Send_Attendance_Notification: group.sendAttendanceNotification,
199
- Send_Service_Notification: group.sendServiceNotification,
200
- Enable_Discussion: group.enableDiscussion,
201
- SMS_Number: group.smsNumber,
202
- Default_Meeting_Room: group.defaultMeetingRoom,
203
- Create_Next_Meeting: group.createNextMeeting,
204
- Next_Scheduled_Meeting: group.nextScheduledMeeting,
205
- Available_On_App: group.availableOnApp,
206
- };
207
- }
101
+ }
@@ -51,61 +51,3 @@ export interface Household {
51
51
  drivingDistance: null | string;
52
52
  drivingTime: null | string;
53
53
  }
54
-
55
- export function mapHouseholdRecord(householdRecord: HouseholdRecord): Household {
56
- return {
57
- householdID: householdRecord.Household_ID,
58
- householdName: householdRecord.Household_Name,
59
- addressID: householdRecord.Address_ID,
60
- homePhone: householdRecord.Home_Phone,
61
- congregationID: householdRecord.Congregation_ID,
62
- carePerson: householdRecord.Care_Person,
63
- householdSourceID: householdRecord.Household_Source_ID,
64
- familyCallNumber: householdRecord.Family_Call_Number,
65
- householdPreferences: householdRecord.Household_Preferences,
66
- homePhoneUnlisted: householdRecord.Home_Phone_Unlisted,
67
- homeAddressUnlisted: householdRecord.Home_Address_Unlisted,
68
- bulkMailOptOut: householdRecord.Bulk_Mail_Opt_Out,
69
- firstDonation: householdRecord._First_Donation,
70
- lastDonation: householdRecord._Last_Donation,
71
- lastActivity: householdRecord._Last_Activity,
72
- seasonalAlternateAddressSettings: householdRecord.Seasonal_Alternate_Address_Settings,
73
- alternateMailingAddress: householdRecord.Alternate_Mailing_Address,
74
- seasonStart: householdRecord.Season_Start,
75
- seasonEnd: householdRecord.Season_End,
76
- repeatsAnnually: householdRecord.Repeats_Annually,
77
- endSeasonalAlternateAddressSettings: householdRecord.End_Seasonal_Alternate_Address_Settings,
78
- congregationDriveTime: householdRecord.Congregation_Drive_Time,
79
- drivingDistance: householdRecord.Driving_Distance,
80
- drivingTime: householdRecord.Driving_Time,
81
- };
82
- }
83
-
84
- export function mapHouseholdToHouseholdRecord(household: Household): HouseholdRecord {
85
- return {
86
- Household_ID: household.householdID,
87
- Household_Name: household.householdName,
88
- Address_ID: household.addressID,
89
- Home_Phone: household.homePhone,
90
- Congregation_ID: household.congregationID,
91
- Care_Person: household.carePerson,
92
- Household_Source_ID: household.householdSourceID,
93
- Family_Call_Number: household.familyCallNumber,
94
- Household_Preferences: household.householdPreferences,
95
- Home_Phone_Unlisted: household.homePhoneUnlisted,
96
- Home_Address_Unlisted: household.homeAddressUnlisted,
97
- Bulk_Mail_Opt_Out: household.bulkMailOptOut,
98
- _First_Donation: household.firstDonation,
99
- _Last_Donation: household.lastDonation,
100
- _Last_Activity: household.lastActivity,
101
- Seasonal_Alternate_Address_Settings: household.seasonalAlternateAddressSettings,
102
- Alternate_Mailing_Address: household.alternateMailingAddress,
103
- Season_Start: household.seasonStart,
104
- Season_End: household.seasonEnd,
105
- Repeats_Annually: household.repeatsAnnually,
106
- End_Seasonal_Alternate_Address_Settings: household.endSeasonalAlternateAddressSettings,
107
- Congregation_Drive_Time: household.congregationDriveTime,
108
- Driving_Distance: household.drivingDistance,
109
- Driving_Time: household.drivingTime,
110
- };
111
- }
@@ -58,70 +58,4 @@ export interface Participant {
58
58
  birthCertificateAddress: null | string;
59
59
  birthCertificateCity: null | string;
60
60
  birthCertificateState: null | string;
61
- }
62
-
63
- export function mapParticipantRecord(record: ParticipantRecord): Participant {
64
- return {
65
- participantID: record.Participant_ID,
66
- redFlagNotes: record.Red_Flag_Notes,
67
- contactID: record.Contact_ID,
68
- participantTypeID: record.Participant_Type_ID,
69
- memberStatusID: record.Member_Status_ID,
70
- participantEngagementID: record.Participant_Engagement_ID,
71
- participantStartDate: record.Participant_Start_Date,
72
- participantEndDate: record.Participant_End_Date,
73
- notes: record.Notes,
74
- firstAttendanceEver: record._First_Attendance_Ever,
75
- secondAttendanceEver: record._Second_Attendance_Ever,
76
- thirdAttendanceEver: record._Third_Attendance_Ever,
77
- lastAttendanceEver: record._Last_Attendance_Ever,
78
- subStatusName: record.SubStatus_Name,
79
- statusDate: record.Status_Date,
80
- formerDenomination: record.Former_Denomination,
81
- formerChurch: record.Former_Church,
82
- backgroundCheckInformation: record._Background_Check_Information,
83
- backgroundCheckType: record._Background_Check_Type,
84
- backgroundCheckStatus: record._Background_Check_Status,
85
- backgroundCheckDate: record._Background_Check_Date,
86
- sacramentInformation: record.Sacrament_Information,
87
- churchOfRecord: record.Church_of_Record,
88
- baptismParishName: record.Baptism_Parish_Name,
89
- baptismParishAddress: record.Baptism_Parish_Address,
90
- birthCertificateAddress: record.Birth_Certificate_Address,
91
- birthCertificateCity: record.Birth_Certificate_City,
92
- birthCertificateState: record.Birth_Certificate_State,
93
- };
94
- }
95
-
96
- export function mapParticipantToParticipantRecord(participant: Participant): ParticipantRecord {
97
- return {
98
- Participant_ID: participant.participantID,
99
- Red_Flag_Notes: participant.redFlagNotes,
100
- Contact_ID: participant.contactID,
101
- Participant_Type_ID: participant.participantTypeID,
102
- Member_Status_ID: participant.memberStatusID,
103
- Participant_Engagement_ID: participant.participantEngagementID,
104
- Participant_Start_Date: participant.participantStartDate,
105
- Participant_End_Date: participant.participantEndDate,
106
- Notes: participant.notes,
107
- _First_Attendance_Ever: participant.firstAttendanceEver,
108
- _Second_Attendance_Ever: participant.secondAttendanceEver,
109
- _Third_Attendance_Ever: participant.thirdAttendanceEver,
110
- _Last_Attendance_Ever: participant.lastAttendanceEver,
111
- SubStatus_Name: participant.subStatusName,
112
- Status_Date: participant.statusDate,
113
- Former_Denomination: participant.formerDenomination,
114
- Former_Church: participant.formerChurch,
115
- _Background_Check_Information: participant.backgroundCheckInformation,
116
- _Background_Check_Type: participant.backgroundCheckType,
117
- _Background_Check_Status: participant.backgroundCheckStatus,
118
- _Background_Check_Date: participant.backgroundCheckDate,
119
- Sacrament_Information: participant.sacramentInformation,
120
- Church_of_Record: participant.churchOfRecord,
121
- Baptism_Parish_Name: participant.baptismParishName,
122
- Baptism_Parish_Address: participant.baptismParishAddress,
123
- Birth_Certificate_Address: participant.birthCertificateAddress,
124
- Birth_Certificate_City: participant.birthCertificateCity,
125
- Birth_Certificate_State: participant.birthCertificateState,
126
- };
127
- }
61
+ }
@@ -1,3 +1,15 @@
1
+ export function stringifyURLParams<T = any>(mpOptions: Record<string, T> = {}) {
2
+ return escapeSql(Object.entries(mpOptions).reduce((acc, [key, value]) => {
3
+ if (!acc) {
4
+ acc += `?$${key}=${value}`;
5
+ } else {
6
+ acc += `&$${key}=${value}`;
7
+ }
8
+ return acc;
9
+ }, ''));
10
+ }
11
+
12
+
1
13
  export function escapeSql(str: string) {
2
14
  return str.replace(/%|(?<=\w)'(?=\w)/g, function (char: string) {
3
15
  switch (char) {
@@ -29,33 +41,34 @@ export function escapeSql(str: string) {
29
41
 
30
42
 
31
43
 
32
- export function toCamelCase(str: string) {
33
- str = str.replace(/((?<=^_|^__))[^\W_]/g, match => match.at(-1)?.toLowerCase() || ''); // keep underscore if first char
34
- str = str.replace(/(?<!^_|^)_[^\W_]/g, match => match.charAt(1).toUpperCase()); // remove underscore if not first char
35
- str = str.charAt(0).toLowerCase() + str.slice(1);
36
- return str.replace(/id$/i, 'ID');
44
+ export function toCamelCase(str: string, { capitalIds = false }: { capitalIds?: boolean; }= {}) {
45
+ str = str.replace('-', '')
46
+ str = str.replace(/^_?[A-Z]{1,3}/, match => match.toLowerCase()); // Don't convert if start with ID, HS, SMS, etc
47
+ str = str.replace(/(?<=^_|^__)[^\W_]/g, match => match.at(-1)?.toLowerCase() || ''); // keep underscore if first char
48
+ str = str.replace(/(?<!^_|^)_[^\W_]/g, match => match.charAt(1).toUpperCase()); // remove underscore if not first char
49
+ return capitalIds ? str.replace(/id$/i, 'ID') : str;
37
50
  }
38
51
 
39
- export function toCapitalSnakeCase(str: string) {
52
+ export function toCapitalSnakeCase(str: string, { capitalIds = false, capitalSnake = true }: { capitalIds?: boolean, capitalSnake?: boolean; }= {}) {
40
53
  str = str.replace(/(?<=^_|^__)[^\W_]/, match => match.at(0)?.toUpperCase() || '');
41
54
  str = str.replace(/(?<!_|\/)(ID|[A-Z])/g, match => `_${match}`);
42
- str = str.charAt(0).toUpperCase() + str.slice(1);
43
- return str.replace(/_id$/i, '_ID');
55
+ str = capitalSnake ? str.charAt(0).toUpperCase() + str.slice(1) : str;
56
+ return capitalIds ? str.replace(/_id$/i, '_ID') : str;
44
57
  }
45
58
 
46
59
  // Function to recursively convert object keys to Capital_Snake_Case
47
- export function caseConverter<T>(obj: T, type: 'toCamel' | 'toSnake') {
60
+ export function caseConverter<T>(obj: T, { type, capitalIds = false }: { type: 'toCamel' | 'toSnake', capitalIds?: boolean; }) {
48
61
  const caseFn = type === 'toCamel' ? toCamelCase : toCapitalSnakeCase;
49
62
  if (Array.isArray(obj)) {
50
- return obj.map(val => caseConverter(val, type)); // Recursively process each array element
63
+ return obj.map(val => caseConverter(val, { type })); // Recursively process each array element
51
64
  }
52
65
 
53
66
  if (obj !== null && typeof obj === 'object') {
54
67
  const snakeCaseObj = {};
55
68
  for (const key in obj) {
56
69
  if (obj.hasOwnProperty(key)) {
57
- const snakeCaseKey = caseFn(key); // Convert key to Snake_Case
58
- snakeCaseObj[snakeCaseKey] = caseConverter(obj[key], type); // Recursively process nested objects
70
+ const snakeCaseKey = caseFn(key, { capitalIds }); // Convert key to Snake_Case
71
+ snakeCaseObj[snakeCaseKey] = caseConverter(obj[key], { type }); // Recursively process nested objects
59
72
  }
60
73
  }
61
74
  return snakeCaseObj;
@@ -64,10 +77,11 @@ export function caseConverter<T>(obj: T, type: 'toCamel' | 'toSnake') {
64
77
  return obj; // Return value if it's neither an array nor an object
65
78
  }
66
79
 
67
- export function convertToCamelCase<T = any, R = any>(obj: T): R {
68
- return caseConverter(obj, 'toCamel');
80
+ export function convertToCamelCase<T = any, R = any>(obj: Partial<T>, capitalIds = true): R {
81
+ return caseConverter(obj, { type: 'toCamel', capitalIds });
82
+ }
83
+
84
+ export function convertToSnakeCase<T = any, R = any>(obj: Partial<T>, capitalIds = true): R {
85
+ return caseConverter(obj, { type: 'toSnake', capitalIds });
69
86
  }
70
87
 
71
- export function convertToSnakeCase<T = any, R = any>(obj: T): R {
72
- return caseConverter(obj, 'toSnake');
73
- }