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,103 @@
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
+ });
package/tsconfig.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ // Change this to match your project
3
+ "include": ["src/**/*"],
4
+ "compilerOptions": {
5
+ "lib": ["ES2022"],
6
+ "module": "node16",
7
+ "target": "ES2022",
8
+ "strictNullChecks": true,
9
+ // Tells TypeScript to read JS files, as
10
+ // normally they are ignored as source files
11
+ "allowJs": true,
12
+ // Generate d.ts files
13
+ "declaration": true,
14
+ // This compiler run should
15
+ // only output d.ts files
16
+ // "emitDeclarationOnly": true,
17
+ // Types should go into this directory.
18
+ // Removing this would place the .d.ts files
19
+ // next to the .js files
20
+ "outDir": "dist",
21
+ // go to js file when using IDE functions like
22
+ // "Go to Definition" in VSCode
23
+ "declarationMap": true
24
+ }
25
+ }