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.
- package/dist/api.d.ts +74 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +158 -0
- package/dist/index.d.ts +51 -48
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +72 -317
- package/dist/tables/addresses.d.ts +0 -2
- package/dist/tables/addresses.d.ts.map +1 -1
- package/dist/tables/addresses.js +0 -58
- package/dist/tables/contact-attributes.d.ts +0 -2
- package/dist/tables/contact-attributes.d.ts.map +1 -1
- package/dist/tables/contact-attributes.js +0 -22
- package/dist/tables/contacts.d.ts +0 -2
- package/dist/tables/contacts.d.ts.map +1 -1
- package/dist/tables/contacts.js +0 -112
- package/dist/tables/event-participants.d.ts +0 -2
- package/dist/tables/event-participants.d.ts.map +1 -1
- package/dist/tables/event-participants.js +0 -50
- package/dist/tables/events.d.ts +0 -2
- package/dist/tables/events.d.ts.map +1 -1
- package/dist/tables/events.js +0 -120
- package/dist/tables/from-response-answers.d.ts +6 -6
- package/dist/tables/from-response-answers.d.ts.map +1 -1
- package/dist/tables/group-participants.d.ts +0 -2
- package/dist/tables/group-participants.d.ts.map +1 -1
- package/dist/tables/group-participants.js +0 -64
- package/dist/tables/groups.d.ts +0 -2
- package/dist/tables/groups.d.ts.map +1 -1
- package/dist/tables/groups.js +0 -106
- package/dist/tables/households.d.ts +0 -2
- package/dist/tables/households.d.ts.map +1 -1
- package/dist/tables/households.js +0 -58
- package/dist/tables/participants.d.ts +0 -2
- package/dist/tables/participants.d.ts.map +1 -1
- package/dist/tables/participants.js +0 -66
- package/dist/utils/strings.d.ts +14 -5
- package/dist/utils/strings.d.ts.map +1 -1
- package/dist/utils/strings.js +28 -15
- package/package.json +1 -1
- package/src/api.ts +266 -0
- package/src/index.ts +197 -435
- package/src/tables/addresses.ts +1 -59
- package/src/tables/contact-attributes.ts +0 -23
- package/src/tables/contacts.ts +0 -118
- package/src/tables/event-participants.ts +1 -51
- package/src/tables/events.ts +0 -119
- package/src/tables/from-response-answers.ts +6 -8
- package/src/tables/group-participants.ts +55 -119
- package/src/tables/groups.ts +1 -107
- package/src/tables/households.ts +0 -58
- package/src/tables/participants.ts +1 -67
- package/src/utils/strings.ts +31 -17
|
@@ -1,60 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mapHouseholdRecord = mapHouseholdRecord;
|
|
4
|
-
exports.mapHouseholdToHouseholdRecord = mapHouseholdToHouseholdRecord;
|
|
5
|
-
function mapHouseholdRecord(householdRecord) {
|
|
6
|
-
return {
|
|
7
|
-
householdID: householdRecord.Household_ID,
|
|
8
|
-
householdName: householdRecord.Household_Name,
|
|
9
|
-
addressID: householdRecord.Address_ID,
|
|
10
|
-
homePhone: householdRecord.Home_Phone,
|
|
11
|
-
congregationID: householdRecord.Congregation_ID,
|
|
12
|
-
carePerson: householdRecord.Care_Person,
|
|
13
|
-
householdSourceID: householdRecord.Household_Source_ID,
|
|
14
|
-
familyCallNumber: householdRecord.Family_Call_Number,
|
|
15
|
-
householdPreferences: householdRecord.Household_Preferences,
|
|
16
|
-
homePhoneUnlisted: householdRecord.Home_Phone_Unlisted,
|
|
17
|
-
homeAddressUnlisted: householdRecord.Home_Address_Unlisted,
|
|
18
|
-
bulkMailOptOut: householdRecord.Bulk_Mail_Opt_Out,
|
|
19
|
-
firstDonation: householdRecord._First_Donation,
|
|
20
|
-
lastDonation: householdRecord._Last_Donation,
|
|
21
|
-
lastActivity: householdRecord._Last_Activity,
|
|
22
|
-
seasonalAlternateAddressSettings: householdRecord.Seasonal_Alternate_Address_Settings,
|
|
23
|
-
alternateMailingAddress: householdRecord.Alternate_Mailing_Address,
|
|
24
|
-
seasonStart: householdRecord.Season_Start,
|
|
25
|
-
seasonEnd: householdRecord.Season_End,
|
|
26
|
-
repeatsAnnually: householdRecord.Repeats_Annually,
|
|
27
|
-
endSeasonalAlternateAddressSettings: householdRecord.End_Seasonal_Alternate_Address_Settings,
|
|
28
|
-
congregationDriveTime: householdRecord.Congregation_Drive_Time,
|
|
29
|
-
drivingDistance: householdRecord.Driving_Distance,
|
|
30
|
-
drivingTime: householdRecord.Driving_Time,
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
function mapHouseholdToHouseholdRecord(household) {
|
|
34
|
-
return {
|
|
35
|
-
Household_ID: household.householdID,
|
|
36
|
-
Household_Name: household.householdName,
|
|
37
|
-
Address_ID: household.addressID,
|
|
38
|
-
Home_Phone: household.homePhone,
|
|
39
|
-
Congregation_ID: household.congregationID,
|
|
40
|
-
Care_Person: household.carePerson,
|
|
41
|
-
Household_Source_ID: household.householdSourceID,
|
|
42
|
-
Family_Call_Number: household.familyCallNumber,
|
|
43
|
-
Household_Preferences: household.householdPreferences,
|
|
44
|
-
Home_Phone_Unlisted: household.homePhoneUnlisted,
|
|
45
|
-
Home_Address_Unlisted: household.homeAddressUnlisted,
|
|
46
|
-
Bulk_Mail_Opt_Out: household.bulkMailOptOut,
|
|
47
|
-
_First_Donation: household.firstDonation,
|
|
48
|
-
_Last_Donation: household.lastDonation,
|
|
49
|
-
_Last_Activity: household.lastActivity,
|
|
50
|
-
Seasonal_Alternate_Address_Settings: household.seasonalAlternateAddressSettings,
|
|
51
|
-
Alternate_Mailing_Address: household.alternateMailingAddress,
|
|
52
|
-
Season_Start: household.seasonStart,
|
|
53
|
-
Season_End: household.seasonEnd,
|
|
54
|
-
Repeats_Annually: household.repeatsAnnually,
|
|
55
|
-
End_Seasonal_Alternate_Address_Settings: household.endSeasonalAlternateAddressSettings,
|
|
56
|
-
Congregation_Drive_Time: household.congregationDriveTime,
|
|
57
|
-
Driving_Distance: household.drivingDistance,
|
|
58
|
-
Driving_Time: household.drivingTime,
|
|
59
|
-
};
|
|
60
|
-
}
|
|
@@ -58,6 +58,4 @@ export interface Participant {
|
|
|
58
58
|
birthCertificateCity: null | string;
|
|
59
59
|
birthCertificateState: null | string;
|
|
60
60
|
}
|
|
61
|
-
export declare function mapParticipantRecord(record: ParticipantRecord): Participant;
|
|
62
|
-
export declare function mapParticipantToParticipantRecord(participant: Participant): ParticipantRecord;
|
|
63
61
|
//# sourceMappingURL=participants.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"participants.d.ts","sourceRoot":"","sources":["../../src/tables/participants.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,iBAAiB;IAC9B,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,IAAI,GAAG,MAAM,CAAC;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,gBAAgB,EAAE,IAAI,GAAG,MAAM,CAAC;IAChC,yBAAyB,EAAE,MAAM,CAAC;IAClC,sBAAsB,EAAE,MAAM,CAAC;IAC/B,oBAAoB,EAAE,IAAI,GAAG,MAAM,CAAC;IACpC,KAAK,EAAE,MAAM,CAAC;IACd,sBAAsB,EAAE,IAAI,GAAG,MAAM,CAAC;IACtC,uBAAuB,EAAE,IAAI,GAAG,MAAM,CAAC;IACvC,sBAAsB,EAAE,IAAI,GAAG,MAAM,CAAC;IACtC,qBAAqB,EAAE,IAAI,GAAG,MAAM,CAAC;IACrC,cAAc,EAAE,IAAI,GAAG,MAAM,CAAC;IAC9B,WAAW,EAAE,IAAI,GAAG,MAAM,CAAC;IAC3B,mBAAmB,EAAE,IAAI,GAAG,MAAM,CAAC;IACnC,aAAa,EAAE,IAAI,GAAG,MAAM,CAAC;IAC7B,6BAA6B,EAAE,IAAI,GAAG,MAAM,CAAC;IAC7C,sBAAsB,EAAE,IAAI,GAAG,MAAM,CAAC;IACtC,wBAAwB,EAAE,IAAI,GAAG,MAAM,CAAC;IACxC,sBAAsB,EAAE,IAAI,GAAG,MAAM,CAAC;IACtC,qBAAqB,EAAE,IAAI,GAAG,MAAM,CAAC;IACrC,gBAAgB,EAAE,IA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B,EAAE,IAAI,GAAG,MAAM,CAAC;IACjC,oBAAoB,EAAE,IAAI,GAAG,MAAM,CAAC;IACpC,uBAAuB,EAAE,IAAI,GAAG,MAAM,CAAC;IACvC,oBAAoB,EAAE,IAAI,GAAG,MAAM,CAAC;IACpC,qBAAqB,EAAE,IAAI,GAAG,MAAM,CAAC;CACxC"}
|
|
@@ -1,68 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mapParticipantRecord = mapParticipantRecord;
|
|
4
|
-
exports.mapParticipantToParticipantRecord = mapParticipantToParticipantRecord;
|
|
5
|
-
function mapParticipantRecord(record) {
|
|
6
|
-
return {
|
|
7
|
-
participantID: record.Participant_ID,
|
|
8
|
-
redFlagNotes: record.Red_Flag_Notes,
|
|
9
|
-
contactID: record.Contact_ID,
|
|
10
|
-
participantTypeID: record.Participant_Type_ID,
|
|
11
|
-
memberStatusID: record.Member_Status_ID,
|
|
12
|
-
participantEngagementID: record.Participant_Engagement_ID,
|
|
13
|
-
participantStartDate: record.Participant_Start_Date,
|
|
14
|
-
participantEndDate: record.Participant_End_Date,
|
|
15
|
-
notes: record.Notes,
|
|
16
|
-
firstAttendanceEver: record._First_Attendance_Ever,
|
|
17
|
-
secondAttendanceEver: record._Second_Attendance_Ever,
|
|
18
|
-
thirdAttendanceEver: record._Third_Attendance_Ever,
|
|
19
|
-
lastAttendanceEver: record._Last_Attendance_Ever,
|
|
20
|
-
subStatusName: record.SubStatus_Name,
|
|
21
|
-
statusDate: record.Status_Date,
|
|
22
|
-
formerDenomination: record.Former_Denomination,
|
|
23
|
-
formerChurch: record.Former_Church,
|
|
24
|
-
backgroundCheckInformation: record._Background_Check_Information,
|
|
25
|
-
backgroundCheckType: record._Background_Check_Type,
|
|
26
|
-
backgroundCheckStatus: record._Background_Check_Status,
|
|
27
|
-
backgroundCheckDate: record._Background_Check_Date,
|
|
28
|
-
sacramentInformation: record.Sacrament_Information,
|
|
29
|
-
churchOfRecord: record.Church_of_Record,
|
|
30
|
-
baptismParishName: record.Baptism_Parish_Name,
|
|
31
|
-
baptismParishAddress: record.Baptism_Parish_Address,
|
|
32
|
-
birthCertificateAddress: record.Birth_Certificate_Address,
|
|
33
|
-
birthCertificateCity: record.Birth_Certificate_City,
|
|
34
|
-
birthCertificateState: record.Birth_Certificate_State,
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
function mapParticipantToParticipantRecord(participant) {
|
|
38
|
-
return {
|
|
39
|
-
Participant_ID: participant.participantID,
|
|
40
|
-
Red_Flag_Notes: participant.redFlagNotes,
|
|
41
|
-
Contact_ID: participant.contactID,
|
|
42
|
-
Participant_Type_ID: participant.participantTypeID,
|
|
43
|
-
Member_Status_ID: participant.memberStatusID,
|
|
44
|
-
Participant_Engagement_ID: participant.participantEngagementID,
|
|
45
|
-
Participant_Start_Date: participant.participantStartDate,
|
|
46
|
-
Participant_End_Date: participant.participantEndDate,
|
|
47
|
-
Notes: participant.notes,
|
|
48
|
-
_First_Attendance_Ever: participant.firstAttendanceEver,
|
|
49
|
-
_Second_Attendance_Ever: participant.secondAttendanceEver,
|
|
50
|
-
_Third_Attendance_Ever: participant.thirdAttendanceEver,
|
|
51
|
-
_Last_Attendance_Ever: participant.lastAttendanceEver,
|
|
52
|
-
SubStatus_Name: participant.subStatusName,
|
|
53
|
-
Status_Date: participant.statusDate,
|
|
54
|
-
Former_Denomination: participant.formerDenomination,
|
|
55
|
-
Former_Church: participant.formerChurch,
|
|
56
|
-
_Background_Check_Information: participant.backgroundCheckInformation,
|
|
57
|
-
_Background_Check_Type: participant.backgroundCheckType,
|
|
58
|
-
_Background_Check_Status: participant.backgroundCheckStatus,
|
|
59
|
-
_Background_Check_Date: participant.backgroundCheckDate,
|
|
60
|
-
Sacrament_Information: participant.sacramentInformation,
|
|
61
|
-
Church_of_Record: participant.churchOfRecord,
|
|
62
|
-
Baptism_Parish_Name: participant.baptismParishName,
|
|
63
|
-
Baptism_Parish_Address: participant.baptismParishAddress,
|
|
64
|
-
Birth_Certificate_Address: participant.birthCertificateAddress,
|
|
65
|
-
Birth_Certificate_City: participant.birthCertificateCity,
|
|
66
|
-
Birth_Certificate_State: participant.birthCertificateState,
|
|
67
|
-
};
|
|
68
|
-
}
|
package/dist/utils/strings.d.ts
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
|
+
export declare function stringifyURLParams<T = any>(mpOptions?: Record<string, T>): string;
|
|
1
2
|
export declare function escapeSql(str: string): string;
|
|
2
|
-
export declare function toCamelCase(str: string
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export declare function
|
|
6
|
-
|
|
3
|
+
export declare function toCamelCase(str: string, { capitalIds }?: {
|
|
4
|
+
capitalIds?: boolean;
|
|
5
|
+
}): string;
|
|
6
|
+
export declare function toCapitalSnakeCase(str: string, { capitalIds, capitalSnake }?: {
|
|
7
|
+
capitalIds?: boolean;
|
|
8
|
+
capitalSnake?: boolean;
|
|
9
|
+
}): string;
|
|
10
|
+
export declare function caseConverter<T>(obj: T, { type, capitalIds }: {
|
|
11
|
+
type: 'toCamel' | 'toSnake';
|
|
12
|
+
capitalIds?: boolean;
|
|
13
|
+
}): any;
|
|
14
|
+
export declare function convertToCamelCase<T = any, R = any>(obj: Partial<T>, capitalIds?: boolean): R;
|
|
15
|
+
export declare function convertToSnakeCase<T = any, R = any>(obj: Partial<T>, capitalIds?: boolean): R;
|
|
7
16
|
//# sourceMappingURL=strings.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"strings.d.ts","sourceRoot":"","sources":["../../src/utils/strings.ts"],"names":[],"mappings":"AAAA,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,UA2BpC;AAID,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"strings.d.ts","sourceRoot":"","sources":["../../src/utils/strings.ts"],"names":[],"mappings":"AAAA,wBAAgB,kBAAkB,CAAC,CAAC,GAAG,GAAG,EAAE,SAAS,GAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAM,UAS5E;AAGD,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,UA2BpC;AAID,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,UAAkB,EAAE,GAAE;IAAE,UAAU,CAAC,EAAE,OAAO,CAAC;CAAM,UAM7F;AAED,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,UAAkB,EAAE,YAAmB,EAAE,GAAE;IAAE,UAAU,CAAC,EAAE,OAAO,CAAC;IAAC,YAAY,CAAC,EAAE,OAAO,CAAC;CAAM,UAKjJ;AAGD,wBAAgB,aAAa,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,UAAkB,EAAE,EAAE;IAAE,IAAI,EAAE,SAAS,GAAG,SAAS,CAAC;IAAC,UAAU,CAAC,EAAE,OAAO,CAAC;CAAE,OAkB5H;AAED,wBAAgB,kBAAkB,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,UAAU,UAAO,GAAG,CAAC,CAE1F;AAED,wBAAgB,kBAAkB,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,UAAU,UAAO,GAAG,CAAC,CAE1F"}
|
package/dist/utils/strings.js
CHANGED
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stringifyURLParams = stringifyURLParams;
|
|
3
4
|
exports.escapeSql = escapeSql;
|
|
4
5
|
exports.toCamelCase = toCamelCase;
|
|
5
6
|
exports.toCapitalSnakeCase = toCapitalSnakeCase;
|
|
6
7
|
exports.caseConverter = caseConverter;
|
|
7
8
|
exports.convertToCamelCase = convertToCamelCase;
|
|
8
9
|
exports.convertToSnakeCase = convertToSnakeCase;
|
|
10
|
+
function stringifyURLParams(mpOptions = {}) {
|
|
11
|
+
return escapeSql(Object.entries(mpOptions).reduce((acc, [key, value]) => {
|
|
12
|
+
if (!acc) {
|
|
13
|
+
acc += `?$${key}=${value}`;
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
acc += `&$${key}=${value}`;
|
|
17
|
+
}
|
|
18
|
+
return acc;
|
|
19
|
+
}, ''));
|
|
20
|
+
}
|
|
9
21
|
function escapeSql(str) {
|
|
10
22
|
return str.replace(/%|(?<=\w)'(?=\w)/g, function (char) {
|
|
11
23
|
switch (char) {
|
|
@@ -34,39 +46,40 @@ function escapeSql(str) {
|
|
|
34
46
|
}
|
|
35
47
|
});
|
|
36
48
|
}
|
|
37
|
-
function toCamelCase(str) {
|
|
38
|
-
str = str.replace(
|
|
49
|
+
function toCamelCase(str, { capitalIds = false } = {}) {
|
|
50
|
+
str = str.replace('-', '');
|
|
51
|
+
str = str.replace(/^_?[A-Z]{1,3}/, match => match.toLowerCase()); // Don't convert if start with ID, HS, SMS, etc
|
|
52
|
+
str = str.replace(/(?<=^_|^__)[^\W_]/g, match => match.at(-1)?.toLowerCase() || ''); // keep underscore if first char
|
|
39
53
|
str = str.replace(/(?<!^_|^)_[^\W_]/g, match => match.charAt(1).toUpperCase()); // remove underscore if not first char
|
|
40
|
-
|
|
41
|
-
return str.replace(/id$/i, 'ID');
|
|
54
|
+
return capitalIds ? str.replace(/id$/i, 'ID') : str;
|
|
42
55
|
}
|
|
43
|
-
function toCapitalSnakeCase(str) {
|
|
56
|
+
function toCapitalSnakeCase(str, { capitalIds = false, capitalSnake = true } = {}) {
|
|
44
57
|
str = str.replace(/(?<=^_|^__)[^\W_]/, match => match.at(0)?.toUpperCase() || '');
|
|
45
58
|
str = str.replace(/(?<!_|\/)(ID|[A-Z])/g, match => `_${match}`);
|
|
46
|
-
str = str.charAt(0).toUpperCase() + str.slice(1);
|
|
47
|
-
return str.replace(/_id$/i, '_ID');
|
|
59
|
+
str = capitalSnake ? str.charAt(0).toUpperCase() + str.slice(1) : str;
|
|
60
|
+
return capitalIds ? str.replace(/_id$/i, '_ID') : str;
|
|
48
61
|
}
|
|
49
62
|
// Function to recursively convert object keys to Capital_Snake_Case
|
|
50
|
-
function caseConverter(obj, type) {
|
|
63
|
+
function caseConverter(obj, { type, capitalIds = false }) {
|
|
51
64
|
const caseFn = type === 'toCamel' ? toCamelCase : toCapitalSnakeCase;
|
|
52
65
|
if (Array.isArray(obj)) {
|
|
53
|
-
return obj.map(val => caseConverter(val, type)); // Recursively process each array element
|
|
66
|
+
return obj.map(val => caseConverter(val, { type })); // Recursively process each array element
|
|
54
67
|
}
|
|
55
68
|
if (obj !== null && typeof obj === 'object') {
|
|
56
69
|
const snakeCaseObj = {};
|
|
57
70
|
for (const key in obj) {
|
|
58
71
|
if (obj.hasOwnProperty(key)) {
|
|
59
|
-
const snakeCaseKey = caseFn(key); // Convert key to Snake_Case
|
|
60
|
-
snakeCaseObj[snakeCaseKey] = caseConverter(obj[key], type); // Recursively process nested objects
|
|
72
|
+
const snakeCaseKey = caseFn(key, { capitalIds }); // Convert key to Snake_Case
|
|
73
|
+
snakeCaseObj[snakeCaseKey] = caseConverter(obj[key], { type }); // Recursively process nested objects
|
|
61
74
|
}
|
|
62
75
|
}
|
|
63
76
|
return snakeCaseObj;
|
|
64
77
|
}
|
|
65
78
|
return obj; // Return value if it's neither an array nor an object
|
|
66
79
|
}
|
|
67
|
-
function convertToCamelCase(obj) {
|
|
68
|
-
return caseConverter(obj, 'toCamel');
|
|
80
|
+
function convertToCamelCase(obj, capitalIds = true) {
|
|
81
|
+
return caseConverter(obj, { type: 'toCamel', capitalIds });
|
|
69
82
|
}
|
|
70
|
-
function convertToSnakeCase(obj) {
|
|
71
|
-
return caseConverter(obj, 'toSnake');
|
|
83
|
+
function convertToSnakeCase(obj, capitalIds = true) {
|
|
84
|
+
return caseConverter(obj, { type: 'toSnake', capitalIds });
|
|
72
85
|
}
|
package/package.json
CHANGED
package/src/api.ts
ADDED
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import axios, { AxiosError, AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
2
|
+
import { URLSearchParams } from 'url';
|
|
3
|
+
import { convertToCamelCase, convertToSnakeCase, stringifyURLParams } from './utils/strings';
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
export type APIGetOneInstance = <T, R>({ id, path, mpOptions, config }: APIGetParameter & { id: number; }) => Promise<R | undefined | { error: ErrorDetails; }>;
|
|
7
|
+
export type APIGetMultipleInstance = <T, R>({ path, mpOptions, config }: APIGetParameter) => Promise<R[] | { error: ErrorDetails; }>;
|
|
8
|
+
export type APICreateInstance = <T, R>({ path, mpOptions, params, config }: APICreateParameter<T>) => Promise<R | { error: ErrorDetails; }>;
|
|
9
|
+
export type APIUpdateInstance = <T, R>({ path, mpOptions, params, config }: APIUpdateParameter<T>) => Promise<R[] | { error: ErrorDetails; }>;
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
export interface MPApiBase {
|
|
13
|
+
getOne: APIGetOneInstance;
|
|
14
|
+
getMultiple: APIGetMultipleInstance;
|
|
15
|
+
create: APICreateInstance;
|
|
16
|
+
update: APIUpdateInstance;
|
|
17
|
+
get: AxiosInstance['get'];
|
|
18
|
+
post: AxiosInstance['post'];
|
|
19
|
+
put: AxiosInstance['put'];
|
|
20
|
+
getError: (error: AxiosError) => ErrorDetails;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface ErrorDetails {
|
|
24
|
+
message: string;
|
|
25
|
+
name: string;
|
|
26
|
+
code?: string;
|
|
27
|
+
status?: number;
|
|
28
|
+
method?: string;
|
|
29
|
+
url?: string;
|
|
30
|
+
data: string;
|
|
31
|
+
error: true;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
const createTokenGetter = (auth: { username: string; password: string; }) => {
|
|
36
|
+
let token: AccessToken | undefined;
|
|
37
|
+
|
|
38
|
+
return async () => {
|
|
39
|
+
// If the token is near expiration, get a new one.
|
|
40
|
+
if (!token || token.expiration - 60000 < Date.now()) {
|
|
41
|
+
const tokenRes = await axios.post<TokenData>(
|
|
42
|
+
'https://mp.revival.com/ministryplatformapi/oauth/connect/token',
|
|
43
|
+
new URLSearchParams({
|
|
44
|
+
grant_type: 'client_credentials',
|
|
45
|
+
scope: 'http://www.thinkministry.com/dataplatform/scopes/all',
|
|
46
|
+
}).toString(),
|
|
47
|
+
{ auth }
|
|
48
|
+
);
|
|
49
|
+
const [, payload] = tokenRes.data.access_token.split('.');
|
|
50
|
+
try {
|
|
51
|
+
const jsonPayload: { exp: number; } = JSON.parse(
|
|
52
|
+
Buffer.from(payload, 'base64url').toString()
|
|
53
|
+
);
|
|
54
|
+
token = {
|
|
55
|
+
digest: tokenRes.data.access_token,
|
|
56
|
+
expiration: jsonPayload.exp * 1000,
|
|
57
|
+
};
|
|
58
|
+
return token.digest;
|
|
59
|
+
} catch (err) {
|
|
60
|
+
console.error(err);
|
|
61
|
+
}
|
|
62
|
+
} else {
|
|
63
|
+
return token.digest;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export const createApiBase = ({ auth }: { auth: { username: string; password: string; }; }): MPApiBase => {
|
|
69
|
+
/**
|
|
70
|
+
* Gets MP oauth token.
|
|
71
|
+
* @returns token
|
|
72
|
+
*/
|
|
73
|
+
const getToken = createTokenGetter(auth);
|
|
74
|
+
const api = axios.create({
|
|
75
|
+
baseURL: 'https://mp.revival.com/ministryplatformapi',
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
const getOne: APIGetOneInstance = async <T, R>({ id, path, mpOptions, config }) => {
|
|
79
|
+
try {
|
|
80
|
+
const url = `${path}/${id}` + stringifyURLParams(mpOptions);
|
|
81
|
+
const res = await api.get<T>(url, {
|
|
82
|
+
...config,
|
|
83
|
+
headers: {
|
|
84
|
+
...config?.headers,
|
|
85
|
+
Authorization: `Bearer ${await getToken()}`,
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
return res.data[0] ? convertToCamelCase<T, R>(res.data[0]) : undefined;
|
|
89
|
+
}
|
|
90
|
+
catch (err) {
|
|
91
|
+
return { error: getError(err) };
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const getMultiple: APIGetMultipleInstance = async <T, R>({ path, mpOptions, config }: APIGetParameter) => {
|
|
96
|
+
try {
|
|
97
|
+
const url = path + stringifyURLParams(mpOptions);
|
|
98
|
+
const res = await api.get<T[]>(url, {
|
|
99
|
+
...config,
|
|
100
|
+
headers: {
|
|
101
|
+
...config?.headers,
|
|
102
|
+
Authorization: `Bearer ${await getToken()}`,
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
return res.data.map(record => convertToCamelCase<T, R>(record));
|
|
106
|
+
}
|
|
107
|
+
catch (err) {
|
|
108
|
+
return { error: getError(err) };
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
const create: APICreateInstance = async <T, R>({ path, mpOptions, params, config }: APICreateParameter<T>) => {
|
|
114
|
+
const query = stringifyURLParams(mpOptions);
|
|
115
|
+
const data = [convertToSnakeCase<T>(params)];
|
|
116
|
+
try {
|
|
117
|
+
const res = await api.post(path + query, data, {
|
|
118
|
+
...config,
|
|
119
|
+
headers: {
|
|
120
|
+
...config?.headers,
|
|
121
|
+
Authorization: `Bearer ${await getToken()}`,
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
return convertToCamelCase<any, R>(res.data[0]);
|
|
125
|
+
}
|
|
126
|
+
catch (err) {
|
|
127
|
+
return { error: getError(err) };
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
const update: APIUpdateInstance = async <T, R>({ path, mpOptions, params, config }: APIUpdateParameter<T>) => {
|
|
134
|
+
const query = stringifyURLParams(mpOptions);
|
|
135
|
+
const data = params.map(r => convertToSnakeCase<T>(r));
|
|
136
|
+
try {
|
|
137
|
+
const res = await api.put(path + query, data, {
|
|
138
|
+
...config,
|
|
139
|
+
headers: {
|
|
140
|
+
...config?.headers,
|
|
141
|
+
Authorization: `Bearer ${await getToken()}`,
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
return res.data.map(record => convertToCamelCase<any, R>(record));
|
|
145
|
+
}
|
|
146
|
+
catch (err) {
|
|
147
|
+
return { error: getError(err) };
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
const get = async <T = any, R = AxiosResponse<T, any>>(
|
|
153
|
+
url: string,
|
|
154
|
+
config?: AxiosRequestConfig
|
|
155
|
+
) =>
|
|
156
|
+
api.get<T, R>(url, {
|
|
157
|
+
...config,
|
|
158
|
+
headers: {
|
|
159
|
+
...config?.headers,
|
|
160
|
+
Authorization: `Bearer ${await getToken()}`,
|
|
161
|
+
},
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
const post = async <T, R = AxiosResponse<T, any>>(
|
|
165
|
+
url: string,
|
|
166
|
+
data?: any,
|
|
167
|
+
config?: AxiosRequestConfig
|
|
168
|
+
) =>
|
|
169
|
+
api.post<T, R>(url, data, {
|
|
170
|
+
...config,
|
|
171
|
+
headers: {
|
|
172
|
+
...config?.headers,
|
|
173
|
+
Authorization: `Bearer ${await getToken()}`,
|
|
174
|
+
},
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
const put = async <T, R = AxiosResponse<T, any>>(
|
|
178
|
+
url: string,
|
|
179
|
+
data?: any,
|
|
180
|
+
config?: AxiosRequestConfig
|
|
181
|
+
) =>
|
|
182
|
+
api.put<T, R>(url, data, {
|
|
183
|
+
...config,
|
|
184
|
+
headers: {
|
|
185
|
+
...config?.headers,
|
|
186
|
+
Authorization: `Bearer ${await getToken()}`,
|
|
187
|
+
},
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
const getError = function (error: AxiosError): ErrorDetails {
|
|
192
|
+
return {
|
|
193
|
+
error: true,
|
|
194
|
+
message: error.message,
|
|
195
|
+
name: error.name,
|
|
196
|
+
code: error.code,
|
|
197
|
+
status: error.status,
|
|
198
|
+
method: error.config?.method,
|
|
199
|
+
url: error.config?.url,
|
|
200
|
+
data: error.config?.data
|
|
201
|
+
};
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
return {
|
|
205
|
+
create,
|
|
206
|
+
update,
|
|
207
|
+
get,
|
|
208
|
+
put,
|
|
209
|
+
post,
|
|
210
|
+
getOne,
|
|
211
|
+
getMultiple,
|
|
212
|
+
getError
|
|
213
|
+
};
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
interface TokenData {
|
|
221
|
+
access_token: string;
|
|
222
|
+
expires_in: number;
|
|
223
|
+
token_type: 'Bearer';
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
interface AccessToken {
|
|
227
|
+
digest: string;
|
|
228
|
+
expiration: number;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export type MPGetOptions = {
|
|
232
|
+
select?: string;
|
|
233
|
+
filter?: string;
|
|
234
|
+
orderBy?: string;
|
|
235
|
+
groupBy?: string;
|
|
236
|
+
top?: number;
|
|
237
|
+
skip?: number;
|
|
238
|
+
distinct?: boolean;
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
export type MPCreateOptions = {
|
|
242
|
+
userId?: number;
|
|
243
|
+
select?: string;
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
export type MPUpdateOptions = MPCreateOptions;
|
|
247
|
+
|
|
248
|
+
interface APIGetParameter {
|
|
249
|
+
path: string;
|
|
250
|
+
mpOptions?: MPGetOptions;
|
|
251
|
+
config?: AxiosRequestConfig;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
interface APICreateParameter<T> {
|
|
255
|
+
path: string;
|
|
256
|
+
params: T,
|
|
257
|
+
mpOptions?: MPCreateOptions;
|
|
258
|
+
config?: AxiosRequestConfig;
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
interface APIUpdateParameter<T> {
|
|
262
|
+
path: string;
|
|
263
|
+
params: T[],
|
|
264
|
+
mpOptions?: MPCreateOptions;
|
|
265
|
+
config?: AxiosRequestConfig;
|
|
266
|
+
};
|