mp-js-api 0.0.1 → 0.0.3

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/.gitattributes ADDED
@@ -0,0 +1,2 @@
1
+ # Auto detect text files and perform LF normalization
2
+ * text=auto
@@ -1 +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,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAaxC,OAAO,EAAE,SAAS,EAAuE,MAAM,qBAAqB,CAAC;AACrH,OAAO,EAAE,OAAO,EAA8D,MAAM,oBAAoB,CAAC;AACzG,OAAO,EAAE,gBAAgB,EAAkG,MAAM,6BAA6B,CAAC;AA8C/J,KAAK,YAAY,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAEnE,MAAM,MAAM,mBAAmB,GAAG,YAAY,CAC1C,OAAO,CAAC,OAAO,CAAC,EAChB,SAAS,GAAG,aAAa,CAC5B,CAAC;AACF,MAAM,MAAM,qBAAqB,GAAG,YAAY,CAC5C,OAAO,CAAC,SAAS,CAAC,EAClB,eAAe,CAClB,CAAC;AACF,MAAM,MAAM,mBAAmB,GAAG,YAAY,CAC1C,OAAO,CAAC,OAAO,CAAC,EAChB,cAAc,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C,EAAE,WAAW,CAAC,EAAE,EACvD,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,OAAO,EAAE,GAAG;QAAE,KAAK,EAAE,GAAG,CAAC;KAAE,CAAC,CAAC;IAExC,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,GAAG,CAAC;KAAE,CAAC,CAAC;CAClD,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,EACL,OAAO,EACP,WAAW,EACX,KAAK,EACL,KAAK,EACL,gBAAgB,EAChB,gBAAgB,EAChB,SAAS,EACT,OAAO,EACP,gBAAgB,EACjB,CAAC"}
package/dist/index.js CHANGED
@@ -19,6 +19,7 @@ const group_participants_2 = require("./tables/group-participants");
19
19
  const households_1 = require("./tables/households");
20
20
  const addresses_1 = require("./tables/addresses");
21
21
  const contact_attributes_1 = require("./tables/contact-attributes");
22
+ const strings_1 = require("./utils/strings");
22
23
  const createTokenGetter = (auth) => {
23
24
  let token;
24
25
  return async () => {
@@ -46,7 +47,7 @@ const createTokenGetter = (auth) => {
46
47
  }
47
48
  };
48
49
  };
49
- const stringifyMPOptions = (mpOptions = {}) => Object.entries(mpOptions).reduce((acc, [key, value]) => {
50
+ const stringifyMPOptions = (mpOptions = {}) => (0, strings_1.escapeSql)(Object.entries(mpOptions).reduce((acc, [key, value]) => {
50
51
  if (!acc) {
51
52
  acc += `?$${key}=${value}`;
52
53
  }
@@ -54,7 +55,7 @@ const stringifyMPOptions = (mpOptions = {}) => Object.entries(mpOptions).reduce(
54
55
  acc += `&$${key}=${value}`;
55
56
  }
56
57
  return acc;
57
- }, '').escapeSql();
58
+ }, ''));
58
59
  const createMPInstance = ({ auth }) => {
59
60
  /**
60
61
  * Gets MP oauth token.
@@ -1,2 +1,2 @@
1
- export {};
1
+ export declare function escapeSql(str: string): string;
2
2
  //# sourceMappingURL=strings.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"strings.d.ts","sourceRoot":"","sources":["../../src/utils/strings.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"strings.d.ts","sourceRoot":"","sources":["../../src/utils/strings.ts"],"names":[],"mappings":"AAAA,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,UA2BpC"}
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- String.prototype.escapeSql = function () {
4
- return this.replace(/%|(?<=\w)'(?=\w)/g, function (char) {
3
+ exports.escapeSql = escapeSql;
4
+ function escapeSql(str) {
5
+ return str.replace(/%|(?<=\w)'(?=\w)/g, function (char) {
5
6
  switch (char) {
6
7
  case "\0":
7
8
  return "\\0";
@@ -27,4 +28,4 @@ String.prototype.escapeSql = function () {
27
28
  return char;
28
29
  }
29
30
  });
30
- };
31
+ }
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "mp-js-api",
3
- "version": "0.0.1",
4
- "description": "",
3
+ "version": "0.0.3",
4
+ "description": "Node MinistryPlatform API",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
7
7
  "test": "mocha --require ts-node/register test/*",
8
- "postinstall": "tsc"
8
+ "compile": "tsc"
9
9
  },
10
10
  "keywords": [],
11
11
  "author": "",
@@ -19,7 +19,7 @@
19
19
  "@types/uuid": "^9.0.7",
20
20
  "dotenv": "^16.3.1",
21
21
  "mocha": "^10.2.0",
22
- "ts-node": "^9.1.1",
22
+ "ts-node": "^10.9.2",
23
23
  "typescript": "^5.3.3",
24
24
  "uuid": "^9.0.1"
25
25
  }
package/src/index.ts CHANGED
@@ -21,551 +21,552 @@ import { mapGroupParticipantRecord } from './tables/group-participants';
21
21
  import { Household, HouseholdRecord, mapHouseholdRecord, mapHouseholdToHouseholdRecord, } from './tables/households';
22
22
  import { Address, AddressRecord, mapAddressRecord, mapAddressToAddressRecord } from './tables/addresses';
23
23
  import { ContactAttribute, ContactAttributeRecord, mapContactAttributeRecord, mapContactAttributeToContactAttributeRecord } from './tables/contact-attributes';
24
+ import { escapeSql } from './utils/strings';
24
25
 
25
26
  interface TokenData {
26
- access_token: string;
27
- expires_in: number;
28
- token_type: 'Bearer';
27
+ access_token: string;
28
+ expires_in: number;
29
+ token_type: 'Bearer';
29
30
  }
30
31
 
31
32
  interface AccessToken {
32
- digest: string;
33
- expiration: number;
33
+ digest: string;
34
+ expiration: number;
34
35
  }
35
36
 
36
37
  const createTokenGetter = (auth: { username: string; password: string; }) => {
37
- let token: AccessToken | undefined;
38
+ let token: AccessToken | undefined;
38
39
 
39
- return async () => {
40
- // If the token is near expiration, get a new one.
41
- if (!token || token.expiration - 60000 < Date.now()) {
42
- const tokenRes = await axios.post<TokenData>(
43
- 'https://mp.revival.com/ministryplatformapi/oauth/connect/token',
44
- new URLSearchParams({
45
- grant_type: 'client_credentials',
46
- scope: 'http://www.thinkministry.com/dataplatform/scopes/all',
47
- }).toString(),
48
- { auth }
49
- );
50
- const [, payload] = tokenRes.data.access_token.split('.');
51
- try {
52
- const jsonPayload: { exp: number; } = JSON.parse(
53
- Buffer.from(payload, 'base64url').toString()
54
- );
55
- token = {
56
- digest: tokenRes.data.access_token,
57
- expiration: jsonPayload.exp * 1000,
58
- };
59
- return token.digest;
60
- } catch (err) {
61
- console.error(err);
62
- }
63
- } else {
64
- return token.digest;
65
- }
66
- };
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
+ };
67
68
  };
68
69
 
69
70
  type WithRequired<T, K extends keyof T> = T & Required<Pick<T, K>>;
70
71
 
71
72
  export type CreateContactParams = WithRequired<
72
- Partial<Contact>,
73
- 'company' | 'displayName'
73
+ Partial<Contact>,
74
+ 'company' | 'displayName'
74
75
  >;
75
76
  export type CreateHouseholdParams = WithRequired<
76
- Partial<Household>,
77
- 'householdName'
77
+ Partial<Household>,
78
+ 'householdName'
78
79
  >;
79
80
  export type CreateAddressParams = WithRequired<
80
- Partial<Address>,
81
- 'addressLine1'
81
+ Partial<Address>,
82
+ 'addressLine1'
82
83
  >;
83
84
  export type CreateParticipantParams = WithRequired<
84
- Partial<Participant>,
85
- 'contactID' | 'participantTypeID' | 'participantStartDate'
85
+ Partial<Participant>,
86
+ 'contactID' | 'participantTypeID' | 'participantStartDate'
86
87
  >;
87
88
  export type CreateEventParticipantParams = WithRequired<
88
- Partial<EventParticipant>,
89
- 'eventID' | 'participantID' | 'participationStatusID'
89
+ Partial<EventParticipant>,
90
+ 'eventID' | 'participantID' | 'participationStatusID'
90
91
  >;
91
92
  export type CreateGroupParticipantParams = WithRequired<
92
- Partial<GroupParticipant>,
93
- 'groupID' | 'participantID' | 'groupRoleID' | 'startDate'
93
+ Partial<GroupParticipant>,
94
+ 'groupID' | 'participantID' | 'groupRoleID' | 'startDate'
94
95
  >;
95
96
  export type CreateContactAttributeParams = WithRequired<
96
- Partial<ContactAttribute>,
97
- 'attributeID' | 'contactID' | 'startDate'
97
+ Partial<ContactAttribute>,
98
+ 'attributeID' | 'contactID' | 'startDate'
98
99
  >;
99
100
 
100
101
  export type MPGetOptions = {
101
- select?: string;
102
- filter?: string;
103
- orderBy?: string;
104
- groupBy?: string;
105
- top?: number;
106
- skip?: number;
107
- distinct?: boolean;
102
+ select?: string;
103
+ filter?: string;
104
+ orderBy?: string;
105
+ groupBy?: string;
106
+ top?: number;
107
+ skip?: number;
108
+ distinct?: boolean;
108
109
  };
109
110
 
110
111
  export type MPCreateOptions = {
111
- user?: number;
112
+ user?: number;
112
113
  };
113
114
 
114
115
  export type MPUpdateOptions = MPCreateOptions;
115
116
  export type MPGetInstance = <T = any, R = AxiosResponse<T, any>>(url: string, mpOptions?: MPGetOptions, config?: AxiosRequestConfig) => Promise<R>;
116
117
  export type MPInstance = {
117
- get: MPGetInstance; // - AxiosInstance['get']
118
- post: AxiosInstance['post'];
119
- put: AxiosInstance['put'];
120
- getContact(
121
- id: number,
122
- options?: MPGetOptions
123
- ): Promise<Contact | undefined | { error: any; }>;
124
- getHousehold(
125
- id: number,
126
- options?: MPGetOptions
127
- ): Promise<Household | undefined | { error: any; }>;
128
- getAddress(
129
- id: number,
130
- options?: MPGetOptions
131
- ): Promise<Address | undefined | { error: any; }>;
132
- getParticipant(
133
- id: number,
134
- options?: MPGetOptions
135
- ): Promise<Participant | undefined | { error: any; }>;
136
- getEvent(
137
- id: number,
138
- options?: MPGetOptions
139
- ): Promise<Event | undefined | { error: any; }>;
140
- getGroup(
141
- id: number,
142
- options?: MPGetOptions
143
- ): Promise<Group | undefined | { error: any; }>;
144
- getEventParticipant(
145
- id: number,
146
- options?: MPGetOptions
147
- ): Promise<EventParticipant | undefined | { error: any; }>;
148
- getGroupParticipant(
149
- id: number,
150
- options?: MPGetOptions
151
- ): Promise<GroupParticipant | undefined | { error: any; }>;
118
+ get: MPGetInstance; // - AxiosInstance['get']
119
+ post: AxiosInstance['post'];
120
+ put: AxiosInstance['put'];
121
+ getContact(
122
+ id: number,
123
+ options?: MPGetOptions
124
+ ): Promise<Contact | undefined | { error: any; }>;
125
+ getHousehold(
126
+ id: number,
127
+ options?: MPGetOptions
128
+ ): Promise<Household | undefined | { error: any; }>;
129
+ getAddress(
130
+ id: number,
131
+ options?: MPGetOptions
132
+ ): Promise<Address | undefined | { error: any; }>;
133
+ getParticipant(
134
+ id: number,
135
+ options?: MPGetOptions
136
+ ): Promise<Participant | undefined | { error: any; }>;
137
+ getEvent(
138
+ id: number,
139
+ options?: MPGetOptions
140
+ ): Promise<Event | undefined | { error: any; }>;
141
+ getGroup(
142
+ id: number,
143
+ options?: MPGetOptions
144
+ ): Promise<Group | undefined | { error: any; }>;
145
+ getEventParticipant(
146
+ id: number,
147
+ options?: MPGetOptions
148
+ ): Promise<EventParticipant | undefined | { error: any; }>;
149
+ getGroupParticipant(
150
+ id: number,
151
+ options?: MPGetOptions
152
+ ): Promise<GroupParticipant | undefined | { error: any; }>;
152
153
 
153
- getContacts(
154
- options?: MPGetOptions
155
- ): Promise<Contact[] | { error: any; }>;
156
- getHouseholds(
157
- options?: MPGetOptions
158
- ): Promise<Household[] | { error: any; }>;
159
- getAddresses(
160
- options?: MPGetOptions
161
- ): Promise<Address[] | { error: any; }>;
162
- getParticipants(
163
- options?: MPGetOptions
164
- ): Promise<Participant[] | { error: any; }>;
165
- getEvents(options?: MPGetOptions): Promise<Event[] | { error: any; }>;
166
- getGroups(options?: MPGetOptions): Promise<Group[] | { error: any; }>;
167
- getEventParticipants(
168
- options?: MPGetOptions
169
- ): Promise<EventParticipant[] | { error: any; }>;
170
- getGroupParticipants(
171
- options?: MPGetOptions
172
- ): Promise<GroupParticipant[] | { error: any; }>;
154
+ getContacts(
155
+ options?: MPGetOptions
156
+ ): Promise<Contact[] | { error: any; }>;
157
+ getHouseholds(
158
+ options?: MPGetOptions
159
+ ): Promise<Household[] | { error: any; }>;
160
+ getAddresses(
161
+ options?: MPGetOptions
162
+ ): Promise<Address[] | { error: any; }>;
163
+ getParticipants(
164
+ options?: MPGetOptions
165
+ ): Promise<Participant[] | { error: any; }>;
166
+ getEvents(options?: MPGetOptions): Promise<Event[] | { error: any; }>;
167
+ getGroups(options?: MPGetOptions): Promise<Group[] | { error: any; }>;
168
+ getEventParticipants(
169
+ options?: MPGetOptions
170
+ ): Promise<EventParticipant[] | { error: any; }>;
171
+ getGroupParticipants(
172
+ options?: MPGetOptions
173
+ ): Promise<GroupParticipant[] | { error: any; }>;
173
174
 
174
- createContact(
175
- params: CreateContactParams,
176
- options?: MPCreateOptions
177
- ): Promise<Contact | { error: any; }>;
178
- createHousehold(
179
- params: CreateHouseholdParams,
180
- options?: MPCreateOptions
181
- ): Promise<Household | { error: any; }>;
182
- createAddress(
183
- params: CreateAddressParams,
184
- options?: MPCreateOptions
185
- ): Promise<Address | { error: any; }>;
186
- createParticipant(
187
- params: CreateParticipantParams,
188
- options?: MPCreateOptions
189
- ): Promise<Participant | { error: any; }>;
190
- createEventParticipant(
191
- params: CreateEventParticipantParams,
192
- options?: MPCreateOptions
193
- ): Promise<EventParticipant | { error: any; }>;
194
- createGroupParticipant(
195
- params: CreateGroupParticipantParams,
196
- options?: MPCreateOptions
197
- ): Promise<GroupParticipant | { error: any; }>;
198
- createContactAttribute(
199
- params: CreateContactAttributeParams,
200
- options?: MPCreateOptions
201
- ): Promise<ContactAttribute | { error: any; }>;
175
+ createContact(
176
+ params: CreateContactParams,
177
+ options?: MPCreateOptions
178
+ ): Promise<Contact | { error: any; }>;
179
+ createHousehold(
180
+ params: CreateHouseholdParams,
181
+ options?: MPCreateOptions
182
+ ): Promise<Household | { error: any; }>;
183
+ createAddress(
184
+ params: CreateAddressParams,
185
+ options?: MPCreateOptions
186
+ ): Promise<Address | { error: any; }>;
187
+ createParticipant(
188
+ params: CreateParticipantParams,
189
+ options?: MPCreateOptions
190
+ ): Promise<Participant | { error: any; }>;
191
+ createEventParticipant(
192
+ params: CreateEventParticipantParams,
193
+ options?: MPCreateOptions
194
+ ): Promise<EventParticipant | { error: any; }>;
195
+ createGroupParticipant(
196
+ params: CreateGroupParticipantParams,
197
+ options?: MPCreateOptions
198
+ ): Promise<GroupParticipant | { error: any; }>;
199
+ createContactAttribute(
200
+ params: CreateContactAttributeParams,
201
+ options?: MPCreateOptions
202
+ ): Promise<ContactAttribute | { error: any; }>;
202
203
 
203
- updateContacts(
204
- contacts: WithRequired<Partial<Contact>, 'contactID'>[],
205
- options?: MPUpdateOptions
206
- ): Promise<Contact[] | { error: any; }>;
204
+ updateContacts(
205
+ contacts: WithRequired<Partial<Contact>, 'contactID'>[],
206
+ options?: MPUpdateOptions
207
+ ): Promise<Contact[] | { error: any; }>;
207
208
 
208
- updateEventParticipants(
209
- participants: WithRequired<Partial<EventParticipant>, 'eventParticipantID'>[],
210
- options?: MPUpdateOptions
211
- ): Promise<EventParticipant[] | { error: any; }>;
209
+ updateEventParticipants(
210
+ participants: WithRequired<Partial<EventParticipant>, 'eventParticipantID'>[],
211
+ options?: MPUpdateOptions
212
+ ): Promise<EventParticipant[] | { error: any; }>;
212
213
  };
213
214
 
214
215
  const stringifyMPOptions = (mpOptions: MPGetOptions | MPCreateOptions | MPUpdateOptions = {}) =>
215
- Object.entries(mpOptions).reduce((acc, [key, value]) => {
216
- if (!acc) {
217
- acc += `?$${key}=${value}`;
218
- } else {
219
- acc += `&$${key}=${value}`;
220
- }
221
- return acc;
222
- }, '').escapeSql();
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
+ }, ''));
223
224
 
224
225
  export const createMPInstance = ({ auth }: { auth: { username: string; password: string; }; }): MPInstance => {
225
- /**
226
- * Gets MP oauth token.
227
- * @returns token
228
- */
229
- const getToken = createTokenGetter(auth);
230
- const api = axios.create({
231
- baseURL: 'https://mp.revival.com/ministryplatformapi',
232
- });
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
+ });
233
234
 
234
- const get = async <T = any, R = AxiosResponse<T, any>>(
235
- url: string,
236
- mpOptions: MPGetOptions,
237
- config?: AxiosRequestConfig
238
- ) =>
239
- api.get<T, R>(url + stringifyMPOptions(mpOptions), {
240
- ...config,
241
- headers: {
242
- ...config?.headers,
243
- Authorization: `Bearer ${await getToken()}`,
244
- },
245
- });
246
- const post = async <T, R = AxiosResponse<T, any>>(
247
- url: string,
248
- data?: any,
249
- config?: AxiosRequestConfig
250
- ) =>
251
- api.post<T, R>(url, data, {
252
- ...config,
253
- headers: {
254
- ...config?.headers,
255
- Authorization: `Bearer ${await getToken()}`,
256
- },
257
- });
258
- const put = async <T, R = AxiosResponse<T, any>>(
259
- url: string,
260
- data?: any,
261
- config?: AxiosRequestConfig
262
- ) =>
263
- api.put<T, R>(url, data, {
264
- ...config,
265
- headers: {
266
- ...config?.headers,
267
- Authorization: `Bearer ${await getToken()}`,
268
- },
269
- });
235
+ const get = async <T = any, R = AxiosResponse<T, any>>(
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
+ });
270
271
 
271
- return {
272
- get,
273
- post,
274
- put,
275
- async getContact(id, options = {}) {
276
- try {
277
- const res = await get<[ContactRecord?]>(
278
- `/tables/contacts/${id}`, options
279
- );
280
- return res.data[0] ? mapContactRecord(res.data[0]) : undefined;
281
- } catch (err) {
282
- return { error: err };
283
- }
284
- },
285
- async getHousehold(id, options = {}) {
286
- try {
287
- const res = await get<[HouseholdRecord?]>(
288
- `/tables/households/${id}`, options
289
- );
290
- return res.data[0]
291
- ? mapHouseholdRecord(res.data[0])
292
- : undefined;
293
- } catch (err) {
294
- return { error: err };
295
- }
296
- },
297
- async getAddress(id, options = {}) {
298
- try {
299
- const res = await get<[AddressRecord?]>(
300
- `/tables/addresses/${id}`, options
301
- );
302
- return res.data[0] ? mapAddressRecord(res.data[0]) : undefined;
303
- } catch (err) {
304
- return { error: err };
305
- }
306
- },
307
- async getParticipant(id, options = {}) {
308
- try {
309
- const res = await get<[ParticipantRecord?]>(
310
- `/tables/participants/${id}`, options
311
- );
312
- return res.data[0]
313
- ? mapParticipantRecord(res.data[0])
314
- : undefined;
315
- } catch (err) {
316
- return { error: err };
317
- }
318
- },
319
- async getEvent(id, options = {}) {
320
- try {
321
- const res = await get<[EventRecord?]>(
322
- `/tables/events/${id}`, options
323
- );
324
- return res.data[0] ? mapEventRecord(res.data[0]) : undefined;
325
- } catch (err) {
326
- return { error: err };
327
- }
328
- },
329
- async getGroup(id, options = {}) {
330
- try {
331
- const res = await get<[GroupRecord?]>(
332
- `/tables/groups/${id}`, options
333
- );
334
- return res.data[0] ? mapGroupRecord(res.data[0]) : undefined;
335
- } catch (err) {
336
- return { error: err };
337
- }
338
- },
339
- async getEventParticipant(id, options = {}) {
340
- try {
341
- const res = await get<[EventParticipantRecord?]>(
342
- `/tables/event_participants/${id}`, options
343
- );
344
- return res.data[0]
345
- ? mapEventParticipantRecord(res.data[0])
346
- : undefined;
347
- } catch (err) {
348
- return { error: err };
349
- }
350
- },
351
- async getGroupParticipant(id, options = {}) {
352
- try {
353
- const res = await get<[GroupParticipantRecord?]>(
354
- `/tables/group_participants/${id}`, options
355
- );
356
- return res.data[0]
357
- ? mapGroupParticipantRecord(res.data[0])
358
- : undefined;
359
- } catch (err) {
360
- return { error: err };
361
- }
362
- },
363
- async getContacts(options = {}) {
364
- try {
365
- const res = await get<ContactRecord[]>(
366
- `/tables/contacts`, options
367
- );
368
- return res.data.map(mapContactRecord);
369
- } catch (err) {
370
- return { error: err };
371
- }
372
- },
373
- async getHouseholds(options = {}) {
374
- try {
375
- const res = await get<HouseholdRecord[]>(
376
- `/tables/households`, options
377
- );
378
- return res.data.map(mapHouseholdRecord);
379
- } catch (err) {
380
- return { error: err };
381
- }
382
- },
383
- async getAddresses(options = {}) {
384
- try {
385
- const res = await get<AddressRecord[]>(
386
- `/tables/addresses`, options
387
- );
388
- return res.data.map(mapAddressRecord);
389
- } catch (err) {
390
- return { error: err };
391
- }
392
- },
393
- async getParticipants(options = {}) {
394
- try {
395
- const res = await get<ParticipantRecord[]>(
396
- `/tables/participants`, options
397
- );
398
- return res.data.map(mapParticipantRecord);
399
- } catch (err) {
400
- return { error: err };
401
- }
402
- },
403
- async getEvents(options = {}) {
404
- try {
405
- const res = await get<EventRecord[]>(`/tables/events`, options);
406
- return res.data.map(mapEventRecord);
407
- } catch (err) {
408
- return { error: err };
409
- }
410
- },
411
- async getGroups(options = {}) {
412
- try {
413
- const res = await get<GroupRecord[]>(`/tables/groups`, options);
414
- return res.data.map(mapGroupRecord);
415
- } catch (err) {
416
- return { error: err };
417
- }
418
- },
419
- async getEventParticipants(options = {}) {
420
- try {
421
- const res = await get<EventParticipantRecord[]>(
422
- `/tables/event_participants`, options
423
- );
424
- return res.data.map(mapEventParticipantRecord);
425
- } catch (err) {
426
- return { error: err };
427
- }
428
- },
429
- async getGroupParticipants(options = {}) {
430
- try {
431
- const res = await get<GroupParticipantRecord[]>(
432
- `/tables/group_participants`, options
433
- );
434
- return res.data.map(mapGroupParticipantRecord);
435
- } catch (err) {
436
- return { error: err };
437
- }
438
- },
439
- async createContact(params, options = {}) {
440
- const query = stringifyMPOptions(options);
441
- try {
442
- const res = await post<[ContactRecord]>(
443
- `/tables/contacts${query}`,
444
- [mapContactToContactRecord(params as Contact)]
445
- );
446
- return mapContactRecord(res.data[0]);
447
- } catch (err) {
448
- return { error: err };
449
- }
450
- },
451
- async createHousehold(params, options = {}) {
452
- const query = stringifyMPOptions(options);
453
- try {
454
- const res = await post<[HouseholdRecord]>(
455
- `/tables/households${query}`,
456
- [mapHouseholdToHouseholdRecord(params as Household)]
457
- );
458
- return mapHouseholdRecord(res.data[0]);
459
- } catch (err) {
460
- return { error: err };
461
- }
462
- },
463
- async createAddress(params, options = {}) {
464
- const query = stringifyMPOptions(options);
465
- try {
466
- const res = await post<[AddressRecord]>(
467
- `/tables/addresses${query}`,
468
- [mapAddressToAddressRecord(params as Address)]
469
- );
470
- return mapAddressRecord(res.data[0]);
471
- } catch (err) {
472
- return { error: err };
473
- }
474
- },
475
- async createParticipant(params, options = {}) {
476
- const query = stringifyMPOptions(options);
477
- try {
478
- const res = await post<[ParticipantRecord]>(
479
- `/tables/participants${query}`,
480
- [mapParticipantToParticipantRecord(params as Participant)]
481
- );
482
- return mapParticipantRecord(res.data[0]);
483
- } catch (err) {
484
- return { error: err };
485
- }
486
- },
487
- async createEventParticipant(params, options = {}) {
488
- const query = stringifyMPOptions(options);
489
- try {
490
- const res = await post<[EventParticipantRecord]>(
491
- `/tables/event_participants${query}`,
492
- [
493
- mapEventParticipantToEventParticipantRecord(
494
- params as EventParticipant
495
- ),
496
- ]
497
- );
498
- return mapEventParticipantRecord(res.data[0]);
499
- } catch (err) {
500
- return { error: err };
501
- }
502
- },
503
- async createGroupParticipant(params, options = {}) {
504
- const query = stringifyMPOptions(options);
505
- try {
506
- const res = await post<[GroupParticipantRecord]>(
507
- `/tables/group_participants${query}`,
508
- [
509
- mapGroupParticipantToGroupParticipantRecord(
510
- params as GroupParticipant
511
- ),
512
- ]
513
- );
514
- return mapGroupParticipantRecord(res.data[0]);
515
- } catch (err) {
516
- return { error: err };
517
- }
518
- },
519
- async createContactAttribute(params, options = {}) {
520
- const query = stringifyMPOptions(options);
521
- try {
522
- const res = await post<[ContactAttributeRecord]>(
523
- `/tables/contact_attributes${query}`,
524
- [
525
- mapContactAttributeToContactAttributeRecord(
526
- params as ContactAttribute
527
- ),
528
- ]
529
- );
530
- return mapContactAttributeRecord(res.data[0]);
531
- } catch (err) {
532
- return { error: err };
533
- }
534
- },
535
- async updateContacts(contacts, options = {}) {
536
- const query = stringifyMPOptions(options);
537
- try {
538
- const res = await put<ContactRecord[]>(
539
- `/tables/contacts${query}`,
540
- contacts.map(mapContactToContactRecord)
541
- );
542
- return res.data.map(mapContactRecord);
543
- } catch (err) {
544
- return { error: err };
545
- }
546
- },
547
- async updateEventParticipants(eventParticipants, options = {}) {
548
- try {
549
- const res = await put<EventParticipantRecord[]>(
550
- `/tables/event_participants`,
551
- eventParticipants.map(mapEventParticipantToEventParticipantRecord)
552
- );
553
- return res.data.map(mapEventParticipantRecord);
554
- } catch (err) {
555
- return { error: err };
556
- }
557
- },
558
- };
272
+ return {
273
+ get,
274
+ post,
275
+ put,
276
+ async getContact(id, options = {}) {
277
+ try {
278
+ const res = await get<[ContactRecord?]>(
279
+ `/tables/contacts/${id}`, options
280
+ );
281
+ return res.data[0] ? mapContactRecord(res.data[0]) : undefined;
282
+ } catch (err) {
283
+ return { error: err };
284
+ }
285
+ },
286
+ async getHousehold(id, options = {}) {
287
+ try {
288
+ const res = await get<[HouseholdRecord?]>(
289
+ `/tables/households/${id}`, options
290
+ );
291
+ return res.data[0]
292
+ ? mapHouseholdRecord(res.data[0])
293
+ : undefined;
294
+ } catch (err) {
295
+ return { error: err };
296
+ }
297
+ },
298
+ async getAddress(id, options = {}) {
299
+ try {
300
+ const res = await get<[AddressRecord?]>(
301
+ `/tables/addresses/${id}`, options
302
+ );
303
+ return res.data[0] ? mapAddressRecord(res.data[0]) : undefined;
304
+ } catch (err) {
305
+ return { error: err };
306
+ }
307
+ },
308
+ async getParticipant(id, options = {}) {
309
+ try {
310
+ const res = await get<[ParticipantRecord?]>(
311
+ `/tables/participants/${id}`, options
312
+ );
313
+ return res.data[0]
314
+ ? mapParticipantRecord(res.data[0])
315
+ : undefined;
316
+ } catch (err) {
317
+ return { error: err };
318
+ }
319
+ },
320
+ async getEvent(id, options = {}) {
321
+ try {
322
+ const res = await get<[EventRecord?]>(
323
+ `/tables/events/${id}`, options
324
+ );
325
+ return res.data[0] ? mapEventRecord(res.data[0]) : undefined;
326
+ } catch (err) {
327
+ return { error: err };
328
+ }
329
+ },
330
+ async getGroup(id, options = {}) {
331
+ try {
332
+ const res = await get<[GroupRecord?]>(
333
+ `/tables/groups/${id}`, options
334
+ );
335
+ return res.data[0] ? mapGroupRecord(res.data[0]) : undefined;
336
+ } catch (err) {
337
+ return { error: err };
338
+ }
339
+ },
340
+ async getEventParticipant(id, options = {}) {
341
+ try {
342
+ const res = await get<[EventParticipantRecord?]>(
343
+ `/tables/event_participants/${id}`, options
344
+ );
345
+ return res.data[0]
346
+ ? mapEventParticipantRecord(res.data[0])
347
+ : undefined;
348
+ } catch (err) {
349
+ return { error: err };
350
+ }
351
+ },
352
+ async getGroupParticipant(id, options = {}) {
353
+ try {
354
+ const res = await get<[GroupParticipantRecord?]>(
355
+ `/tables/group_participants/${id}`, options
356
+ );
357
+ return res.data[0]
358
+ ? mapGroupParticipantRecord(res.data[0])
359
+ : undefined;
360
+ } catch (err) {
361
+ return { error: err };
362
+ }
363
+ },
364
+ async getContacts(options = {}) {
365
+ try {
366
+ const res = await get<ContactRecord[]>(
367
+ `/tables/contacts`, options
368
+ );
369
+ return res.data.map(mapContactRecord);
370
+ } catch (err) {
371
+ return { error: err };
372
+ }
373
+ },
374
+ async getHouseholds(options = {}) {
375
+ try {
376
+ const res = await get<HouseholdRecord[]>(
377
+ `/tables/households`, options
378
+ );
379
+ return res.data.map(mapHouseholdRecord);
380
+ } catch (err) {
381
+ return { error: err };
382
+ }
383
+ },
384
+ async getAddresses(options = {}) {
385
+ try {
386
+ const res = await get<AddressRecord[]>(
387
+ `/tables/addresses`, options
388
+ );
389
+ return res.data.map(mapAddressRecord);
390
+ } catch (err) {
391
+ return { error: err };
392
+ }
393
+ },
394
+ async getParticipants(options = {}) {
395
+ try {
396
+ const res = await get<ParticipantRecord[]>(
397
+ `/tables/participants`, options
398
+ );
399
+ return res.data.map(mapParticipantRecord);
400
+ } catch (err) {
401
+ return { error: err };
402
+ }
403
+ },
404
+ async getEvents(options = {}) {
405
+ try {
406
+ const res = await get<EventRecord[]>(`/tables/events`, options);
407
+ return res.data.map(mapEventRecord);
408
+ } catch (err) {
409
+ return { error: err };
410
+ }
411
+ },
412
+ async getGroups(options = {}) {
413
+ try {
414
+ const res = await get<GroupRecord[]>(`/tables/groups`, options);
415
+ return res.data.map(mapGroupRecord);
416
+ } catch (err) {
417
+ return { error: err };
418
+ }
419
+ },
420
+ async getEventParticipants(options = {}) {
421
+ try {
422
+ const res = await get<EventParticipantRecord[]>(
423
+ `/tables/event_participants`, options
424
+ );
425
+ return res.data.map(mapEventParticipantRecord);
426
+ } catch (err) {
427
+ return { error: err };
428
+ }
429
+ },
430
+ async getGroupParticipants(options = {}) {
431
+ try {
432
+ const res = await get<GroupParticipantRecord[]>(
433
+ `/tables/group_participants`, options
434
+ );
435
+ return res.data.map(mapGroupParticipantRecord);
436
+ } catch (err) {
437
+ return { error: err };
438
+ }
439
+ },
440
+ async createContact(params, options = {}) {
441
+ const query = stringifyMPOptions(options);
442
+ try {
443
+ const res = await post<[ContactRecord]>(
444
+ `/tables/contacts${query}`,
445
+ [mapContactToContactRecord(params as Contact)]
446
+ );
447
+ return mapContactRecord(res.data[0]);
448
+ } catch (err) {
449
+ return { error: err };
450
+ }
451
+ },
452
+ async createHousehold(params, options = {}) {
453
+ const query = stringifyMPOptions(options);
454
+ try {
455
+ const res = await post<[HouseholdRecord]>(
456
+ `/tables/households${query}`,
457
+ [mapHouseholdToHouseholdRecord(params as Household)]
458
+ );
459
+ return mapHouseholdRecord(res.data[0]);
460
+ } catch (err) {
461
+ return { error: err };
462
+ }
463
+ },
464
+ async createAddress(params, options = {}) {
465
+ const query = stringifyMPOptions(options);
466
+ try {
467
+ const res = await post<[AddressRecord]>(
468
+ `/tables/addresses${query}`,
469
+ [mapAddressToAddressRecord(params as Address)]
470
+ );
471
+ return mapAddressRecord(res.data[0]);
472
+ } catch (err) {
473
+ return { error: err };
474
+ }
475
+ },
476
+ async createParticipant(params, options = {}) {
477
+ const query = stringifyMPOptions(options);
478
+ try {
479
+ const res = await post<[ParticipantRecord]>(
480
+ `/tables/participants${query}`,
481
+ [mapParticipantToParticipantRecord(params as Participant)]
482
+ );
483
+ return mapParticipantRecord(res.data[0]);
484
+ } catch (err) {
485
+ return { error: err };
486
+ }
487
+ },
488
+ async createEventParticipant(params, options = {}) {
489
+ const query = stringifyMPOptions(options);
490
+ try {
491
+ const res = await post<[EventParticipantRecord]>(
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
+ }
503
+ },
504
+ async createGroupParticipant(params, options = {}) {
505
+ const query = stringifyMPOptions(options);
506
+ try {
507
+ const res = await post<[GroupParticipantRecord]>(
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
+ }
519
+ },
520
+ async createContactAttribute(params, options = {}) {
521
+ const query = stringifyMPOptions(options);
522
+ try {
523
+ const res = await post<[ContactAttributeRecord]>(
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
+ }
535
+ },
536
+ async updateContacts(contacts, options = {}) {
537
+ const query = stringifyMPOptions(options);
538
+ try {
539
+ const res = await put<ContactRecord[]>(
540
+ `/tables/contacts${query}`,
541
+ contacts.map(mapContactToContactRecord)
542
+ );
543
+ return res.data.map(mapContactRecord);
544
+ } catch (err) {
545
+ return { error: err };
546
+ }
547
+ },
548
+ async updateEventParticipants(eventParticipants, options = {}) {
549
+ try {
550
+ const res = await put<EventParticipantRecord[]>(
551
+ `/tables/event_participants`,
552
+ eventParticipants.map(mapEventParticipantToEventParticipantRecord)
553
+ );
554
+ return res.data.map(mapEventParticipantRecord);
555
+ } catch (err) {
556
+ return { error: err };
557
+ }
558
+ },
559
+ };
559
560
  };
560
561
 
561
562
  export {
562
- Contact,
563
- Participant,
564
- Event,
565
- Group,
566
- EventParticipant,
567
- GroupParticipant,
568
- Household,
569
- Address,
570
- ContactAttribute
563
+ Contact,
564
+ Participant,
565
+ Event,
566
+ Group,
567
+ EventParticipant,
568
+ GroupParticipant,
569
+ Household,
570
+ Address,
571
+ ContactAttribute
571
572
  };
@@ -1,6 +1,5 @@
1
-
2
- String.prototype.escapeSql = function () {
3
- return this.replace(/%|(?<=\w)'(?=\w)/g, function (char) {
1
+ export function escapeSql(str: string) {
2
+ return str.replace(/%|(?<=\w)'(?=\w)/g, function (char: string) {
4
3
  switch (char) {
5
4
  case "\0":
6
5
  return "\\0";
@@ -15,9 +14,9 @@ String.prototype.escapeSql = function () {
15
14
  case "\r":
16
15
  return "\\r";
17
16
  case "%":
18
- return "%25"
17
+ return "%25";
19
18
  case "'":
20
- return "''"
19
+ return "''";
21
20
  case "\"":
22
21
  case "\\":
23
22
  return "\\" + char; // prepends a backslash to backslash, percent,
@@ -1,103 +0,0 @@
1
- import { createMPInstance } from '../src/index';
2
- import * as dotenv from 'dotenv';
3
- import * as assert from 'assert';
4
- import AxiosError from 'axios/lib/core/AxiosError';
5
- import { v4 } from 'uuid';
6
-
7
- dotenv.config();
8
-
9
- const { MP_USERNAME, MP_PASSWORD } = process.env as {
10
- MP_USERNAME: string;
11
- MP_PASSWORD: string;
12
- };
13
-
14
- const mp = createMPInstance({
15
- auth: { username: MP_USERNAME, password: MP_PASSWORD },
16
- });
17
-
18
- describe('MP Instance', function () {
19
- it('should find many contacts by filter', async function () {
20
- const contacts = await mp.getContacts({
21
- filter: 'Last_Name LIKE \'Ferreira\'',
22
- });
23
- if ('error' in contacts) {
24
- const { error } = contacts;
25
- if (
26
- typeof error === 'object' &&
27
- error !== null &&
28
- 'response' in error &&
29
- typeof error.response === 'object' &&
30
- error.response !== null &&
31
- 'data' in error.response
32
- ) {
33
- console.error(error.response.data);
34
- } else {
35
- console.error(error);
36
- }
37
- assert.fail();
38
- } else {
39
- assert(contacts instanceof Array, 'response is an array');
40
- assert(contacts.length > 0, 'array length is greater than 0');
41
- }
42
- });
43
- it('should find one contact by id', async function () {
44
- const contactID = 111129;
45
- const contact = await mp.findOneContact(contactID);
46
- if (!contact) {
47
- assert.fail('no contact found');
48
- } else if ('error' in contact) {
49
- const { error } = contact;
50
- if (error instanceof Error) {
51
- assert.fail(error);
52
- } else {
53
- assert.fail(`Error: ${JSON.stringify(error, null, 2)}`);
54
- }
55
- } else {
56
- assert.equal(contact.firstName, 'Daniel', 'contact first name is Daniel');
57
- assert.equal(contact.middleName, 'Barbosa', 'contact middle name is Barbosa');
58
- assert.equal(contact.lastName, 'Ferreira', 'contact last name is Ferreira');
59
- }
60
- });
61
- it('should find many events with options: filter, select, top', async function () {
62
- const events = await mp.getEvents({
63
- filter: `Event_Start_Date <= '2022-12-31' AND Event_Start_Date >= '2022-01-01'`,
64
- select: 'Event_ID,Event_Title,Event_Start_Date',
65
- top: 10
66
- });
67
- if ('error' in events) {
68
- const { error } = events;
69
- if (error?.response?.data) {
70
- assert.fail(`AxiosError: ${JSON.stringify(error.response.data, null, 2)}`);
71
- } else if (error instanceof Error) {
72
- assert.fail(error);
73
- } else {
74
- assert.fail(JSON.stringify(error, null, 2));
75
- }
76
- } else {
77
- assert(events instanceof Array, 'response is an array');
78
- assert.equal(events.length, 10, 'array length is 10');
79
- }
80
- });
81
- it('should create one contact', async function () {
82
- const contact = await mp.createContact({
83
- firstName: 'John',
84
- lastName: 'Doe',
85
- emailAddress: `test${v4().replace(/-/g, '')}@revival.com`,
86
- dateOfBirth: '1999-01-01',
87
- company: false,
88
- displayName: 'Doe, John'
89
- });
90
-
91
- if ('error' in contact) {
92
- const { error } = contact;
93
- console.log(error.config);
94
- if (error?.response?.data) {
95
- assert.fail(`AxiosError: ${JSON.stringify(error.response.data, null, 2)}`);
96
- } else if (error instanceof Error) {
97
- assert.fail(error);
98
- } else {
99
- assert.fail(JSON.stringify(error, null, 2));
100
- }
101
- }
102
- });
103
- });