mp-js-api 0.0.3 → 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 +56 -48
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +73 -306
- 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/form-responses.d.ts +49 -0
- package/dist/tables/form-responses.d.ts.map +1 -0
- package/dist/tables/form-responses.js +2 -0
- package/dist/tables/from-response-answers.d.ts +21 -0
- package/dist/tables/from-response-answers.d.ts.map +1 -0
- package/dist/tables/from-response-answers.js +2 -0
- 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 -0
- package/dist/utils/strings.d.ts.map +1 -1
- package/dist/utils/strings.js +54 -0
- package/package.json +1 -1
- package/src/api.ts +266 -0
- package/src/index.ts +207 -424
- 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/form-responses.ts +51 -0
- package/src/tables/from-response-answers.ts +23 -0
- 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 +60 -1
package/src/index.ts
CHANGED
|
@@ -1,76 +1,24 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import { Contact,
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import { GroupRecord } from './tables/groups';
|
|
16
|
-
import { mapGroupRecord } from './tables/groups';
|
|
17
|
-
import { mapEventParticipantRecord } from './tables/event-participants';
|
|
18
|
-
import { EventParticipantRecord } from './tables/event-participants';
|
|
19
|
-
import { GroupParticipantRecord } from './tables/group-participants';
|
|
20
|
-
import { mapGroupParticipantRecord } from './tables/group-participants';
|
|
21
|
-
import { Household, HouseholdRecord, mapHouseholdRecord, mapHouseholdToHouseholdRecord, } from './tables/households';
|
|
22
|
-
import { Address, AddressRecord, mapAddressRecord, mapAddressToAddressRecord } from './tables/addresses';
|
|
23
|
-
import { ContactAttribute, ContactAttributeRecord, mapContactAttributeRecord, mapContactAttributeToContactAttributeRecord } from './tables/contact-attributes';
|
|
24
|
-
import { escapeSql } from './utils/strings';
|
|
1
|
+
import { createApiBase, MPApiBase, ErrorDetails, MPGetOptions, MPCreateOptions, MPUpdateOptions } from './api';
|
|
2
|
+
import { convertToCamelCase, convertToSnakeCase, escapeSql, stringifyURLParams } from './utils/strings';
|
|
3
|
+
import { Contact, ContactRecord } from './tables/contacts';
|
|
4
|
+
import { Event, EventRecord } from './tables/events';
|
|
5
|
+
import { Group, GroupRecord } from './tables/groups';
|
|
6
|
+
import { Address, AddressRecord } from './tables/addresses';
|
|
7
|
+
import { Household, HouseholdRecord } from './tables/households';
|
|
8
|
+
import { Participant, ParticipantRecord } from './tables/participants';
|
|
9
|
+
import { EventParticipant, EventParticipantRecord } from './tables/event-participants';
|
|
10
|
+
import { GroupParticipant, GroupParticipantRecord } from './tables/group-participants';
|
|
11
|
+
import { ContactAttribute, ContactAttributeRecord } from './tables/contact-attributes';
|
|
12
|
+
import { FormResponse, FormResponseRecord } from './tables/form-responses';
|
|
13
|
+
import { FormResponseAnswer } from './tables/from-response-answers';
|
|
14
|
+
import { AxiosInstance } from 'axios';
|
|
25
15
|
|
|
26
|
-
interface TokenData {
|
|
27
|
-
access_token: string;
|
|
28
|
-
expires_in: number;
|
|
29
|
-
token_type: 'Bearer';
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
interface AccessToken {
|
|
33
|
-
digest: string;
|
|
34
|
-
expiration: number;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const createTokenGetter = (auth: { username: string; password: string; }) => {
|
|
38
|
-
let token: AccessToken | undefined;
|
|
39
|
-
|
|
40
|
-
return async () => {
|
|
41
|
-
// If the token is near expiration, get a new one.
|
|
42
|
-
if (!token || token.expiration - 60000 < Date.now()) {
|
|
43
|
-
const tokenRes = await axios.post<TokenData>(
|
|
44
|
-
'https://mp.revival.com/ministryplatformapi/oauth/connect/token',
|
|
45
|
-
new URLSearchParams({
|
|
46
|
-
grant_type: 'client_credentials',
|
|
47
|
-
scope: 'http://www.thinkministry.com/dataplatform/scopes/all',
|
|
48
|
-
}).toString(),
|
|
49
|
-
{ auth }
|
|
50
|
-
);
|
|
51
|
-
const [, payload] = tokenRes.data.access_token.split('.');
|
|
52
|
-
try {
|
|
53
|
-
const jsonPayload: { exp: number; } = JSON.parse(
|
|
54
|
-
Buffer.from(payload, 'base64url').toString()
|
|
55
|
-
);
|
|
56
|
-
token = {
|
|
57
|
-
digest: tokenRes.data.access_token,
|
|
58
|
-
expiration: jsonPayload.exp * 1000,
|
|
59
|
-
};
|
|
60
|
-
return token.digest;
|
|
61
|
-
} catch (err) {
|
|
62
|
-
console.error(err);
|
|
63
|
-
}
|
|
64
|
-
} else {
|
|
65
|
-
return token.digest;
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
};
|
|
69
16
|
|
|
70
17
|
type WithRequired<T, K extends keyof T> = T & Required<Pick<T, K>>;
|
|
71
18
|
|
|
19
|
+
|
|
72
20
|
export type CreateContactParams = WithRequired<
|
|
73
|
-
Partial<Contact>,
|
|
21
|
+
Omit<Partial<Contact>, 'contactID'>,
|
|
74
22
|
'company' | 'displayName'
|
|
75
23
|
>;
|
|
76
24
|
export type CreateHouseholdParams = WithRequired<
|
|
@@ -97,464 +45,293 @@ export type CreateContactAttributeParams = WithRequired<
|
|
|
97
45
|
Partial<ContactAttribute>,
|
|
98
46
|
'attributeID' | 'contactID' | 'startDate'
|
|
99
47
|
>;
|
|
48
|
+
export type CreateFormResponseParams = WithRequired<
|
|
49
|
+
Omit<Partial<FormResponse>, 'formResponseID'>,
|
|
50
|
+
'formID' | 'responseDate'
|
|
51
|
+
>;
|
|
52
|
+
export type CreateFormResponseAnswerParams = WithRequired<
|
|
53
|
+
Omit<Partial<FormResponseAnswer>, 'formResponseAnswerID'>,
|
|
54
|
+
'formFieldID' | 'formResponseID'
|
|
55
|
+
>;
|
|
100
56
|
|
|
101
|
-
export type MPGetOptions = {
|
|
102
|
-
select?: string;
|
|
103
|
-
filter?: string;
|
|
104
|
-
orderBy?: string;
|
|
105
|
-
groupBy?: string;
|
|
106
|
-
top?: number;
|
|
107
|
-
skip?: number;
|
|
108
|
-
distinct?: boolean;
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
export type MPCreateOptions = {
|
|
112
|
-
user?: number;
|
|
113
|
-
};
|
|
114
57
|
|
|
115
|
-
export type MPUpdateOptions = MPCreateOptions;
|
|
116
|
-
export type MPGetInstance = <T = any, R = AxiosResponse<T, any>>(url: string, mpOptions?: MPGetOptions, config?: AxiosRequestConfig) => Promise<R>;
|
|
117
58
|
export type MPInstance = {
|
|
118
|
-
|
|
119
|
-
|
|
59
|
+
|
|
60
|
+
get: AxiosInstance['get'];
|
|
120
61
|
put: AxiosInstance['put'];
|
|
62
|
+
post: AxiosInstance['post'];
|
|
63
|
+
create: MPApiBase['create'];
|
|
64
|
+
update: MPApiBase['update'];
|
|
65
|
+
getOne: MPApiBase['getOne'];
|
|
66
|
+
getMultiple: MPApiBase['getMultiple'];
|
|
67
|
+
|
|
121
68
|
getContact(
|
|
122
69
|
id: number,
|
|
123
70
|
options?: MPGetOptions
|
|
124
|
-
): Promise<Contact | undefined | { error:
|
|
71
|
+
): Promise<Contact | undefined | { error: ErrorDetails; }>;
|
|
125
72
|
getHousehold(
|
|
126
73
|
id: number,
|
|
127
74
|
options?: MPGetOptions
|
|
128
|
-
): Promise<Household | undefined | { error:
|
|
75
|
+
): Promise<Household | undefined | { error: ErrorDetails; }>;
|
|
129
76
|
getAddress(
|
|
130
77
|
id: number,
|
|
131
78
|
options?: MPGetOptions
|
|
132
|
-
): Promise<Address | undefined | { error:
|
|
79
|
+
): Promise<Address | undefined | { error: ErrorDetails; }>;
|
|
133
80
|
getParticipant(
|
|
134
81
|
id: number,
|
|
135
82
|
options?: MPGetOptions
|
|
136
|
-
): Promise<Participant | undefined | { error:
|
|
83
|
+
): Promise<Participant | undefined | { error: ErrorDetails; }>;
|
|
84
|
+
getContactAttribute(
|
|
85
|
+
id: number,
|
|
86
|
+
options?: MPGetOptions
|
|
87
|
+
): Promise<ContactAttribute | undefined | { error: ErrorDetails; }>;
|
|
137
88
|
getEvent(
|
|
138
89
|
id: number,
|
|
139
90
|
options?: MPGetOptions
|
|
140
|
-
): Promise<Event | undefined | { error:
|
|
91
|
+
): Promise<Event | undefined | { error: ErrorDetails; }>;
|
|
141
92
|
getGroup(
|
|
142
93
|
id: number,
|
|
143
94
|
options?: MPGetOptions
|
|
144
|
-
): Promise<Group | undefined | { error:
|
|
95
|
+
): Promise<Group | undefined | { error: ErrorDetails; }>;
|
|
145
96
|
getEventParticipant(
|
|
146
97
|
id: number,
|
|
147
98
|
options?: MPGetOptions
|
|
148
|
-
): Promise<EventParticipant | undefined | { error:
|
|
99
|
+
): Promise<EventParticipant | undefined | { error: ErrorDetails; }>;
|
|
149
100
|
getGroupParticipant(
|
|
150
101
|
id: number,
|
|
151
102
|
options?: MPGetOptions
|
|
152
|
-
): Promise<GroupParticipant | undefined | { error:
|
|
103
|
+
): Promise<GroupParticipant | undefined | { error: ErrorDetails; }>;
|
|
104
|
+
getFormResponse(
|
|
105
|
+
id: number,
|
|
106
|
+
options?: MPGetOptions
|
|
107
|
+
): Promise<FormResponse | undefined | { error: ErrorDetails; }>;
|
|
153
108
|
|
|
154
109
|
getContacts(
|
|
155
110
|
options?: MPGetOptions
|
|
156
|
-
): Promise<Contact[] | { error:
|
|
111
|
+
): Promise<Contact[] | { error: ErrorDetails; }>;
|
|
157
112
|
getHouseholds(
|
|
158
113
|
options?: MPGetOptions
|
|
159
|
-
): Promise<Household[] | { error:
|
|
114
|
+
): Promise<Household[] | { error: ErrorDetails; }>;
|
|
160
115
|
getAddresses(
|
|
161
116
|
options?: MPGetOptions
|
|
162
|
-
): Promise<Address[] | { error:
|
|
117
|
+
): Promise<Address[] | { error: ErrorDetails; }>;
|
|
163
118
|
getParticipants(
|
|
164
119
|
options?: MPGetOptions
|
|
165
|
-
): Promise<Participant[] | { error:
|
|
166
|
-
getEvents(options?: MPGetOptions): Promise<Event[] | { error:
|
|
167
|
-
getGroups(options?: MPGetOptions): Promise<Group[] | { error:
|
|
120
|
+
): Promise<Participant[] | { error: ErrorDetails; }>;
|
|
121
|
+
getEvents(options?: MPGetOptions): Promise<Event[] | { error: ErrorDetails; }>;
|
|
122
|
+
getGroups(options?: MPGetOptions): Promise<Group[] | { error: ErrorDetails; }>;
|
|
168
123
|
getEventParticipants(
|
|
169
124
|
options?: MPGetOptions
|
|
170
|
-
): Promise<EventParticipant[] | { error:
|
|
125
|
+
): Promise<EventParticipant[] | { error: ErrorDetails; }>;
|
|
171
126
|
getGroupParticipants(
|
|
172
127
|
options?: MPGetOptions
|
|
173
|
-
): Promise<GroupParticipant[] | { error:
|
|
128
|
+
): Promise<GroupParticipant[] | { error: ErrorDetails; }>;
|
|
174
129
|
|
|
175
130
|
createContact(
|
|
176
131
|
params: CreateContactParams,
|
|
177
132
|
options?: MPCreateOptions
|
|
178
|
-
): Promise<Contact | { error:
|
|
133
|
+
): Promise<Contact | { error: ErrorDetails; }>;
|
|
179
134
|
createHousehold(
|
|
180
135
|
params: CreateHouseholdParams,
|
|
181
136
|
options?: MPCreateOptions
|
|
182
|
-
): Promise<Household | { error:
|
|
137
|
+
): Promise<Household | { error: ErrorDetails; }>;
|
|
183
138
|
createAddress(
|
|
184
139
|
params: CreateAddressParams,
|
|
185
140
|
options?: MPCreateOptions
|
|
186
|
-
): Promise<Address | { error:
|
|
141
|
+
): Promise<Address | { error: ErrorDetails; }>;
|
|
187
142
|
createParticipant(
|
|
188
143
|
params: CreateParticipantParams,
|
|
189
144
|
options?: MPCreateOptions
|
|
190
|
-
): Promise<Participant | { error:
|
|
145
|
+
): Promise<Participant | { error: ErrorDetails; }>;
|
|
191
146
|
createEventParticipant(
|
|
192
147
|
params: CreateEventParticipantParams,
|
|
193
148
|
options?: MPCreateOptions
|
|
194
|
-
): Promise<EventParticipant | { error:
|
|
149
|
+
): Promise<EventParticipant | { error: ErrorDetails; }>;
|
|
195
150
|
createGroupParticipant(
|
|
196
151
|
params: CreateGroupParticipantParams,
|
|
197
152
|
options?: MPCreateOptions
|
|
198
|
-
): Promise<GroupParticipant | { error:
|
|
153
|
+
): Promise<GroupParticipant | { error: ErrorDetails; }>;
|
|
199
154
|
createContactAttribute(
|
|
200
155
|
params: CreateContactAttributeParams,
|
|
201
156
|
options?: MPCreateOptions
|
|
202
|
-
): Promise<ContactAttribute | { error:
|
|
203
|
-
|
|
157
|
+
): Promise<ContactAttribute | { error: ErrorDetails; }>;
|
|
158
|
+
createFormResponse(
|
|
159
|
+
params: CreateFormResponseParams,
|
|
160
|
+
options?: MPCreateOptions
|
|
161
|
+
): Promise<FormResponse | { error: ErrorDetails; }>;
|
|
162
|
+
createFormResponseAnswers(
|
|
163
|
+
params: CreateFormResponseAnswerParams,
|
|
164
|
+
options?: MPCreateOptions
|
|
165
|
+
): Promise<FormResponseAnswer | { error: ErrorDetails; }>;
|
|
166
|
+
|
|
204
167
|
updateContacts(
|
|
205
168
|
contacts: WithRequired<Partial<Contact>, 'contactID'>[],
|
|
206
169
|
options?: MPUpdateOptions
|
|
207
|
-
): Promise<Contact[] | { error:
|
|
208
|
-
|
|
170
|
+
): Promise<Contact[] | { error: ErrorDetails; }>;
|
|
209
171
|
updateEventParticipants(
|
|
210
172
|
participants: WithRequired<Partial<EventParticipant>, 'eventParticipantID'>[],
|
|
211
173
|
options?: MPUpdateOptions
|
|
212
|
-
): Promise<EventParticipant[] | { error:
|
|
174
|
+
): Promise<EventParticipant[] | { error: ErrorDetails; }>;
|
|
213
175
|
};
|
|
214
176
|
|
|
215
|
-
const stringifyMPOptions = (mpOptions: MPGetOptions | MPCreateOptions | MPUpdateOptions = {}) =>
|
|
216
|
-
escapeSql(Object.entries(mpOptions).reduce((acc, [key, value]) => {
|
|
217
|
-
if (!acc) {
|
|
218
|
-
acc += `?$${key}=${value}`;
|
|
219
|
-
} else {
|
|
220
|
-
acc += `&$${key}=${value}`;
|
|
221
|
-
}
|
|
222
|
-
return acc;
|
|
223
|
-
}, ''));
|
|
224
177
|
|
|
225
178
|
export const createMPInstance = ({ auth }: { auth: { username: string; password: string; }; }): MPInstance => {
|
|
226
|
-
/**
|
|
227
|
-
* Gets MP oauth token.
|
|
228
|
-
* @returns token
|
|
229
|
-
*/
|
|
230
|
-
const getToken = createTokenGetter(auth);
|
|
231
|
-
const api = axios.create({
|
|
232
|
-
baseURL: 'https://mp.revival.com/ministryplatformapi',
|
|
233
|
-
});
|
|
234
179
|
|
|
235
|
-
const
|
|
236
|
-
url: string,
|
|
237
|
-
mpOptions: MPGetOptions,
|
|
238
|
-
config?: AxiosRequestConfig
|
|
239
|
-
) =>
|
|
240
|
-
api.get<T, R>(url + stringifyMPOptions(mpOptions), {
|
|
241
|
-
...config,
|
|
242
|
-
headers: {
|
|
243
|
-
...config?.headers,
|
|
244
|
-
Authorization: `Bearer ${await getToken()}`,
|
|
245
|
-
},
|
|
246
|
-
});
|
|
247
|
-
const post = async <T, R = AxiosResponse<T, any>>(
|
|
248
|
-
url: string,
|
|
249
|
-
data?: any,
|
|
250
|
-
config?: AxiosRequestConfig
|
|
251
|
-
) =>
|
|
252
|
-
api.post<T, R>(url, data, {
|
|
253
|
-
...config,
|
|
254
|
-
headers: {
|
|
255
|
-
...config?.headers,
|
|
256
|
-
Authorization: `Bearer ${await getToken()}`,
|
|
257
|
-
},
|
|
258
|
-
});
|
|
259
|
-
const put = async <T, R = AxiosResponse<T, any>>(
|
|
260
|
-
url: string,
|
|
261
|
-
data?: any,
|
|
262
|
-
config?: AxiosRequestConfig
|
|
263
|
-
) =>
|
|
264
|
-
api.put<T, R>(url, data, {
|
|
265
|
-
...config,
|
|
266
|
-
headers: {
|
|
267
|
-
...config?.headers,
|
|
268
|
-
Authorization: `Bearer ${await getToken()}`,
|
|
269
|
-
},
|
|
270
|
-
});
|
|
180
|
+
const { getOne, getMultiple, create, update, get, post, put, getError } = createApiBase({ auth });
|
|
271
181
|
|
|
272
182
|
return {
|
|
183
|
+
getOne,
|
|
184
|
+
getMultiple,
|
|
185
|
+
create,
|
|
186
|
+
update,
|
|
273
187
|
get,
|
|
274
188
|
post,
|
|
275
189
|
put,
|
|
276
|
-
async getContact(id,
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
190
|
+
async getContact(id, mpOptions = {}) {
|
|
191
|
+
return getOne<ContactRecord, Contact>(
|
|
192
|
+
{ path: `/tables/contacts`, id, mpOptions }
|
|
193
|
+
);
|
|
194
|
+
},
|
|
195
|
+
async getHousehold(id, mpOptions = {}) {
|
|
196
|
+
return getOne<HouseholdRecord, Household>(
|
|
197
|
+
{ path: `/tables/households`, id, mpOptions }
|
|
198
|
+
);
|
|
199
|
+
},
|
|
200
|
+
async getAddress(id, mpOptions = {}) {
|
|
201
|
+
return getOne<AddressRecord, Address>(
|
|
202
|
+
{ path: `/tables/addresses`, id, mpOptions }
|
|
203
|
+
);
|
|
285
204
|
},
|
|
286
|
-
async
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
);
|
|
291
|
-
return res.data[0]
|
|
292
|
-
? mapHouseholdRecord(res.data[0])
|
|
293
|
-
: undefined;
|
|
294
|
-
} catch (err) {
|
|
295
|
-
return { error: err };
|
|
296
|
-
}
|
|
205
|
+
async getParticipant(id, mpOptions = {}) {
|
|
206
|
+
return getOne<ParticipantRecord, Participant>(
|
|
207
|
+
{ path: `/tables/participants`, id, mpOptions }
|
|
208
|
+
);
|
|
297
209
|
},
|
|
298
|
-
async
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
);
|
|
303
|
-
return res.data[0] ? mapAddressRecord(res.data[0]) : undefined;
|
|
304
|
-
} catch (err) {
|
|
305
|
-
return { error: err };
|
|
306
|
-
}
|
|
210
|
+
async getContactAttribute(id, mpOptions = {}) {
|
|
211
|
+
return getOne<ContactAttributeRecord, ContactAttribute>(
|
|
212
|
+
{ path: `/tables/participants`, id, mpOptions }
|
|
213
|
+
);
|
|
307
214
|
},
|
|
308
|
-
async
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
);
|
|
313
|
-
return res.data[0]
|
|
314
|
-
? mapParticipantRecord(res.data[0])
|
|
315
|
-
: undefined;
|
|
316
|
-
} catch (err) {
|
|
317
|
-
return { error: err };
|
|
318
|
-
}
|
|
215
|
+
async getEvent(id, mpOptions = {}) {
|
|
216
|
+
return getOne<EventRecord, Event>(
|
|
217
|
+
{ path: `/tables/events`, id, mpOptions }
|
|
218
|
+
);
|
|
319
219
|
},
|
|
320
|
-
async
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
);
|
|
325
|
-
return res.data[0] ? mapEventRecord(res.data[0]) : undefined;
|
|
326
|
-
} catch (err) {
|
|
327
|
-
return { error: err };
|
|
328
|
-
}
|
|
220
|
+
async getGroup(id, mpOptions = {}) {
|
|
221
|
+
return getOne<GroupRecord, Group>(
|
|
222
|
+
{ path: `/tables/groups`, id, mpOptions }
|
|
223
|
+
);
|
|
329
224
|
},
|
|
330
|
-
async
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
);
|
|
335
|
-
return res.data[0] ? mapGroupRecord(res.data[0]) : undefined;
|
|
336
|
-
} catch (err) {
|
|
337
|
-
return { error: err };
|
|
338
|
-
}
|
|
225
|
+
async getEventParticipant(id, mpOptions = {}) {
|
|
226
|
+
return getOne<EventParticipantRecord, EventParticipant>(
|
|
227
|
+
{ path: `/tables/event_participants`, id, mpOptions }
|
|
228
|
+
);
|
|
339
229
|
},
|
|
340
|
-
async
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
);
|
|
345
|
-
return res.data[0]
|
|
346
|
-
? mapEventParticipantRecord(res.data[0])
|
|
347
|
-
: undefined;
|
|
348
|
-
} catch (err) {
|
|
349
|
-
return { error: err };
|
|
350
|
-
}
|
|
230
|
+
async getGroupParticipant(id, mpOptions = {}) {
|
|
231
|
+
return getOne<GroupParticipantRecord, GroupParticipant>(
|
|
232
|
+
{ path: `/tables/group_participants`, id, mpOptions }
|
|
233
|
+
);
|
|
351
234
|
},
|
|
352
|
-
async
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
);
|
|
357
|
-
return res.data[0]
|
|
358
|
-
? mapGroupParticipantRecord(res.data[0])
|
|
359
|
-
: undefined;
|
|
360
|
-
} catch (err) {
|
|
361
|
-
return { error: err };
|
|
362
|
-
}
|
|
235
|
+
async getFormResponse(id, mpOptions = {}) {
|
|
236
|
+
return getOne<FormResponseRecord, FormResponse>(
|
|
237
|
+
{ path: `/tables/form_responses`, id, mpOptions }
|
|
238
|
+
);
|
|
363
239
|
},
|
|
364
|
-
async getContacts(
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
);
|
|
369
|
-
return res.data.map(mapContactRecord);
|
|
370
|
-
} catch (err) {
|
|
371
|
-
return { error: err };
|
|
372
|
-
}
|
|
240
|
+
async getContacts(mpOptions = {}) {
|
|
241
|
+
return getMultiple<ContactRecord, Contact>(
|
|
242
|
+
{ path: `/tables/contacts`, mpOptions }
|
|
243
|
+
);
|
|
373
244
|
},
|
|
374
|
-
async getHouseholds(
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
);
|
|
379
|
-
return res.data.map(mapHouseholdRecord);
|
|
380
|
-
} catch (err) {
|
|
381
|
-
return { error: err };
|
|
382
|
-
}
|
|
245
|
+
async getHouseholds(mpOptions = {}) {
|
|
246
|
+
return getMultiple<HouseholdRecord, Household>(
|
|
247
|
+
{ path: `/tables/households`, mpOptions }
|
|
248
|
+
);
|
|
383
249
|
},
|
|
384
|
-
async getAddresses(
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
);
|
|
389
|
-
return res.data.map(mapAddressRecord);
|
|
390
|
-
} catch (err) {
|
|
391
|
-
return { error: err };
|
|
392
|
-
}
|
|
250
|
+
async getAddresses(mpOptions = {}) {
|
|
251
|
+
return getMultiple<AddressRecord, Address>(
|
|
252
|
+
{ path: `/tables/addresses`, mpOptions }
|
|
253
|
+
);
|
|
393
254
|
},
|
|
394
|
-
async getParticipants(
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
);
|
|
399
|
-
return res.data.map(mapParticipantRecord);
|
|
400
|
-
} catch (err) {
|
|
401
|
-
return { error: err };
|
|
402
|
-
}
|
|
255
|
+
async getParticipants(mpOptions = {}) {
|
|
256
|
+
return getMultiple<ParticipantRecord, Participant>(
|
|
257
|
+
{ path: `/tables/participants`, mpOptions }
|
|
258
|
+
);
|
|
403
259
|
},
|
|
404
|
-
async getEvents(
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
} catch (err) {
|
|
409
|
-
return { error: err };
|
|
410
|
-
}
|
|
260
|
+
async getEvents(mpOptions = {}) {
|
|
261
|
+
return getMultiple<EventRecord, Event>(
|
|
262
|
+
{ path: `/tables/events`, mpOptions }
|
|
263
|
+
);
|
|
411
264
|
},
|
|
412
|
-
async getGroups(
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
} catch (err) {
|
|
417
|
-
return { error: err };
|
|
418
|
-
}
|
|
265
|
+
async getGroups(mpOptions = {}) {
|
|
266
|
+
return getMultiple<GroupRecord, Group>(
|
|
267
|
+
{ path: `/tables/groups`, mpOptions }
|
|
268
|
+
);
|
|
419
269
|
},
|
|
420
|
-
async getEventParticipants(
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
);
|
|
425
|
-
return res.data.map(mapEventParticipantRecord);
|
|
426
|
-
} catch (err) {
|
|
427
|
-
return { error: err };
|
|
428
|
-
}
|
|
270
|
+
async getEventParticipants(mpOptions = {}) {
|
|
271
|
+
return getMultiple<EventParticipantRecord, EventParticipant>(
|
|
272
|
+
{ path: `/tables/event_participants`, mpOptions }
|
|
273
|
+
);
|
|
429
274
|
},
|
|
430
|
-
async getGroupParticipants(
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
);
|
|
435
|
-
return res.data.map(mapGroupParticipantRecord);
|
|
436
|
-
} catch (err) {
|
|
437
|
-
return { error: err };
|
|
438
|
-
}
|
|
275
|
+
async getGroupParticipants(mpOptions = {}) {
|
|
276
|
+
return getMultiple<GroupParticipantRecord, GroupParticipant>(
|
|
277
|
+
{ path: `/tables/group_participants`, mpOptions }
|
|
278
|
+
);
|
|
439
279
|
},
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
}
|
|
280
|
+
|
|
281
|
+
async createContact(params, mpOptions = {}) {
|
|
282
|
+
return create<CreateContactParams, Contact>(
|
|
283
|
+
{ path: `/tables/contacts`, mpOptions, params }
|
|
284
|
+
);
|
|
285
|
+
},
|
|
286
|
+
async createHousehold(params, mpOptions) {
|
|
287
|
+
return create<CreateHouseholdParams, Household>(
|
|
288
|
+
{ path: `/tables/households`, mpOptions, params }
|
|
289
|
+
);
|
|
451
290
|
},
|
|
452
|
-
async
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
return { error: err };
|
|
462
|
-
}
|
|
291
|
+
async createAddress(params, mpOptions) {
|
|
292
|
+
return create<CreateAddressParams, Address>(
|
|
293
|
+
{ path: `/tables/addresses`, mpOptions, params }
|
|
294
|
+
);
|
|
295
|
+
},
|
|
296
|
+
async createParticipant(params, mpOptions) {
|
|
297
|
+
return create<CreateParticipantParams, Participant>(
|
|
298
|
+
{ path: `/tables/participants`, mpOptions, params }
|
|
299
|
+
);
|
|
463
300
|
},
|
|
464
|
-
async
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
`/tables/addresses${query}`,
|
|
469
|
-
[mapAddressToAddressRecord(params as Address)]
|
|
470
|
-
);
|
|
471
|
-
return mapAddressRecord(res.data[0]);
|
|
472
|
-
} catch (err) {
|
|
473
|
-
return { error: err };
|
|
474
|
-
}
|
|
301
|
+
async createEventParticipant(params, mpOptions) {
|
|
302
|
+
return create<CreateEventParticipantParams, EventParticipant>(
|
|
303
|
+
{ path: `/tables/event_participants`, mpOptions, params }
|
|
304
|
+
);
|
|
475
305
|
},
|
|
476
|
-
async
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
`/tables/participants${query}`,
|
|
481
|
-
[mapParticipantToParticipantRecord(params as Participant)]
|
|
482
|
-
);
|
|
483
|
-
return mapParticipantRecord(res.data[0]);
|
|
484
|
-
} catch (err) {
|
|
485
|
-
return { error: err };
|
|
486
|
-
}
|
|
306
|
+
async createGroupParticipant(params, mpOptions) {
|
|
307
|
+
return create<CreateGroupParticipantParams, GroupParticipant>(
|
|
308
|
+
{ path: `/tables/group_participants`, mpOptions, params }
|
|
309
|
+
);
|
|
487
310
|
},
|
|
488
|
-
async
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
`/tables/event_participants${query}`,
|
|
493
|
-
[
|
|
494
|
-
mapEventParticipantToEventParticipantRecord(
|
|
495
|
-
params as EventParticipant
|
|
496
|
-
),
|
|
497
|
-
]
|
|
498
|
-
);
|
|
499
|
-
return mapEventParticipantRecord(res.data[0]);
|
|
500
|
-
} catch (err) {
|
|
501
|
-
return { error: err };
|
|
502
|
-
}
|
|
311
|
+
async createContactAttribute(params, mpOptions) {
|
|
312
|
+
return create<CreateContactAttributeParams, ContactAttribute>(
|
|
313
|
+
{ path: `/tables/contact_attributes`, mpOptions, params }
|
|
314
|
+
);
|
|
503
315
|
},
|
|
504
|
-
async
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
`/tables/group_participants${query}`,
|
|
509
|
-
[
|
|
510
|
-
mapGroupParticipantToGroupParticipantRecord(
|
|
511
|
-
params as GroupParticipant
|
|
512
|
-
),
|
|
513
|
-
]
|
|
514
|
-
);
|
|
515
|
-
return mapGroupParticipantRecord(res.data[0]);
|
|
516
|
-
} catch (err) {
|
|
517
|
-
return { error: err };
|
|
518
|
-
}
|
|
316
|
+
async createFormResponse(params: CreateFormResponseParams, mpOptions) {
|
|
317
|
+
return create<CreateFormResponseParams, FormResponse>(
|
|
318
|
+
{ path: `/tables/form_responses`, mpOptions, params }
|
|
319
|
+
);
|
|
519
320
|
},
|
|
520
|
-
async
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
`/tables/contact_attributes${query}`,
|
|
525
|
-
[
|
|
526
|
-
mapContactAttributeToContactAttributeRecord(
|
|
527
|
-
params as ContactAttribute
|
|
528
|
-
),
|
|
529
|
-
]
|
|
530
|
-
);
|
|
531
|
-
return mapContactAttributeRecord(res.data[0]);
|
|
532
|
-
} catch (err) {
|
|
533
|
-
return { error: err };
|
|
534
|
-
}
|
|
321
|
+
async createFormResponseAnswers(params, mpOptions) {
|
|
322
|
+
return create<CreateFormResponseAnswerParams, FormResponseAnswer>(
|
|
323
|
+
{ path: `/tables/form_response_answers`, mpOptions, params }
|
|
324
|
+
);
|
|
535
325
|
},
|
|
536
|
-
async updateContacts(
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
`/tables/contacts${query}`,
|
|
541
|
-
contacts.map(mapContactToContactRecord)
|
|
542
|
-
);
|
|
543
|
-
return res.data.map(mapContactRecord);
|
|
544
|
-
} catch (err) {
|
|
545
|
-
return { error: err };
|
|
546
|
-
}
|
|
326
|
+
async updateContacts(params, mpOptions) {
|
|
327
|
+
return update<Partial<Contact>, Contact>(
|
|
328
|
+
{ path: `/tables/contacts`, mpOptions, params }
|
|
329
|
+
);
|
|
547
330
|
},
|
|
548
|
-
async updateEventParticipants(
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
eventParticipants.map(mapEventParticipantToEventParticipantRecord)
|
|
553
|
-
);
|
|
554
|
-
return res.data.map(mapEventParticipantRecord);
|
|
555
|
-
} catch (err) {
|
|
556
|
-
return { error: err };
|
|
557
|
-
}
|
|
331
|
+
async updateEventParticipants(params, mpOptions) {
|
|
332
|
+
return update<Partial<EventParticipant>, EventParticipant>(
|
|
333
|
+
{ path: `/tables/event_participants`, mpOptions, params }
|
|
334
|
+
);
|
|
558
335
|
},
|
|
559
336
|
};
|
|
560
337
|
};
|
|
@@ -566,7 +343,13 @@ export {
|
|
|
566
343
|
Group,
|
|
567
344
|
EventParticipant,
|
|
568
345
|
GroupParticipant,
|
|
346
|
+
ContactAttribute,
|
|
569
347
|
Household,
|
|
570
348
|
Address,
|
|
571
|
-
|
|
349
|
+
FormResponse,
|
|
350
|
+
ErrorDetails,
|
|
351
|
+
convertToCamelCase,
|
|
352
|
+
convertToSnakeCase,
|
|
353
|
+
stringifyURLParams,
|
|
354
|
+
escapeSql
|
|
572
355
|
};
|