mp-js-api 0.0.1

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 (48) hide show
  1. package/dist/index.d.ts +120 -0
  2. package/dist/index.d.ts.map +1 -0
  3. package/dist/index.js +341 -0
  4. package/dist/tables/addresses.d.ts +55 -0
  5. package/dist/tables/addresses.d.ts.map +1 -0
  6. package/dist/tables/addresses.js +60 -0
  7. package/dist/tables/contact-attributes.d.ts +19 -0
  8. package/dist/tables/contact-attributes.d.ts.map +1 -0
  9. package/dist/tables/contact-attributes.js +24 -0
  10. package/dist/tables/contacts.d.ts +105 -0
  11. package/dist/tables/contacts.d.ts.map +1 -0
  12. package/dist/tables/contacts.js +114 -0
  13. package/dist/tables/event-participants.d.ts +47 -0
  14. package/dist/tables/event-participants.d.ts.map +1 -0
  15. package/dist/tables/event-participants.js +52 -0
  16. package/dist/tables/events.d.ts +117 -0
  17. package/dist/tables/events.d.ts.map +1 -0
  18. package/dist/tables/events.js +122 -0
  19. package/dist/tables/group-participants.d.ts +61 -0
  20. package/dist/tables/group-participants.d.ts.map +1 -0
  21. package/dist/tables/group-participants.js +66 -0
  22. package/dist/tables/groups.d.ts +103 -0
  23. package/dist/tables/groups.d.ts.map +1 -0
  24. package/dist/tables/groups.js +108 -0
  25. package/dist/tables/households.d.ts +55 -0
  26. package/dist/tables/households.d.ts.map +1 -0
  27. package/dist/tables/households.js +60 -0
  28. package/dist/tables/participants.d.ts +63 -0
  29. package/dist/tables/participants.d.ts.map +1 -0
  30. package/dist/tables/participants.js +68 -0
  31. package/dist/utils/strings.d.ts +2 -0
  32. package/dist/utils/strings.d.ts.map +1 -0
  33. package/dist/utils/strings.js +30 -0
  34. package/package.json +26 -0
  35. package/src/index.ts +571 -0
  36. package/src/tables/addresses.ts +111 -0
  37. package/src/tables/contact-attributes.ts +40 -0
  38. package/src/tables/contacts.ts +223 -0
  39. package/src/tables/event-participants.ts +95 -0
  40. package/src/tables/events.ts +235 -0
  41. package/src/tables/group-participants.ts +123 -0
  42. package/src/tables/groups.ts +207 -0
  43. package/src/tables/households.ts +111 -0
  44. package/src/tables/participants.ts +127 -0
  45. package/src/utils/strings.ts +29 -0
  46. package/src/utils/types.d.ts +7 -0
  47. package/test/index.spec.ts +103 -0
  48. package/tsconfig.json +25 -0
@@ -0,0 +1,120 @@
1
+ import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
2
+ import { Contact } from './tables/contacts';
3
+ import { Participant } from './tables/participants';
4
+ import { EventParticipant } from './tables/event-participants';
5
+ import { GroupParticipant } from './tables/group-participants';
6
+ import { Event } from './tables/events';
7
+ import { Group } from './tables/groups';
8
+ import { Household } from './tables/households';
9
+ import { Address } from './tables/addresses';
10
+ import { ContactAttribute } from './tables/contact-attributes';
11
+ type WithRequired<T, K extends keyof T> = T & Required<Pick<T, K>>;
12
+ export type CreateContactParams = WithRequired<Partial<Contact>, 'company' | 'displayName'>;
13
+ export type CreateHouseholdParams = WithRequired<Partial<Household>, 'householdName'>;
14
+ export type CreateAddressParams = WithRequired<Partial<Address>, 'addressLine1'>;
15
+ export type CreateParticipantParams = WithRequired<Partial<Participant>, 'contactID' | 'participantTypeID' | 'participantStartDate'>;
16
+ export type CreateEventParticipantParams = WithRequired<Partial<EventParticipant>, 'eventID' | 'participantID' | 'participationStatusID'>;
17
+ export type CreateGroupParticipantParams = WithRequired<Partial<GroupParticipant>, 'groupID' | 'participantID' | 'groupRoleID' | 'startDate'>;
18
+ export type CreateContactAttributeParams = WithRequired<Partial<ContactAttribute>, 'attributeID' | 'contactID' | 'startDate'>;
19
+ export type MPGetOptions = {
20
+ select?: string;
21
+ filter?: string;
22
+ orderBy?: string;
23
+ groupBy?: string;
24
+ top?: number;
25
+ skip?: number;
26
+ distinct?: boolean;
27
+ };
28
+ export type MPCreateOptions = {
29
+ user?: number;
30
+ };
31
+ export type MPUpdateOptions = MPCreateOptions;
32
+ export type MPGetInstance = <T = any, R = AxiosResponse<T, any>>(url: string, mpOptions?: MPGetOptions, config?: AxiosRequestConfig) => Promise<R>;
33
+ export type MPInstance = {
34
+ get: MPGetInstance;
35
+ post: AxiosInstance['post'];
36
+ put: AxiosInstance['put'];
37
+ getContact(id: number, options?: MPGetOptions): Promise<Contact | undefined | {
38
+ error: any;
39
+ }>;
40
+ getHousehold(id: number, options?: MPGetOptions): Promise<Household | undefined | {
41
+ error: any;
42
+ }>;
43
+ getAddress(id: number, options?: MPGetOptions): Promise<Address | undefined | {
44
+ error: any;
45
+ }>;
46
+ getParticipant(id: number, options?: MPGetOptions): Promise<Participant | undefined | {
47
+ error: any;
48
+ }>;
49
+ getEvent(id: number, options?: MPGetOptions): Promise<Event | undefined | {
50
+ error: any;
51
+ }>;
52
+ getGroup(id: number, options?: MPGetOptions): Promise<Group | undefined | {
53
+ error: any;
54
+ }>;
55
+ getEventParticipant(id: number, options?: MPGetOptions): Promise<EventParticipant | undefined | {
56
+ error: any;
57
+ }>;
58
+ getGroupParticipant(id: number, options?: MPGetOptions): Promise<GroupParticipant | undefined | {
59
+ error: any;
60
+ }>;
61
+ getContacts(options?: MPGetOptions): Promise<Contact[] | {
62
+ error: any;
63
+ }>;
64
+ getHouseholds(options?: MPGetOptions): Promise<Household[] | {
65
+ error: any;
66
+ }>;
67
+ getAddresses(options?: MPGetOptions): Promise<Address[] | {
68
+ error: any;
69
+ }>;
70
+ getParticipants(options?: MPGetOptions): Promise<Participant[] | {
71
+ error: any;
72
+ }>;
73
+ getEvents(options?: MPGetOptions): Promise<Event[] | {
74
+ error: any;
75
+ }>;
76
+ getGroups(options?: MPGetOptions): Promise<Group[] | {
77
+ error: any;
78
+ }>;
79
+ getEventParticipants(options?: MPGetOptions): Promise<EventParticipant[] | {
80
+ error: any;
81
+ }>;
82
+ getGroupParticipants(options?: MPGetOptions): Promise<GroupParticipant[] | {
83
+ error: any;
84
+ }>;
85
+ createContact(params: CreateContactParams, options?: MPCreateOptions): Promise<Contact | {
86
+ error: any;
87
+ }>;
88
+ createHousehold(params: CreateHouseholdParams, options?: MPCreateOptions): Promise<Household | {
89
+ error: any;
90
+ }>;
91
+ createAddress(params: CreateAddressParams, options?: MPCreateOptions): Promise<Address | {
92
+ error: any;
93
+ }>;
94
+ createParticipant(params: CreateParticipantParams, options?: MPCreateOptions): Promise<Participant | {
95
+ error: any;
96
+ }>;
97
+ createEventParticipant(params: CreateEventParticipantParams, options?: MPCreateOptions): Promise<EventParticipant | {
98
+ error: any;
99
+ }>;
100
+ createGroupParticipant(params: CreateGroupParticipantParams, options?: MPCreateOptions): Promise<GroupParticipant | {
101
+ error: any;
102
+ }>;
103
+ createContactAttribute(params: CreateContactAttributeParams, options?: MPCreateOptions): Promise<ContactAttribute | {
104
+ error: any;
105
+ }>;
106
+ updateContacts(contacts: WithRequired<Partial<Contact>, 'contactID'>[], options?: MPUpdateOptions): Promise<Contact[] | {
107
+ error: any;
108
+ }>;
109
+ updateEventParticipants(participants: WithRequired<Partial<EventParticipant>, 'eventParticipantID'>[], options?: MPUpdateOptions): Promise<EventParticipant[] | {
110
+ error: any;
111
+ }>;
112
+ };
113
+ export declare const createMPInstance: ({ auth }: {
114
+ auth: {
115
+ username: string;
116
+ password: string;
117
+ };
118
+ }) => MPInstance;
119
+ export { Contact, Participant, Event, Group, EventParticipant, GroupParticipant, Household, Address, ContactAttribute };
120
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,aAAa,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAEhF,OAAO,EAAE,OAAO,EAA6B,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAAE,WAAW,EAAsC,MAAM,uBAAuB,CAAC;AACxF,OAAO,EAAE,gBAAgB,EAAgD,MAAM,6BAA6B,CAAC;AAC7G,OAAO,EAAE,gBAAgB,EAAgD,MAAM,6BAA6B,CAAC;AAC7G,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1B,OAAO,CAAC,gBAAgB,GAAG;QAAE,KAAK,EAAE,GAAG,CAAC;KAAE,CAAC,CAAC;IAC/C,sBAAsB,CAClB,MAAM,EAAE,4BAA4B,EACpC,OAAO,CAAC,EAAE,eAAe,GAC1B,OAAO,CAAC,gBAAgB,GAAG;QAAE,KAAK,EAAE,GAAG,CAAC;KAAE,CAAC,CAAC;IAC/C,sBAAsB,CAClB,MAAM,EAAE,4BAA4B,EACpC,OAAO,CAAC,EAAE,eAAe,GAC1B,OAAO,CAAC,gBAAgB,GAAG;QAAE,KAAK,EAAE,GAAG,CAAC;KAAE,CAAC,CAAC;IAE/C,cAAc,CACV,QAAQ,EAAE,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,WAAW,CAAC,EAAE,EACvD,OAAO,CAAC,EAAE,eAAe,GAC1B,OAAO,CAAC,OAAO,EAAE,GAAG;QAAE,KAAK,EAAE,GAAG,CAAC;KAAE,CAAC,CAAC;IAExC,uBAAuB,CACnB,YAAY,EAAE,YAAY,CAAC,OAAO,CAAC,gBAAgB,CAAC,EAAE,oBAAoB,CAAC,EAAE,EAC7E,OAAO,CAAC,EAAE,eAAe,GAC1B,OAAO,CAAC,gBAAgB,EAAE,GAAG;QAAE,KAAK,EAAE,GAAG,CAAC;KAAE,CAAC,CAAC;CACpD,CAAC;AAYF,eAAO,MAAM,gBAAgB,aAAc;IAAE,IAAI,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;KAAE,CAAC;CAAE,KAAG,UA+U/F,CAAC;AAEF,OAAO,EACH,OAAO,EACP,WAAW,EACX,KAAK,EACL,KAAK,EACL,gBAAgB,EAChB,gBAAgB,EAChB,SAAS,EACT,OAAO,EACP,gBAAgB,EACnB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,341 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createMPInstance = void 0;
7
+ const axios_1 = __importDefault(require("axios"));
8
+ const url_1 = require("url");
9
+ const contacts_1 = require("./tables/contacts");
10
+ const participants_1 = require("./tables/participants");
11
+ const event_participants_1 = require("./tables/event-participants");
12
+ const group_participants_1 = require("./tables/group-participants");
13
+ const contacts_2 = require("./tables/contacts");
14
+ const participants_2 = require("./tables/participants");
15
+ const events_1 = require("./tables/events");
16
+ const groups_1 = require("./tables/groups");
17
+ const event_participants_2 = require("./tables/event-participants");
18
+ const group_participants_2 = require("./tables/group-participants");
19
+ const households_1 = require("./tables/households");
20
+ const addresses_1 = require("./tables/addresses");
21
+ const contact_attributes_1 = require("./tables/contact-attributes");
22
+ const createTokenGetter = (auth) => {
23
+ let token;
24
+ return async () => {
25
+ // If the token is near expiration, get a new one.
26
+ if (!token || token.expiration - 60000 < Date.now()) {
27
+ const tokenRes = await axios_1.default.post('https://mp.revival.com/ministryplatformapi/oauth/connect/token', new url_1.URLSearchParams({
28
+ grant_type: 'client_credentials',
29
+ scope: 'http://www.thinkministry.com/dataplatform/scopes/all',
30
+ }).toString(), { auth });
31
+ const [, payload] = tokenRes.data.access_token.split('.');
32
+ try {
33
+ const jsonPayload = JSON.parse(Buffer.from(payload, 'base64url').toString());
34
+ token = {
35
+ digest: tokenRes.data.access_token,
36
+ expiration: jsonPayload.exp * 1000,
37
+ };
38
+ return token.digest;
39
+ }
40
+ catch (err) {
41
+ console.error(err);
42
+ }
43
+ }
44
+ else {
45
+ return token.digest;
46
+ }
47
+ };
48
+ };
49
+ const stringifyMPOptions = (mpOptions = {}) => Object.entries(mpOptions).reduce((acc, [key, value]) => {
50
+ if (!acc) {
51
+ acc += `?$${key}=${value}`;
52
+ }
53
+ else {
54
+ acc += `&$${key}=${value}`;
55
+ }
56
+ return acc;
57
+ }, '').escapeSql();
58
+ const createMPInstance = ({ auth }) => {
59
+ /**
60
+ * Gets MP oauth token.
61
+ * @returns token
62
+ */
63
+ const getToken = createTokenGetter(auth);
64
+ const api = axios_1.default.create({
65
+ baseURL: 'https://mp.revival.com/ministryplatformapi',
66
+ });
67
+ const get = async (url, mpOptions, config) => api.get(url + stringifyMPOptions(mpOptions), {
68
+ ...config,
69
+ headers: {
70
+ ...config?.headers,
71
+ Authorization: `Bearer ${await getToken()}`,
72
+ },
73
+ });
74
+ const post = async (url, data, config) => api.post(url, data, {
75
+ ...config,
76
+ headers: {
77
+ ...config?.headers,
78
+ Authorization: `Bearer ${await getToken()}`,
79
+ },
80
+ });
81
+ const put = async (url, data, config) => api.put(url, data, {
82
+ ...config,
83
+ headers: {
84
+ ...config?.headers,
85
+ Authorization: `Bearer ${await getToken()}`,
86
+ },
87
+ });
88
+ return {
89
+ get,
90
+ post,
91
+ put,
92
+ async getContact(id, options = {}) {
93
+ try {
94
+ const res = await get(`/tables/contacts/${id}`, options);
95
+ return res.data[0] ? (0, contacts_2.mapContactRecord)(res.data[0]) : undefined;
96
+ }
97
+ catch (err) {
98
+ return { error: err };
99
+ }
100
+ },
101
+ async getHousehold(id, options = {}) {
102
+ try {
103
+ const res = await get(`/tables/households/${id}`, options);
104
+ return res.data[0]
105
+ ? (0, households_1.mapHouseholdRecord)(res.data[0])
106
+ : undefined;
107
+ }
108
+ catch (err) {
109
+ return { error: err };
110
+ }
111
+ },
112
+ async getAddress(id, options = {}) {
113
+ try {
114
+ const res = await get(`/tables/addresses/${id}`, options);
115
+ return res.data[0] ? (0, addresses_1.mapAddressRecord)(res.data[0]) : undefined;
116
+ }
117
+ catch (err) {
118
+ return { error: err };
119
+ }
120
+ },
121
+ async getParticipant(id, options = {}) {
122
+ try {
123
+ const res = await get(`/tables/participants/${id}`, options);
124
+ return res.data[0]
125
+ ? (0, participants_2.mapParticipantRecord)(res.data[0])
126
+ : undefined;
127
+ }
128
+ catch (err) {
129
+ return { error: err };
130
+ }
131
+ },
132
+ async getEvent(id, options = {}) {
133
+ try {
134
+ const res = await get(`/tables/events/${id}`, options);
135
+ return res.data[0] ? (0, events_1.mapEventRecord)(res.data[0]) : undefined;
136
+ }
137
+ catch (err) {
138
+ return { error: err };
139
+ }
140
+ },
141
+ async getGroup(id, options = {}) {
142
+ try {
143
+ const res = await get(`/tables/groups/${id}`, options);
144
+ return res.data[0] ? (0, groups_1.mapGroupRecord)(res.data[0]) : undefined;
145
+ }
146
+ catch (err) {
147
+ return { error: err };
148
+ }
149
+ },
150
+ async getEventParticipant(id, options = {}) {
151
+ try {
152
+ const res = await get(`/tables/event_participants/${id}`, options);
153
+ return res.data[0]
154
+ ? (0, event_participants_2.mapEventParticipantRecord)(res.data[0])
155
+ : undefined;
156
+ }
157
+ catch (err) {
158
+ return { error: err };
159
+ }
160
+ },
161
+ async getGroupParticipant(id, options = {}) {
162
+ try {
163
+ const res = await get(`/tables/group_participants/${id}`, options);
164
+ return res.data[0]
165
+ ? (0, group_participants_2.mapGroupParticipantRecord)(res.data[0])
166
+ : undefined;
167
+ }
168
+ catch (err) {
169
+ return { error: err };
170
+ }
171
+ },
172
+ async getContacts(options = {}) {
173
+ try {
174
+ const res = await get(`/tables/contacts`, options);
175
+ return res.data.map(contacts_2.mapContactRecord);
176
+ }
177
+ catch (err) {
178
+ return { error: err };
179
+ }
180
+ },
181
+ async getHouseholds(options = {}) {
182
+ try {
183
+ const res = await get(`/tables/households`, options);
184
+ return res.data.map(households_1.mapHouseholdRecord);
185
+ }
186
+ catch (err) {
187
+ return { error: err };
188
+ }
189
+ },
190
+ async getAddresses(options = {}) {
191
+ try {
192
+ const res = await get(`/tables/addresses`, options);
193
+ return res.data.map(addresses_1.mapAddressRecord);
194
+ }
195
+ catch (err) {
196
+ return { error: err };
197
+ }
198
+ },
199
+ async getParticipants(options = {}) {
200
+ try {
201
+ const res = await get(`/tables/participants`, options);
202
+ return res.data.map(participants_2.mapParticipantRecord);
203
+ }
204
+ catch (err) {
205
+ return { error: err };
206
+ }
207
+ },
208
+ async getEvents(options = {}) {
209
+ try {
210
+ const res = await get(`/tables/events`, options);
211
+ return res.data.map(events_1.mapEventRecord);
212
+ }
213
+ catch (err) {
214
+ return { error: err };
215
+ }
216
+ },
217
+ async getGroups(options = {}) {
218
+ try {
219
+ const res = await get(`/tables/groups`, options);
220
+ return res.data.map(groups_1.mapGroupRecord);
221
+ }
222
+ catch (err) {
223
+ return { error: err };
224
+ }
225
+ },
226
+ async getEventParticipants(options = {}) {
227
+ try {
228
+ const res = await get(`/tables/event_participants`, options);
229
+ return res.data.map(event_participants_2.mapEventParticipantRecord);
230
+ }
231
+ catch (err) {
232
+ return { error: err };
233
+ }
234
+ },
235
+ async getGroupParticipants(options = {}) {
236
+ try {
237
+ const res = await get(`/tables/group_participants`, options);
238
+ return res.data.map(group_participants_2.mapGroupParticipantRecord);
239
+ }
240
+ catch (err) {
241
+ return { error: err };
242
+ }
243
+ },
244
+ async createContact(params, options = {}) {
245
+ const query = stringifyMPOptions(options);
246
+ try {
247
+ const res = await post(`/tables/contacts${query}`, [(0, contacts_1.mapContactToContactRecord)(params)]);
248
+ return (0, contacts_2.mapContactRecord)(res.data[0]);
249
+ }
250
+ catch (err) {
251
+ return { error: err };
252
+ }
253
+ },
254
+ async createHousehold(params, options = {}) {
255
+ const query = stringifyMPOptions(options);
256
+ try {
257
+ const res = await post(`/tables/households${query}`, [(0, households_1.mapHouseholdToHouseholdRecord)(params)]);
258
+ return (0, households_1.mapHouseholdRecord)(res.data[0]);
259
+ }
260
+ catch (err) {
261
+ return { error: err };
262
+ }
263
+ },
264
+ async createAddress(params, options = {}) {
265
+ const query = stringifyMPOptions(options);
266
+ try {
267
+ const res = await post(`/tables/addresses${query}`, [(0, addresses_1.mapAddressToAddressRecord)(params)]);
268
+ return (0, addresses_1.mapAddressRecord)(res.data[0]);
269
+ }
270
+ catch (err) {
271
+ return { error: err };
272
+ }
273
+ },
274
+ async createParticipant(params, options = {}) {
275
+ const query = stringifyMPOptions(options);
276
+ try {
277
+ const res = await post(`/tables/participants${query}`, [(0, participants_1.mapParticipantToParticipantRecord)(params)]);
278
+ return (0, participants_2.mapParticipantRecord)(res.data[0]);
279
+ }
280
+ catch (err) {
281
+ return { error: err };
282
+ }
283
+ },
284
+ async createEventParticipant(params, options = {}) {
285
+ const query = stringifyMPOptions(options);
286
+ try {
287
+ const res = await post(`/tables/event_participants${query}`, [
288
+ (0, event_participants_1.mapEventParticipantToEventParticipantRecord)(params),
289
+ ]);
290
+ return (0, event_participants_2.mapEventParticipantRecord)(res.data[0]);
291
+ }
292
+ catch (err) {
293
+ return { error: err };
294
+ }
295
+ },
296
+ async createGroupParticipant(params, options = {}) {
297
+ const query = stringifyMPOptions(options);
298
+ try {
299
+ const res = await post(`/tables/group_participants${query}`, [
300
+ (0, group_participants_1.mapGroupParticipantToGroupParticipantRecord)(params),
301
+ ]);
302
+ return (0, group_participants_2.mapGroupParticipantRecord)(res.data[0]);
303
+ }
304
+ catch (err) {
305
+ return { error: err };
306
+ }
307
+ },
308
+ async createContactAttribute(params, options = {}) {
309
+ const query = stringifyMPOptions(options);
310
+ try {
311
+ const res = await post(`/tables/contact_attributes${query}`, [
312
+ (0, contact_attributes_1.mapContactAttributeToContactAttributeRecord)(params),
313
+ ]);
314
+ return (0, contact_attributes_1.mapContactAttributeRecord)(res.data[0]);
315
+ }
316
+ catch (err) {
317
+ return { error: err };
318
+ }
319
+ },
320
+ async updateContacts(contacts, options = {}) {
321
+ const query = stringifyMPOptions(options);
322
+ try {
323
+ const res = await put(`/tables/contacts${query}`, contacts.map(contacts_1.mapContactToContactRecord));
324
+ return res.data.map(contacts_2.mapContactRecord);
325
+ }
326
+ catch (err) {
327
+ return { error: err };
328
+ }
329
+ },
330
+ async updateEventParticipants(eventParticipants, options = {}) {
331
+ try {
332
+ const res = await put(`/tables/event_participants`, eventParticipants.map(event_participants_1.mapEventParticipantToEventParticipantRecord));
333
+ return res.data.map(event_participants_2.mapEventParticipantRecord);
334
+ }
335
+ catch (err) {
336
+ return { error: err };
337
+ }
338
+ },
339
+ };
340
+ };
341
+ exports.createMPInstance = createMPInstance;
@@ -0,0 +1,55 @@
1
+ export interface AddressRecord {
2
+ Address_ID: number;
3
+ Address_Line_1: string;
4
+ Address_Line_2: string;
5
+ City: string;
6
+ 'State/Region': string;
7
+ Postal_Code: string;
8
+ Foreign_Country: null | string;
9
+ Country_Code: string;
10
+ Carrier_Route: null | string;
11
+ Lot_Number: null | string;
12
+ Delivery_Point_Code: null | string;
13
+ Delivery_Point_Check_Digit: null | string;
14
+ Latitude: null | number;
15
+ Longitude: null | number;
16
+ Altitude: null | number;
17
+ Time_Zone: null | string;
18
+ Bar_Code: null | string;
19
+ Area_Code: null | string;
20
+ Last_Validation_Attempt: null | string;
21
+ County: string;
22
+ Validated: null | string;
23
+ Do_Not_Validate: boolean;
24
+ Last_GeoCode_Attempt: null | string;
25
+ Country: null | string;
26
+ }
27
+ export interface Address {
28
+ addressID: number;
29
+ addressLine1: string;
30
+ addressLine2: string;
31
+ city: string;
32
+ stateRegion: string;
33
+ postalCode: string;
34
+ foreignCountry: null | string;
35
+ countryCode: string;
36
+ carrierRoute: null | string;
37
+ lotNumber: null | string;
38
+ deliveryPointCode: null | string;
39
+ deliveryPointCheckDigit: null | string;
40
+ latitude: null | number;
41
+ longitude: null | number;
42
+ altitude: null | number;
43
+ timeZone: null | string;
44
+ barCode: null | string;
45
+ areaCode: null | string;
46
+ lastValidationAttempt: null | string;
47
+ county: string;
48
+ validated: null | string;
49
+ doNotValidate: boolean;
50
+ lastGeoCodeAttempt: null | string;
51
+ country: null | string;
52
+ }
53
+ export declare function mapAddressRecord(addressRecord: AddressRecord): Address;
54
+ export declare function mapAddressToAddressRecord(address: Address): AddressRecord;
55
+ //# sourceMappingURL=addresses.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addresses.d.ts","sourceRoot":"","sources":["../../src/tables/addresses.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAA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B,iBAAiB,EAAE,IAAI,GAAG,MAAM,CAAC;IACjC,uBAAuB,EAAE,IAAI,GAAG,MAAM,CAAC;IACvC,QAAQ,EAAE,IAAI,GAAG,MAAM,CAAC;IACxB,SAAS,EAAE,IAAI,GAAG,MAAM,CAAC;IACzB,QAAQ,EAAE,IAAI,GAAG,MAAM,CAAC;IACxB,QAAQ,EAAE,IAAI,GAAG,MAAM,CAAC;IACxB,OAAO,EAAE,IAAI,GAAG,MAAM,CAAC;IACvB,QAAQ,EAAE,IAAI,GAAG,MAAM,CAAC;IACxB,qBAAqB,EAAE,IAAI,GAAG,MAAM,CAAC;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,IAAI,GAAG,MAAM,CAAC;IACzB,aAAa,EAAE,OAAO,CAAC;IACvB,kBAAkB,EAAE,IAAI,GAAG,MAAM,CAAC;IAClC,OAAO,EAAE,IAAI,GAAG,MAAM,CAAC;CAC1B;AAED,wBAAgB,gBAAgB,CAAC,aAAa,EAAE,aAAa,GAAG,OAAO,CA2BtE;AAED,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,OAAO,GAAG,aAAa,CA2BzE"}
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mapAddressRecord = mapAddressRecord;
4
+ exports.mapAddressToAddressRecord = mapAddressToAddressRecord;
5
+ function mapAddressRecord(addressRecord) {
6
+ return {
7
+ addressID: addressRecord.Address_ID,
8
+ addressLine1: addressRecord.Address_Line_1,
9
+ addressLine2: addressRecord.Address_Line_2,
10
+ city: addressRecord.City,
11
+ stateRegion: addressRecord['State/Region'],
12
+ postalCode: addressRecord.Postal_Code,
13
+ foreignCountry: addressRecord.Foreign_Country,
14
+ countryCode: addressRecord.Country_Code,
15
+ carrierRoute: addressRecord.Carrier_Route,
16
+ lotNumber: addressRecord.Lot_Number,
17
+ deliveryPointCode: addressRecord.Delivery_Point_Code,
18
+ deliveryPointCheckDigit: addressRecord.Delivery_Point_Check_Digit,
19
+ latitude: addressRecord.Latitude,
20
+ longitude: addressRecord.Longitude,
21
+ altitude: addressRecord.Altitude,
22
+ timeZone: addressRecord.Time_Zone,
23
+ barCode: addressRecord.Bar_Code,
24
+ areaCode: addressRecord.Area_Code,
25
+ lastValidationAttempt: addressRecord.Last_Validation_Attempt,
26
+ county: addressRecord.County,
27
+ validated: addressRecord.Validated,
28
+ doNotValidate: addressRecord.Do_Not_Validate,
29
+ lastGeoCodeAttempt: addressRecord.Last_GeoCode_Attempt,
30
+ country: addressRecord.Country,
31
+ };
32
+ }
33
+ function mapAddressToAddressRecord(address) {
34
+ return {
35
+ Address_ID: address.addressID,
36
+ Address_Line_1: address.addressLine1,
37
+ Address_Line_2: address.addressLine2,
38
+ City: address.city,
39
+ ['State/Region']: address.stateRegion,
40
+ Postal_Code: address.postalCode,
41
+ Foreign_Country: address.foreignCountry,
42
+ Country_Code: address.countryCode,
43
+ Carrier_Route: address.carrierRoute,
44
+ Lot_Number: address.lotNumber,
45
+ Delivery_Point_Code: address.deliveryPointCode,
46
+ Delivery_Point_Check_Digit: address.deliveryPointCheckDigit,
47
+ Latitude: address.latitude,
48
+ Longitude: address.longitude,
49
+ Altitude: address.altitude,
50
+ Time_Zone: address.timeZone,
51
+ Bar_Code: address.barCode,
52
+ Area_Code: address.areaCode,
53
+ Last_Validation_Attempt: address.lastValidationAttempt,
54
+ County: address.county,
55
+ Validated: address.validated,
56
+ Do_Not_Validate: address.doNotValidate,
57
+ Last_GeoCode_Attempt: address.lastGeoCodeAttempt,
58
+ Country: address.country,
59
+ };
60
+ }
@@ -0,0 +1,19 @@
1
+ export interface ContactAttributeRecord {
2
+ Contact_Attribute_ID: number;
3
+ Contact_ID: number;
4
+ Attribute_ID: number;
5
+ Start_Date: string;
6
+ End_Date?: string | null;
7
+ Notes?: string | null;
8
+ }
9
+ export interface ContactAttribute {
10
+ contactAttributeID: number;
11
+ contactID: number;
12
+ attributeID: number;
13
+ startDate: string;
14
+ endDate?: string | null;
15
+ notes?: string | null;
16
+ }
17
+ export declare function mapContactAttributeRecord(originalObject: ContactAttributeRecord): ContactAttribute;
18
+ export declare function mapContactAttributeToContactAttributeRecord(contactAttribute: ContactAttribute): ContactAttributeRecord;
19
+ //# sourceMappingURL=contact-attributes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contact-attributes.d.ts","sourceRoot":"","sources":["../../src/tables/contact-attributes.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,sBAAsB;IACrC,oBAAoB,EAAE,MAAM,CAAC;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB;AAED,MAAM,WAAW,gBAAgB;IAC/B,kBAAkB,EAAE,MAAM,CAAC;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB;AAGD,wBAAgB,yBAAyB,CAAC,cAAc,EAAE,sBAAsB,GAAG,gBAAgB,CASlG;AAED,wBAAgB,2CAA2C,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,sBAAsB,CAStH"}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mapContactAttributeRecord = mapContactAttributeRecord;
4
+ exports.mapContactAttributeToContactAttributeRecord = mapContactAttributeToContactAttributeRecord;
5
+ function mapContactAttributeRecord(originalObject) {
6
+ return {
7
+ contactAttributeID: originalObject.Contact_Attribute_ID,
8
+ contactID: originalObject.Contact_ID,
9
+ attributeID: originalObject.Attribute_ID,
10
+ startDate: originalObject.Start_Date,
11
+ endDate: originalObject.End_Date,
12
+ notes: originalObject.Notes
13
+ };
14
+ }
15
+ function mapContactAttributeToContactAttributeRecord(contactAttribute) {
16
+ return {
17
+ Contact_Attribute_ID: contactAttribute.contactAttributeID,
18
+ Contact_ID: contactAttribute.contactID,
19
+ Attribute_ID: contactAttribute.attributeID,
20
+ Start_Date: contactAttribute.startDate,
21
+ End_Date: contactAttribute.endDate,
22
+ Notes: contactAttribute.notes
23
+ };
24
+ }