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