mp-js-api 0.0.6 → 0.0.8
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 +14 -4
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +23 -4
- package/dist/index.d.ts +5 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +21 -20
- package/dist/tables/form-responses.d.ts.map +1 -1
- package/dist/utils/strings.js +1 -1
- package/package.json +2 -2
- package/src/api.ts +45 -15
- package/src/index.ts +55 -27
- package/src/tables/contact-email-addresses.ts +19 -0
- package/src/tables/form-responses.ts +44 -44
- package/src/utils/strings.ts +1 -1
- package/src/utils/types.d.ts +1 -5
package/dist/api.d.ts
CHANGED
|
@@ -7,7 +7,10 @@ export type APIGetOneInstance = <T, R>({ id, path, mpOptions, config }: APIGetPa
|
|
|
7
7
|
export type APIGetMultipleInstance = <T, R>({ path, mpOptions, config }: APIGetParameter) => Promise<R[] | {
|
|
8
8
|
error: ErrorDetails;
|
|
9
9
|
}>;
|
|
10
|
-
export type
|
|
10
|
+
export type APICreateOneInstance = <T, R>({ path, mpOptions, params, config }: APICreateOneParameter<T>) => Promise<R | {
|
|
11
|
+
error: ErrorDetails;
|
|
12
|
+
}>;
|
|
13
|
+
export type APICreateManyInstance = <T, R>({ path, mpOptions, params, config }: APICreateManyParameter<T>) => Promise<R[] | {
|
|
11
14
|
error: ErrorDetails;
|
|
12
15
|
}>;
|
|
13
16
|
export type APIUpdateInstance = <T, R>({ path, mpOptions, params, config }: APIUpdateParameter<T>) => Promise<R[] | {
|
|
@@ -15,8 +18,9 @@ export type APIUpdateInstance = <T, R>({ path, mpOptions, params, config }: APIU
|
|
|
15
18
|
}>;
|
|
16
19
|
export interface MPApiBase {
|
|
17
20
|
getOne: APIGetOneInstance;
|
|
18
|
-
|
|
19
|
-
|
|
21
|
+
getMany: APIGetMultipleInstance;
|
|
22
|
+
createOne: APICreateOneInstance;
|
|
23
|
+
createMany: APICreateManyInstance;
|
|
20
24
|
update: APIUpdateInstance;
|
|
21
25
|
get: AxiosInstance['get'];
|
|
22
26
|
post: AxiosInstance['post'];
|
|
@@ -58,12 +62,18 @@ interface APIGetParameter {
|
|
|
58
62
|
mpOptions?: MPGetOptions;
|
|
59
63
|
config?: AxiosRequestConfig;
|
|
60
64
|
}
|
|
61
|
-
interface
|
|
65
|
+
interface APICreateOneParameter<T> {
|
|
62
66
|
path: string;
|
|
63
67
|
params: T;
|
|
64
68
|
mpOptions?: MPCreateOptions;
|
|
65
69
|
config?: AxiosRequestConfig;
|
|
66
70
|
}
|
|
71
|
+
interface APICreateManyParameter<T> {
|
|
72
|
+
path: string;
|
|
73
|
+
params: T[];
|
|
74
|
+
mpOptions?: MPCreateOptions;
|
|
75
|
+
config?: AxiosRequestConfig;
|
|
76
|
+
}
|
|
67
77
|
interface APIUpdateParameter<T> {
|
|
68
78
|
path: string;
|
|
69
79
|
params: T[];
|
package/dist/api.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,UAAU,EAAE,aAAa,EAAE,kBAAkB,EAAiB,MAAM,OAAO,CAAC;AAK5F,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,eAAe,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;CAAE,KAAK,OAAO,CAAC,CAAC,GAAG,SAAS,GAAG;IAAE,KAAK,EAAE,YAAY,CAAC;CAAE,CAAC,CAAC;AAChK,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,eAAe,KAAK,OAAO,CAAC,CAAC,EAAE,GAAG;IAAE,KAAK,EAAE,YAAY,CAAC;CAAE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AAC;CACpB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG,eAAe,CAAC;AAE9C,UAAU,eAAe;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,YAAY,CAAC;IACzB,MAAM,CAAC,EAAE,kBAAkB,CAAC;CAC7B;AAED,UAAU,qBAAqB,CAAC,CAAC;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,CAAC,CAAC;IACV,SAAS,CAAC,EAAE,eAAe,CAAC;IAC5B,MAAM,CAAC,EAAE,kBAAkB,CAAC;CAC7B;AACD,UAAU,sBAAsB,CAAC,CAAC;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,CAAC,EAAE,CAAC;IACZ,SAAS,CAAC,EAAE,eAAe,CAAC;IAC5B,MAAM,CAAC,EAAE,kBAAkB,CAAC;CAC7B;AAED,UAAU,kBAAkB,CAAC,CAAC;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,CAAC,EAAE,CAAC;IACZ,SAAS,CAAC,EAAE,eAAe,CAAC;IAC5B,MAAM,CAAC,EAAE,kBAAkB,CAAC;CAC7B"}
|
package/dist/api.js
CHANGED
|
@@ -59,7 +59,7 @@ const createApiBase = ({ auth }) => {
|
|
|
59
59
|
return { error: getError(err) };
|
|
60
60
|
}
|
|
61
61
|
};
|
|
62
|
-
const
|
|
62
|
+
const getMany = async ({ path, mpOptions, config }) => {
|
|
63
63
|
try {
|
|
64
64
|
const url = path + (0, strings_1.stringifyURLParams)(mpOptions);
|
|
65
65
|
const res = await api.get(url, {
|
|
@@ -75,7 +75,7 @@ const createApiBase = ({ auth }) => {
|
|
|
75
75
|
return { error: getError(err) };
|
|
76
76
|
}
|
|
77
77
|
};
|
|
78
|
-
const
|
|
78
|
+
const createOne = async ({ path, mpOptions, params, config }) => {
|
|
79
79
|
const query = (0, strings_1.stringifyURLParams)(mpOptions);
|
|
80
80
|
const data = [(0, strings_1.convertToSnakeCase)(params)];
|
|
81
81
|
try {
|
|
@@ -92,6 +92,23 @@ const createApiBase = ({ auth }) => {
|
|
|
92
92
|
return { error: getError(err) };
|
|
93
93
|
}
|
|
94
94
|
};
|
|
95
|
+
const createMany = async ({ path, mpOptions, params, config }) => {
|
|
96
|
+
const query = (0, strings_1.stringifyURLParams)(mpOptions);
|
|
97
|
+
const data = params.map(p => (0, strings_1.convertToSnakeCase)(p));
|
|
98
|
+
try {
|
|
99
|
+
const res = await api.post(path + query, data, {
|
|
100
|
+
...config,
|
|
101
|
+
headers: {
|
|
102
|
+
...config?.headers,
|
|
103
|
+
Authorization: `Bearer ${await getToken()}`,
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
return res.data.map(record => (0, strings_1.convertToCamelCase)(record));
|
|
107
|
+
}
|
|
108
|
+
catch (err) {
|
|
109
|
+
return { error: getError(err) };
|
|
110
|
+
}
|
|
111
|
+
};
|
|
95
112
|
const update = async ({ path, mpOptions, params, config }) => {
|
|
96
113
|
const query = (0, strings_1.stringifyURLParams)(mpOptions);
|
|
97
114
|
const data = params.map(r => (0, strings_1.convertToSnakeCase)(r));
|
|
@@ -143,16 +160,18 @@ const createApiBase = ({ auth }) => {
|
|
|
143
160
|
};
|
|
144
161
|
};
|
|
145
162
|
return {
|
|
146
|
-
|
|
163
|
+
createOne,
|
|
164
|
+
createMany,
|
|
147
165
|
update,
|
|
148
166
|
get,
|
|
149
167
|
put,
|
|
150
168
|
post,
|
|
151
169
|
getOne,
|
|
152
|
-
|
|
170
|
+
getMany: getMany,
|
|
153
171
|
getError
|
|
154
172
|
};
|
|
155
173
|
};
|
|
156
174
|
exports.createApiBase = createApiBase;
|
|
157
175
|
;
|
|
158
176
|
;
|
|
177
|
+
;
|
package/dist/index.d.ts
CHANGED
|
@@ -26,10 +26,11 @@ export type MPInstance = {
|
|
|
26
26
|
get: AxiosInstance['get'];
|
|
27
27
|
put: AxiosInstance['put'];
|
|
28
28
|
post: AxiosInstance['post'];
|
|
29
|
-
|
|
29
|
+
createOne: MPApiBase['createOne'];
|
|
30
|
+
createMany: MPApiBase['createMany'];
|
|
30
31
|
update: MPApiBase['update'];
|
|
31
32
|
getOne: MPApiBase['getOne'];
|
|
32
|
-
|
|
33
|
+
getMany: MPApiBase['getMany'];
|
|
33
34
|
getContact(id: number, options?: MPGetOptions): Promise<Contact | undefined | {
|
|
34
35
|
error: ErrorDetails;
|
|
35
36
|
}>;
|
|
@@ -108,7 +109,7 @@ export type MPInstance = {
|
|
|
108
109
|
createFormResponse(params: CreateFormResponseParams, options?: MPCreateOptions): Promise<FormResponse | {
|
|
109
110
|
error: ErrorDetails;
|
|
110
111
|
}>;
|
|
111
|
-
createFormResponseAnswers(params: CreateFormResponseAnswerParams, options?: MPCreateOptions): Promise<FormResponseAnswer | {
|
|
112
|
+
createFormResponseAnswers(params: CreateFormResponseAnswerParams[], options?: MPCreateOptions): Promise<FormResponseAnswer[] | {
|
|
112
113
|
error: ErrorDetails;
|
|
113
114
|
}>;
|
|
114
115
|
updateContacts(contacts: WithRequired<Partial<Contact>, 'contactID'>[], options?: MPUpdateOptions): Promise<Contact[] | {
|
|
@@ -124,5 +125,5 @@ export declare const createMPInstance: ({ auth }: {
|
|
|
124
125
|
password: string;
|
|
125
126
|
};
|
|
126
127
|
}) => MPInstance;
|
|
127
|
-
export { Contact, Participant, Event, Group, EventParticipant, GroupParticipant, ContactAttribute, Household, Address, FormResponse, ErrorDetails, convertToCamelCase, convertToSnakeCase, stringifyURLParams, escapeSql };
|
|
128
|
+
export { Contact, Participant, Event, Group, EventParticipant, GroupParticipant, ContactAttribute, Household, Address, FormResponse, FormResponseAnswer, ErrorDetails, convertToCamelCase, convertToSnakeCase, stringifyURLParams, escapeSql };
|
|
128
129
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.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AY,GAAG;QAAE,KAAK,EAAE,YAAY,CAAC;KAAE,CAAC,CAAC;IACpD,yBAAyB,CACvB,MAAM,EAAE,8BAA8B,EAAE,EACxC,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,kBAAkB,EAAE,GAAG;QAAE,KAAK,EAAE,YAAY,CAAC;KAAE,CAAC,CAAC;IAE5D,cAAc,CACZ,QAAQ,EAAE,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,WAAW,CAAC,EAAE,EACvD,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,OAAO,EAAE,GAAG;QAAE,KAAK,EAAE,YAAY,CAAC;KAAE,CAAC,CAAC;IACjD,uBAAuB,CACrB,YAAY,EAAE,YAAY,CAAC,OAAO,CAAC,gBAAgB,CAAC,EAAE,oBAAoB,CAAC,EAAE,EAC7E,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,gBAAgB,EAAE,GAAG;QAAE,KAAK,EAAE,YAAY,CAAC;KAAE,CAAC,CAAC;CAC3D,CAAC;AAGF,eAAO,MAAM,gBAAgB,aAAc;IAAE,IAAI,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;KAAE,CAAC;CAAE,KAAG,UAgK/F,CAAC;AAEF,OAAO,EACL,OAAO,EACP,WAAW,EACX,KAAK,EACL,KAAK,EACL,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,SAAS,EACT,OAAO,EACP,YAAY,EACZ,kBAAkB,EAClB,YAAY,EACZ,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,SAAS,EACV,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -8,11 +8,12 @@ Object.defineProperty(exports, "convertToSnakeCase", { enumerable: true, get: fu
|
|
|
8
8
|
Object.defineProperty(exports, "escapeSql", { enumerable: true, get: function () { return strings_1.escapeSql; } });
|
|
9
9
|
Object.defineProperty(exports, "stringifyURLParams", { enumerable: true, get: function () { return strings_1.stringifyURLParams; } });
|
|
10
10
|
const createMPInstance = ({ auth }) => {
|
|
11
|
-
const { getOne,
|
|
11
|
+
const { getOne, getMany, createOne, createMany, update, get, post, put } = (0, api_1.createApiBase)({ auth });
|
|
12
12
|
return {
|
|
13
13
|
getOne,
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
getMany,
|
|
15
|
+
createOne,
|
|
16
|
+
createMany,
|
|
16
17
|
update,
|
|
17
18
|
get,
|
|
18
19
|
post,
|
|
@@ -48,55 +49,55 @@ const createMPInstance = ({ auth }) => {
|
|
|
48
49
|
return getOne({ path: `/tables/form_responses`, id, mpOptions });
|
|
49
50
|
},
|
|
50
51
|
async getContacts(mpOptions = {}) {
|
|
51
|
-
return
|
|
52
|
+
return getMany({ path: `/tables/contacts`, mpOptions });
|
|
52
53
|
},
|
|
53
54
|
async getHouseholds(mpOptions = {}) {
|
|
54
|
-
return
|
|
55
|
+
return getMany({ path: `/tables/households`, mpOptions });
|
|
55
56
|
},
|
|
56
57
|
async getAddresses(mpOptions = {}) {
|
|
57
|
-
return
|
|
58
|
+
return getMany({ path: `/tables/addresses`, mpOptions });
|
|
58
59
|
},
|
|
59
60
|
async getParticipants(mpOptions = {}) {
|
|
60
|
-
return
|
|
61
|
+
return getMany({ path: `/tables/participants`, mpOptions });
|
|
61
62
|
},
|
|
62
63
|
async getEvents(mpOptions = {}) {
|
|
63
|
-
return
|
|
64
|
+
return getMany({ path: `/tables/events`, mpOptions });
|
|
64
65
|
},
|
|
65
66
|
async getGroups(mpOptions = {}) {
|
|
66
|
-
return
|
|
67
|
+
return getMany({ path: `/tables/groups`, mpOptions });
|
|
67
68
|
},
|
|
68
69
|
async getEventParticipants(mpOptions = {}) {
|
|
69
|
-
return
|
|
70
|
+
return getMany({ path: `/tables/event_participants`, mpOptions });
|
|
70
71
|
},
|
|
71
72
|
async getGroupParticipants(mpOptions = {}) {
|
|
72
|
-
return
|
|
73
|
+
return getMany({ path: `/tables/group_participants`, mpOptions });
|
|
73
74
|
},
|
|
74
75
|
async createContact(params, mpOptions = {}) {
|
|
75
|
-
return
|
|
76
|
+
return createOne({ path: `/tables/contacts`, mpOptions, params });
|
|
76
77
|
},
|
|
77
78
|
async createHousehold(params, mpOptions) {
|
|
78
|
-
return
|
|
79
|
+
return createOne({ path: `/tables/households`, mpOptions, params });
|
|
79
80
|
},
|
|
80
81
|
async createAddress(params, mpOptions) {
|
|
81
|
-
return
|
|
82
|
+
return createOne({ path: `/tables/addresses`, mpOptions, params });
|
|
82
83
|
},
|
|
83
84
|
async createParticipant(params, mpOptions) {
|
|
84
|
-
return
|
|
85
|
+
return createOne({ path: `/tables/participants`, mpOptions, params });
|
|
85
86
|
},
|
|
86
87
|
async createEventParticipant(params, mpOptions) {
|
|
87
|
-
return
|
|
88
|
+
return createOne({ path: `/tables/event_participants`, mpOptions, params });
|
|
88
89
|
},
|
|
89
90
|
async createGroupParticipant(params, mpOptions) {
|
|
90
|
-
return
|
|
91
|
+
return createOne({ path: `/tables/group_participants`, mpOptions, params });
|
|
91
92
|
},
|
|
92
93
|
async createContactAttribute(params, mpOptions) {
|
|
93
|
-
return
|
|
94
|
+
return createOne({ path: `/tables/contact_attributes`, mpOptions, params });
|
|
94
95
|
},
|
|
95
96
|
async createFormResponse(params, mpOptions) {
|
|
96
|
-
return
|
|
97
|
+
return createOne({ path: `/tables/form_responses`, mpOptions, params });
|
|
97
98
|
},
|
|
98
99
|
async createFormResponseAnswers(params, mpOptions) {
|
|
99
|
-
return
|
|
100
|
+
return createMany({ path: `/tables/form_response_answers`, mpOptions, params });
|
|
100
101
|
},
|
|
101
102
|
async updateContacts(params, mpOptions) {
|
|
102
103
|
return update({ path: `/tables/contacts`, mpOptions, params });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"form-responses.d.ts","sourceRoot":"","sources":["../../src/tables/form-responses.ts"],"names":[],"mappings":"AACA,MAAM,WAAW,kBAAkB;
|
|
1
|
+
{"version":3,"file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Y,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,gBAAgB,EAAE,IAAI,CAAC;IACvB,aAAa,EAAE,IAAI,CAAC;IACpB,mBAAmB,EAAE,IAAI,CAAC;IAC1B,cAAc,EAAE,MAAM,CAAC;IACvB,gBAAgB,EAAE,OAAO,CAAC;IAC1B,OAAO,EAAE,IAAI,CAAC;IACd,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAAC;CACnC"}
|
package/dist/utils/strings.js
CHANGED
|
@@ -55,7 +55,7 @@ function toCamelCase(str, { capitalIds = false } = {}) {
|
|
|
55
55
|
}
|
|
56
56
|
function toCapitalSnakeCase(str, { capitalIds = false, capitalSnake = true } = {}) {
|
|
57
57
|
str = str.replace(/(?<=^_|^__)[^\W_]/, match => match.at(0)?.toUpperCase() || '');
|
|
58
|
-
str = str.replace(/(?<!_|\/)(ID|[A-Z])/g, match => `_${match}`);
|
|
58
|
+
str = str.replace(/(?<!_|\/)(ID|[A-Z]|\d)/g, match => `_${match}`);
|
|
59
59
|
str = capitalSnake ? str.charAt(0).toUpperCase() + str.slice(1) : str;
|
|
60
60
|
return capitalIds ? str.replace(/_id$/i, '_ID') : str;
|
|
61
61
|
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mp-js-api",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"description": "Node MinistryPlatform API",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "mocha --require ts-node/register test/*",
|
|
8
|
-
"
|
|
8
|
+
"postinstall": "tsc"
|
|
9
9
|
},
|
|
10
10
|
"keywords": [],
|
|
11
11
|
"author": "",
|
package/src/api.ts
CHANGED
|
@@ -5,14 +5,16 @@ import { convertToCamelCase, convertToSnakeCase, stringifyURLParams } from './ut
|
|
|
5
5
|
|
|
6
6
|
export type APIGetOneInstance = <T, R>({ id, path, mpOptions, config }: APIGetParameter & { id: number; }) => Promise<R | undefined | { error: ErrorDetails; }>;
|
|
7
7
|
export type APIGetMultipleInstance = <T, R>({ path, mpOptions, config }: APIGetParameter) => Promise<R[] | { error: ErrorDetails; }>;
|
|
8
|
-
export type
|
|
8
|
+
export type APICreateOneInstance = <T, R>({ path, mpOptions, params, config }: APICreateOneParameter<T>) => Promise<R | { error: ErrorDetails; }>;
|
|
9
|
+
export type APICreateManyInstance = <T, R>({ path, mpOptions, params, config }: APICreateManyParameter<T>) => Promise<R[] | { error: ErrorDetails; }>;
|
|
9
10
|
export type APIUpdateInstance = <T, R>({ path, mpOptions, params, config }: APIUpdateParameter<T>) => Promise<R[] | { error: ErrorDetails; }>;
|
|
10
11
|
|
|
11
12
|
|
|
12
13
|
export interface MPApiBase {
|
|
13
14
|
getOne: APIGetOneInstance;
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
getMany: APIGetMultipleInstance;
|
|
16
|
+
createOne: APICreateOneInstance;
|
|
17
|
+
createMany: APICreateManyInstance;
|
|
16
18
|
update: APIUpdateInstance;
|
|
17
19
|
get: AxiosInstance['get'];
|
|
18
20
|
post: AxiosInstance['post'];
|
|
@@ -22,13 +24,12 @@ export interface MPApiBase {
|
|
|
22
24
|
|
|
23
25
|
export interface ErrorDetails {
|
|
24
26
|
message: string;
|
|
25
|
-
name
|
|
27
|
+
name?: string;
|
|
26
28
|
code?: string;
|
|
27
29
|
status?: number;
|
|
28
30
|
method?: string;
|
|
29
31
|
url?: string;
|
|
30
|
-
data
|
|
31
|
-
error: true;
|
|
32
|
+
data?: string;
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
|
|
@@ -75,7 +76,7 @@ export const createApiBase = ({ auth }: { auth: { username: string; password: st
|
|
|
75
76
|
baseURL: 'https://mp.revival.com/ministryplatformapi',
|
|
76
77
|
});
|
|
77
78
|
|
|
78
|
-
const getOne: APIGetOneInstance = async <T, R>({ id, path, mpOptions, config }) => {
|
|
79
|
+
const getOne: APIGetOneInstance = async <T, R>({ id, path, mpOptions, config }: APIGetParameter & { id: number; }) => {
|
|
79
80
|
try {
|
|
80
81
|
const url = `${path}/${id}` + stringifyURLParams(mpOptions);
|
|
81
82
|
const res = await api.get<T>(url, {
|
|
@@ -92,9 +93,9 @@ export const createApiBase = ({ auth }: { auth: { username: string; password: st
|
|
|
92
93
|
}
|
|
93
94
|
};
|
|
94
95
|
|
|
95
|
-
const
|
|
96
|
+
const getMany: APIGetMultipleInstance = async <T, R>({ id, path, mpOptions, config }: APIGetParameter) => {
|
|
96
97
|
try {
|
|
97
|
-
const url = path + stringifyURLParams(mpOptions);
|
|
98
|
+
const url = id ? `${path}/${id}` : path + stringifyURLParams(mpOptions);
|
|
98
99
|
const res = await api.get<T[]>(url, {
|
|
99
100
|
...config,
|
|
100
101
|
headers: {
|
|
@@ -110,7 +111,7 @@ export const createApiBase = ({ auth }: { auth: { username: string; password: st
|
|
|
110
111
|
};
|
|
111
112
|
|
|
112
113
|
|
|
113
|
-
const
|
|
114
|
+
const createOne: APICreateOneInstance = async <T, R>({ path, mpOptions, params, config }: APICreateOneParameter<T>) => {
|
|
114
115
|
const query = stringifyURLParams(mpOptions);
|
|
115
116
|
const data = [convertToSnakeCase<T>(params)];
|
|
116
117
|
try {
|
|
@@ -130,6 +131,26 @@ export const createApiBase = ({ auth }: { auth: { username: string; password: st
|
|
|
130
131
|
};
|
|
131
132
|
|
|
132
133
|
|
|
134
|
+
const createMany: APICreateManyInstance = async <T, R>({ path, mpOptions, params, config }: APICreateManyParameter<T>) => {
|
|
135
|
+
const query = stringifyURLParams(mpOptions);
|
|
136
|
+
const data = params.map(p => convertToSnakeCase<T>(p));
|
|
137
|
+
try {
|
|
138
|
+
const res = await api.post(path + query, data, {
|
|
139
|
+
...config,
|
|
140
|
+
headers: {
|
|
141
|
+
...config?.headers,
|
|
142
|
+
Authorization: `Bearer ${await getToken()}`,
|
|
143
|
+
},
|
|
144
|
+
});
|
|
145
|
+
return res.data.map(record => convertToCamelCase<any, R>(record));
|
|
146
|
+
}
|
|
147
|
+
catch (err) {
|
|
148
|
+
return { error: getError(err) };
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
|
|
133
154
|
const update: APIUpdateInstance = async <T, R>({ path, mpOptions, params, config }: APIUpdateParameter<T>) => {
|
|
134
155
|
const query = stringifyURLParams(mpOptions);
|
|
135
156
|
const data = params.map(r => convertToSnakeCase<T>(r));
|
|
@@ -190,7 +211,6 @@ export const createApiBase = ({ auth }: { auth: { username: string; password: st
|
|
|
190
211
|
|
|
191
212
|
const getError = function (error: AxiosError): ErrorDetails {
|
|
192
213
|
return {
|
|
193
|
-
error: true,
|
|
194
214
|
message: error.message,
|
|
195
215
|
name: error.name,
|
|
196
216
|
code: error.code,
|
|
@@ -202,13 +222,14 @@ export const createApiBase = ({ auth }: { auth: { username: string; password: st
|
|
|
202
222
|
};
|
|
203
223
|
|
|
204
224
|
return {
|
|
205
|
-
|
|
225
|
+
createOne,
|
|
226
|
+
createMany,
|
|
206
227
|
update,
|
|
207
228
|
get,
|
|
208
229
|
put,
|
|
209
230
|
post,
|
|
210
231
|
getOne,
|
|
211
|
-
|
|
232
|
+
getMany: getMany,
|
|
212
233
|
getError
|
|
213
234
|
};
|
|
214
235
|
};
|
|
@@ -246,21 +267,30 @@ export type MPCreateOptions = {
|
|
|
246
267
|
export type MPUpdateOptions = MPCreateOptions;
|
|
247
268
|
|
|
248
269
|
interface APIGetParameter {
|
|
270
|
+
id?: number;
|
|
249
271
|
path: string;
|
|
250
272
|
mpOptions?: MPGetOptions;
|
|
251
273
|
config?: AxiosRequestConfig;
|
|
252
274
|
}
|
|
253
275
|
|
|
254
|
-
interface
|
|
276
|
+
interface APICreateOneParameter<T> {
|
|
255
277
|
path: string;
|
|
256
278
|
params: T,
|
|
257
279
|
mpOptions?: MPCreateOptions;
|
|
258
280
|
config?: AxiosRequestConfig;
|
|
259
281
|
};
|
|
282
|
+
interface APICreateManyParameter<T> {
|
|
283
|
+
path: string;
|
|
284
|
+
params: T[],
|
|
285
|
+
mpOptions?: MPCreateOptions;
|
|
286
|
+
config?: AxiosRequestConfig;
|
|
287
|
+
};
|
|
260
288
|
|
|
261
289
|
interface APIUpdateParameter<T> {
|
|
262
290
|
path: string;
|
|
263
291
|
params: T[],
|
|
264
292
|
mpOptions?: MPCreateOptions;
|
|
265
293
|
config?: AxiosRequestConfig;
|
|
266
|
-
};
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
export type DateTimeIsoString = `${number}-${number}-${number}T${number}:${number}:${number}`;
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createApiBase, MPApiBase, ErrorDetails, MPGetOptions, MPCreateOptions, MPUpdateOptions } from './api';
|
|
1
|
+
import { createApiBase, MPApiBase, ErrorDetails, MPGetOptions, MPCreateOptions, MPUpdateOptions, DateTimeIsoString } from './api';
|
|
2
2
|
import { convertToCamelCase, convertToSnakeCase, escapeSql, stringifyURLParams } from './utils/strings';
|
|
3
3
|
import { Contact, ContactRecord } from './tables/contacts';
|
|
4
4
|
import { Event, EventRecord } from './tables/events';
|
|
@@ -12,6 +12,7 @@ import { ContactAttribute, ContactAttributeRecord } from './tables/contact-attri
|
|
|
12
12
|
import { FormResponse, FormResponseRecord } from './tables/form-responses';
|
|
13
13
|
import { FormResponseAnswer } from './tables/from-response-answers';
|
|
14
14
|
import { AxiosInstance } from 'axios';
|
|
15
|
+
import { ContactEmailAddress, ContactEmailAddressRecord } from './tables/contact-email-addresses';
|
|
15
16
|
|
|
16
17
|
|
|
17
18
|
type WithRequired<T, K extends keyof T> = T & Required<Pick<T, K>>;
|
|
@@ -53,6 +54,10 @@ export type CreateFormResponseAnswerParams = WithRequired<
|
|
|
53
54
|
Omit<Partial<FormResponseAnswer>, 'formResponseAnswerID'>,
|
|
54
55
|
'formFieldID' | 'formResponseID'
|
|
55
56
|
>;
|
|
57
|
+
export type CreateContactEmailAddressParams = WithRequired<
|
|
58
|
+
Omit<Partial<ContactEmailAddress>, 'emailAddressID'>,
|
|
59
|
+
'emailAddress' | 'contactID'
|
|
60
|
+
>;
|
|
56
61
|
|
|
57
62
|
|
|
58
63
|
export type MPInstance = {
|
|
@@ -60,10 +65,11 @@ export type MPInstance = {
|
|
|
60
65
|
get: AxiosInstance['get'];
|
|
61
66
|
put: AxiosInstance['put'];
|
|
62
67
|
post: AxiosInstance['post'];
|
|
63
|
-
|
|
68
|
+
createOne: MPApiBase['createOne'];
|
|
69
|
+
createMany: MPApiBase['createMany'];
|
|
64
70
|
update: MPApiBase['update'];
|
|
65
71
|
getOne: MPApiBase['getOne'];
|
|
66
|
-
|
|
72
|
+
getMany: MPApiBase['getMany'];
|
|
67
73
|
|
|
68
74
|
getContact(
|
|
69
75
|
id: number,
|
|
@@ -109,6 +115,10 @@ export type MPInstance = {
|
|
|
109
115
|
getContacts(
|
|
110
116
|
options?: MPGetOptions
|
|
111
117
|
): Promise<Contact[] | { error: ErrorDetails; }>;
|
|
118
|
+
getContactEmailAddresses(
|
|
119
|
+
id?: number,
|
|
120
|
+
options?: MPGetOptions
|
|
121
|
+
): Promise<ContactEmailAddress[] | { error: ErrorDetails; }>;
|
|
112
122
|
getHouseholds(
|
|
113
123
|
options?: MPGetOptions
|
|
114
124
|
): Promise<Household[] | { error: ErrorDetails; }>;
|
|
@@ -160,10 +170,14 @@ export type MPInstance = {
|
|
|
160
170
|
options?: MPCreateOptions
|
|
161
171
|
): Promise<FormResponse | { error: ErrorDetails; }>;
|
|
162
172
|
createFormResponseAnswers(
|
|
163
|
-
params: CreateFormResponseAnswerParams,
|
|
173
|
+
params: CreateFormResponseAnswerParams[],
|
|
174
|
+
options?: MPCreateOptions
|
|
175
|
+
): Promise<FormResponseAnswer[] | { error: ErrorDetails; }>;
|
|
176
|
+
createContactEmailAddress(
|
|
177
|
+
params: CreateContactEmailAddressParams[],
|
|
164
178
|
options?: MPCreateOptions
|
|
165
|
-
): Promise<
|
|
166
|
-
|
|
179
|
+
): Promise<ContactEmailAddress[] | { error: ErrorDetails; }>;
|
|
180
|
+
|
|
167
181
|
updateContacts(
|
|
168
182
|
contacts: WithRequired<Partial<Contact>, 'contactID'>[],
|
|
169
183
|
options?: MPUpdateOptions
|
|
@@ -177,12 +191,13 @@ export type MPInstance = {
|
|
|
177
191
|
|
|
178
192
|
export const createMPInstance = ({ auth }: { auth: { username: string; password: string; }; }): MPInstance => {
|
|
179
193
|
|
|
180
|
-
const { getOne,
|
|
194
|
+
const { getOne, getMany, createOne, createMany, update, get, post, put } = createApiBase({ auth });
|
|
181
195
|
|
|
182
196
|
return {
|
|
183
197
|
getOne,
|
|
184
|
-
|
|
185
|
-
|
|
198
|
+
getMany,
|
|
199
|
+
createOne,
|
|
200
|
+
createMany,
|
|
186
201
|
update,
|
|
187
202
|
get,
|
|
188
203
|
post,
|
|
@@ -238,91 +253,101 @@ export const createMPInstance = ({ auth }: { auth: { username: string; password:
|
|
|
238
253
|
);
|
|
239
254
|
},
|
|
240
255
|
async getContacts(mpOptions = {}) {
|
|
241
|
-
return
|
|
256
|
+
return getMany<ContactRecord, Contact>(
|
|
242
257
|
{ path: `/tables/contacts`, mpOptions }
|
|
243
258
|
);
|
|
244
259
|
},
|
|
245
260
|
async getHouseholds(mpOptions = {}) {
|
|
246
|
-
return
|
|
261
|
+
return getMany<HouseholdRecord, Household>(
|
|
247
262
|
{ path: `/tables/households`, mpOptions }
|
|
248
263
|
);
|
|
249
264
|
},
|
|
250
265
|
async getAddresses(mpOptions = {}) {
|
|
251
|
-
return
|
|
266
|
+
return getMany<AddressRecord, Address>(
|
|
252
267
|
{ path: `/tables/addresses`, mpOptions }
|
|
253
268
|
);
|
|
254
269
|
},
|
|
270
|
+
async getContactEmailAddresses(id, mpOptions = {}) {
|
|
271
|
+
return getMany<ContactEmailAddressRecord, ContactEmailAddress>(
|
|
272
|
+
{ path: `/tables/contact_email_addresses`, id, mpOptions }
|
|
273
|
+
);
|
|
274
|
+
},
|
|
255
275
|
async getParticipants(mpOptions = {}) {
|
|
256
|
-
return
|
|
276
|
+
return getMany<ParticipantRecord, Participant>(
|
|
257
277
|
{ path: `/tables/participants`, mpOptions }
|
|
258
278
|
);
|
|
259
279
|
},
|
|
260
280
|
async getEvents(mpOptions = {}) {
|
|
261
|
-
return
|
|
281
|
+
return getMany<EventRecord, Event>(
|
|
262
282
|
{ path: `/tables/events`, mpOptions }
|
|
263
283
|
);
|
|
264
284
|
},
|
|
265
285
|
async getGroups(mpOptions = {}) {
|
|
266
|
-
return
|
|
286
|
+
return getMany<GroupRecord, Group>(
|
|
267
287
|
{ path: `/tables/groups`, mpOptions }
|
|
268
288
|
);
|
|
269
289
|
},
|
|
270
290
|
async getEventParticipants(mpOptions = {}) {
|
|
271
|
-
return
|
|
291
|
+
return getMany<EventParticipantRecord, EventParticipant>(
|
|
272
292
|
{ path: `/tables/event_participants`, mpOptions }
|
|
273
293
|
);
|
|
274
294
|
},
|
|
275
295
|
async getGroupParticipants(mpOptions = {}) {
|
|
276
|
-
return
|
|
296
|
+
return getMany<GroupParticipantRecord, GroupParticipant>(
|
|
277
297
|
{ path: `/tables/group_participants`, mpOptions }
|
|
278
298
|
);
|
|
279
299
|
},
|
|
280
300
|
|
|
281
301
|
async createContact(params, mpOptions = {}) {
|
|
282
|
-
return
|
|
302
|
+
return createOne<CreateContactParams, Contact>(
|
|
283
303
|
{ path: `/tables/contacts`, mpOptions, params }
|
|
284
304
|
);
|
|
285
305
|
},
|
|
286
306
|
async createHousehold(params, mpOptions) {
|
|
287
|
-
return
|
|
307
|
+
return createOne<CreateHouseholdParams, Household>(
|
|
288
308
|
{ path: `/tables/households`, mpOptions, params }
|
|
289
309
|
);
|
|
290
310
|
},
|
|
291
311
|
async createAddress(params, mpOptions) {
|
|
292
|
-
return
|
|
312
|
+
return createOne<CreateAddressParams, Address>(
|
|
293
313
|
{ path: `/tables/addresses`, mpOptions, params }
|
|
294
314
|
);
|
|
295
315
|
},
|
|
296
316
|
async createParticipant(params, mpOptions) {
|
|
297
|
-
return
|
|
317
|
+
return createOne<CreateParticipantParams, Participant>(
|
|
298
318
|
{ path: `/tables/participants`, mpOptions, params }
|
|
299
319
|
);
|
|
300
320
|
},
|
|
301
321
|
async createEventParticipant(params, mpOptions) {
|
|
302
|
-
return
|
|
322
|
+
return createOne<CreateEventParticipantParams, EventParticipant>(
|
|
303
323
|
{ path: `/tables/event_participants`, mpOptions, params }
|
|
304
324
|
);
|
|
305
325
|
},
|
|
306
326
|
async createGroupParticipant(params, mpOptions) {
|
|
307
|
-
return
|
|
327
|
+
return createOne<CreateGroupParticipantParams, GroupParticipant>(
|
|
308
328
|
{ path: `/tables/group_participants`, mpOptions, params }
|
|
309
329
|
);
|
|
310
330
|
},
|
|
311
331
|
async createContactAttribute(params, mpOptions) {
|
|
312
|
-
return
|
|
332
|
+
return createOne<CreateContactAttributeParams, ContactAttribute>(
|
|
313
333
|
{ path: `/tables/contact_attributes`, mpOptions, params }
|
|
314
334
|
);
|
|
315
335
|
},
|
|
316
336
|
async createFormResponse(params: CreateFormResponseParams, mpOptions) {
|
|
317
|
-
return
|
|
337
|
+
return createOne<CreateFormResponseParams, FormResponse>(
|
|
318
338
|
{ path: `/tables/form_responses`, mpOptions, params }
|
|
319
339
|
);
|
|
320
340
|
},
|
|
321
341
|
async createFormResponseAnswers(params, mpOptions) {
|
|
322
|
-
return
|
|
342
|
+
return createMany<CreateFormResponseAnswerParams, FormResponseAnswer>(
|
|
323
343
|
{ path: `/tables/form_response_answers`, mpOptions, params }
|
|
324
344
|
);
|
|
325
345
|
},
|
|
346
|
+
async createContactEmailAddress(params, mpOptions) {
|
|
347
|
+
return createMany<CreateContactEmailAddressParams, ContactEmailAddress>(
|
|
348
|
+
{ path: `/tables/contact_email_addresses`, mpOptions, params }
|
|
349
|
+
);
|
|
350
|
+
},
|
|
326
351
|
async updateContacts(params, mpOptions) {
|
|
327
352
|
return update<Partial<Contact>, Contact>(
|
|
328
353
|
{ path: `/tables/contacts`, mpOptions, params }
|
|
@@ -347,9 +372,12 @@ export {
|
|
|
347
372
|
Household,
|
|
348
373
|
Address,
|
|
349
374
|
FormResponse,
|
|
375
|
+
FormResponseAnswer,
|
|
376
|
+
ContactEmailAddress,
|
|
350
377
|
ErrorDetails,
|
|
378
|
+
DateTimeIsoString,
|
|
351
379
|
convertToCamelCase,
|
|
352
380
|
convertToSnakeCase,
|
|
353
381
|
stringifyURLParams,
|
|
354
382
|
escapeSql
|
|
355
|
-
};
|
|
383
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { DateTimeIsoString } from "../api";
|
|
2
|
+
|
|
3
|
+
export interface ContactEmailAddressRecord {
|
|
4
|
+
Email_Address_ID: number;
|
|
5
|
+
Email_Address: string;
|
|
6
|
+
Contact_ID: number;
|
|
7
|
+
Email_Type_ID?: number;
|
|
8
|
+
End_Date?: DateTimeIsoString | null;
|
|
9
|
+
Notes?: string | null;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface ContactEmailAddress {
|
|
13
|
+
emailAddressID: number;
|
|
14
|
+
emailAddress: string;
|
|
15
|
+
contactID: number;
|
|
16
|
+
emailTypeID?: number;
|
|
17
|
+
endDate?: DateTimeIsoString | null;
|
|
18
|
+
notes?: string | null;
|
|
19
|
+
}
|
|
@@ -1,51 +1,51 @@
|
|
|
1
1
|
|
|
2
2
|
export interface FormResponseRecord {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
3
|
+
Form_Response_ID: number;
|
|
4
|
+
Form_ID: number;
|
|
5
|
+
Response_Date: string;
|
|
6
|
+
IP_Address: string | null;
|
|
7
|
+
Contact_ID: number;
|
|
8
|
+
First_Name: string;
|
|
9
|
+
Last_Name: string;
|
|
10
|
+
Email_Address: string | null;
|
|
11
|
+
Phone_Number: string | null;
|
|
12
|
+
Address_Line_1: string | null;
|
|
13
|
+
Address_Line_2: string | null;
|
|
14
|
+
Address_City: string | null;
|
|
15
|
+
Address_State: string | null;
|
|
16
|
+
Address_Zip: number | null;
|
|
17
|
+
Event_ID: number;
|
|
18
|
+
Pledge_Campaign_ID: null;
|
|
19
|
+
Opportunity_ID: null;
|
|
20
|
+
Opportunity_Response: null;
|
|
21
|
+
Congregation_ID: number;
|
|
22
|
+
Notification_Sent: boolean;
|
|
23
|
+
Expires: null;
|
|
24
|
+
Event_Participant_ID: number | null;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
|
|
28
28
|
export interface FormResponse {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
29
|
+
formResponseID: number;
|
|
30
|
+
formID: number;
|
|
31
|
+
responseDate: string;
|
|
32
|
+
iPAddress: string | null;
|
|
33
|
+
contactID: number;
|
|
34
|
+
firstName: string;
|
|
35
|
+
lastName: string;
|
|
36
|
+
emailAddress: string | null;
|
|
37
|
+
phoneNumber: string | null;
|
|
38
|
+
addressLine1: string | null;
|
|
39
|
+
addressLine2: string | null;
|
|
40
|
+
addressCity: string | null;
|
|
41
|
+
addressState: string | null;
|
|
42
|
+
addressZip: string | null;
|
|
43
|
+
eventID: number;
|
|
44
|
+
pledgeCampaignID: null;
|
|
45
|
+
opportunityID: null;
|
|
46
|
+
opportunityResponse: null;
|
|
47
|
+
congregationID: number;
|
|
48
|
+
notificationSent: boolean;
|
|
49
|
+
expires: null;
|
|
50
|
+
eventParticipantID: number | null;
|
|
51
51
|
}
|
package/src/utils/strings.ts
CHANGED
|
@@ -51,7 +51,7 @@ export function toCamelCase(str: string, { capitalIds = false }: { capitalIds?:
|
|
|
51
51
|
|
|
52
52
|
export function toCapitalSnakeCase(str: string, { capitalIds = false, capitalSnake = true }: { capitalIds?: boolean, capitalSnake?: boolean; }= {}) {
|
|
53
53
|
str = str.replace(/(?<=^_|^__)[^\W_]/, match => match.at(0)?.toUpperCase() || '');
|
|
54
|
-
str = str.replace(/(?<!_|\/)(ID|[A-Z])/g, match => `_${match}`);
|
|
54
|
+
str = str.replace(/(?<!_|\/)(ID|[A-Z]|\d)/g, match => `_${match}`);
|
|
55
55
|
str = capitalSnake ? str.charAt(0).toUpperCase() + str.slice(1) : str;
|
|
56
56
|
return capitalIds ? str.replace(/_id$/i, '_ID') : str;
|
|
57
57
|
}
|